1 | /* |
---|
2 | * Retorna as regras por remetente e que o usuário deseja ser avisado |
---|
3 | * |
---|
4 | */ |
---|
5 | function getFromAlertRules() { |
---|
6 | var filters = DataLayer.get("filter"); |
---|
7 | fromRules = []; |
---|
8 | var alertMessage; |
---|
9 | for (var index in filters) { |
---|
10 | alertMessage = filters[index]['alertMessage']; |
---|
11 | for(var criterias in filters[index]['actions']) { |
---|
12 | if (filters[index]['actions'][criterias]['type'] == 'fileinto' && alertMessage == 'true') |
---|
13 | fromRules[fromRules.length] = filters[index]['actions'][criterias]['parameter']; |
---|
14 | } |
---|
15 | } |
---|
16 | return fromRules; |
---|
17 | } |
---|
18 | |
---|
19 | function outOfficeVerify() { |
---|
20 | DataLayer.remove('filter', false); |
---|
21 | var filters = DataLayer.get("filter"); |
---|
22 | var outoffice_active = false; |
---|
23 | outoffice = false; |
---|
24 | for(var index in filters){ |
---|
25 | if(filters[index].id == "vacation") |
---|
26 | outoffice = true; |
---|
27 | if(filters[index].id == "vacation" && filters[index].enabled == "true"){ |
---|
28 | write_msg(get_lang("Attention, you are in out of office mode."), true); |
---|
29 | outoffice_active = true; |
---|
30 | break; |
---|
31 | } |
---|
32 | } |
---|
33 | if(!outoffice_active) |
---|
34 | clean_msg(); |
---|
35 | } |
---|
36 | |
---|
37 | valid_save = function(){ |
---|
38 | var accord = list_container.find(".rule-details-container").accordion({autoHeight: false}); |
---|
39 | if(list_container.find('[name="name"]').attr("disabled") != "disabled") |
---|
40 | { |
---|
41 | if($.trim(list_container.find('[name="name"]').val()) == ""){ |
---|
42 | $.Zebra_Dialog(get_lang("No name filled"),{ |
---|
43 | 'onClose': function(caption) { |
---|
44 | list_container.find('[name="name"]').focus(); |
---|
45 | } |
---|
46 | }); |
---|
47 | accord.accordion('activate',0); |
---|
48 | return false; |
---|
49 | }else if($.trim(list_container.find('[name="name"]').val()) == "vacation"){ |
---|
50 | $.Zebra_Dialog(get_lang("Invalid name, 'vacation' is a reserved word"),{ |
---|
51 | 'onClose': function(caption) { |
---|
52 | list_container.find('[name="name"]').val("").focus(); |
---|
53 | } |
---|
54 | }); |
---|
55 | accord.accordion('activate',0); |
---|
56 | return false; |
---|
57 | }else{ |
---|
58 | filter_list = DataLayer.get("filter", true); |
---|
59 | var error = false; |
---|
60 | $.each(filter_list, function(index, value){ |
---|
61 | if(filter_list[index].name == list_container.find('[name="name"]').val()){ |
---|
62 | $.Zebra_Dialog(get_lang("There is already a filter with this name"),{ |
---|
63 | 'onClose': function(caption) { |
---|
64 | list_container.find('[name="name"]').val("").focus(); |
---|
65 | } |
---|
66 | }); |
---|
67 | accord.accordion('activate',0); |
---|
68 | error = true; |
---|
69 | return; |
---|
70 | } |
---|
71 | }); |
---|
72 | if(error){ |
---|
73 | return false; |
---|
74 | } |
---|
75 | } |
---|
76 | } |
---|
77 | var criteria = ""; |
---|
78 | var criteria_list = list_container.find('[name="criteriaValue[]"]'); |
---|
79 | var er_num = /^[0-9]+$/; |
---|
80 | |
---|
81 | if($(".sizeRule").val() != "" && er_num.test($(".sizeRule").val()) == false) { |
---|
82 | $.Zebra_Dialog(get_lang("Size rule must be a number"),{ |
---|
83 | 'onClose': function(caption) { |
---|
84 | list_container.find('[name="actionType[]"]:checked').parent().find("input:text, textarea").focus(); |
---|
85 | } |
---|
86 | }); |
---|
87 | accord.accordion('activate',0); |
---|
88 | return false; |
---|
89 | } |
---|
90 | $.each(criteria_list, function(index, value){ |
---|
91 | criteria += $.trim($(criteria_list[index]).val()); |
---|
92 | }); |
---|
93 | if(criteria == ""){ |
---|
94 | $.Zebra_Dialog(get_lang("No criteria filled"),{ |
---|
95 | 'onClose': function(caption) { |
---|
96 | list_container.find('[name="criteriaValue[]"]:first').focus(); |
---|
97 | } |
---|
98 | }); |
---|
99 | accord.accordion('activate',0); |
---|
100 | return false; |
---|
101 | } |
---|
102 | if(list_container.find('[name="actionType[]"]:checked').parent().find("input:text, textarea").length){ |
---|
103 | if($.trim(list_container.find('[name="actionType[]"]:checked').parent().find("input:text, textarea").val()) == ""){ |
---|
104 | $.Zebra_Dialog(get_lang("Fill the action value"),{ |
---|
105 | 'onClose': function(caption) { |
---|
106 | list_container.find('[name="actionType[]"]:checked').parent().find("input:text, textarea").focus(); |
---|
107 | } |
---|
108 | }); |
---|
109 | return false; |
---|
110 | } |
---|
111 | var er_mail = RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); |
---|
112 | if(er_mail.test($.trim(list_container.find('[value="redirect"]:checked').parent().find("input:text, textarea").val())) == false){ |
---|
113 | $.Zebra_Dialog(get_lang("Invalid mail"),{ |
---|
114 | 'onClose': function(caption) { |
---|
115 | list_container.find('[name="actionType[]"]:checked').parent().find("input:text, textarea").focus(); |
---|
116 | } |
---|
117 | }); |
---|
118 | return false; |
---|
119 | } |
---|
120 | } |
---|
121 | return true; |
---|
122 | }; |
---|
123 | |
---|
124 | bytes2Size = function(bytes) { |
---|
125 | var sizes = ['B', 'KB', 'MB', 'GB', 'TB']; |
---|
126 | if (bytes === 0) return 'n/a'; |
---|
127 | var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); |
---|
128 | var size = (i<2) ? Math.round((bytes / Math.pow(1024, i))) : Math.round((bytes / Math.pow(1024, i)) * 100)/100; |
---|
129 | return size + ' ' + sizes[i]; |
---|
130 | }; |
---|
131 | |
---|
132 | flags2Class = function(cellvalue) { |
---|
133 | var flags_enum = cellvalue.split(','); |
---|
134 | var classes = ''; |
---|
135 | for (var i=0; i<flags_enum.length; i++){ |
---|
136 | classes += '<span class="icon-'+flags_enum[i].toLowerCase()+'"> </span>'; |
---|
137 | } |
---|
138 | return classes; |
---|
139 | }; |
---|
140 | |
---|
141 | date2Time = function (timestamp) { |
---|
142 | var date = new Date(); |
---|
143 | if ((date.getTime() - timestamp) < (24*60*60*1000)) { |
---|
144 | return '<span class="timable" title="'+timestamp+'"> </span>'; |
---|
145 | } else { |
---|
146 | date = new Date(timestamp); |
---|
147 | var b = date.toISOString().split("T")[0].split("-"); |
---|
148 | var c = b[2] + "/" + b[1] + "/" + b[0]; |
---|
149 | return '<span class="datable">' + c + '</span>'; |
---|
150 | } |
---|
151 | }; |
---|
152 | |
---|
153 | keys = function( object ){ |
---|
154 | |
---|
155 | var array = []; |
---|
156 | |
---|
157 | for( var key in object ) |
---|
158 | array[ array.length ] = key; |
---|
159 | |
---|
160 | return( array ); |
---|
161 | |
---|
162 | } |
---|
163 | |
---|
164 | showDetails = function( filter ){ |
---|
165 | |
---|
166 | form.get(0).reset(); |
---|
167 | |
---|
168 | nameObj.val( filter.name ); |
---|
169 | nameObj.attr("disabled", "disabled"); |
---|
170 | for( var i = 0; i < filter.criteria.length; i++ ){ |
---|
171 | criterias.filter( '[value="' + filter.criteria[i].field + '"]' ) |
---|
172 | .siblings( '[name="criteriaOperator[]"]' ).val( filter.criteria[i].operator ).end() |
---|
173 | .siblings( '[name="criteriaValue[]"]' ).val( filter.criteria[i].value ); |
---|
174 | } |
---|
175 | for( var i = 0; i < filter.actions.length; i++ ){ |
---|
176 | actions.filter( '[value="' + filter.actions[i].type + '"]' ).attr("checked", "True"); |
---|
177 | actions.filter( '[value="' + filter.actions[i].type + '"]' ).val( filter.actions[i].type ) |
---|
178 | .siblings( '[name="actionParameter[]"]' ).val( filter.actions[i].parameter ); |
---|
179 | if(filter.actions[i].type == "redirect") |
---|
180 | actions.siblings('[name="addressRedirect"]').val(filter.actions[i].parameter); |
---|
181 | if(filter.actions[i].type == "reject") |
---|
182 | actions.siblings('[name="messageReject"]').val(filter.actions[i].parameter); |
---|
183 | if(filter.actions[i].type == "fileinto" || filter.actions[i].type == "setflag") |
---|
184 | actions.parent().find('[value="'+filter.actions[i].parameter+'"]').attr("selected", "selected"); |
---|
185 | } |
---|
186 | //isExact.val( filter.isExact != "false"? "and" : "or" ); |
---|
187 | isExact.filter('[value="'+(filter.isExact != "false"? "and" : "or")+'"]').attr("checked", "True"); |
---|
188 | } |
---|
189 | |
---|
190 | /* --- ------ --- */ |
---|
191 | |
---|
192 | DataLayer.codec( "filter", "detail", { |
---|
193 | decoder: function( form ){ |
---|
194 | if( form.vacation ) |
---|
195 | return { |
---|
196 | criteria: [{ value: "vacation", operator: "", field: "vacation" }], |
---|
197 | actions: [{ parameter: form.vacation, type: "vacation" }], |
---|
198 | id: "vacation", |
---|
199 | name: "vacation", |
---|
200 | isExact: false, |
---|
201 | applyMessages : "", |
---|
202 | enabled : true |
---|
203 | } |
---|
204 | |
---|
205 | var apply_messages_ = keys(selectedMessages); |
---|
206 | delete selectedMessages; |
---|
207 | |
---|
208 | return { |
---|
209 | //id: form.name, |
---|
210 | name: form.name ? form.name.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') : nameObj.val().replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'), |
---|
211 | isExact: ( form.isExact === "and" ), |
---|
212 | criteria: $.map( form.criteriaOperator || [], function( criteriaOperator, i ){ |
---|
213 | return (!form.criteriaValue[i]) ? null: |
---|
214 | { |
---|
215 | value: form.criteriaValue[i].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'), |
---|
216 | operator: criteriaOperator, |
---|
217 | field: form.criteriaType[i].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') |
---|
218 | }; |
---|
219 | }), |
---|
220 | actions: $.map( form.actionType || [], function( type, i ){ |
---|
221 | var the_parameter = form.actionParameter[i]; |
---|
222 | |
---|
223 | !the_parameter ? the_parameter = form.actionParameter[i+1] : ""; |
---|
224 | if (type == 'alertMessage') { |
---|
225 | //if(!$('[value="alertMessage"]').parent().hasClass("hidden")){ |
---|
226 | type = 'addflag'; |
---|
227 | the_parameter = '$FilteredMessage'; |
---|
228 | //}else{ |
---|
229 | // return; |
---|
230 | //} |
---|
231 | } |
---|
232 | if (type == 'fileinto') { |
---|
233 | the_parameter = form.valueFileInto; |
---|
234 | } |
---|
235 | if (type == 'reject') { |
---|
236 | the_parameter = form.messageReject; |
---|
237 | } |
---|
238 | if (type == 'fileintoInbox') { |
---|
239 | if(!$('[value="fileintoInbox"]').parent().hasClass("hidden")){ |
---|
240 | type = 'fileinto'; |
---|
241 | the_parameter = 'INBOX'; |
---|
242 | }else{ |
---|
243 | return; |
---|
244 | } |
---|
245 | } |
---|
246 | if (type == 'fileintoTrash') { |
---|
247 | type = 'fileinto'; |
---|
248 | the_parameter = 'INBOX/Trash'; |
---|
249 | } |
---|
250 | if (type == 'redirect') { |
---|
251 | the_parameter = form.addressRedirect; |
---|
252 | } |
---|
253 | if (type == 'setflag') { |
---|
254 | the_parameter = form.valueSetFlag; |
---|
255 | } |
---|
256 | return (!type) ? null: |
---|
257 | {parameter: the_parameter, type: type }; |
---|
258 | |
---|
259 | }), |
---|
260 | enabled : true, |
---|
261 | alertMessage: $('.alertMessage').is(':checked'), |
---|
262 | //applyMessages: allMessages? !$.isEmptyObject( selectedMessages ) ? |
---|
263 | //keys( selectedMessages ) : allMessages : "" |
---|
264 | applyMessages: apply_messages_ |
---|
265 | //applyMessages: "" |
---|
266 | }; |
---|
267 | }, |
---|
268 | |
---|
269 | encoder: function( filters ){ |
---|
270 | var rules = []; |
---|
271 | |
---|
272 | for( var id in filters ) |
---|
273 | rules[ rules.length ] = filters[id]; |
---|
274 | |
---|
275 | return { rules: rules }; |
---|
276 | |
---|
277 | } |
---|
278 | |
---|
279 | }); |
---|
280 | |
---|
281 | DataLayer.codec( "folder", "select", { |
---|
282 | |
---|
283 | decoder:function(){ |
---|
284 | |
---|
285 | |
---|
286 | |
---|
287 | }, |
---|
288 | encoder:function( data ){ |
---|
289 | var tree1 = [], tree2 = [], tree3 = []; |
---|
290 | |
---|
291 | for (var i=0; i<data.length; i++) { |
---|
292 | |
---|
293 | if (/^INBOX/.test(data[i].id)) { |
---|
294 | if (!unorphanize(tree1, data[i])) { |
---|
295 | data[i].children = []; |
---|
296 | tree1.push(data[i]); |
---|
297 | } |
---|
298 | } |
---|
299 | else if (/^user/.test(data[i].id)) { |
---|
300 | if (!unorphanize(tree2, data[i])) { |
---|
301 | data[i].children = []; |
---|
302 | tree2.push(data[i]); |
---|
303 | } |
---|
304 | } |
---|
305 | else if (/^local_messages/.test(data[i].id)) { |
---|
306 | if (!unorphanize(tree3, data[i])) { |
---|
307 | data[i].children = []; |
---|
308 | tree3.push(data[i]); |
---|
309 | } |
---|
310 | } |
---|
311 | |
---|
312 | } |
---|
313 | |
---|
314 | return {folders: [ tree1, tree2, tree3 ]}; |
---|
315 | |
---|
316 | } |
---|
317 | |
---|
318 | }); |
---|
319 | |
---|
320 | fromRules = getFromAlertRules(); |
---|
321 | |
---|
322 | var BASE_PATH = '../prototype/'; |
---|
323 | |
---|
324 | DataLayer.basePath = BASE_PATH + "REST.php?q="; |
---|
325 | DataLayer.dispatchPath = BASE_PATH; |
---|
326 | |
---|
327 | var selectedMessages = {}; |
---|
328 | var allMessages = false; |
---|
329 | |
---|
330 | function block_user_email(email) { |
---|
331 | //var id = "block_"+email; |
---|
332 | var idd = email; |
---|
333 | /** TODO - Mudar quando API abstrair atualizações no cache */ |
---|
334 | DataLayer.remove('filter', false); |
---|
335 | var filters = DataLayer.get('filter'); |
---|
336 | //var filters = DataLayer.get("filter", true); |
---|
337 | for(var index in filters){ |
---|
338 | if(filters[index].name == email) { |
---|
339 | if(confirm(get_lang("This user is already blocked. Would you like to unlock it?"))) { |
---|
340 | DataLayer.remove( 'filter', filters[index].id ); |
---|
341 | DataLayer.commit("filter", false, function(){ |
---|
342 | $.Zebra_Dialog(get_lang("Lock User") + " " + email + " " + get_lang("removed")); |
---|
343 | list_filters(); |
---|
344 | }); |
---|
345 | return true; |
---|
346 | }else |
---|
347 | return true; |
---|
348 | } |
---|
349 | } |
---|
350 | if(confirm(get_lang("Want to block the user") + " " + email + "?")){ |
---|
351 | DataLayer.put( 'filter', idd, |
---|
352 | { name: email, isExact: false, |
---|
353 | criteria:{ 0: {value: email, operator: "=", field: "from"} }, |
---|
354 | actions: { 0: {parameter: "INBOX" + cyrus_delimiter + "Spam", type: "fileinto"}}, |
---|
355 | enabled: true, |
---|
356 | id: email, |
---|
357 | block: true |
---|
358 | }); |
---|
359 | DataLayer.commit("filter", false, function(){ |
---|
360 | $.Zebra_Dialog(get_lang("User") + " " + email + " " + get_lang("blocked")); |
---|
361 | list_filters(); |
---|
362 | }); |
---|
363 | |
---|
364 | } |
---|
365 | } |
---|
366 | |
---|
367 | function showGridMessages(thiss) { |
---|
368 | var criteria_list = list_container.find('[name="criteriaValue[]"]'); |
---|
369 | var criteria_operator_list = list_container.find('[name="criteriaOperator[]"]'); |
---|
370 | var criteria_value = ""; |
---|
371 | var criteria = ""; |
---|
372 | $.each(criteria_list, function(index, value){ |
---|
373 | criteria += $.trim($(criteria_list[index]).val()) + ","; |
---|
374 | }); |
---|
375 | var criteria_ = criteria.split(","); |
---|
376 | var criteria_operator = ""; |
---|
377 | $.each(criteria_operator_list, function(index, value){ |
---|
378 | criteria_operator += $.trim($(criteria_list[index]).val()) != "" ? index + "," : ","; |
---|
379 | criteria_value += $.trim($(criteria_operator_list[index]).val()) + ","; |
---|
380 | }); |
---|
381 | var criteria_operator_ = criteria_operator.split(","); |
---|
382 | var criteria_value_ = criteria_value.split(","); |
---|
383 | var options = ["from", "to", "subject", "body", "size"]; |
---|
384 | var criterias_ = new Array(); |
---|
385 | var j = 0; |
---|
386 | for (i in criteria_) { |
---|
387 | if(criteria_[i] != "") { |
---|
388 | (j == 0) ? criterias_[j] = {"0": options[i], "1": criteria_value_[i], "2": criteria_[i]} : criterias_[j] = {"0": "OR", "1": options[i], "2": criteria_value_[i], "3": criteria_[i]}; |
---|
389 | j++; |
---|
390 | } |
---|
391 | } |
---|
392 | showGridButton = thiss.parent(); |
---|
393 | $.ajax({ |
---|
394 | url: DataLayer.basePath + 'folder/INBOX/message&' + $.param( {"filter": criterias_} ), |
---|
395 | dataType: 'json', |
---|
396 | success: function(data){ |
---|
397 | allMessages = data; |
---|
398 | |
---|
399 | var parametro = { "filter": ( data != false ? [ "msgNumber", "IN", data ] : criterias_ ) }; |
---|
400 | |
---|
401 | if (typeof grid !== "undefined") { |
---|
402 | grid.jqGrid( 'setGridParam', { url: DataLayer.basePath + 'folder/INBOX/message&' + $.param( parametro ) } ).trigger( 'reloadGrid' ); |
---|
403 | //return; |
---|
404 | } |
---|
405 | grid = showGridButton.siblings(".fields-search-messages-grid, .fields-search-messages-grid-pager") |
---|
406 | .removeClass('hidden').filter(".fields-search-messages-grid").trigger( 'reloadGrid' ).jqGrid({ |
---|
407 | //url: DataLayer.basePath + 'folder/INBOX/message&' + $.param( {"filter": [ "msgNumber", "IN", data ]} ), |
---|
408 | url: DataLayer.basePath + 'folder/INBOX/message&' + $.param( parametro ), |
---|
409 | datatype: "json", |
---|
410 | mtype: 'GET', |
---|
411 | colNames:['#', 'De', 'Assunto', 'Data', 'Tamanho'], |
---|
412 | colModel:[ |
---|
413 | {name:'msg_number',index:'msg_number', width:45, hidden:true, sortable:false}, |
---|
414 | {name:'from.email',index:'msg_number', width:130, sortable:false}, |
---|
415 | {name:'subject',index:'subject', width:250, sortable:false}, |
---|
416 | {name:'timestamp',index:'timestamp', width:65, align:"center", sortable:false, formatter:date2Time}, |
---|
417 | {name:'size',index:'size', width:50, align:"right", sortable:false, formatter:bytes2Size} |
---|
418 | ], |
---|
419 | jsonReader : { |
---|
420 | root:"rows", |
---|
421 | page: "page", |
---|
422 | total: "total", |
---|
423 | records: "records", |
---|
424 | repeatitems: false, |
---|
425 | id: "0" |
---|
426 | }, |
---|
427 | rowNum:10, |
---|
428 | //rowList:[10,25,50], |
---|
429 | rowList:[10], |
---|
430 | pager: '#fields-search-messages-grid-pager', |
---|
431 | sortname: 'id', |
---|
432 | viewrecords: true, |
---|
433 | sortorder: "desc", |
---|
434 | multiselect: true, |
---|
435 | autowidth: true, |
---|
436 | reloadAfterEdit: true, |
---|
437 | reloadAfterSubmit: true, |
---|
438 | height:200, |
---|
439 | loadComplete: function(data) { |
---|
440 | // // aplica o contador |
---|
441 | // jQuery('.timable').each(function (i) { |
---|
442 | // jQuery(this).countdown({ |
---|
443 | // since: new Date(parseInt(this.title)), |
---|
444 | // significant: 1, |
---|
445 | // layout: 'há {d<}{dn} {dl} {d>}{h<}{hn} {hl} {h>}{m<}{mn} {ml} {m>}{s<}{sn} {sl}{s>}', |
---|
446 | // description: ' atrás' |
---|
447 | // }); |
---|
448 | // }); |
---|
449 | }, |
---|
450 | onSelectRow: function (id, selected) { |
---|
451 | if( selected ) |
---|
452 | { |
---|
453 | selectedMessages[ id ] = true; |
---|
454 | } |
---|
455 | else |
---|
456 | { |
---|
457 | delete selectedMessages[ id ]; |
---|
458 | } |
---|
459 | }, |
---|
460 | caption: 'Mensagens que atendem aos critérios' |
---|
461 | }); // end jqGrid |
---|
462 | } // end success |
---|
463 | }); // end ajax |
---|
464 | } |
---|
465 | |
---|
466 | |
---|
467 | function list_filters(html){ |
---|
468 | outOfficeVerify(); |
---|
469 | if(html){ |
---|
470 | if( ! $(".filters-windows").length ) |
---|
471 | container = $('.expressomail-module-container').append("<div class='filters-windows'></div>").find(".filters-windows").html( html ).find(".expresso-window-container"); |
---|
472 | list_container = $('.expressomail-module-container').find(".rule-list-container"); |
---|
473 | } |
---|
474 | list_container = $(".expresso-window-filters").dialog({ |
---|
475 | width:700, |
---|
476 | modal: true, |
---|
477 | resizable: false, |
---|
478 | closeOnEscape:true, |
---|
479 | close:function(event, ui) { |
---|
480 | event.stopPropagation(); |
---|
481 | if(list_container.find(".cancel").length) |
---|
482 | list_container.find(".cancel").trigger('click'); |
---|
483 | $(".dialog-head-buttonpane").hide(); |
---|
484 | }, |
---|
485 | open: function () { |
---|
486 | $(".ui-dialog .ui-dialog-titlebar") |
---|
487 | .append('<a href="#" class="ui-dialog-titlebar-minimize ui-corner-all" role="button"><span class="ui-icon ui-icon-minusthick">minimize</span></a>') |
---|
488 | .find('.ui-dialog-titlebar-minimize').click(function() { |
---|
489 | $(".ui-dialog-buttonpane, .ui-dialog-content").toggle(); |
---|
490 | $(".ui-icon-minusthick, .ui-icon-newwin").toggleClass('ui-icon-minusthick').toggleClass('ui-icon-newwin'); |
---|
491 | }); |
---|
492 | $(".dialog-head-buttonpane").show(); |
---|
493 | }, |
---|
494 | autoOpen: false, |
---|
495 | buttons: [{ |
---|
496 | text : get_lang("Close"), |
---|
497 | click : function() { |
---|
498 | $( this ).dialog( "close" ); |
---|
499 | } |
---|
500 | }] |
---|
501 | }); |
---|
502 | $(".ui-dialog-titlebar").after("<div class='dialog-head-buttonpane ui-dialog-buttonpane ui-widget-content ui-helper-clearfix' style='background-color: rgb(224, 238, 238); '><div class='ui-dialog-buttonset header-buttonpane'></div></div>"); |
---|
503 | $(".dialog-head-buttonpane").css("padding", "5px"). |
---|
504 | find(".header-buttonpane").html("<a href='#' class='button add' title='"+get_lang("Add new rule")+"'>"+get_lang("New rule")+"</a>"+(!outoffice ? "<a href='#' class='button add vacation' title='"+get_lang("Add rule out of office")+"'>"+get_lang("Out of office")+"</a>" : "")).find(".button").button(); |
---|
505 | |
---|
506 | $(".ui-dialog-buttonpane.ui-widget-content").css("background-color", "#E0EEEE"); |
---|
507 | var list = DataLayer.render( BASE_PATH + 'modules/filters/filter-list.ejs', DataLayer.get("filter:detail", true)); |
---|
508 | list_container.html(list).find(".button").button(); |
---|
509 | |
---|
510 | list_container.find(".rule-list").selectable({ |
---|
511 | selecting: function(event, ui) { |
---|
512 | $(ui.selecting).find(':checkbox').attr('checked', true); |
---|
513 | }, |
---|
514 | unselecting: function(event, ui) { |
---|
515 | $(ui.unselecting).find(':checkbox').attr('checked', false); |
---|
516 | } |
---|
517 | }); |
---|
518 | |
---|
519 | list_container.find( ".menu-control .button" ).filter(".update").button({ |
---|
520 | icons: { |
---|
521 | primary: "ui-icon-pencil" |
---|
522 | }, |
---|
523 | text: false |
---|
524 | }).click(function(){ |
---|
525 | var id = $(this).parents("li.rule").find('.id').val(); |
---|
526 | var filters = DataLayer.get( 'filter', true); |
---|
527 | for(var i =0; i < filters.length; i++){ |
---|
528 | if(filters[i].id == id){ |
---|
529 | filters = filters[i]; |
---|
530 | break; |
---|
531 | } |
---|
532 | } |
---|
533 | DataLayer.render( BASE_PATH + 'modules/filters/edit-filter.ejs', {folders : DataLayer.get("folder", true), delimiter: cyrus_delimiter},function(html){ |
---|
534 | var details_container = $(".expresso-window-filters").html(html); |
---|
535 | if(filters.name != "vacation"){ |
---|
536 | form = container.find("form"); |
---|
537 | criterias = details_container.find( 'fieldset input[name="criteriaType[]"]' ); |
---|
538 | actions = details_container.find( 'fieldset input[name="actionType[]"]' ); |
---|
539 | nameObj = details_container.find( 'input[name="name"]' ); |
---|
540 | isExact = details_container.find( 'input[name="isExact"]' ); |
---|
541 | showDetails(filters); |
---|
542 | var accord = list_container.find(".rule-details-container").accordion({autoHeight: false}); |
---|
543 | list_container.find(".button").button().filter(".forth").click(function(){ |
---|
544 | accord.accordion('activate',1); |
---|
545 | }).end().filter(".forth2").click(function(){ |
---|
546 | accord.accordion('activate',2); |
---|
547 | }).end().filter(".back").click(function(){ |
---|
548 | accord.accordion('activate',0); |
---|
549 | }).end().filter(".back2").click(function(){ |
---|
550 | accord.accordion('activate',1); |
---|
551 | }).end().filter(".cancel").click(function(){ |
---|
552 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
553 | }).end().filter(".submit").click(function(){ |
---|
554 | if(nameObj) |
---|
555 | nameObj.attr("disabled", "false"); |
---|
556 | if(valid_save()) |
---|
557 | $(this).submit(); |
---|
558 | else |
---|
559 | return; |
---|
560 | DataLayer.commit( 'filter', false,function(){ |
---|
561 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
562 | }); |
---|
563 | }).end().filter('.button.search').click(function() { |
---|
564 | /* Valida se o usuário preencheu as informações */ |
---|
565 | if(valid_save()) |
---|
566 | showGridMessages($(this)); |
---|
567 | else |
---|
568 | return; |
---|
569 | }) |
---|
570 | }else{ |
---|
571 | list_container.find(".vacation-details-container").removeClass("hidden"); |
---|
572 | list_container.find(".rule-details-container").addClass("hidden"); |
---|
573 | list_container.find(".button").button().filter(".back").click(function(){ |
---|
574 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
575 | }).end().filter(".submit").click(function(){ |
---|
576 | $(this).submit(); |
---|
577 | DataLayer.commit( 'filter', false,function(){ |
---|
578 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
579 | }); |
---|
580 | }); |
---|
581 | details_container.find('[name="vacation"]').val(filters.actions[0].parameter); |
---|
582 | } |
---|
583 | }); |
---|
584 | }).end() |
---|
585 | .filter(".enable").button({ |
---|
586 | icons: { |
---|
587 | primary: "ui-icon-circle-close" |
---|
588 | }, |
---|
589 | text: false |
---|
590 | }).click(function(){ |
---|
591 | var id = $(this).parents("li.rule").find('.id').val(); |
---|
592 | DataLayer.put( 'filter', id, { enabled: false }); |
---|
593 | DataLayer.commit("filter", false,function(){ |
---|
594 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
595 | }); |
---|
596 | }).end() |
---|
597 | |
---|
598 | .filter(".disable").button({ |
---|
599 | icons: { |
---|
600 | primary: "ui-icon-circle-check" |
---|
601 | }, |
---|
602 | text: false |
---|
603 | }).click(function(){ |
---|
604 | var id = $(this).parents("li.rule").find('.id').val(); |
---|
605 | DataLayer.put( 'filter', id, { enabled: true }); |
---|
606 | DataLayer.commit("filter", false,function(){ |
---|
607 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
608 | }); |
---|
609 | }).end() |
---|
610 | |
---|
611 | .filter(".close").button({ |
---|
612 | icons: { |
---|
613 | primary: "ui-icon-close" |
---|
614 | }, |
---|
615 | text: false |
---|
616 | }).click(function(event){ |
---|
617 | var filter_name = $(event.target).parents("li.rule").find('.id').val(); |
---|
618 | var filter_screen_name = $(event.target).parents("li.rule").find('.title').html(); |
---|
619 | $.Zebra_Dialog(get_lang("Are you sure to delete the filter") + ": <strong>"+filter_screen_name+"</strong>",{ |
---|
620 | 'type': 'question', |
---|
621 | 'title': get_lang("Exclusion Confirmation"), |
---|
622 | 'buttons': [get_lang('Yes'), get_lang('No')], |
---|
623 | 'onClose': function(caption) { |
---|
624 | if(caption == get_lang('Yes')){ |
---|
625 | /** TODO - Mudar quando API abstrair atualizações no cache */ |
---|
626 | DataLayer.remove('filter', false); |
---|
627 | DataLayer.get('filter'); |
---|
628 | DataLayer.remove( 'filter', filter_name); |
---|
629 | DataLayer.commit("filter", false,function(){ |
---|
630 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
631 | }); |
---|
632 | }else{ |
---|
633 | $(event.target).removeClass("ui-selected").parent().removeClass("ui-selected"); |
---|
634 | } |
---|
635 | } |
---|
636 | }); |
---|
637 | }).end().removeClass("ui-button-icon-only"); |
---|
638 | |
---|
639 | $(".button.allenable").click(function(){ |
---|
640 | container.find('.rule-list').find('.rule').find('.select').find(':checked').parents('.rule').find('.title').each(function(i,o){ |
---|
641 | DataLayer.put( 'filter', o.innerHTML, { enabled: true }); |
---|
642 | }); |
---|
643 | DataLayer.commit("filter", false, function(){ |
---|
644 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
645 | }); |
---|
646 | }); |
---|
647 | |
---|
648 | $(".button.alldisable").click(function(){ |
---|
649 | container.find('.rule-list').find('.rule').find('.select').find(':checked').parents('.rule').find('.title').each(function(i,o){ |
---|
650 | DataLayer.put( 'filter', o.innerHTML, { enabled: false }); |
---|
651 | }); |
---|
652 | DataLayer.commit("filter", false, function(){ |
---|
653 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
654 | }); |
---|
655 | }); |
---|
656 | |
---|
657 | |
---|
658 | |
---|
659 | $(".button.alldelete").click(function(){ |
---|
660 | $.Zebra_Dialog(get_lang("Are you sure to delete the filters?"),{ |
---|
661 | 'type': 'question', |
---|
662 | 'title': get_lang("Exclusion Confirmation"), |
---|
663 | 'buttons': [get_lang('Yes'), get_lang('No')], |
---|
664 | 'onClose': function(caption) { |
---|
665 | if(caption == get_lang('Yes')){ |
---|
666 | /** TODO - Mudar quando API abstrair atualizações no cache */ |
---|
667 | DataLayer.remove('filter', false); |
---|
668 | DataLayer.get('filter'); |
---|
669 | container.find('.rule-list').find('.rule').find('.select').find(':checked').parents('.rule').find('.title').each(function(i,o){ |
---|
670 | DataLayer.remove( 'filter', o.innerHTML ); |
---|
671 | }); |
---|
672 | DataLayer.commit("filter", false,function(){ |
---|
673 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
674 | }); |
---|
675 | }else{ |
---|
676 | return true; |
---|
677 | } |
---|
678 | } |
---|
679 | }); |
---|
680 | }); |
---|
681 | |
---|
682 | var aa = 0; |
---|
683 | |
---|
684 | list_container.parent().find(".button.add:first").click(function(){ |
---|
685 | list_container.parent().find(".dialog-head-buttonpane").addClass("hidden"); |
---|
686 | DataLayer.render( BASE_PATH + 'modules/filters/edit-filter.ejs', {folders : DataLayer.get("folder", true), delimiter: cyrus_delimiter},function(html){ |
---|
687 | list_container.html(html); |
---|
688 | var accord = list_container.find(".rule-details-container").accordion({autoHeight: false}); |
---|
689 | list_container.find(".button").button().filter(".forth").click(function(){ |
---|
690 | accord.accordion('activate',1); |
---|
691 | }).end().filter(".forth2").click(function(){ |
---|
692 | accord.accordion('activate',2); |
---|
693 | }).end().filter(".back").click(function(){ |
---|
694 | accord.accordion('activate',0); |
---|
695 | }).end().filter(".back2").click(function(){ |
---|
696 | accord.accordion('activate',1); |
---|
697 | }).end().filter(".cancel").click(function(){ |
---|
698 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
699 | }).end().filter(".submit").click(function() { |
---|
700 | if(valid_save()) |
---|
701 | $(this).submit(); |
---|
702 | else |
---|
703 | return; |
---|
704 | DataLayer.commit( 'filter',false,function(){ |
---|
705 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
706 | }); |
---|
707 | }).end().filter('.button.search').click(function() { |
---|
708 | if(valid_save()) |
---|
709 | showGridMessages($(this)); |
---|
710 | else |
---|
711 | return; |
---|
712 | }); // end function click |
---|
713 | }); // end DataLayer.render |
---|
714 | }); |
---|
715 | list_container.parent().find(".button.add.vacation").click(function(){ |
---|
716 | list_container.parent().find(".dialog-head-buttonpane").addClass("hidden"); |
---|
717 | DataLayer.render( BASE_PATH + 'modules/filters/edit-filter.ejs', {folders : DataLayer.get("folder", true), delimiter: cyrus_delimiter},function(html){ |
---|
718 | list_container.html(html); |
---|
719 | list_container.find(".vacation-details-container").removeClass("hidden"); |
---|
720 | list_container.find(".rule-details-container").addClass("hidden"); |
---|
721 | list_container.find(".button").button().filter(".back").click(function(){ |
---|
722 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
723 | }).end().filter(".submit").click(function(){ |
---|
724 | $(this).submit(); |
---|
725 | DataLayer.commit( 'filter',false,function(){ |
---|
726 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
727 | }); |
---|
728 | }); |
---|
729 | }); |
---|
730 | }); |
---|
731 | } |
---|
732 | function init_filters(){ |
---|
733 | var html = DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {}); |
---|
734 | list_filters(html); |
---|
735 | } |
---|