source: admin/WebConsole/asistentes/jscripts/asistentes.js @ 7d14d26

Last change on this file since 7d14d26 was aa7c8e4, checked in by Irina Gómez <irinagomez@…>, 6 years ago

#802 For EFI partition: in console in 'RestoreImage?' command can't select it and deploy wizard show a message.

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