source: admin/WebConsole/asistentes/jscripts/asistentes.js @ 83167ac

configure-oglivelgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacion
Last change on this file since 83167ac was 9fe0fe3, checked in by Irina Gómez <irinagomez@…>, 5 years ago

#841 Fixes bug in partitioning wizard when configure MBR: ogGetBootMbr function is created for detect MBR content and used in wizard.

  • Property mode set to 100644
File size: 25.9 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 \
[9fe0fe3]301  ogGetBootMbr "+n_disk+" | grep unknow && ogBootMbrGeneric "+n_disk+" \n \
[7082c6f]302  ogExecAndLog command session log ogListPartitions "+n_disk+" \n\
[90ac583]303  "+ swapCode +"\
[e521fb8]304  if ogFindCache &>/dev/null; then \n\
305    ogMountCache || ogFormatCache \n\
306    updateBootCache \n \
307  fi \n \
[552a6ae]308else \n \
[a00cca1]309  ogEcho session log \"[100] ERROR: $MSG_HELP_ogCreatePartitions\" \n \
[62eba32]310  return $EVAL \n \
[552a6ae]311fi";
[eb3e2b8]312}
[a71cfe29]313
[523c8ac]314
[f5d9d43]315function codeParticionadoGPT (form) {
316        var partCode="";
317        var logicalCode="";
[a32f9ad]318        var sizecacheCode="";
[b2651a6]319        var cacheCode="";
[f5d9d43]320        var cacheSize;
321        var extended=false;
322        var n_disk = form.n_disk.value;
323        var tipo_part_table = form.tipo_part_table.value;
[4a7bf32]324        var swapPart = [];
[90ac583]325        var swapCode = "";
[4a7bf32]326                var numParts=document.getElementById("numGPTpartitions").value;
[f5d9d43]327               
328        for (var nPart=1; nPart <= numParts; nPart++) {
329                var partCheck=eval("form.checkGPT"+nPart);
330                if (partCheck.checked) {
[523c8ac]331                        // Distinguimos entre cache y el resto de particiones
[b2651a6]332                        // Solo tratamos la particion 4 como cache, si se selecciono este tipo
[4a7bf32]333                        if(nPart === 4 && form.partGPT4.value === "CACHE") {
334                                if (form.sizeGPT4.value === "0") {
[a32f9ad]335                                        sizecacheCode="\
[62eba32]336ogEcho session \"[20] $MSG_HELP_ogGetCacheSize\" \n \
337sizecache=`ogGetCacheSize` \n ";
[a32f9ad]338                                        cacheCode="\
[d1795da]339ogEcho session \"[50] $MSG_HELP_ogCreateCache\"\n \
[a32f9ad]340initCache "+ n_disk +" $sizecache NOMOUNT &>/dev/null \n ";
[523c8ac]341                                } else {
[4a7bf32]342                                        if (form.sizeGPT4.value === "CUSTOM") {
[523c8ac]343                                                cacheSize = form.sizeGPT4custom.value;
344                                        } else {
345                                                cacheSize = form.sizeGPT4.value;
[f5d9d43]346                                        }
[523c8ac]347                                        cacheCode="\
[d1795da]348ogEcho session \"[50] $MSG_HELP_ogCreateCache\"\n \
[7082c6f]349initCache "  + n_disk +" "+ cacheSize + " NOMOUNT &>/dev/null \n ";
[523c8ac]350                                }
[7082c6f]351                                cacheCode += "ogEcho session \"[60] $MSG_HELP_ogListPartitions "+n_disk+"\"\n ";
352                                cacheCode += "ogExecAndLog command session ogListPartitions "+n_disk+" \n ";
[523c8ac]353                        } else{
354                                var partType=eval("form.partGPT"+nPart);
[4a7bf32]355                                if (partType.value === "CUSTOM" ) {
[523c8ac]356                                        var partTypeCustom=eval("form.partGPT"+nPart+"custom");
357                                        partCode += " " + partTypeCustom.value;
[90ac583]358                                        // Partición swap
[4a7bf32]359                                        if (partTypeCustom.value === "LINUX-SWAP")
360                                                swapPart.push(nPart);
[523c8ac]361                                } else {
362                                        partCode += " " + partType.value;
[90ac583]363                                        // Partición swap
[4a7bf32]364                                        if (partType.value === "LINUX-SWAP")
365                                                swapPart.push(nPart);
[523c8ac]366                                }
367                                var partSize=eval("form.sizeGPT"+nPart);
[4a7bf32]368                                if (partSize.value === "CUSTOM" ) {
[523c8ac]369                                        var partSizeCustom=eval("form.sizeGPT"+nPart+"custom");
370                                        partCode += ":" + partSizeCustom.value;
371                                } else {
372                                        partCode += ":" + partSize.value;
373                                }
374                        }
375                } else {
[7082c6f]376                        partCode += " EMPTY:0";
[f5d9d43]377                }
378        }
[90ac583]379        // Formateo de la partición swap
380        if (swapPart.length > 0) {
381            for (var i=0; i < swapPart.length; i++) {
[7082c6f]382                swapCode += " ogEcho session log \"[95] $MSG_HELP_ogFormat "+n_disk+" "+swapPart[i]+" LINUX-SWAP \" \n" ;
383                swapCode += " ogExecAndLog command ogFormat "+n_disk+" "+swapPart[i]+" LINUX-SWAP \n";
[90ac583]384            }
385        }
386           
[523c8ac]387        form.codigo.value="\
[4a7bf32]388ogEcho log session \"[0]  $MSG_HELP_ogCreatePartitions "+n_disk+"\"\n \
[d1795da]389ogEcho session \"[10] $MSG_HELP_ogUnmountAll "+n_disk+"\"\n \
[7082c6f]390ogUnmountAll "+n_disk+" \n \
[1a2fa9d8]391ogUnmountCache \n \
[62eba32]392" + sizecacheCode + "\
[7082c6f]393ogEcho session \"[30] $MSG_HELP_ogUpdatePartitionTable "+n_disk+"\"\n \
[62eba32]394ogCreatePartitionTable "+n_disk+" "+tipo_part_table +" \n \
[7082c6f]395ogDeletePartitionTable "+n_disk+" \n \
396ogUpdatePartitionTable "+n_disk+" \n \
397" + cacheCode + "\
[d1795da]398ogEcho session \"[70] $MSG_HELP_ogCreatePartitions " + partCode + "\"\n \
[62eba32]399ogExecAndLog command ogCreatePartitions "+n_disk+" " + partCode + "\n \
400EVAL=$? \n \
401if [ $EVAL -eq 0 ]; then \n \
402    ogEcho session \"[80] $MSG_HELP_ogSetPartitionActive "+n_disk+" 1\"\n \
403    ogSetPartitionActive "+n_disk+" 1 \n \
404    ogEcho log session \"[90] $MSG_HELP_ogListPartitions "+n_disk+"\"\n \
405    ogUpdatePartitionTable "+n_disk+" \n \
[9fe0fe3]406    ogGetBootMbr "+n_disk+" | grep -e unknow -e zeroed && ogBootMbrGeneric "+n_disk+" \n \
[62eba32]407    ogExecAndLog command session log ogListPartitions "+n_disk+" \n \
[e521fb8]408    if ogFindCache &>/dev/null; then \n\
409      ogMountCache || ogFormatCache \n\
410      updateBootCache \n \
411    fi \n \
[62eba32]412else \n \
413    ogEcho session log \"[100] ERROR: $MSG_HELP_ogCreatePartitions\" \n \
414    return $EVAL \n \
415fi \n ";
[90ac583]416
417// Formateo de la swap
418form.codigo.value += swapCode;
[f5d9d43]419}
420
421
[523c8ac]422function showPartitionForm (tipo_table_part) {
[f5d9d43]423        document.getElementById("form"+tipo_table_part).style.display="inline";
[4a7bf32]424        if(tipo_table_part === "MSDOS"){
[f5d9d43]425                // De los dos tipos, se oculta el otro
426                document.getElementById("formGPT").style.display="none";
[502daab]427                document.getElementById("warngpt").style.display="none";
[523c8ac]428        } else{
[f5d9d43]429                document.getElementById("formMSDOS").style.display="none";
[502daab]430                // Para GPT obliga que primera partición sea EFI
431                document.getElementById("checkGPT1").checked=true;
432                document.getElementById("checkGPT1").disabled=true;
433                document.getElementById("partGPT1").value="CUSTOM";
434                document.getElementById("partGPT1custom").value="EFI";
435                document.getElementById("sizeGPT1").value="CUSTOM";
436                document.getElementById("sizeGPT1").disabled=false;
437                document.getElementById("sizeGPT1custom").value="512000";
438                document.getElementById("sizeGPT1custom").disabled=false;
439                document.getElementById("warngpt").style.display="table-row";
[f5d9d43]440        }
441}
442
[a71cfe29]443
444// Código de pulsación de selección de partición.
[523c8ac]445function clickPartitionCheckbox (form, npart, isGPT) {
[f5d9d43]446        // Si el parametro no esta definido, se toma como false
447        isGPT = (isGPT)?isGPT:"false";
[4a7bf32]448        var prefix="";
449        if(isGPT === true){
[f5d9d43]450                prefix="GPT";
451        }
452        var partCheck=eval("form.check"+prefix+npart);
453        var partType=eval("form.part"+prefix+npart);
454        var partSize=eval("form.size"+prefix+npart);
455        var partTypeCustom=eval("form.part"+prefix+npart+"custom");
456        var partSizeCustom=eval("form.size"+prefix+npart+"custom");
457        var freeDisk=document.getElementById("freedisk"+prefix);
458        //var logical=document.getElementById("logicas"+prefix);
[a71cfe29]459        if (partCheck.checked) {
460                partType.disabled=false;
461                partSize.disabled=false;
[4a7bf32]462                if(npart !== 4){
463                        if (partType.options[partType.selectedIndex].value === "CUSTOM") {
[f5d9d43]464                                partTypeCustom.disabled=false;
465                        }
[a71cfe29]466                }
[4a7bf32]467                partSizeCustom.disabled = partSize.options[partSize.selectedIndex].value !== "CUSTOM";
[a71cfe29]468        } else {
469                partType.disabled=true;
470                partSize.disabled=true;
[b2651a6]471                // El campo TypeCustom no existe para la particion 4
[4a7bf32]472                if(npart !== 4)
[b2651a6]473                        partTypeCustom.disabled=true;
[a71cfe29]474                partSizeCustom.disabled=true;
475        }
[66d40b0]476        if (npart <= 4) {
[f5d9d43]477                // Si el formulario es GPT no hay extendidas
[4a7bf32]478                if(isGPT !== true){
[f5d9d43]479                        checkExtendedPartition(form);
480                }
[66d40b0]481                calculateFreeDisk(form);
482        }
[a71cfe29]483}
484
[92cf666]485/**
486 * Dado un numero de disco, recorre todos los input hidden con nombre disksize_"disco"
487 * y devuelve el de menor valor
488 */
489function getMinDiskSize(disk){
490        var diskSizeArray = document.getElementsByName("disksize_"+disk);
491        var minSize = diskSizeArray[0].value;
492        for(var i= 1; i < diskSizeArray.length; i++){
493                if(diskSizeArray[i].value < minSize)
494                        minSize = diskSizeArray[i].value;
495        }
[fe06132]496        // Restar sectores iniciales del disco al tamaño total (1 MB).
497        return (minSize > 1024 ? minSize - 1024 : minSize)
[92cf666]498}
[a71cfe29]499
[dd14ed2]500// Calcula el tamaño de la mayor cache y lo guarda en un campo oculto
501function getMaxCacheSize() {
502        var cacheSizeArray = document.getElementsByName("cachesize");
[62eba32]503        // Si no existe cache el valor es cero.
504        if (cacheSizeArray[0]) {
505            var maxSize = cacheSizeArray[0].value;
506            for(var i= 1; i < cacheSizeArray.length; i++){
[dd14ed2]507                if(maxSize < cacheSizeArray[i].value)
508                        maxSize = cacheSizeArray[i].value;
[62eba32]509            }
510            document.getElementById("maxcachesize").value = maxSize;
511        } else {
512            document.getElementById("maxcachesize").value = 0;
513        }
[dd14ed2]514}
515
516
517// Comprueba que la cache quepa en el espacio libre del disco
518function validaCache (freedisk) {
519        var form = document.fdatos;
520        var maxcachesize = parseInt(document.getElementById("maxcachesize").value);
[4a7bf32]521        if(form.part4.value === "CACHE" && form.check4.checked && form.size4.value === 0 ){
[74c410a]522            return ((freedisk - maxcachesize) > 0);
[dd14ed2]523        }
524        return true;
525}
526
[a71cfe29]527// Código para calcular el espacio libre del disco.
[66d40b0]528function calculateFreeDisk(form) {
[f5d9d43]529        // Si esta seleccionada la opcion GPT, se llama a la funcion correspondiente
[4a7bf32]530        if(document.getElementById("tipo_part_table").value === "GPT"){
[f5d9d43]531                calculateFreeGPTDisk(form);
532        }
[2e69949]533        // Capturamos el disco seleccionado
534        var disk = document.getElementById("n_disk").value;
[92cf666]535        // Buscamos por nombre todos los campos disksize_"disk" y nos quedamos con el de menor valor
536        var diskSize = getMinDiskSize(disk);
537       
[2e69949]538               
[a71cfe29]539        var freeDisk=document.getElementById("freedisk");
[2e69949]540        freeDisk.value=diskSize;
[12603f8]541        for (var npart=1; npart<=4; npart++) {
[a71cfe29]542                var partCheck=eval("form.check"+npart);
543                var partSize=eval("form.size"+npart);
544                var partSizeCustom=eval("form.size"+npart+"custom");
545                if (partCheck.checked) {
[4a7bf32]546                        if (partSize.options[partSize.selectedIndex].value === "CUSTOM") {
[a71cfe29]547                                freeDisk.value -= parseInt(partSizeCustom.value);
548                        } else {
549                                freeDisk.value -= parseInt(partSize.options[partSize.selectedIndex].value);
550                        }
551                }
552        }
553        if (parseInt(freeDisk.value) < 0) {
554                freeDisk.style.fontWeight = "bold";
555                freeDisk.style.fontStyle = "italic";
556        } else {
557                freeDisk.style.fontWeight = "normal";
558                freeDisk.style.fontStyle = "normal";
559        }
[4a7bf32]560        if (form.size4.value === 0) {
[a71cfe29]561                freeDisk.value += " (- cache)";         // Aviso de caché sin modificar.
562        }
563}
564
[f5d9d43]565// Código para calcular el espacio libre del disco. en el formulario GPT
566function calculateFreeGPTDisk(form) {
567        // Si esta seleccionada la opcion MSDOS, se llama a la funcion correspondiente
[4a7bf32]568        if(document.getElementById("tipo_part_table").value === "MSDOS"){
[0975195]569                calculateFreeDisk(form);
570        }
571        // Capturamos el disco seleccionado
[2e69949]572        var disk = document.getElementById("n_disk").value;
573        // Buscamos el input hidden para el disco seleccionado
[0975195]574        document.getElementById('freediskGPT').value=getMinDiskSize(disk);
[2e69949]575       
[f5d9d43]576        var freeDisk=document.getElementById("freediskGPT");
577        // Capturamos el numero de particiones que hay hechas
[4a7bf32]578        var numParts=document.getElementById("numGPTpartitions").value;
579        for (var npart=1; npart<=numParts; npart++) {
[2e69949]580            var partCheck=eval("form.checkGPT"+npart);
581            var partSize=eval("form.sizeGPT"+npart);
582            var partSizeCustom=eval("form.sizeGPT"+npart+"custom");
583            if (partCheck.checked) {
[4a7bf32]584                    if (partSize.options[partSize.selectedIndex].value === "CUSTOM") {
[8ddf21a]585                            freeDisk.value -= parseInt(partSizeCustom.value);
[2e69949]586                    } else {
587                            freeDisk.value -= parseInt(partSize.options[partSize.selectedIndex].value);
588                    }
589            }
590    }
591    if (parseInt(freeDisk.value) < 0) {
592            freeDisk.style.fontWeight = "bold";
593            freeDisk.style.fontStyle = "italic";
594    } else {
595            freeDisk.style.fontWeight = "normal";
596            freeDisk.style.fontStyle = "normal";
597    }
[4a7bf32]598    if (form.size4.value === 0) {
[2e69949]599            freeDisk.value += " (- cache)";         // Aviso de caché sin modificar.
600    }
[f5d9d43]601}
602
603// Agrega una nueva fila a la tabla de particiones con una nueva particion
604function addGPTPartition(){
605        var partitionTypes = "";
[9f31169]606        partitionTypes+='<OPTION value="WINDOWS"> Windows </OPTION>';
607        partitionTypes+='<OPTION value="WIN-RESERV"> Windows Reserved </OPTION>';
608        partitionTypes+='<OPTION value="LINUX"> Linux </OTION>';
609        partitionTypes+='<OPTION value="LINUX-RESERV"> Linux Reserved </OPTION>';
610        partitionTypes+='<OPTION value="LINUX-SWAP"> Linux Swap </OPTION>';
611        partitionTypes+='<OPTION value="LINUX-RAID"> Linux RAID </OPTION>';
612        partitionTypes+='<OPTION value="LINUX-LVM"> Linux LVM </OPTION>';
613        partitionTypes+='<OPTION value="CHROMEOS"> ChromeOS </OTION>';
614        partitionTypes+='<OPTION value="CHROMEOS-KRN"> ChromeOS Kernel </OPTION>';
615        partitionTypes+='<OPTION value="CHROMEOS-RESERV"> ChromeOS Reserved </OPTION>';
616        partitionTypes+='<OPTION value="HFS"> MacOS HFS </OPTION>';
[fea9dfb]617        partitionTypes+='<OPTION value="HFS-BOOT"> MacOS HFS Boot </OPTION>';
[9f31169]618        partitionTypes+='<OPTION value="HFS-RAID"> MacOS HFS RAID </OPTION>';
619        partitionTypes+='<OPTION value="FREEBSD"> FreeBSD </OPTION>';
620        partitionTypes+='<OPTION value="FREEBSD-DISK"> FreeBSD Disk </OPTION>';
621        partitionTypes+='<OPTION value="FREEBSD-BOOT"> FreeBSD Boot </OPTION>';
622        partitionTypes+='<OPTION value="FREEBSD-SWAP"> FreeBSD Swap </OPTION>';
623        partitionTypes+='<OPTION value="SOLARIS"> Solaris </OPTION>';
624        partitionTypes+='<OPTION value="SOLARIS-DISK"> Solaris Disk </OPTION>';
625        partitionTypes+='<OPTION value="SOLARIS-BOOT"> Solaris Boot </OPTION>';
626        partitionTypes+='<OPTION value="SOLARIS-SWAP"> Solaris Swap </OPTION>';
627        partitionTypes+='<OPTION value="EFI"> EFI </OPTION>';
628        partitionTypes+='<OPTION value="MBR"> MBR </OPTION>';
629        partitionTypes+='<OPTION value="BIOS-BOOT"> BIOS Boot </OPTION>';
[f5d9d43]630
631
[4a7bf32]632        var table = document.getElementById("particionesGPT");
[f5d9d43]633        // Capturamos el numero de particiones, antes incrementamos
[3806a31]634        document.getElementById("numGPTpartitions").value = parseInt(document.getElementById("numGPTpartitions").value)+1;
[4a7bf32]635        var numPart=document.getElementById("numGPTpartitions").value;
636        var partitionRow = table.insertRow(-1);
[f5d9d43]637        partitionRow.id = "trPartition"+numPart;
638        partitionRow.innerHTML="<td> \
639<input type='checkbox' name='checkGPT"+numPart+"' value='checkGPT"+numPart+"' onclick='clickPartitionCheckbox(this.form, "+numPart+",true);' /> Partici&oacute;n "+numPart+"</td> \
640<td>\
641<select name='partGPT"+numPart+"' id='partGPT"+numPart+"' style='width:220' disabled='true' onclick=' \
[4a7bf32]642        if (this.options[this.selectedIndex].value === \"CUSTOM\") { \
[f5d9d43]643                this.form.partGPT"+numPart+"custom.disabled=false; \
644        } else { \
645                this.form.partGPT"+numPart+"custom.disabled=true; \
646        }'><option value='CUSTOM'> Personalizar </option> \
647</select> \
648<br> \
[4a7bf32]649<select name='partGPT"+numPart+"custom' id='partGPT"+numPart+"custom' style='width:220px' disabled='true' >"+partitionTypes+"</select> \
[f5d9d43]650</td> \
651<td> \
[4a7bf32]652<select name='sizeGPT"+numPart+"' id='sizeGPT"+numPart+"' style='width:220px' disabled='true' onclick=' \
653        if (this.form.size"+numPart+".options[this.form.size"+numPart+".selectedIndex].value === \"CUSTOM\") { \
[f5d9d43]654                this.form.sizeGPT"+numPart+"custom.disabled=false; \
655        } else { \
656                this.form.sizeGPT"+numPart+"custom.disabled=true; \
657        } \
658' onchange='calculateFreeGPTDisk(this.form);'>0<option value='CUSTOM'> Personalizar </option> \
659</select> \
660<br /> \
[4a7bf32]661<input type='text' style='width:100px' name='sizeGPT"+numPart+"custom' value='0' disabled='true' onchange='calculateFreeDisk(this.form);' /> \
[f5d9d43]662</td>"
663
664}
665
666// Agrega una nueva fila a la tabla de particiones con una nueva particion
667function deleteGPTPartition(){
[4a7bf32]668        var table = document.getElementById("particionesGPT");
[f5d9d43]669        // Capturamos el numero de particiones
[4a7bf32]670        var numPart=document.getElementById("numGPTpartitions").value;
[c7b62bd]671        // Si ya solo quedan 4 particiones, no se elimina ni se decrementa el contador
[f5d9d43]672        if(numPart > 4){
[4a7bf32]673                var partitionRow = document.getElementById("trPartition"+numPart);
[f5d9d43]674                table.deleteRow(partitionRow.rowIndex);
[c7b62bd]675                // Decrementamos el numero de particiones
676                document.getElementById("numGPTpartitions").value = parseInt(document.getElementById("numGPTpartitions").value)-1;
[f5d9d43]677        }
678}
679
[66d40b0]680// Código para comprobar si hay partición extendida activa para mostrar las lógicas.
681function checkExtendedPartition(form) {
682        var logical=document.getElementById("logicas");
683        var visible=false;
[4a7bf32]684        for (var npart=1; npart<=4; npart++) {
[66d40b0]685                var partCheck=eval("form.check"+npart);
686                var partType=eval("form.part"+npart);
687                var partTypeCustom=eval("form.part"+npart+"custom");
688                if (partCheck.checked) {
689                        partType.style.fontWeight = "normal";
[b2651a6]690
[4a7bf32]691                        if (partType.value === "EXTENDED") {
[66d40b0]692                                visible=true;
693                                partType.style.fontWeight = "bold";
694                        }
[b2651a6]695                        // La particion 4 no tiene partTypeCustom
[4a7bf32]696                        if(npart !== 4){
697                                partTypeCustom.style.fontWeight = "normal";
698                                if (partType.value === "CUSTOM" && partTypeCustom.value === "EXTENDED") {
[b2651a6]699                                        visible=true;
700                                        partTypeCustom.style.fontWeight = "bold";
701                                }
[66d40b0]702                        }
703                }
704        }
705        if (visible) {
706                logical.style.visibility="visible";
707        } else {
708                logical.style.visibility="hidden";
709        }
710}
Note: See TracBrowser for help on using the repository browser.