source: admin/WebConsole/asistentes/jscripts/asistentes.js @ 8ee5519

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 8ee5519 was 8ddf21a, checked in by ramon <ramongomez@…>, 7 years ago

#834: Corregir errata en r5634 y eliminar código JavaScript? no accesible.

git-svn-id: https://opengnsys.es/svn/branches/version1.1@5635 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100644
File size: 26.0 KB
RevLine 
[eb3e2b8]1// ***********************************************************************************************************
2// Libreria de scripts de Javascript
3// Autor:
4// Fecha Creación: 2011
5// Fecha Última modificación: enero-2011
6// Nombre del fichero: asistentes.js
7// Descripción :
8//              Este fichero implementa las funciones javascript del fichero AsistentesEjecutarScripts.php (Comandos)
[0285a39]9// version 1.1: cliente con varios repositorios - Imagenes de todos los repositorios de la UO.
10// autor: Irina Gomez, Universidad de Sevilla
11// fecha 2015-06-17
[502daab]12// version 1.1: showPartitionForm: Se incluye aviso para particiones GTP.
13// autor: Irina Gomez, ETSII Universidad de Sevilla
14// fecha: 2016-06-21
[ab79b5e]15// version 1.1: codeDeployImage: Compone atributo para el comando restaurar imagen (ticket #757)
16// autor: Irina Gomez, ETSII Universidad de Sevilla
17// fecha: 2016-10-27
[eb3e2b8]18// ***********************************************************************************************************
19
20function codeCloneRemotePartition(form){
[a710997]21var command ;
[62ccd9b]22switch (form.idmetodo.value)
23{
24        case "MULTICAST":
25                protocol="MULTICAST " + form.mcastpuerto.value  + ":" + form.mcastmodo.value + ":" + form.mcastdireccion.value + ":" + form.mcastvelocidad.value + "M:" + form.mcastnclien.value + ":" + form.mcastseg.value + " ";
26                break;
27        case "UNICAST":
28                protocol="UNICAST " +  form.ucastport.value + ":" + form.ucastclient.value + " ";
29                break;
30}
31//form.codigo.value="cloneRemoteFromMaster " + form.ipMaster.value + " 1 " + form.PartOrigen.value + "  " + form.mcastpuerto.value  + ":" + form.mcastmodo.value + ":" + form.mcastdireccion.value + ":" + form.mcastvelocidad.value + "M:" + form.mcastnclien.value + ":" + form.mcastseg.value + " 1 " + form.PartOrigen.value + " " + form.tool.value + " " + form.compresor.value;
[f311787]32command="cloneRemoteFromMaster " + form.ipMaster.value + " " + form.source.value + "  " + protocol  + " " + form.targetpart.value + " " + form.tool.value + " " + form.compresor.value;
33form.codigo.value="\
[a710997]34ogEcho log session \"[0] $MSG_SCRIPTS_TASK_START " + command + "\"\n \
[9a1df17]35ogExecAndLog command " + command + " \n ";
[eb3e2b8]36}
37
[1a2fa9d8]38// disableDirect(form): En Deploy de imagenes si se elige updateCache se impide elegir multicast-direct o unicast-direct
39function disableDirect(form){
40        // MULTICAST-DIRECT
41        form.idmetodo.options[2].disabled=true;
42        // UNICAST-DIRECT
43        form.idmetodo.options[4].disabled=true;
44}
45// enableDirect(form): En Deploy de imagenes si se elige deployCache se permite elegir multicast-direct o unicast-direct
46function enableDirect(form){
47        // MULTICAST-DIRECT
48        form.idmetodo.options[2].disabled=false;
49        // UNICAST-DIRECT
50        form.idmetodo.options[4].disabled=false;
51}
52
53
[eb3e2b8]54function codeDeployImage(form){
55switch (form.idmetodo.value)
56{
57        case "MULTICAST":
58                protocol="MULTICAST " + form.mcastpuerto.value  + ":" + form.mcastmodo.value + ":" + form.mcastdireccion.value + ":" + form.mcastvelocidad.value + "M:" + form.mcastnclien.value + ":" + form.mcastseg.value + " ";
59                break;
[1a2fa9d8]60        case "MULTICAST-DIRECT":
61                protocol="MULTICAST-DIRECT " + form.mcastpuerto.value  + ":" + form.mcastmodo.value + ":" + form.mcastdireccion.value + ":" + form.mcastvelocidad.value + "M:" + form.mcastnclien.value + ":" + form.mcastseg.value + " ";
62                break;
[eb3e2b8]63        case "TORRENT":
[ab79b5e]64                protocol="TORRENT " +  form.modp2p.value + ":" + form.timep2p.value;
[eb3e2b8]65                break;
[3b3043b]66        case "UNICAST":
[ab79b5e]67                protocol="UNICAST";
[3b3043b]68                break;
[1a2fa9d8]69        case "UNICAST-DIRECT":
[ab79b5e]70                protocol="UNICAST-DIRECT";
[1a2fa9d8]71                break;
[eb3e2b8]72}
[26c54b6]73
74// Datos imagen
75var imagen = form.idimagen.value.split("_");
76
[eb3e2b8]77//form.codigo.value="deployImage REPO /";
[3b3043b]78if (form.modo[0].checked)
79{
[b2651a6]80        // UHU - Distinguimos entre disco y particion, el valor de idparticion sera disco;particion. eje. 1;1
81        var diskPart = form.idparticion.value.split(";");
[349f70c]82        var imagen = form.idimagen.value.split("_");
[26c54b6]83        command="deployImage " + imagen[0] + " /" + imagen[1] + " "+diskPart[0]+" " + diskPart[1] + " " + protocol  ;
[f311787]84        form.codigo.value="\
[d1795da]85ogEcho log session \"[0] $MSG_SCRIPTS_TASK_START " + command + "\"\n \ " +
[4fcbcc8]86command + " \n";
[ab79b5e]87
88        // Atributos para comando RestaurarImagen
89        form.atrib_restore.value = "dsk=" + diskPart[0] + "@par="+ diskPart[1] +"@idi=" +imagen[2] +
90                                   "@nci="+imagen[1] + "@ipr="+ imagen[0] +"@ifs=" +imagen[3] +
91                                   "@ptc="+protocol +"@";
[3b3043b]92}
93else
94{
[26c54b6]95        command="updateCache REPO /" + imagen[1] + ".img" + " " + protocol  ;
[f311787]96        form.codigo.value="\
[d1795da]97ogEcho log session \"[0] $MSG_SCRIPTS_TASK_START " + command +"\"\n \ " +
98command + " \n";
[f311787]99        //form.codigo.value="updateCache REPO /" + form.idimagen.value + ".img" + " " + protocol  ;
[3b3043b]100}
101
[eb3e2b8]102}
103
[a91defc]104// Activa el área de texto del código, permitiendo modificarlo.
105function modificarCodigo() {
106        document.getElementById("codigo").disabled = false;
107}
108
[f5d9d43]109function codeParticionado(form){
110        var n_disk = form.n_disk.value;
111        var tipo_part_table = form.tipo_part_table.value;
112        // Comprobamos si la opcion elejida es GPT o MSDOS para llamar a una funcion u otra
113        if(tipo_part_table == "GPT"){
[dd14ed2]114                var freediskGPT = parseInt(document.getElementById("freediskGPT").value);
[2e69949]115                // Comprobamos que el espacio libre en el disco no sea negativo, si lo es, dar aviso
[dd14ed2]116                if(freediskGPT < 0){
117                        alert(TbMsg['NODISKSIZE']);
118                }
119                else if (!validaCache(freediskGPT)) {
120                        alert(TbMsg['NOCACHESIZE']);
[2e69949]121                }
122                else{
123                        codeParticionadoGPT(form);
124                }
[f5d9d43]125        }
126        else{
[dd14ed2]127                var freedisk = parseInt(document.getElementById("freedisk").value);
[2e69949]128                // Comprobamos que el espacio libre en el disco no sea negativo, si lo es, dar aviso
[dd14ed2]129                if(freedisk < 0){
130                        alert(TbMsg['NODISKSIZE']);
131                }
132                else if (!validaCache(freedisk)) {
133                        alert(TbMsg['NOCACHESIZE']);
[2e69949]134                }
135                else{
136                        codeParticionadoMSDOS(form);
137                }
[f5d9d43]138        }
[dd14ed2]139
[f5d9d43]140}
141
142
143function codeParticionadoMSDOS (form) {
[66d40b0]144        var partCode="";
145        var logicalCode="";
[a32f9ad]146        var sizecacheCode="";
[66d40b0]147        var cacheCode;
148        var cacheSize;
149        var extended=false;
[f5d9d43]150        var n_disk = form.n_disk.value;
151        var tipo_part_table = form.tipo_part_table.value;
[b2651a6]152        var maxParts = 4;
[90ac583]153        var swapPart = new Array();
154        var swapCode = "";
[b2651a6]155       
156        // Comprobamos si esta seleccionada la cuarta particion y no es CACHE
157        if(form.check4.checked && form.part4.value != "CACHE")
158                maxParts = 5;
[f5d9d43]159
[b2651a6]160        for (var nPart=1; nPart<maxParts; nPart++) {
[66d40b0]161                var partCheck=eval("form.check"+nPart);
162                if (partCheck.checked) {
163                        var partType=eval("form.part"+nPart);
164                        if (partType.value == "CUSTOM" ) {
165                                var partTypeCustom=eval("form.part"+nPart+"custom");
166                                partCode += " " + partTypeCustom.value;
[90ac583]167                                switch(partTypeCustom.value) {
168                                    case "EXTENDED":
[66d40b0]169                                        extended=true;
[90ac583]170                                        break;
171                                    case "LINUX-SWAP":
172                                        swapPart.push(nPart);
173                                        break;
[66d40b0]174                                }
[90ac583]175       
[66d40b0]176                        } else {
177                                partCode += " " + partType.value;
[90ac583]178                                switch(partType.value) {
179                                    case "EXTENDED":
[66d40b0]180                                        extended=true;
[90ac583]181                                        break;
182                                    case "LINUX-SWAP":
183                                        swapPart.push(nPart);
184                                        break;
[66d40b0]185                                }
186                        }
187                        var partSize=eval("form.size"+nPart);
188                        if (partSize.value == "CUSTOM" ) {
189                                var partSizeCustom=eval("form.size"+nPart+"custom");
190                                partCode += ":" + partSizeCustom.value;
191                        } else {
192                                partCode += ":" + partSize.value;
193                        }
194                } else {
195                        partCode += " EMPTY:0";
196                }
[1ec9b7a]197        }
[b2651a6]198        var cacheCode="";
199
200        // Si se selecciono la particion 4 y es CACHE
201        if(form.part4.value == "CACHE"){
202                if (form.check4.checked) {
203                        if (form.size4.value == "0") {
[a32f9ad]204                                sizecacheCode="\
[d1795da]205ogEcho session \"[20] $MSG_HELP_ogGetCacheSize\"\n \
[a32f9ad]206sizecache=`ogGetCacheSize` \n ";
207                                cacheCode="\
[d1795da]208ogEcho session \"[30] $MSG_HELP_ogUpdatePartitionTable "+n_disk+"\"\n \
[a00cca1]209ogCreatePartitionTable "+n_disk+" "+tipo_part_table +" \n \
[d1795da]210ogDeletePartitionTable "+n_disk+" \n \
[9a1df17]211ogExecAndLog command ogUpdatePartitionTable "+n_disk+" \n \
[d1795da]212ogEcho session \"[50] $MSG_HELP_ogCreateCache\"\n \
[a32f9ad]213initCache "+n_disk+" $sizecache NOMOUNT  &>/dev/null \n ";             
[09da038]214                        } else {
[b2651a6]215                                if (form.size4.value == "CUSTOM") {
216                                        cacheSize = form.size4custom.value;
217                                } else {
218                                        cacheSize = form.size4.value;
219                                }
220                                cacheCode="\
[d1795da]221ogEcho session \"[30] $MSG_HELP_ogUpdatePartitionTable "+n_disk+"\"\n \
[a00cca1]222ogCreatePartitionTable "+n_disk+" "+tipo_part_table +" \n \
[d1795da]223ogDeletePartitionTable "+n_disk+" \n \
[523c8ac]224ogUpdatePartitionTable "+n_disk+" \n \
[d1795da]225ogEcho session \"[50] $MSG_HELP_ogCreateCache\"\n \
[a32f9ad]226initCache " + n_disk + " " + cacheSize + " NOMOUNT &>/dev/null";       
[b2651a6]227                        }
228                } else {
229                        cacheCode="\
[d1795da]230ogEcho session \"[30] $MSG_HELP_ogUpdatePartitionTable "+n_disk+"\"\n \
[a00cca1]231ogCreatePartitionTable "+n_disk+" "+tipo_part_table +" \n \
[523c8ac]232ogDeletePartitionTable "+n_disk+" \n \
233ogUpdatePartitionTable "+n_disk+" \n";
234partCode += " EMPTY:0";
[b2651a6]235                }
[09da038]236        }
[b2651a6]237
[66d40b0]238        if (extended) {
239                var lastLogical=5;
240                for (var nPart=9; nPart>5; nPart--) {
241                        if (eval ("form.check"+nPart+".checked")) {
242                                lastLogical = nPart;
243                                break;
244                        }
245                }
246                for (var nPart=5; nPart<=lastLogical; nPart++) {
247                        var partCheck=eval("form.check"+nPart);
248                        if (partCheck.checked) {
249                                var partType=eval("form.part"+nPart);
250                                if (partType.value == "CUSTOM" ) {
251                                        var partTypeCustom=eval("form.part"+nPart+"custom");
252                                        logicalCode += " " + partTypeCustom.value;
[90ac583]253                                        // Partición swap
254                                        if (partTypeCustom.value == "LINUX-SWAP")
255                                                swapPart.push(nPart);
[66d40b0]256                                } else {
257                                        logicalCode += " " + partType.value;
[90ac583]258                                        // Partición swap
259                                        if (partType.value == "LINUX-SWAP")
260                                                swapPart.push(nPart);
[66d40b0]261                                }
262                                var partSize=eval("form.size"+nPart);
263                                if (partSize.value == "CUSTOM" ) {
264                                        var partSizeCustom=eval("form.size"+nPart+"custom");
265                                        logicalCode += ":" + partSizeCustom.value;
266                                } else {
267                                        logicalCode += ":" + partSize.value;
268                                }
269                        } else {
270                                logicalCode += " EMPTY:0";
271                        }
272                }
273                partCode += logicalCode;
274        }
[eb3e2b8]275
[90ac583]276        // Formateo de la partición swap
277        if (swapPart.length > 0) {
278            for (var i=0; i < swapPart.length; i++) {
279                swapCode += "ogEcho session log \"$MSG_HELP_ogFormat "+n_disk+" "+swapPart[i]+" LINUX-SWAP \" \n   " ;
280                swapCode += "ogExecAndLog command session log ogFormat "+n_disk+" "+swapPart[i]+" LINUX-SWAP \n   ";
281            }
282
283        }
284
[523c8ac]285        form.codigo.value="\
[a32f9ad]286" + sizecacheCode + " \n \
[d1795da]287ogEcho session \"[10] $MSG_HELP_ogUnmountAll "+n_disk+"\"\n \
[a00cca1]288ogUnmountAll "+n_disk+" 2>/dev/null \n \
[1a2fa9d8]289ogUnmountCache \n \
[66d40b0]290" + cacheCode + " \n \
[d1795da]291ogEcho session \"[60] $MSG_HELP_ogListPartitions "+n_disk+"\"\n \
[9a1df17]292ogExecAndLog command session ogListPartitions "+n_disk+" \n \
[d1795da]293ogEcho session \"[70] $MSG_HELP_ogCreatePartitions  " + partCode + "\"\n \
[552a6ae]294if ogExecAndLog command session ogCreatePartitions "+n_disk+" " + partCode + "; then \n \
295  ogEcho session \"[80] $MSG_HELP_ogSetPartitionActive "+n_disk+" 1\"\n \
296  ogSetPartitionActive "+n_disk+" 1 \n \
297  ogEcho log session \"[100] $MSG_HELP_ogListPartitions  "+n_disk+"\"\n \
298  ogUpdatePartitionTable "+n_disk+" \n \
299  ms-sys /dev/sda | grep unknow && ms-sys /dev/sda \n \
300  ogExecAndLog command session log ogListPartitions "+n_disk+" \n \
[90ac583]301  "+ swapCode +"\
[552a6ae]302else \n \
[a00cca1]303  ogEcho session log \"[100] ERROR: $MSG_HELP_ogCreatePartitions\" \n \
[552a6ae]304  sleep 5 \n \
305fi";
[eb3e2b8]306}
[a71cfe29]307
[523c8ac]308
[f5d9d43]309function codeParticionadoGPT (form) {
310        var partCode="";
311        var logicalCode="";
[a32f9ad]312        var sizecacheCode="";
[b2651a6]313        var cacheCode="";
[f5d9d43]314        var cacheSize;
315        var extended=false;
316        var n_disk = form.n_disk.value;
317        var tipo_part_table = form.tipo_part_table.value;
[90ac583]318        var swapPart = new Array();
319        var swapCode = "";
320
[f5d9d43]321                numParts=document.getElementById("numGPTpartitions").value;
322               
323        for (var nPart=1; nPart <= numParts; nPart++) {
324                var partCheck=eval("form.checkGPT"+nPart);
325                if (partCheck.checked) {
[523c8ac]326                        // Distinguimos entre cache y el resto de particiones
[b2651a6]327                        // Solo tratamos la particion 4 como cache, si se selecciono este tipo
328                        if(nPart == 4 && form.partGPT4.value == "CACHE") {
[523c8ac]329                                if (form.sizeGPT4.value == "0") {
[a32f9ad]330                                        sizecacheCode="\
[d1795da]331ogEcho session \"[20] $MSG_HELP_ogGetCacheSize\"\n \
[a32f9ad]332sizecache=`ogGetCacheSize` \n ";
333                                        cacheCode="\
[d1795da]334ogEcho session \"[30] $MSG_HELP_ogUpdatePartitionTable "+n_disk+"\"\n \
[523c8ac]335ogDeletePartitionTable "+n_disk+"  \n \
[9a1df17]336ogExecAndLog command ogUpdatePartitionTable "+n_disk+" \n \
[d1795da]337ogEcho session \"[50] $MSG_HELP_ogCreateCache\"\n \
[a32f9ad]338initCache "+ n_disk +" $sizecache NOMOUNT &>/dev/null \n ";
[523c8ac]339                                } else {
340                                        if (form.sizeGPT4.value == "CUSTOM") {
341                                                cacheSize = form.sizeGPT4custom.value;
342                                        } else {
343                                                cacheSize = form.sizeGPT4.value;
[f5d9d43]344                                        }
[523c8ac]345                                        cacheCode="\
[d1795da]346ogEcho session \"[30] $MSG_HELP_ogUpdatePartitionTable "+n_disk+"\"\n \
347ogDeletePartitionTable "+n_disk+" \n \
[523c8ac]348ogUpdatePartitionTable "+n_disk+" \n \
[d1795da]349ogEcho session \"[50] $MSG_HELP_ogCreateCache\"\n \
[a32f9ad]350initCache "  + n_disk +" "+ cacheSize + " NOMOUNT &>/dev/null";
[523c8ac]351                                }
352                        } else{
353                                var partType=eval("form.partGPT"+nPart);
354                                if (partType.value == "CUSTOM" ) {
355                                        var partTypeCustom=eval("form.partGPT"+nPart+"custom");
356                                        partCode += " " + partTypeCustom.value;
[90ac583]357                                        // Partición swap
358                                        if (partTypeCustom.value == "LINUX-SWAP")
359                                                swapPart.push(nPart);
[523c8ac]360                                } else {
361                                        partCode += " " + partType.value;
[90ac583]362                                        // Partición swap
363                                        if (partType.value == "LINUX-SWAP")
364                                                swapPart.push(nPart);
[523c8ac]365                                }
366                                var partSize=eval("form.sizeGPT"+nPart);
367                                if (partSize.value == "CUSTOM" ) {
368                                        var partSizeCustom=eval("form.sizeGPT"+nPart+"custom");
369                                        partCode += ":" + partSizeCustom.value;
370                                } else {
371                                        partCode += ":" + partSize.value;
372                                }
373                        }
374                } else {
375                        if(nPart == 4){
376                                cacheCode="\
[d1795da]377ogEcho session \"[30] $MSG_HELP_ogUpdatePartitionTable "+n_disk+"\"\n \
[523c8ac]378ogDeletePartitionTable "+n_disk+" \n \
379ogUpdatePartitionTable "+n_disk+" \n";
380partCode += " EMPTY:0";
381                        } else{
382                                partCode += " EMPTY:0";
383                        }
[f5d9d43]384                }
385        }
[90ac583]386        // Formateo de la partición swap
387        if (swapPart.length > 0) {
388            for (var i=0; i < swapPart.length; i++) {
389                swapCode += " ogEcho session log \"$MSG_HELP_ogFormat "+n_disk+" "+swapPart[i]+" LINUX-SWAP \" \n" ;
390                swapCode += " ogExecAndLog command session log ogFormat "+n_disk+" "+swapPart[i]+" LINUX-SWAP \n";
391            }
392        }
393           
[523c8ac]394        form.codigo.value="\
[a32f9ad]395" + sizecacheCode + " \n \
[f5d9d43]396ogCreatePartitionTable "+n_disk+" "+tipo_part_table +" \n \
[d1795da]397ogEcho log session \"[0]  $MSG_HELP_ogCreatePartitions "+n_disk+"\"\n \
398ogEcho session \"[10] $MSG_HELP_ogUnmountAll "+n_disk+"\"\n \
[f5d9d43]399ogUnmountAll "+n_disk+" \n  \
[1a2fa9d8]400ogUnmountCache \n \
[f5d9d43]401" + cacheCode + " \n \
[d1795da]402ogEcho session \"[60] $MSG_HELP_ogListPartitions "+n_disk+"\"\n \
[9a1df17]403ogExecAndLog command session ogListPartitions "+n_disk+" \n \
[d1795da]404ogEcho session \"[70] $MSG_HELP_ogCreatePartitions " + partCode + "\"\n \
[9a1df17]405ogExecAndLog command ogCreatePartitions "+n_disk+" " + partCode + " \n \
[d1795da]406ogEcho session \"[80] $MSG_HELP_ogSetPartitionActive "+n_disk+" 1\"\n \
[f5d9d43]407ogSetPartitionActive "+n_disk+" 1 \n \
[d1795da]408ogEcho log session \"[100] $MSG_HELP_ogListPartitions "+n_disk+"\"\n \
[f5d9d43]409ogUpdatePartitionTable "+n_disk+" \n \
410ms-sys /dev/sda | grep unknow && ms-sys /dev/sda \n \
[90ac583]411ogExecAndLog command session log ogListPartitions "+n_disk+" \n"; 
412
413// Formateo de la swap
414form.codigo.value += swapCode;
[f5d9d43]415}
416
417
[523c8ac]418function showPartitionForm (tipo_table_part) {
[f5d9d43]419        document.getElementById("form"+tipo_table_part).style.display="inline";
420        if(tipo_table_part == "MSDOS"){
421                // De los dos tipos, se oculta el otro
422                document.getElementById("formGPT").style.display="none";
[502daab]423                document.getElementById("warngpt").style.display="none";
[523c8ac]424        } else{
[f5d9d43]425                document.getElementById("formMSDOS").style.display="none";
[502daab]426                // Para GPT obliga que primera partición sea EFI
427                document.getElementById("checkGPT1").checked=true;
428                document.getElementById("checkGPT1").disabled=true;
429                document.getElementById("partGPT1").value="CUSTOM";
430                document.getElementById("partGPT1custom").value="EFI";
431                document.getElementById("sizeGPT1").value="CUSTOM";
432                document.getElementById("sizeGPT1").disabled=false;
433                document.getElementById("sizeGPT1custom").value="512000";
434                document.getElementById("sizeGPT1custom").disabled=false;
435                document.getElementById("warngpt").style.display="table-row";
[f5d9d43]436        }
437}
438
[a71cfe29]439
440// Código de pulsación de selección de partición.
[523c8ac]441function clickPartitionCheckbox (form, npart, isGPT) {
[f5d9d43]442        // Si el parametro no esta definido, se toma como false
443        isGPT = (isGPT)?isGPT:"false";
444        if(isGPT == true){
445                prefix="GPT";
[523c8ac]446        } else {
[f5d9d43]447                prefix="";
448        }
449        var partCheck=eval("form.check"+prefix+npart);
450        var partType=eval("form.part"+prefix+npart);
451        var partSize=eval("form.size"+prefix+npart);
452        var partTypeCustom=eval("form.part"+prefix+npart+"custom");
453        var partSizeCustom=eval("form.size"+prefix+npart+"custom");
454        var freeDisk=document.getElementById("freedisk"+prefix);
455        //var logical=document.getElementById("logicas"+prefix);
[a71cfe29]456        if (partCheck.checked) {
457                partType.disabled=false;
458                partSize.disabled=false;
[f5d9d43]459                if(npart != 4){
460                        if (partType.options[partType.selectedIndex].value == "CUSTOM") {
461                                partTypeCustom.disabled=false;
462                        }
[a71cfe29]463                }
464                if (partSize.options[partSize.selectedIndex].value == "CUSTOM") {
465                        partSizeCustom.disabled=false;
466                } else {
467                        partSizeCustom.disabled=true;
468                }
469        } else {
470                partType.disabled=true;
471                partSize.disabled=true;
[b2651a6]472                // El campo TypeCustom no existe para la particion 4
473                if(npart != 4)
474                        partTypeCustom.disabled=true;
[a71cfe29]475                partSizeCustom.disabled=true;
476        }
[66d40b0]477        if (npart <= 4) {
[f5d9d43]478                // Si el formulario es GPT no hay extendidas
479                if(isGPT != true){
480                        checkExtendedPartition(form);
481                }
[66d40b0]482                calculateFreeDisk(form);
483        }
[a71cfe29]484}
485
[92cf666]486/**
487 * Dado un numero de disco, recorre todos los input hidden con nombre disksize_"disco"
488 * y devuelve el de menor valor
489 */
490function getMinDiskSize(disk){
491        var diskSizeArray = document.getElementsByName("disksize_"+disk);
492        var minSize = diskSizeArray[0].value;
493        for(var i= 1; i < diskSizeArray.length; i++){
494                if(diskSizeArray[i].value < minSize)
495                        minSize = diskSizeArray[i].value;
496        }
[fe06132]497        // Restar sectores iniciales del disco al tamaño total (1 MB).
498        return (minSize > 1024 ? minSize - 1024 : minSize)
[92cf666]499}
[a71cfe29]500
[dd14ed2]501// Calcula el tamaño de la mayor cache y lo guarda en un campo oculto
502function getMaxCacheSize() {
503        var cacheSizeArray = document.getElementsByName("cachesize");
504        var maxSize = cacheSizeArray[0].value;
505        for(var i= 1; i < cacheSizeArray.length; i++){
506                if(maxSize < cacheSizeArray[i].value)
507                        maxSize = cacheSizeArray[i].value;
508        }
509        document.getElementById("maxcachesize").value = maxSize;
510}
511
512
513// Comprueba que la cache quepa en el espacio libre del disco
514function validaCache (freedisk) {
515        var form = document.fdatos;
516        var maxcachesize = parseInt(document.getElementById("maxcachesize").value);
[74c410a]517        if(form.part4.value === "CACHE" && form.check4.checked && form.size4.value == 0 ){
518            return ((freedisk - maxcachesize) > 0);
[dd14ed2]519        }
520        return true;
521}
522
[a71cfe29]523// Código para calcular el espacio libre del disco.
[66d40b0]524function calculateFreeDisk(form) {
[f5d9d43]525        // Si esta seleccionada la opcion GPT, se llama a la funcion correspondiente
526        if(document.getElementById("tipo_part_table").value == "GPT"){
527                calculateFreeGPTDisk(form);
528        }
[2e69949]529        // Capturamos el disco seleccionado
530        var disk = document.getElementById("n_disk").value;
[92cf666]531        // Buscamos por nombre todos los campos disksize_"disk" y nos quedamos con el de menor valor
532        var diskSize = getMinDiskSize(disk);
533       
[2e69949]534               
[a71cfe29]535        var freeDisk=document.getElementById("freedisk");
[2e69949]536        freeDisk.value=diskSize;
[12603f8]537        for (var npart=1; npart<=4; npart++) {
[a71cfe29]538                var partCheck=eval("form.check"+npart);
539                var partSize=eval("form.size"+npart);
540                var partSizeCustom=eval("form.size"+npart+"custom");
541                if (partCheck.checked) {
542                        if (partSize.options[partSize.selectedIndex].value == "CUSTOM") {
543                                freeDisk.value -= parseInt(partSizeCustom.value);
544                        } else {
545                                freeDisk.value -= parseInt(partSize.options[partSize.selectedIndex].value);
546                        }
547                }
548        }
549        if (parseInt(freeDisk.value) < 0) {
550                freeDisk.style.fontWeight = "bold";
551                freeDisk.style.fontStyle = "italic";
552        } else {
553                freeDisk.style.fontWeight = "normal";
554                freeDisk.style.fontStyle = "normal";
555        }
556        if (form.size4.value == 0) {
557                freeDisk.value += " (- cache)";         // Aviso de caché sin modificar.
558        }
559}
560
[f5d9d43]561// Código para calcular el espacio libre del disco. en el formulario GPT
562function calculateFreeGPTDisk(form) {
563        // Si esta seleccionada la opcion MSDOS, se llama a la funcion correspondiente
[0975195]564        if(document.getElementById("tipo_part_table").value == "MSDOS"){
565                calculateFreeDisk(form);
566        }
567        // Capturamos el disco seleccionado
[2e69949]568        var disk = document.getElementById("n_disk").value;
569        // Buscamos el input hidden para el disco seleccionado
[0975195]570        document.getElementById('freediskGPT').value=getMinDiskSize(disk);
[2e69949]571       
[f5d9d43]572        var freeDisk=document.getElementById("freediskGPT");
573        // Capturamos el numero de particiones que hay hechas
574        numParts=document.getElementById("numGPTpartitions").value;
[0975195]575        for (npart=1; npart<=numParts; npart++) {
[2e69949]576            var partCheck=eval("form.checkGPT"+npart);
577            var partSize=eval("form.sizeGPT"+npart);
578            var partSizeCustom=eval("form.sizeGPT"+npart+"custom");
579            if (partCheck.checked) {
580                    if (partSize.options[partSize.selectedIndex].value == "CUSTOM") {
[8ddf21a]581                            freeDisk.value -= parseInt(partSizeCustom.value);
[2e69949]582                    } else {
583                            freeDisk.value -= parseInt(partSize.options[partSize.selectedIndex].value);
584                    }
585            }
586    }
587    if (parseInt(freeDisk.value) < 0) {
588            freeDisk.style.fontWeight = "bold";
589            freeDisk.style.fontStyle = "italic";
590    } else {
591            freeDisk.style.fontWeight = "normal";
592            freeDisk.style.fontStyle = "normal";
593    }
594    if (form.size4.value == 0) {
595            freeDisk.value += " (- cache)";         // Aviso de caché sin modificar.
596    }
[f5d9d43]597}
598
599// Agrega una nueva fila a la tabla de particiones con una nueva particion
600function addGPTPartition(){
601        var partitionTypes = "";
[9f31169]602        partitionTypes+='<OPTION value="WINDOWS"> Windows </OPTION>';
603        partitionTypes+='<OPTION value="WIN-RESERV"> Windows Reserved </OPTION>';
604        partitionTypes+='<OPTION value="LINUX"> Linux </OTION>';
605        partitionTypes+='<OPTION value="LINUX-RESERV"> Linux Reserved </OPTION>';
606        partitionTypes+='<OPTION value="LINUX-SWAP"> Linux Swap </OPTION>';
607        partitionTypes+='<OPTION value="LINUX-RAID"> Linux RAID </OPTION>';
608        partitionTypes+='<OPTION value="LINUX-LVM"> Linux LVM </OPTION>';
609        partitionTypes+='<OPTION value="CHROMEOS"> ChromeOS </OTION>';
610        partitionTypes+='<OPTION value="CHROMEOS-KRN"> ChromeOS Kernel </OPTION>';
611        partitionTypes+='<OPTION value="CHROMEOS-RESERV"> ChromeOS Reserved </OPTION>';
612        partitionTypes+='<OPTION value="HFS"> MacOS HFS </OPTION>';
[fea9dfb]613        partitionTypes+='<OPTION value="HFS-BOOT"> MacOS HFS Boot </OPTION>';
[9f31169]614        partitionTypes+='<OPTION value="HFS-RAID"> MacOS HFS RAID </OPTION>';
615        partitionTypes+='<OPTION value="FREEBSD"> FreeBSD </OPTION>';
616        partitionTypes+='<OPTION value="FREEBSD-DISK"> FreeBSD Disk </OPTION>';
617        partitionTypes+='<OPTION value="FREEBSD-BOOT"> FreeBSD Boot </OPTION>';
618        partitionTypes+='<OPTION value="FREEBSD-SWAP"> FreeBSD Swap </OPTION>';
619        partitionTypes+='<OPTION value="SOLARIS"> Solaris </OPTION>';
620        partitionTypes+='<OPTION value="SOLARIS-DISK"> Solaris Disk </OPTION>';
621        partitionTypes+='<OPTION value="SOLARIS-BOOT"> Solaris Boot </OPTION>';
622        partitionTypes+='<OPTION value="SOLARIS-SWAP"> Solaris Swap </OPTION>';
623        partitionTypes+='<OPTION value="EFI"> EFI </OPTION>';
624        partitionTypes+='<OPTION value="MBR"> MBR </OPTION>';
625        partitionTypes+='<OPTION value="BIOS-BOOT"> BIOS Boot </OPTION>';
[f5d9d43]626
627
628        table = document.getElementById("particionesGPT");
629        // Capturamos el numero de particiones, antes incrementamos
[3806a31]630        document.getElementById("numGPTpartitions").value = parseInt(document.getElementById("numGPTpartitions").value)+1;
[f5d9d43]631        numPart=document.getElementById("numGPTpartitions").value;
632        partitionRow = table.insertRow(-1);
633        partitionRow.id = "trPartition"+numPart;
634        partitionRow.innerHTML="<td> \
635<input type='checkbox' name='checkGPT"+numPart+"' value='checkGPT"+numPart+"' onclick='clickPartitionCheckbox(this.form, "+numPart+",true);' /> Partici&oacute;n "+numPart+"</td> \
636<td>\
637<select name='partGPT"+numPart+"' id='partGPT"+numPart+"' style='width:220' disabled='true' onclick=' \
638        if (this.options[this.selectedIndex].value == \'CUSTOM\') { \
639                this.form.partGPT"+numPart+"custom.disabled=false; \
640        } else { \
641                this.form.partGPT"+numPart+"custom.disabled=true; \
642        }'><option value='CUSTOM'> Personalizar </option> \
643</select> \
644<br> \
645<select name='partGPT"+numPart+"custom' id='partGPT"+numPart+"custom' style='width:220' disabled='true' >"+partitionTypes+"</select> \
646</td> \
647<td> \
648<select name='sizeGPT"+numPart+"' id='sizeGPT"+numPart+"' style='width:220' disabled='true' onclick=' \
649        if (this.form.size"+numPart+".options[this.form.size"+numPart+".selectedIndex].value == \'CUSTOM\') { \
650                this.form.sizeGPT"+numPart+"custom.disabled=false; \
651        } else { \
652                this.form.sizeGPT"+numPart+"custom.disabled=true; \
653        } \
654' onchange='calculateFreeGPTDisk(this.form);'>0<option value='CUSTOM'> Personalizar </option> \
655</select> \
656<br /> \
657<input type='text' style='width:100' name='sizeGPT"+numPart+"custom' value='0' disabled='true' onchange='calculateFreeDisk(this.form);' /> \
658</td>"
659
660}
661
662// Agrega una nueva fila a la tabla de particiones con una nueva particion
663function deleteGPTPartition(){
664        table = document.getElementById("particionesGPT");
665        // Capturamos el numero de particiones
666        numPart=document.getElementById("numGPTpartitions").value;
[c7b62bd]667        // Si ya solo quedan 4 particiones, no se elimina ni se decrementa el contador
[f5d9d43]668        if(numPart > 4){
669                partitionRow = document.getElementById("trPartition"+numPart);
670                table.deleteRow(partitionRow.rowIndex);
[c7b62bd]671                // Decrementamos el numero de particiones
672                document.getElementById("numGPTpartitions").value = parseInt(document.getElementById("numGPTpartitions").value)-1;
[f5d9d43]673        }
674}
675
[66d40b0]676// Código para comprobar si hay partición extendida activa para mostrar las lógicas.
677function checkExtendedPartition(form) {
678        var logical=document.getElementById("logicas");
679        var visible=false;
[b2651a6]680        for (npart=1; npart<=4; npart++) {
[66d40b0]681                var partCheck=eval("form.check"+npart);
682                var partType=eval("form.part"+npart);
683                var partTypeCustom=eval("form.part"+npart+"custom");
684                if (partCheck.checked) {
685                        partType.style.fontWeight = "normal";
[b2651a6]686
[66d40b0]687                        if (partType.value == "EXTENDED") {
688                                visible=true;
689                                partType.style.fontWeight = "bold";
690                        }
[b2651a6]691                        // La particion 4 no tiene partTypeCustom
692                        if(npart != 4){
693                                partTypeCustom.style.fontWeight = "normal";
694                                if (partType.value == "CUSTOM" && partTypeCustom.value == "EXTENDED") {
695                                        visible=true;
696                                        partTypeCustom.style.fontWeight = "bold";
697                                }
[66d40b0]698                        }
699                }
700        }
701        if (visible) {
702                logical.style.visibility="visible";
703        } else {
704                logical.style.visibility="hidden";
705        }
706}
707
[dd14ed2]708
Note: See TracBrowser for help on using the repository browser.