functions.js
5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
$(function () {
$("#arbolCategorias").dynatree({
checkbox: true,
selectMode: 2,
debugLevel: 0,
onDblClick: function (node, event) {
//Marcar una opción al hacerle doble click
node.toggleSelect();
},
onKeydown: function (node, event) {
//Marcar la opción activa usando la barra espaciadora
if (event.which == 32) {
node.toggleSelect();
return false;
}
},
// The following options are only required, if we have more than one tree on one page:
// initId: "treeData",
cookieId: "dynatree-Cb3",
idPrefix: "dynatree-Cb3-"
});
//Expandir los nodos activos
var arbol = $("#arbolCategorias").dynatree("getTree");
var marcados = arbol.getSelectedNodes(false);
for (var i = 0, len = marcados.length; i < len; i++) {
marcados[i].makeVisible();
}
//Buscador
$('input[name="buscador"]').keyup(function () {
var texto = $(this).val();
var arbol = $("#arbolCategorias").dynatree("getTree");
arbol.getRoot().toDict(true, function (dict) {
if (dict.title !== null) {
var nodo = arbol.getNodeByKey(dict.key);
if (texto !== '' && dict.title.toLowerCase().search(texto.toLowerCase()) >= 0) {
//Lo marcamos
nodo.makeVisible();
$(nodo.span).addClass('imax_marcado');
}
else {
//Lo desmarcamos
$(nodo.span).removeClass('imax_marcado');
}
}
});
});
//Botón enviar
$('button[name="opcionesConfiguracion"]').click(function () {
//Así accedo a los ids de los check marcados
var arbolCat = $("#arbolCategorias").dynatree("getTree");
var marcadosCat = arbolCat.getSelectedNodes(false);
var catString = "";
for (var x in marcadosCat) {
catString += marcadosCat[x].data.key + ",";
}
if (catString.length > 0) {
catString = catString.substring(0, catString.length - 1);
}
$('[name="catList"]').val(catString);
$(this).parent().submit();
});
});
//Agregamos los criterios de desactivacion
$('#tablaCriteriosDesactivacion tbody').sortable({
stop: rellenarOrden
});
for(var i in criteriosSeleccionados) {
agregarFilaCriterioDesactivacion(criteriosSeleccionados[i]['caracteristicaSeleccionada'], criteriosSeleccionados[i]['valorCaracteristicaSeleccionado'], criteriosSeleccionados[i]['tipoSeleccionado']);
}
$('button[name="agregarCriterio"]').click(function() {
agregarFilaCriterioDesactivacion();
});
/**
* Pone valor al input de orden.
*/
function rellenarOrden() {
var orden = 0;
$('#tablaCriteriosDesactivacion input[name*="orden"]').each(function() {
$(this).val(orden);
orden++;
});
}
/**
* Agrega una fila de desactivacion en la tabla.
* @param {int} caracteristicaSeleccionada
* @param {int} valorCaracteristicaSeleccionado
* @param {int} tipoSeleccionado
*/
function agregarFilaCriterioDesactivacion(caracteristicaSeleccionada, valorCaracteristicaSeleccionado, tipoSeleccionado) {
var indice = -1;
$('#tablaCriteriosDesactivacion').find('td:first-child').children('select[name^="desactivacion"]').each(function() {
var nombreTemp = $(this).attr('name').split('[');
var indiceTemp = nombreTemp[1].substr(0, nombreTemp[1].length - 1);
if(indiceTemp > indice) {
indice = indiceTemp;
}
});
indice++;
var html = '<tr>';
html += '<td>' + generarSelectDesactivacion('caracteristicaSeleccionada', indice, caracteristicasFormateadas, caracteristicaSeleccionada) + '</td>';
html += '<td>' + generarSelectDesactivacion('valorCaracteristicaSeleccionado', indice, (typeof valoresCaracteristicaFormateados[caracteristicaSeleccionada] !== 'undefined' ? valoresCaracteristicaFormateados[caracteristicaSeleccionada] : { 0: '- Seleccione uno -' }), valorCaracteristicaSeleccionado) + '</td>';
html += '<td>' + generarSelectDesactivacion('tipoSeleccionado', indice, tiposFormateados, tipoSeleccionado) + '</td>';
html += '<td><input type="hidden" name="desactivacion[' + indice + '][orden]" value=""/> <input class="btn btn-default" type="button" name="eliminarFilaCriterioDesactivacion" value="-"/></td>';
html += '</tr>';
var fila = $(html);
//Eliminar fila
fila.find('input[name="eliminarFilaCriterioDesactivacion"]').click(function() {
$(this).parent().parent().remove();
});
//Modificar el select de valores
fila.find('select[name*="caracteristicaSeleccionada"]').change(function() {
var parent = fila.find('select[name*="valorCaracteristicaSeleccionado"]').parent();
var nombreTemp = $(this).attr('name').split('[');
var indiceTemp = nombreTemp[1].substr(0, nombreTemp[1].length - 1);
fila.find('select[name*="valorCaracteristicaSeleccionado"]').remove();
parent.append(generarSelectDesactivacion('valorCaracteristicaSeleccionado', indiceTemp, (typeof valoresCaracteristicaFormateados[$(this).val()] !== 'undefined' ? valoresCaracteristicaFormateados[$(this).val()] : { 0: '- Seleccione uno -' })));
});
$('#tablaCriteriosDesactivacion tbody').append(fila);
rellenarOrden();
}