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