source: admin/WebConsole/asistentes/jscripts/asistentes.js @ 9e0f6c9

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-instalacion
Last change on this file since 9e0f6c9 was f1bc9d8, checked in by antoniodoblas <adv@…>, 6 years ago

#909 updateCache in assistant.js identifies the REPO with its IP address

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