1 | /** |
---|
2 | * Función para aumentar la barra de progreso si se responde la encuesta |
---|
3 | **/ |
---|
4 | function control_progress() { |
---|
5 | var content = $('.carousel-inner .active'); |
---|
6 | var not_empty = 0; |
---|
7 | var elements = $('.carousel-indicators li').length-1; |
---|
8 | $.each(content.find('input'),function(index,value){ |
---|
9 | var name = $(value).attr('name'); |
---|
10 | if(name.search('radio')!=-1 || name.search('check')!=-1 || name.search('sino')!=-1){ |
---|
11 | not_empty = $(value).parent().attr('class').search('checked') !== -1 ? 1:not_empty; |
---|
12 | if (name.search('sino')!=-1) { |
---|
13 | if ($(value).parent().attr('class').search('checked') !== -1 && $(value).val()=="No") { |
---|
14 | if ($(value).attr('class').search('need_justification')!=-1) { |
---|
15 | var text_area = $(value).parent().parent().find('textarea'); |
---|
16 | not_empty = $(text_area).val().trim() !== '' ? 1:0; |
---|
17 | not_empty = $(text_area).val().length >= 1 && $(text_area).val().length <= 2000 ? 1:0; |
---|
18 | if ($(text_area).val().length >2000) { |
---|
19 | bootbox.alert("La longitud de la respuesta debe ser menor a 2000 cáracteres"); |
---|
20 | } |
---|
21 | } |
---|
22 | } |
---|
23 | } |
---|
24 | } |
---|
25 | }); |
---|
26 | $.each(content.find('textarea'),function(index,value){ |
---|
27 | var name = $(value).attr('name'); |
---|
28 | if (name.search('abierta')!==-1) { |
---|
29 | not_empty = $(value).val().trim() !== '' ? 1:not_empty; |
---|
30 | not_empty = $(value).val().length >= 1 && $(value).val().length <= 2000 ? 1:0; |
---|
31 | if ($(value).val().length >2000) { |
---|
32 | bootbox.alert("La longitud de la respuesta debe ser menor a 2000 cáracteres"); |
---|
33 | } |
---|
34 | } |
---|
35 | }); |
---|
36 | if (not_empty) { |
---|
37 | $('#status .bar span').css({'color':'white'}); |
---|
38 | $('#myCarousel').carousel('next'); |
---|
39 | var current_value = ($('#status .progress-bar').width()/$('#status').width())*100; |
---|
40 | var final_value = current_value+(100/elements); |
---|
41 | $('#status .progress-bar').width(final_value+"%"); |
---|
42 | |
---|
43 | if (final_value>=99.9) { |
---|
44 | $('#status .progress-bar').width("100%"); |
---|
45 | $('#status .bar span').text("Finalizado"); |
---|
46 | $('#status .progress-bar').addClass('progress-bar-success'); |
---|
47 | } |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * Función para enviar los respuestas de la encuesta |
---|
53 | * @param event Recibe el evento |
---|
54 | **/ |
---|
55 | function send_poll(event) { |
---|
56 | event.preventDefault(); |
---|
57 | $('.btn-success').attr('disabled',true); |
---|
58 | var form = $("#encuesta_form"); |
---|
59 | var routes = $(location).attr('pathname').split('/') |
---|
60 | var pk = routes[routes.length-3] |
---|
61 | var participacion; |
---|
62 | $.get('/validar-participacion-ajax?user='+USER+"&consulta="+ENCUESTA) |
---|
63 | .done(function(response){ |
---|
64 | if (response.mensaje) { |
---|
65 | participacion = response.participacion |
---|
66 | if (participacion) { |
---|
67 | bootbox.alert("Este usuario Ya participó en esta encuenta <br>Será direccionado en 4 segundos"); |
---|
68 | setTimeout(function(){ |
---|
69 | $(location).attr('href', document.referrer) |
---|
70 | },4000); |
---|
71 | } |
---|
72 | else |
---|
73 | { |
---|
74 | $.ajax({ |
---|
75 | type: 'POST', |
---|
76 | data: $(form).serialize(), |
---|
77 | url: URL, |
---|
78 | success: function(response) { |
---|
79 | if (response.code == true) { |
---|
80 | bootbox.alert("Se registró su participación con éxito <br>Será direccionado en 4 segundos"); |
---|
81 | setTimeout(function(){ |
---|
82 | $(location).attr('href', document.referrer) |
---|
83 | },4000); |
---|
84 | } |
---|
85 | else{ |
---|
86 | bootbox.alert("Ocurrió un error inesperado"); |
---|
87 | $('.btn-success').attr('disabled',false); |
---|
88 | } |
---|
89 | }, |
---|
90 | error:function(error) |
---|
91 | { |
---|
92 | bootbox.alert("Ocurrió un error inesperado"); |
---|
93 | $('.btn-success').attr('disabled',false); |
---|
94 | } |
---|
95 | }); |
---|
96 | } |
---|
97 | } |
---|
98 | else{ |
---|
99 | bootbox.alert(response.error); |
---|
100 | } |
---|
101 | }) |
---|
102 | .fail(function(response){ |
---|
103 | bootbox.alert("Ocurrió un error inesperado"); |
---|
104 | }); |
---|
105 | } |
---|
106 | |
---|
107 | /** |
---|
108 | * Función para retroceder en el carrusel y bajar el valor de la |
---|
109 | * barra de progreso |
---|
110 | **/ |
---|
111 | function go_back() { |
---|
112 | var first_element = $('.carousel-indicators li')[0]; |
---|
113 | if($(first_element).attr('class')!=='active') |
---|
114 | { |
---|
115 | $('#myCarousel').carousel('prev'); |
---|
116 | var elements = $('.carousel-indicators li').length-1; |
---|
117 | var current_value = ($('#status .progress-bar').width()/$('#status').width())*100; |
---|
118 | var final_value = current_value-(100/elements); |
---|
119 | $('#status .progress-bar').width(final_value+"%"); |
---|
120 | if (final_value!=100) { |
---|
121 | $('#status .bar span').text() == "Finalizado" ? $('#status .bar span').text('Progreso'):''; |
---|
122 | $('#status .progress-bar').removeClass('progress-bar-success'); |
---|
123 | } |
---|
124 | if (final_value<=0) { |
---|
125 | $('#status .bar span').css({'color':'black'}); |
---|
126 | } |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | * Función para abrir el modal de moficicar las respuestas |
---|
132 | **/ |
---|
133 | |
---|
134 | function abrir_modal(url) |
---|
135 | { |
---|
136 | $('#popup').load(url, function() |
---|
137 | { |
---|
138 | $(this).modal('show'); |
---|
139 | }); |
---|
140 | return false; |
---|
141 | } |
---|
142 | |
---|
143 | /** |
---|
144 | * Función para cerrar el modal de moficicar las respuestas |
---|
145 | **/ |
---|
146 | |
---|
147 | function cerrar_modal() |
---|
148 | { |
---|
149 | $('#popup').modal('hide'); |
---|
150 | return false; |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | * Función que crea la tabla DataTable con las respuestas a las encuestas |
---|
155 | * |
---|
156 | **/ |
---|
157 | $(document).ready(function() { |
---|
158 | var table = $('#tabla-participacion').DataTable({ |
---|
159 | "columnDefs": [ |
---|
160 | { width: '40%', targets: 'social0' }, |
---|
161 | { width: '50%', targets: 'social1' }, |
---|
162 | { width: '20%', targets: 'politica2' }, |
---|
163 | ], |
---|
164 | initComplete: function () { |
---|
165 | this.api().columns([2]).every( function () { |
---|
166 | var column = this; |
---|
167 | var select = $('#select_filter') |
---|
168 | .on( 'change', function () { |
---|
169 | var val = $.fn.dataTable.util.escapeRegex( |
---|
170 | $(this).val() |
---|
171 | ); |
---|
172 | |
---|
173 | column |
---|
174 | .search( val ? '^'+val+'$' : '', true, false ) |
---|
175 | .draw(); |
---|
176 | } ); |
---|
177 | |
---|
178 | column.data().unique().sort().each( function ( d, j ) { |
---|
179 | select.append( '<option value="'+d+'">'+d+'</option>' ) |
---|
180 | } ); |
---|
181 | } ); |
---|
182 | }, |
---|
183 | "language": { |
---|
184 | url: "/static/DataTables/media/js/Spanish.json" |
---|
185 | }, |
---|
186 | "lengthMenu": [ [10, 50, 100, -1], [10, 50, 100, "Todo"] ], |
---|
187 | |
---|
188 | |
---|
189 | "scrollX": true, |
---|
190 | "fixedColumns": true , |
---|
191 | "dom": 'lfrtBSip', |
---|
192 | "buttons": ['copy', 'csv', 'excel', 'pdf', 'print'] |
---|
193 | }); |
---|
194 | }); |
---|
195 | |
---|
196 | |
---|
197 | |
---|
198 | |
---|
199 | |
---|
200 | |
---|