source: admin/WebConsole/asistentes/jscripts/asistentes.js @ 5d05b06

Last change on this file since 5d05b06 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
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  ogGetBootMbr "+n_disk+" | grep unknow && ogBootMbrGeneric "+n_disk+" \n \
302  ogExecAndLog command session log ogListPartitions "+n_disk+" \n\
303  "+ swapCode +"\
304  if ogFindCache &>/dev/null; then \n\
305    ogMountCache || ogFormatCache \n\
306    updateBootCache \n \
307  fi \n \
308else \n \
309  ogEcho session log \"[100] ERROR: $MSG_HELP_ogCreatePartitions\" \n \
310  return $EVAL \n \
311fi";
312}
313
314
315function codeParticionadoGPT (form) {
316        var partCode="";
317        var logicalCode="";
318        var sizecacheCode="";
319        var cacheCode="";
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;
324        var swapPart = [];
325        var swapCode = "";
326                var numParts=document.getElementById("numGPTpartitions").value;
327               
328        for (var nPart=1; nPart <= numParts; nPart++) {
329                var partCheck=eval("form.checkGPT"+nPart);
330                if (partCheck.checked) {
331                        // Distinguimos entre cache y el resto de particiones
332                        // Solo tratamos la particion 4 como cache, si se selecciono este tipo
333                        if(nPart === 4 && form.partGPT4.value === "CACHE") {
334                                if (form.sizeGPT4.value === "0") {
335                                        sizecacheCode="\
336ogEcho session \"[20] $MSG_HELP_ogGetCacheSize\" \n \
337sizecache=`ogGetCacheSize` \n ";
338                                        cacheCode="\
339ogEcho session \"[50] $MSG_HELP_ogCreateCache\"\n \
340initCache "+ n_disk +" $sizecache NOMOUNT &>/dev/null \n ";
341                                } else {
342                                        if (form.sizeGPT4.value === "CUSTOM") {
343                                                cacheSize = form.sizeGPT4custom.value;
344                                        } else {
345                                                cacheSize = form.sizeGPT4.value;
346                                        }
347                                        cacheCode="\
348ogEcho session \"[50] $MSG_HELP_ogCreateCache\"\n \
349initCache "  + n_disk +" "+ cacheSize + " NOMOUNT &>/dev/null \n ";
350                                }
351                                cacheCode += "ogEcho session \"[60] $MSG_HELP_ogListPartitions "+n_disk+"\"\n ";
352                                cacheCode += "ogExecAndLog command session ogListPartitions "+n_disk+" \n ";
353                        } else{
354                                var partType=eval("form.partGPT"+nPart);
355                                if (partType.value === "CUSTOM" ) {
356                                        var partTypeCustom=eval("form.partGPT"+nPart+"custom");
357                                        partCode += " " + partTypeCustom.value;
358                                        // Partición swap
359                                        if (partTypeCustom.value === "LINUX-SWAP")
360                                                swapPart.push(nPart);
361                                } else {
362                                        partCode += " " + partType.value;
363                                        // Partición swap
364                                        if (partType.value === "LINUX-SWAP")
365                                                swapPart.push(nPart);
366                                }
367                                var partSize=eval("form.sizeGPT"+nPart);
368                                if (partSize.value === "CUSTOM" ) {
369                                        var partSizeCustom=eval("form.sizeGPT"+nPart+"custom");
370                                        partCode += ":" + partSizeCustom.value;
371                                } else {
372                                        partCode += ":" + partSize.value;
373                                }
374                        }
375                } else {
376                        partCode += " EMPTY:0";
377                }
378        }
379        // Formateo de la partición swap
380        if (swapPart.length > 0) {
381            for (var i=0; i < swapPart.length; i++) {
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";
384            }
385        }
386           
387        form.codigo.value="\
388ogEcho log session \"[0]  $MSG_HELP_ogCreatePartitions "+n_disk+"\"\n \
389ogEcho session \"[10] $MSG_HELP_ogUnmountAll "+n_disk+"\"\n \
390ogUnmountAll "+n_disk+" \n \
391ogUnmountCache \n \
392" + sizecacheCode + "\
393ogEcho session \"[30] $MSG_HELP_ogUpdatePartitionTable "+n_disk+"\"\n \
394ogCreatePartitionTable "+n_disk+" "+tipo_part_table +" \n \
395ogDeletePartitionTable "+n_disk+" \n \
396ogUpdatePartitionTable "+n_disk+" \n \
397" + cacheCode + "\
398ogEcho session \"[70] $MSG_HELP_ogCreatePartitions " + partCode + "\"\n \
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 \
406    ogGetBootMbr "+n_disk+" | grep -e unknow -e zeroed && ogBootMbrGeneric "+n_disk+" \n \
407    ogExecAndLog command session log ogListPartitions "+n_disk+" \n \
408    if ogFindCache &>/dev/null; then \n\
409      ogMountCache || ogFormatCache \n\
410      updateBootCache \n \
411    fi \n \
412else \n \
413    ogEcho session log \"[100] ERROR: $MSG_HELP_ogCreatePartitions\" \n \
414    return $EVAL \n \
415fi \n ";
416
417// Formateo de la swap
418form.codigo.value += swapCode;
419}
420
421
422function showPartitionForm (tipo_table_part) {
423        document.getElementById("form"+tipo_table_part).style.display="inline";
424        if(tipo_table_part === "MSDOS"){
425                // De los dos tipos, se oculta el otro
426                document.getElementById("formGPT").style.display="none";
427                document.getElementById("warngpt").style.display="none";
428        } else{
429                document.getElementById("formMSDOS").style.display="none";
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";
440        }
441}
442
443
444// Código de pulsación de selección de partición.
445function clickPartitionCheckbox (form, npart, isGPT) {
446        // Si el parametro no esta definido, se toma como false
447        isGPT = (isGPT)?isGPT:"false";
448        var prefix="";
449        if(isGPT === true){
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);
459        if (partCheck.checked) {
460                partType.disabled=false;
461                partSize.disabled=false;
462                if(npart !== 4){
463                        if (partType.options[partType.selectedIndex].value === "CUSTOM") {
464                                partTypeCustom.disabled=false;
465                        }
466                }
467                partSizeCustom.disabled = partSize.options[partSize.selectedIndex].value !== "CUSTOM";
468        } else {
469                partType.disabled=true;
470                partSize.disabled=true;
471                // El campo TypeCustom no existe para la particion 4
472                if(npart !== 4)
473                        partTypeCustom.disabled=true;
474                partSizeCustom.disabled=true;
475        }
476        if (npart <= 4) {
477                // Si el formulario es GPT no hay extendidas
478                if(isGPT !== true){
479                        checkExtendedPartition(form);
480                }
481                calculateFreeDisk(form);
482        }
483}
484
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        }
496        // Restar sectores iniciales del disco al tamaño total (1 MB).
497        return (minSize > 1024 ? minSize - 1024 : minSize)
498}
499
500// Calcula el tamaño de la mayor cache y lo guarda en un campo oculto
501function getMaxCacheSize() {
502        var cacheSizeArray = document.getElementsByName("cachesize");
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++){
507                if(maxSize < cacheSizeArray[i].value)
508                        maxSize = cacheSizeArray[i].value;
509            }
510            document.getElementById("maxcachesize").value = maxSize;
511        } else {
512            document.getElementById("maxcachesize").value = 0;
513        }
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);
521        if(form.part4.value === "CACHE" && form.check4.checked && form.size4.value === 0 ){
522            return ((freedisk - maxcachesize) > 0);
523        }
524        return true;
525}
526
527// Código para calcular el espacio libre del disco.
528function calculateFreeDisk(form) {
529        // Si esta seleccionada la opcion GPT, se llama a la funcion correspondiente
530        if(document.getElementById("tipo_part_table").value === "GPT"){
531                calculateFreeGPTDisk(form);
532        }
533        // Capturamos el disco seleccionado
534        var disk = document.getElementById("n_disk").value;
535        // Buscamos por nombre todos los campos disksize_"disk" y nos quedamos con el de menor valor
536        var diskSize = getMinDiskSize(disk);
537       
538               
539        var freeDisk=document.getElementById("freedisk");
540        freeDisk.value=diskSize;
541        for (var npart=1; npart<=4; npart++) {
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) {
546                        if (partSize.options[partSize.selectedIndex].value === "CUSTOM") {
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        }
560        if (form.size4.value === 0) {
561                freeDisk.value += " (- cache)";         // Aviso de caché sin modificar.
562        }
563}
564
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
568        if(document.getElementById("tipo_part_table").value === "MSDOS"){
569                calculateFreeDisk(form);
570        }
571        // Capturamos el disco seleccionado
572        var disk = document.getElementById("n_disk").value;
573        // Buscamos el input hidden para el disco seleccionado
574        document.getElementById('freediskGPT').value=getMinDiskSize(disk);
575       
576        var freeDisk=document.getElementById("freediskGPT");
577        // Capturamos el numero de particiones que hay hechas
578        var numParts=document.getElementById("numGPTpartitions").value;
579        for (var npart=1; npart<=numParts; npart++) {
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) {
584                    if (partSize.options[partSize.selectedIndex].value === "CUSTOM") {
585                            freeDisk.value -= parseInt(partSizeCustom.value);
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    }
598    if (form.size4.value === 0) {
599            freeDisk.value += " (- cache)";         // Aviso de caché sin modificar.
600    }
601}
602
603// Agrega una nueva fila a la tabla de particiones con una nueva particion
604function addGPTPartition(){
605        var partitionTypes = "";
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>';
617        partitionTypes+='<OPTION value="HFS-BOOT"> MacOS HFS Boot </OPTION>';
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>';
630
631
632        var table = document.getElementById("particionesGPT");
633        // Capturamos el numero de particiones, antes incrementamos
634        document.getElementById("numGPTpartitions").value = parseInt(document.getElementById("numGPTpartitions").value)+1;
635        var numPart=document.getElementById("numGPTpartitions").value;
636        var partitionRow = table.insertRow(-1);
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=' \
642        if (this.options[this.selectedIndex].value === \"CUSTOM\") { \
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> \
649<select name='partGPT"+numPart+"custom' id='partGPT"+numPart+"custom' style='width:220px' disabled='true' >"+partitionTypes+"</select> \
650</td> \
651<td> \
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\") { \
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 /> \
661<input type='text' style='width:100px' name='sizeGPT"+numPart+"custom' value='0' disabled='true' onchange='calculateFreeDisk(this.form);' /> \
662</td>"
663
664}
665
666// Agrega una nueva fila a la tabla de particiones con una nueva particion
667function deleteGPTPartition(){
668        var table = document.getElementById("particionesGPT");
669        // Capturamos el numero de particiones
670        var numPart=document.getElementById("numGPTpartitions").value;
671        // Si ya solo quedan 4 particiones, no se elimina ni se decrementa el contador
672        if(numPart > 4){
673                var partitionRow = document.getElementById("trPartition"+numPart);
674                table.deleteRow(partitionRow.rowIndex);
675                // Decrementamos el numero de particiones
676                document.getElementById("numGPTpartitions").value = parseInt(document.getElementById("numGPTpartitions").value)-1;
677        }
678}
679
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;
684        for (var npart=1; npart<=4; npart++) {
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";
690
691                        if (partType.value === "EXTENDED") {
692                                visible=true;
693                                partType.style.fontWeight = "bold";
694                        }
695                        // La particion 4 no tiene partTypeCustom
696                        if(npart !== 4){
697                                partTypeCustom.style.fontWeight = "normal";
698                                if (partType.value === "CUSTOM" && partTypeCustom.value === "EXTENDED") {
699                                        visible=true;
700                                        partTypeCustom.style.fontWeight = "bold";
701                                }
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.