source: admin/WebConsole/asistentes/jscripts/asistentes.js @ 062ea34

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 062ea34 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
Line 
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)
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
12// version 1.1: showPartitionForm: Se incluye aviso para particiones GTP.
13// autor: Irina Gomez, ETSII Universidad de Sevilla
14// fecha: 2016-06-21
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
18// ***********************************************************************************************************
19
20function codeCloneRemotePartition(form){
21var protocol;
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;
32var command="cloneRemoteFromMaster " + form.ipMaster.value + " " + form.source.value + "  " + protocol  + " " + form.targetpart.value + " " + form.tool.value + " " + form.compresor.value;
33form.codigo.value="\
34ogEcho log session \"[0] $MSG_SCRIPTS_TASK_START " + command + "\"\n \
35ogExecAndLog command " + command + " \n ";
36}
37
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
54function codeDeployImage(form){
55var diskPart;
56var imagen;
57var command;
58
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;
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;
67        case "TORRENT":
68                protocol="TORRENT " +  form.modp2p.value + ":" + form.timep2p.value;
69                break;
70        case "UNICAST":
71                protocol="UNICAST";
72                break;
73        case "UNICAST-DIRECT":
74                protocol="UNICAST-DIRECT";
75                break;
76}
77
78// Datos imagen
79imagen = form.idimagen.value.split("_");
80
81//form.codigo.value="deployImage REPO /";
82if (form.modo[0].checked)
83{
84        // UHU - Distinguimos entre disco y particion, el valor de idparticion sera disco;particion. eje. 1;1
85        diskPart = form.idparticion.value.split(";");
86        imagen = form.idimagen.value.split("_");
87        command="deployImage " + imagen[0] + " /" + imagen[1] + " "+diskPart[0]+" " + diskPart[1] + " " + protocol  ;
88        form.codigo.value="\
89ogEcho log session \"[0] $MSG_SCRIPTS_TASK_START " + command + "\"\n \ " +
90command + " \n";
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 +"@";
96        // Si la partición es EFI mostramos un aviso.
97        if (diskPart[2] == "EFI") alert (TbMsg['EFIPART']);
98}
99else
100{
101        command="updateCache " + imagen[0] + " /" + imagen[1] + ".img" + " " + protocol  ;
102        form.codigo.value="\
103ogEcho log session \"[0] $MSG_SCRIPTS_TASK_START " + command +"\"\n \ " +
104command + " \n";
105        //form.codigo.value="updateCache REPO /" + form.idimagen.value + ".img" + " " + protocol  ;
106}
107
108}
109
110// Activa el área de texto del código, permitiendo modificarlo.
111function modificarCodigo() {
112        document.getElementById("codigo").disabled = false;
113}
114
115function codeParticionado(form){
116        var n_disk = form.n_disk.value;
117        var tipo_part_table = form.tipo_part_table.value;
118        var freedisk;
119        var freediskGPT;
120        // Comprobamos si la opcion elejida es GPT o MSDOS para llamar a una funcion u otra
121        if(tipo_part_table === "GPT"){
122                freediskGPT = parseInt(document.getElementById("freediskGPT").value);
123                // Comprobamos que el espacio libre en el disco no sea negativo, si lo es, dar aviso
124                if(freediskGPT < 0){
125                        alert(TbMsg['NODISKSIZE']);
126                }
127                else if (!validaCache(freediskGPT)) {
128                        alert(TbMsg['NOCACHESIZE']);
129                }
130                else{
131                        codeParticionadoGPT(form);
132                }
133        }
134        else{
135                freedisk = parseInt(document.getElementById("freedisk").value);
136                // Comprobamos que el espacio libre en el disco no sea negativo, si lo es, dar aviso
137                if(freedisk < 0){
138                        alert(TbMsg['NODISKSIZE']);
139                }
140                else if (!validaCache(freedisk)) {
141                        alert(TbMsg['NOCACHESIZE']);
142                }
143                else{
144                        codeParticionadoMSDOS(form);
145                }
146        }
147}
148
149
150function codeParticionadoMSDOS (form) {
151        var partCode="";
152        var logicalCode="";
153        var sizecacheCode="";
154        var cacheCode="";
155        var cacheSize;
156        var extended=false;
157        var n_disk = form.n_disk.value;
158        var tipo_part_table = form.tipo_part_table.value;
159        var maxParts = 4;
160        var swapPart = [];
161        var swapCode = "";
162        var partCheck;
163        var partType;
164        var partTypeCustom;
165        var partSize;
166        var partSizeCustom;
167        // Comprobamos si esta seleccionada la cuarta particion y no es CACHE
168        if(form.check4.checked && form.part4.value !== "CACHE")
169                maxParts = 5;
170
171        for (var nPart=1; nPart<maxParts; nPart++) {
172                partCheck=eval("form.check"+nPart);
173                if (partCheck.checked) {
174                        partType=eval("form.part"+nPart);
175                        if (partType.value === "CUSTOM" ) {
176                                partTypeCustom=eval("form.part"+nPart+"custom");
177                                partCode += " " + partTypeCustom.value;
178                                switch(partTypeCustom.value) {
179                                    case "EXTENDED":
180                                        extended=true;
181                                        break;
182                                    case "LINUX-SWAP":
183                                        swapPart.push(nPart);
184                                        break;
185                                }
186       
187                        } else {
188                                partCode += " " + partType.value;
189                                switch(partType.value) {
190                                    case "EXTENDED":
191                                        extended=true;
192                                        break;
193                                    case "LINUX-SWAP":
194                                        swapPart.push(nPart);
195                                        break;
196                                }
197                        }
198                        partSize=eval("form.size"+nPart);
199                        if (partSize.value === "CUSTOM" ) {
200                                partSizeCustom=eval("form.size"+nPart+"custom");
201                                partCode += ":" + partSizeCustom.value;
202                        } else {
203                                partCode += ":" + partSize.value;
204                        }
205                } else {
206                        partCode += " EMPTY:0";
207                }
208        }
209
210        // Si se selecciono la particion 4 y es CACHE
211        if(form.part4.value === "CACHE"){
212                if (form.check4.checked) {
213                        if (form.size4.value === "0") {
214                                sizecacheCode="\
215ogEcho session \"[20] $MSG_HELP_ogGetCacheSize\"\n \
216sizecache=`ogGetCacheSize` \n ";
217                                cacheCode="\
218initCache "+n_disk+" $sizecache NOMOUNT  &>/dev/null \n ";             
219                        } else {
220                                if (form.size4.value === "CUSTOM") {
221                                        cacheSize = form.size4custom.value;
222                                } else {
223                                        cacheSize = form.size4.value;
224                                }
225                                cacheCode="\
226initCache " + n_disk + " " + cacheSize + " NOMOUNT &>/dev/null \n ";
227                        }
228                        cacheCode += "ogEcho session \"[60] $MSG_HELP_ogListPartitions "+n_disk+"\" \n ";
229                        cacheCode += "ogExecAndLog command session ogListPartitions "+n_disk+" \n ";
230                } else {
231                        partCode += " EMPTY:0";
232                }
233        }
234
235        if (extended) {
236                var lastLogical=5;
237                for (nPart=9; nPart>5; nPart--) {
238                        if (eval ("form.check"+nPart+".checked")) {
239                                lastLogical = nPart;
240                                break;
241                        }
242                }
243                for (nPart=5; nPart<=lastLogical; nPart++) {
244                        partCheck=eval("form.check"+nPart);
245                        if (partCheck.checked) {
246                                partType=eval("form.part"+nPart);
247                                if (partType.value === "CUSTOM" ) {
248                                        partTypeCustom=eval("form.part"+nPart+"custom");
249                                        logicalCode += " " + partTypeCustom.value;
250                                        // Partición swap
251                                        if (partTypeCustom.value === "LINUX-SWAP")
252                                                swapPart.push(nPart);
253                                } else {
254                                        logicalCode += " " + partType.value;
255                                        // Partición swap
256                                        if (partType.value === "LINUX-SWAP")
257                                                swapPart.push(nPart);
258                                }
259                                partSize=eval("form.size"+nPart);
260                                if (partSize.value === "CUSTOM" ) {
261                                        partSizeCustom=eval("form.size"+nPart+"custom");
262                                        logicalCode += ":" + partSizeCustom.value;
263                                } else {
264                                        logicalCode += ":" + partSize.value;
265                                }
266                        } else {
267                                logicalCode += " EMPTY:0";
268                        }
269                }
270                partCode += logicalCode;
271        }
272
273        // Formateo de la partición swap
274        if (swapPart.length > 0) {
275            for (var i=0; i < swapPart.length; i++) {
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 ";
278            }
279
280        }
281
282        form.codigo.value="\
283ogEcho log session \"[0]  $MSG_HELP_ogCreatePartitions "+n_disk+"\"\n \
284ogEcho session \"[10] $MSG_HELP_ogUnmountAll "+n_disk+"\"\n \
285ogUnmountAll "+n_disk+" 2>/dev/null \n \
286ogUnmountCache \n \
287" + sizecacheCode + "\
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 + "\
293ogEcho session \"[70] $MSG_HELP_ogCreatePartitions  " + partCode + "\"\n \
294ogExecAndLog command ogCreatePartitions "+n_disk+" " + partCode + " \n \
295EVAL=$? \n \
296if [ $EVAL -eq 0 ]; then \n \
297  ogEcho session \"[80] $MSG_HELP_ogSetPartitionActive "+n_disk+" 1\"\n \
298  ogSetPartitionActive "+n_disk+" 1 \n \
299  ogEcho log session \"[90] $MSG_HELP_ogListPartitions  "+n_disk+"\"\n \
300  ogUpdatePartitionTable "+n_disk+" \n \
301  ms-sys /dev/sda | grep unknow && ms-sys /dev/sda \n \
302  ogExecAndLog command session log ogListPartitions "+n_disk+" \n\
303  "+ swapCode +"\
304else \n \
305  ogEcho session log \"[100] ERROR: $MSG_HELP_ogCreatePartitions\" \n \
306  return $EVAL \n \
307fi";
308}
309
310
311function codeParticionadoGPT (form) {
312        var partCode="";
313        var logicalCode="";
314        var sizecacheCode="";
315        var cacheCode="";
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;
320        var swapPart = [];
321        var swapCode = "";
322                var numParts=document.getElementById("numGPTpartitions").value;
323               
324        for (var nPart=1; nPart <= numParts; nPart++) {
325                var partCheck=eval("form.checkGPT"+nPart);
326                if (partCheck.checked) {
327                        // Distinguimos entre cache y el resto de particiones
328                        // Solo tratamos la particion 4 como cache, si se selecciono este tipo
329                        if(nPart === 4 && form.partGPT4.value === "CACHE") {
330                                if (form.sizeGPT4.value === "0") {
331                                        sizecacheCode="\
332ogEcho session \"[20] $MSG_HELP_ogGetCacheSize\" \n \
333sizecache=`ogGetCacheSize` \n ";
334                                        cacheCode="\
335ogEcho session \"[50] $MSG_HELP_ogCreateCache\"\n \
336initCache "+ n_disk +" $sizecache NOMOUNT &>/dev/null \n ";
337                                } else {
338                                        if (form.sizeGPT4.value === "CUSTOM") {
339                                                cacheSize = form.sizeGPT4custom.value;
340                                        } else {
341                                                cacheSize = form.sizeGPT4.value;
342                                        }
343                                        cacheCode="\
344ogEcho session \"[50] $MSG_HELP_ogCreateCache\"\n \
345initCache "  + n_disk +" "+ cacheSize + " NOMOUNT &>/dev/null \n ";
346                                }
347                                cacheCode += "ogEcho session \"[60] $MSG_HELP_ogListPartitions "+n_disk+"\"\n ";
348                                cacheCode += "ogExecAndLog command session ogListPartitions "+n_disk+" \n ";
349                        } else{
350                                var partType=eval("form.partGPT"+nPart);
351                                if (partType.value === "CUSTOM" ) {
352                                        var partTypeCustom=eval("form.partGPT"+nPart+"custom");
353                                        partCode += " " + partTypeCustom.value;
354                                        // Partición swap
355                                        if (partTypeCustom.value === "LINUX-SWAP")
356                                                swapPart.push(nPart);
357                                } else {
358                                        partCode += " " + partType.value;
359                                        // Partición swap
360                                        if (partType.value === "LINUX-SWAP")
361                                                swapPart.push(nPart);
362                                }
363                                var partSize=eval("form.sizeGPT"+nPart);
364                                if (partSize.value === "CUSTOM" ) {
365                                        var partSizeCustom=eval("form.sizeGPT"+nPart+"custom");
366                                        partCode += ":" + partSizeCustom.value;
367                                } else {
368                                        partCode += ":" + partSize.value;
369                                }
370                        }
371                } else {
372                        partCode += " EMPTY:0";
373                }
374        }
375        // Formateo de la partición swap
376        if (swapPart.length > 0) {
377            for (var i=0; i < swapPart.length; i++) {
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";
380            }
381        }
382           
383        form.codigo.value="\
384ogEcho log session \"[0]  $MSG_HELP_ogCreatePartitions "+n_disk+"\"\n \
385ogEcho session \"[10] $MSG_HELP_ogUnmountAll "+n_disk+"\"\n \
386ogUnmountAll "+n_disk+" \n \
387ogUnmountCache \n \
388" + sizecacheCode + "\
389ogEcho session \"[30] $MSG_HELP_ogUpdatePartitionTable "+n_disk+"\"\n \
390ogCreatePartitionTable "+n_disk+" "+tipo_part_table +" \n \
391ogDeletePartitionTable "+n_disk+" \n \
392ogUpdatePartitionTable "+n_disk+" \n \
393" + cacheCode + "\
394ogEcho session \"[70] $MSG_HELP_ogCreatePartitions " + partCode + "\"\n \
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 ";
408
409// Formateo de la swap
410form.codigo.value += swapCode;
411}
412
413
414function showPartitionForm (tipo_table_part) {
415        document.getElementById("form"+tipo_table_part).style.display="inline";
416        if(tipo_table_part === "MSDOS"){
417                // De los dos tipos, se oculta el otro
418                document.getElementById("formGPT").style.display="none";
419                document.getElementById("warngpt").style.display="none";
420        } else{
421                document.getElementById("formMSDOS").style.display="none";
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";
432        }
433}
434
435
436// Código de pulsación de selección de partición.
437function clickPartitionCheckbox (form, npart, isGPT) {
438        // Si el parametro no esta definido, se toma como false
439        isGPT = (isGPT)?isGPT:"false";
440        var prefix="";
441        if(isGPT === true){
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);
451        if (partCheck.checked) {
452                partType.disabled=false;
453                partSize.disabled=false;
454                if(npart !== 4){
455                        if (partType.options[partType.selectedIndex].value === "CUSTOM") {
456                                partTypeCustom.disabled=false;
457                        }
458                }
459                partSizeCustom.disabled = partSize.options[partSize.selectedIndex].value !== "CUSTOM";
460        } else {
461                partType.disabled=true;
462                partSize.disabled=true;
463                // El campo TypeCustom no existe para la particion 4
464                if(npart !== 4)
465                        partTypeCustom.disabled=true;
466                partSizeCustom.disabled=true;
467        }
468        if (npart <= 4) {
469                // Si el formulario es GPT no hay extendidas
470                if(isGPT !== true){
471                        checkExtendedPartition(form);
472                }
473                calculateFreeDisk(form);
474        }
475}
476
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        }
488        // Restar sectores iniciales del disco al tamaño total (1 MB).
489        return (minSize > 1024 ? minSize - 1024 : minSize)
490}
491
492// Calcula el tamaño de la mayor cache y lo guarda en un campo oculto
493function getMaxCacheSize() {
494        var cacheSizeArray = document.getElementsByName("cachesize");
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++){
499                if(maxSize < cacheSizeArray[i].value)
500                        maxSize = cacheSizeArray[i].value;
501            }
502            document.getElementById("maxcachesize").value = maxSize;
503        } else {
504            document.getElementById("maxcachesize").value = 0;
505        }
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);
513        if(form.part4.value === "CACHE" && form.check4.checked && form.size4.value === 0 ){
514            return ((freedisk - maxcachesize) > 0);
515        }
516        return true;
517}
518
519// Código para calcular el espacio libre del disco.
520function calculateFreeDisk(form) {
521        // Si esta seleccionada la opcion GPT, se llama a la funcion correspondiente
522        if(document.getElementById("tipo_part_table").value === "GPT"){
523                calculateFreeGPTDisk(form);
524        }
525        // Capturamos el disco seleccionado
526        var disk = document.getElementById("n_disk").value;
527        // Buscamos por nombre todos los campos disksize_"disk" y nos quedamos con el de menor valor
528        var diskSize = getMinDiskSize(disk);
529       
530               
531        var freeDisk=document.getElementById("freedisk");
532        freeDisk.value=diskSize;
533        for (var npart=1; npart<=4; npart++) {
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) {
538                        if (partSize.options[partSize.selectedIndex].value === "CUSTOM") {
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        }
552        if (form.size4.value === 0) {
553                freeDisk.value += " (- cache)";         // Aviso de caché sin modificar.
554        }
555}
556
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
560        if(document.getElementById("tipo_part_table").value === "MSDOS"){
561                calculateFreeDisk(form);
562        }
563        // Capturamos el disco seleccionado
564        var disk = document.getElementById("n_disk").value;
565        // Buscamos el input hidden para el disco seleccionado
566        document.getElementById('freediskGPT').value=getMinDiskSize(disk);
567       
568        var freeDisk=document.getElementById("freediskGPT");
569        // Capturamos el numero de particiones que hay hechas
570        var numParts=document.getElementById("numGPTpartitions").value;
571        for (var npart=1; npart<=numParts; npart++) {
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) {
576                    if (partSize.options[partSize.selectedIndex].value === "CUSTOM") {
577                            freeDisk.value -= parseInt(partSizeCustom.value);
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    }
590    if (form.size4.value === 0) {
591            freeDisk.value += " (- cache)";         // Aviso de caché sin modificar.
592    }
593}
594
595// Agrega una nueva fila a la tabla de particiones con una nueva particion
596function addGPTPartition(){
597        var partitionTypes = "";
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>';
609        partitionTypes+='<OPTION value="HFS-BOOT"> MacOS HFS Boot </OPTION>';
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>';
622
623
624        var table = document.getElementById("particionesGPT");
625        // Capturamos el numero de particiones, antes incrementamos
626        document.getElementById("numGPTpartitions").value = parseInt(document.getElementById("numGPTpartitions").value)+1;
627        var numPart=document.getElementById("numGPTpartitions").value;
628        var partitionRow = table.insertRow(-1);
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=' \
634        if (this.options[this.selectedIndex].value === \"CUSTOM\") { \
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> \
641<select name='partGPT"+numPart+"custom' id='partGPT"+numPart+"custom' style='width:220px' disabled='true' >"+partitionTypes+"</select> \
642</td> \
643<td> \
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\") { \
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 /> \
653<input type='text' style='width:100px' name='sizeGPT"+numPart+"custom' value='0' disabled='true' onchange='calculateFreeDisk(this.form);' /> \
654</td>"
655
656}
657
658// Agrega una nueva fila a la tabla de particiones con una nueva particion
659function deleteGPTPartition(){
660        var table = document.getElementById("particionesGPT");
661        // Capturamos el numero de particiones
662        var numPart=document.getElementById("numGPTpartitions").value;
663        // Si ya solo quedan 4 particiones, no se elimina ni se decrementa el contador
664        if(numPart > 4){
665                var partitionRow = document.getElementById("trPartition"+numPart);
666                table.deleteRow(partitionRow.rowIndex);
667                // Decrementamos el numero de particiones
668                document.getElementById("numGPTpartitions").value = parseInt(document.getElementById("numGPTpartitions").value)-1;
669        }
670}
671
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;
676        for (var npart=1; npart<=4; npart++) {
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";
682
683                        if (partType.value === "EXTENDED") {
684                                visible=true;
685                                partType.style.fontWeight = "bold";
686                        }
687                        // La particion 4 no tiene partTypeCustom
688                        if(npart !== 4){
689                                partTypeCustom.style.fontWeight = "normal";
690                                if (partType.value === "CUSTOM" && partTypeCustom.value === "EXTENDED") {
691                                        visible=true;
692                                        partTypeCustom.style.fontWeight = "bold";
693                                }
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.