1 | valid_save = function(){ |
---|
2 | var accord = list_container.find(".rule-details-container").accordion({autoHeight: false}); |
---|
3 | if(list_container.find('[name="name"]').attr("disabled") != "disabled") |
---|
4 | { |
---|
5 | if($.trim(list_container.find('[name="name"]').val()) == ""){ |
---|
6 | $.Zebra_Dialog(get_lang("No name filled"),{ |
---|
7 | 'onClose': function(caption) { |
---|
8 | list_container.find('[name="name"]').focus(); |
---|
9 | } |
---|
10 | }); |
---|
11 | accord.accordion('activate',0); |
---|
12 | return false; |
---|
13 | }else if($.trim(list_container.find('[name="name"]').val()) == "vacation"){ |
---|
14 | $.Zebra_Dialog(get_lang("Invalid name, 'vacation' is a reserved word"),{ |
---|
15 | 'onClose': function(caption) { |
---|
16 | list_container.find('[name="name"]').val("").focus(); |
---|
17 | } |
---|
18 | }); |
---|
19 | accord.accordion('activate',0); |
---|
20 | return false; |
---|
21 | }else{ |
---|
22 | filter_list = DataLayer.get("filter", true); |
---|
23 | var error = false; |
---|
24 | $.each(filter_list, function(index, value){ |
---|
25 | if(filter_list[index].name == list_container.find('[name="name"]').val()){ |
---|
26 | $.Zebra_Dialog(get_lang("There is already a filter with this name"),{ |
---|
27 | 'onClose': function(caption) { |
---|
28 | list_container.find('[name="name"]').val("").focus(); |
---|
29 | } |
---|
30 | }); |
---|
31 | accord.accordion('activate',0); |
---|
32 | error = true; |
---|
33 | return; |
---|
34 | } |
---|
35 | }); |
---|
36 | if(error){ |
---|
37 | return false; |
---|
38 | } |
---|
39 | } |
---|
40 | } |
---|
41 | var criteria = ""; |
---|
42 | var criteria_list = list_container.find('[name="criteriaValue[]"]'); |
---|
43 | $.each(criteria_list, function(index, value){ |
---|
44 | criteria += $.trim($(criteria_list[index]).val()); |
---|
45 | }); |
---|
46 | if(criteria == ""){ |
---|
47 | $.Zebra_Dialog(get_lang("No criteria filled"),{ |
---|
48 | 'onClose': function(caption) { |
---|
49 | list_container.find('[name="criteriaValue[]"]:first').focus(); |
---|
50 | } |
---|
51 | }); |
---|
52 | accord.accordion('activate',0); |
---|
53 | return false; |
---|
54 | } |
---|
55 | if(list_container.find('[name="actionType[]"]:checked').parent().find("input:text, textarea").length){ |
---|
56 | if($.trim(list_container.find('[name="actionType[]"]:checked').parent().find("input:text, textarea").val()) == ""){ |
---|
57 | $.Zebra_Dialog(get_lang("Fill the action value"),{ |
---|
58 | 'onClose': function(caption) { |
---|
59 | list_container.find('[name="actionType[]"]:checked').parent().find("input:text, textarea").focus(); |
---|
60 | } |
---|
61 | }); |
---|
62 | return false; |
---|
63 | } |
---|
64 | } |
---|
65 | return true; |
---|
66 | }; |
---|
67 | |
---|
68 | bytes2Size = function(bytes) { |
---|
69 | var sizes = ['B', 'KB', 'MB', 'GB', 'TB']; |
---|
70 | if (bytes === 0) return 'n/a'; |
---|
71 | var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); |
---|
72 | var size = (i<2) ? Math.round((bytes / Math.pow(1024, i))) : Math.round((bytes / Math.pow(1024, i)) * 100)/100; |
---|
73 | return size + ' ' + sizes[i]; |
---|
74 | }; |
---|
75 | |
---|
76 | flags2Class = function(cellvalue) { |
---|
77 | var flags_enum = cellvalue.split(','); |
---|
78 | var classes = ''; |
---|
79 | for (var i=0; i<flags_enum.length; i++){ |
---|
80 | classes += '<span class="icon-'+flags_enum[i].toLowerCase()+'"> </span>'; |
---|
81 | } |
---|
82 | return classes; |
---|
83 | }; |
---|
84 | |
---|
85 | date2Time = function (timestamp) { |
---|
86 | var date = new Date(); |
---|
87 | if ((date.getTime() - timestamp) < (24*60*60*1000)) { |
---|
88 | return '<span class="timable" title="'+timestamp+'"> </span>'; |
---|
89 | } else { |
---|
90 | date = new Date(timestamp); |
---|
91 | var b = date.toISOString().split("T")[0].split("-"); |
---|
92 | var c = b[2] + "/" + b[1] + "/" + b[0]; |
---|
93 | return '<span class="datable">' + c + '</span>'; |
---|
94 | } |
---|
95 | }; |
---|
96 | |
---|
97 | keys = function( object ){ |
---|
98 | |
---|
99 | var array = []; |
---|
100 | |
---|
101 | for( var key in object ) |
---|
102 | array[ array.length ] = key; |
---|
103 | |
---|
104 | return( array ); |
---|
105 | |
---|
106 | } |
---|
107 | |
---|
108 | showDetails = function( filter ){ |
---|
109 | |
---|
110 | form.get(0).reset(); |
---|
111 | |
---|
112 | nameObj.val( filter.name ); |
---|
113 | nameObj.attr("disabled", "disabled"); |
---|
114 | for( var i = 0; i < filter.criteria.length; i++ ){ |
---|
115 | |
---|
116 | criterias.filter( '[value="' + filter.criteria[i].field + '"]' ) |
---|
117 | .siblings( '[name="criteriaOperator[]"]' ).val( filter.criteria[i].operator ).end() |
---|
118 | .siblings( '[name="criteriaValue[]"]' ).val( filter.criteria[i].value ); |
---|
119 | |
---|
120 | } |
---|
121 | |
---|
122 | |
---|
123 | for( var i = 0; i < filter.actions.length; i++ ){ |
---|
124 | actions.filter( '[value="' + filter.actions[i].type + '"]' ).attr("checked", "True"); |
---|
125 | actions.filter( '[value="' + filter.actions[i].type + '"]' ).val( filter.actions[i].type ) |
---|
126 | .siblings( '[name="actionParameter[]"]' ).val( filter.actions[i].parameter ); |
---|
127 | if(filter.actions[i].type == "redirect") |
---|
128 | actions.siblings('[name="addressRedirect"]').val(filter.actions[i].parameter); |
---|
129 | if(filter.actions[i].type == "reject") |
---|
130 | actions.siblings('[name="messageReject"]').val(filter.actions[i].parameter); |
---|
131 | if(filter.actions[i].type == "fileinto" || filter.actions[i].type == "setflag") |
---|
132 | actions.parent().find('[value="'+filter.actions[i].parameter+'"]').attr("selected", "selected"); |
---|
133 | } |
---|
134 | |
---|
135 | //isExact.val( filter.isExact != "false"? "and" : "or" ); |
---|
136 | isExact.filter('[value="'+(filter.isExact != "false"? "and" : "or")+'"]').attr("checked", "True"); |
---|
137 | } |
---|
138 | |
---|
139 | /* --- ------ --- */ |
---|
140 | |
---|
141 | DataLayer.codec( "filter", "detail", { |
---|
142 | |
---|
143 | decoder: function( form ){ |
---|
144 | if( form.vacation ) |
---|
145 | return { |
---|
146 | |
---|
147 | criteria: [{ value: "vacation", operator: "", field: "vacation" }], |
---|
148 | actions: [{ parameter: form.vacation, type: "vacation" }], |
---|
149 | id: "vacation", |
---|
150 | name: "vacation", |
---|
151 | isExact: false, |
---|
152 | applyMessages : "", |
---|
153 | enabled : true |
---|
154 | } |
---|
155 | |
---|
156 | var apply_messages_ = keys(selectedMessages); |
---|
157 | delete selectedMessages; |
---|
158 | |
---|
159 | return { |
---|
160 | //id: form.name, |
---|
161 | name: form.name ? form.name : nameObj.val(), |
---|
162 | isExact: ( form.isExact === "and" ), |
---|
163 | criteria: $.map( form.criteriaOperator || [], function( criteriaOperator, i ){ |
---|
164 | return (!form.criteriaValue[i]) ? null: |
---|
165 | {value: form.criteriaValue[i], |
---|
166 | operator: criteriaOperator, |
---|
167 | field: form.criteriaType[i]}; |
---|
168 | |
---|
169 | }), |
---|
170 | actions: $.map( form.actionType || [], function( type, i ){ |
---|
171 | var the_parameter = form.actionParameter[i]; |
---|
172 | |
---|
173 | !the_parameter ? the_parameter = form.actionParameter[i+1] : ""; |
---|
174 | if (type == 'fileinto') { |
---|
175 | the_parameter = form.valueFileInto; |
---|
176 | } |
---|
177 | if (type == 'reject') { |
---|
178 | the_parameter = form.messageReject; |
---|
179 | } |
---|
180 | if (type == 'fileintoInbox') { |
---|
181 | if(!$('[value="fileintoInbox"]').parent().hasClass("hidden")){ |
---|
182 | type = 'fileinto'; |
---|
183 | the_parameter = 'INBOX'; |
---|
184 | }else{ |
---|
185 | return; |
---|
186 | } |
---|
187 | } |
---|
188 | if (type == 'fileintoTrash') { |
---|
189 | type = 'fileinto'; |
---|
190 | the_parameter = 'INBOX/Trash'; |
---|
191 | } |
---|
192 | if (type == 'redirect') { |
---|
193 | the_parameter = form.addressRedirect; |
---|
194 | } |
---|
195 | if (type == 'setflag') { |
---|
196 | the_parameter = form.valueSetFlag; |
---|
197 | } |
---|
198 | |
---|
199 | return (!type) ? null: |
---|
200 | {parameter: the_parameter, type: type }; |
---|
201 | |
---|
202 | }), |
---|
203 | enabled : true, |
---|
204 | //applyMessages: allMessages? !$.isEmptyObject( selectedMessages ) ? |
---|
205 | //keys( selectedMessages ) : allMessages : "" |
---|
206 | applyMessages: apply_messages_ |
---|
207 | //applyMessages: "" |
---|
208 | }; |
---|
209 | }, |
---|
210 | |
---|
211 | encoder: function( filters ){ |
---|
212 | var rules = []; |
---|
213 | |
---|
214 | for( var id in filters ) |
---|
215 | rules[ rules.length ] = filters[id]; |
---|
216 | |
---|
217 | return { rules: rules }; |
---|
218 | |
---|
219 | } |
---|
220 | |
---|
221 | }); |
---|
222 | |
---|
223 | DataLayer.codec( "folder", "select", { |
---|
224 | |
---|
225 | decoder:function(){ |
---|
226 | |
---|
227 | |
---|
228 | |
---|
229 | }, |
---|
230 | encoder:function( data ){ |
---|
231 | |
---|
232 | var tree1 = [], tree2 = [], tree3 = []; |
---|
233 | |
---|
234 | for (var i=0; i<data.length; i++) { |
---|
235 | |
---|
236 | if (/^INBOX/.test(data[i].id)) { |
---|
237 | if (!unorphanize(tree1, data[i])) { |
---|
238 | data[i].children = []; |
---|
239 | tree1.push(data[i]); |
---|
240 | } |
---|
241 | } |
---|
242 | else if (/^user/.test(data[i].id)) { |
---|
243 | if (!unorphanize(tree2, data[i])) { |
---|
244 | data[i].children = []; |
---|
245 | tree2.push(data[i]); |
---|
246 | } |
---|
247 | } |
---|
248 | else if (/^local_messages/.test(data[i].id)) { |
---|
249 | if (!unorphanize(tree3, data[i])) { |
---|
250 | data[i].children = []; |
---|
251 | tree3.push(data[i]); |
---|
252 | } |
---|
253 | } |
---|
254 | |
---|
255 | } |
---|
256 | |
---|
257 | return {folders: [ tree1, tree2, tree3 ]}; |
---|
258 | |
---|
259 | } |
---|
260 | |
---|
261 | }); |
---|
262 | |
---|
263 | |
---|
264 | |
---|
265 | |
---|
266 | var BASE_PATH = '../prototype/'; |
---|
267 | |
---|
268 | DataLayer.basePath = BASE_PATH + "REST.php?q="; |
---|
269 | DataLayer.dispatchPath = BASE_PATH; |
---|
270 | |
---|
271 | var selectedMessages = {}; |
---|
272 | var allMessages = false; |
---|
273 | //list_container = container.find(".rule-list-container"); |
---|
274 | /* |
---|
275 | var raster = function( html ){ |
---|
276 | container = $('body.expressomail-module-container').append( html ).find(".expresso-window-container"); |
---|
277 | list_container = container.find(".rule-list-container"); |
---|
278 | details_container = container.find(".rule-details-container"); |
---|
279 | vacation_container = container.find(".vacation-details-container"); |
---|
280 | form = container.find("form"); |
---|
281 | criterias = details_container.find( 'fieldset input[name="criteriaType[]"]' ); |
---|
282 | actions = details_container.find( 'fieldset input[name="actionType[]"]' ); |
---|
283 | nameObj = details_container.find( 'input[name="name"]' ); |
---|
284 | isExact = details_container.find( 'input[name="isExact"]' ); |
---|
285 | formatter(); |
---|
286 | container = container.dialog({ |
---|
287 | width:700, |
---|
288 | modal: true, |
---|
289 | closeOnEscape:true, |
---|
290 | close:function(event, ui) { |
---|
291 | event.stopPropagation(); |
---|
292 | list_container.removeClass('hidden'); |
---|
293 | details_container.addClass('hidden'); |
---|
294 | vacation_container.addClass('hidden'); |
---|
295 | }, |
---|
296 | open: function () { |
---|
297 | $(".ui-dialog .ui-dialog-titlebar") |
---|
298 | .append('<a href="#" class="ui-dialog-titlebar-minimize ui-corner-all" role="button"><span class="ui-icon ui-icon-minusthick">minimize</span></a>') |
---|
299 | .find('.ui-dialog-titlebar-minimize').click(function() { |
---|
300 | $(".ui-dialog-buttonpane, .ui-dialog-content").toggle(); |
---|
301 | $(".ui-icon-minusthick, .ui-icon-newwin").toggleClass('ui-icon-minusthick').toggleClass('ui-icon-newwin'); |
---|
302 | }); |
---|
303 | }, |
---|
304 | autoOpen: false |
---|
305 | }); |
---|
306 | details_container.accordion({autoHeight: false}); |
---|
307 | |
---|
308 | DataLayer.render( BASE_PATH + 'api/templates/folderselect.ejs', 'folder:select', function( html ){ |
---|
309 | details_container.find(".select-folderlist").append( html ); |
---|
310 | }); |
---|
311 | |
---|
312 | |
---|
313 | container.find(".button").button() |
---|
314 | |
---|
315 | .filter(".menu-filters > .button") |
---|
316 | |
---|
317 | .click(function(){ |
---|
318 | |
---|
319 | container.dialog( 'close' ); |
---|
320 | |
---|
321 | }) |
---|
322 | |
---|
323 | .filter(".cancel") |
---|
324 | |
---|
325 | .click(function(){ |
---|
326 | |
---|
327 | DataLayer.rollback( 'filter' ); |
---|
328 | return( false ); |
---|
329 | |
---|
330 | }) |
---|
331 | |
---|
332 | .end().filter(".submit") |
---|
333 | |
---|
334 | .click(function(){ |
---|
335 | |
---|
336 | DataLayer.commit( 'filter' ); |
---|
337 | return( false ); |
---|
338 | |
---|
339 | }); |
---|
340 | |
---|
341 | details_container.find( ".menu-container" ) |
---|
342 | |
---|
343 | .find(".button.cancel").click(function(event){ |
---|
344 | |
---|
345 | details_container.accordion('activate',0); |
---|
346 | |
---|
347 | showGridButton.removeClass('hidden'); |
---|
348 | grid.addClass('hidden').jqGrid('GridDestroy'); |
---|
349 | |
---|
350 | list_container.removeClass('hidden'); |
---|
351 | details_container.addClass('hidden'); |
---|
352 | |
---|
353 | return( false ); |
---|
354 | |
---|
355 | }).end() |
---|
356 | .find(".button.submit").click(function(event){ |
---|
357 | |
---|
358 | $(this).submit(); |
---|
359 | |
---|
360 | details_container.accordion('activate',0); |
---|
361 | |
---|
362 | showGridButton.removeClass('hidden'); |
---|
363 | grid.addClass('hidden').jqGrid('GridDestroy'); |
---|
364 | |
---|
365 | list_container.removeClass('hidden'); |
---|
366 | details_container.addClass('hidden'); |
---|
367 | |
---|
368 | return( false ); |
---|
369 | |
---|
370 | }).end() |
---|
371 | .find(".button.back").click(function(event){ |
---|
372 | |
---|
373 | details_container.accordion('activate',0); |
---|
374 | |
---|
375 | return( false ); |
---|
376 | |
---|
377 | }).end() |
---|
378 | .find(".button.forth").click(function(event){ |
---|
379 | |
---|
380 | details_container.accordion('activate',1); |
---|
381 | |
---|
382 | return( false ); |
---|
383 | |
---|
384 | }).end() |
---|
385 | |
---|
386 | //$( ".expresso-window-container .rule-details-container" ).accordion(); |
---|
387 | // var removeURL = new RegExp("^*.#"); |
---|
388 | |
---|
389 | // ------------------------------------------------------------ |
---|
390 | // ------------------------------------------------------------ |
---|
391 | |
---|
392 | //jqgrid |
---|
393 | .end().find(".fields-search-messages .button.search") |
---|
394 | |
---|
395 | .click(function(){ |
---|
396 | |
---|
397 | var rule = DataLayer.form( form ); |
---|
398 | |
---|
399 | showGridButton = $(this).parent(); |
---|
400 | |
---|
401 | var connect = rule.isExact ? "AND" : "OR"; |
---|
402 | |
---|
403 | var filter = $.map( rule.criteria, function( criteria, i ){ |
---|
404 | |
---|
405 | if( i === 0 ) |
---|
406 | return {"0": criteria.field, "1": criteria.operator, "2": criteria.value}; |
---|
407 | else |
---|
408 | return {"0": connect, "1": criteria.field, "2": criteria.operator, "3": criteria.value}; |
---|
409 | }); |
---|
410 | |
---|
411 | $.ajax( { |
---|
412 | url: DataLayer.basePath + 'folder/INBOX/message&' + $.param( {"filter": filter} ), |
---|
413 | |
---|
414 | dataType: 'json', |
---|
415 | |
---|
416 | success: function(data){ |
---|
417 | |
---|
418 | allMessages = data; |
---|
419 | |
---|
420 | grid = showGridButton.addClass('hidden') |
---|
421 | .siblings(".fields-search-messages-grid, .fields-search-messages-grid-pager") |
---|
422 | .removeClass('hidden').filter(".fields-search-messages-grid").jqGrid({ |
---|
423 | |
---|
424 | url: DataLayer.basePath + 'folder/INBOX/message&' + $.param( {"filter": [ "msgNumber", "IN", data ]} ), |
---|
425 | datatype: "json", |
---|
426 | mtype: 'GET', |
---|
427 | colNames:['#', ' ', 'De', 'Assunto', 'Data', 'Tamanho'], |
---|
428 | colModel:[ |
---|
429 | {name:'msg_number',index:'msg_number', width:45, hidden:true, sortable:false}, |
---|
430 | {name:'flags',index:'msg_number', width:40, sortable:false, formatter:flags2Class}, |
---|
431 | {name:'from.name',index:'msg_number', width:130, sortable:false}, |
---|
432 | {name:'subject',index:'subject', width:250, sortable:false}, |
---|
433 | {name:'timestamp',index:'timestamp', width:65, align:"center", sortable:false, formatter:date2Time}, |
---|
434 | {name:'size',index:'size', width:50, align:"right", sortable:false, formatter:bytes2Size} |
---|
435 | ], |
---|
436 | jsonReader : { |
---|
437 | root:"rows", |
---|
438 | page: "page", |
---|
439 | total: "total", |
---|
440 | records: "records", |
---|
441 | repeatitems: false, |
---|
442 | id: "0" |
---|
443 | }, |
---|
444 | rowNum:10, |
---|
445 | rowList:[10,25,50], |
---|
446 | pager: '#fields-search-messages-grid-pager', |
---|
447 | sortname: 'id', |
---|
448 | viewrecords: true, |
---|
449 | sortorder: "desc", |
---|
450 | multiselect: true, |
---|
451 | autowidth: true, |
---|
452 | height:40, |
---|
453 | loadComplete: function(data) { |
---|
454 | // // aplica o contador |
---|
455 | // jQuery('.timable').each(function (i) { |
---|
456 | // jQuery(this).countdown({ |
---|
457 | // since: new Date(parseInt(this.title)), |
---|
458 | // significant: 1, |
---|
459 | // layout: 'há {d<}{dn} {dl} {d>}{h<}{hn} {hl} {h>}{m<}{mn} {ml} {m>}{s<}{sn} {sl}{s>}', |
---|
460 | // description: ' atrás' |
---|
461 | // }); |
---|
462 | // }); |
---|
463 | }, |
---|
464 | onSelectRow: function (id, selected) { |
---|
465 | |
---|
466 | if( selected ) |
---|
467 | selectedMessages[ id ] = true; |
---|
468 | else |
---|
469 | delete selectedMessages[ id ]; |
---|
470 | |
---|
471 | }, |
---|
472 | caption: 'Mensagens que atendem aos critérios' |
---|
473 | }); |
---|
474 | } |
---|
475 | } ); |
---|
476 | |
---|
477 | |
---|
478 | }); |
---|
479 | |
---|
480 | vacation_container.find( ".menu-container" ) |
---|
481 | .find(".button.back").click(function(event){ |
---|
482 | |
---|
483 | list_container.removeClass('hidden'); |
---|
484 | vacation_container.addClass('hidden'); |
---|
485 | |
---|
486 | return( false ); |
---|
487 | |
---|
488 | }).end() |
---|
489 | .find(".button.submit").click(function(event){ |
---|
490 | |
---|
491 | $(this).submit(); |
---|
492 | |
---|
493 | list_container.removeClass('hidden'); |
---|
494 | vacation_container.addClass('hidden'); |
---|
495 | return( false ); |
---|
496 | }); |
---|
497 | |
---|
498 | } |
---|
499 | |
---|
500 | var reraster = function( html ){ |
---|
501 | |
---|
502 | //$(".rule-list-container").next().addClass("hidden"); |
---|
503 | |
---|
504 | list_container.find( '.ui-widget' ).remove(); |
---|
505 | |
---|
506 | list_container.html( html ).find(".button").button(); |
---|
507 | |
---|
508 | formatter(); |
---|
509 | } |
---|
510 | |
---|
511 | var formatter = function(){ |
---|
512 | |
---|
513 | checkBoxes = container.find(".rule-list").selectable({ |
---|
514 | selecting: function(event, ui) { |
---|
515 | $(ui.selecting).find(':checkbox').attr('checked', true); |
---|
516 | }, |
---|
517 | unselecting: function(event, ui) { |
---|
518 | $(ui.unselecting).find(':checkbox').attr('checked', false); |
---|
519 | } |
---|
520 | }) |
---|
521 | .find(':checkbox').change(function () { |
---|
522 | |
---|
523 | // if ($(this).attr("checked")) |
---|
524 | // $(this).parents('.rule').addClass('ui-selected'); |
---|
525 | // else |
---|
526 | $(this).parents('.rule').toggleClass('ui-selected'); |
---|
527 | |
---|
528 | }); |
---|
529 | |
---|
530 | list_container.children() |
---|
531 | |
---|
532 | .filter( ".fields-add" ) |
---|
533 | |
---|
534 | .find(".button.add").click(function(){ |
---|
535 | |
---|
536 | list_container.addClass('hidden'); |
---|
537 | details_container.removeClass('hidden'); |
---|
538 | form.get(0).reset(); |
---|
539 | |
---|
540 | return( false ); |
---|
541 | }) |
---|
542 | .filter(".vacation").click(function(){ |
---|
543 | |
---|
544 | details_container.addClass('hidden'); |
---|
545 | vacation_container.removeClass('hidden'); |
---|
546 | form.get(0).reset(); |
---|
547 | |
---|
548 | return( false ); |
---|
549 | |
---|
550 | }).end().end() |
---|
551 | |
---|
552 | .end().filter( ".fields-selected-itens" ) |
---|
553 | |
---|
554 | .find(".button.enable").click(function(){ |
---|
555 | |
---|
556 | var values = []; |
---|
557 | |
---|
558 | checkBoxes.filter(':checked').parents(".rule-list").find('.title').each(function(){ |
---|
559 | |
---|
560 | values[ values.length ] = { id: this.innerHTML, enabled: true }; |
---|
561 | |
---|
562 | }); |
---|
563 | |
---|
564 | DataLayer.put( 'filter', values ); |
---|
565 | |
---|
566 | }).end() |
---|
567 | |
---|
568 | .find(".button.disable").click(function(){ |
---|
569 | |
---|
570 | var values = []; |
---|
571 | |
---|
572 | checkBoxes.filter(':checked').parents(".rule-list").find('.title').each(function(){ |
---|
573 | |
---|
574 | values[ values.length ] = { id: this.innerHTML, enabled: false }; |
---|
575 | |
---|
576 | }); |
---|
577 | |
---|
578 | DataLayer.put( 'filter', values ); |
---|
579 | |
---|
580 | }).end() |
---|
581 | |
---|
582 | .find(".button.delete").click(function(){ |
---|
583 | |
---|
584 | checkBoxes.filter(':checked').parents(".rule-list").find('.title').each(function(i, o){ |
---|
585 | |
---|
586 | DataLayer.remove( 'filter', o.html() ); |
---|
587 | |
---|
588 | }); |
---|
589 | |
---|
590 | }).end() |
---|
591 | |
---|
592 | |
---|
593 | .end().find( ".menu-control .button" ).filter(".update").button({ |
---|
594 | icons: { |
---|
595 | primary: "ui-icon-pencil" |
---|
596 | }, |
---|
597 | text: false |
---|
598 | }).end() |
---|
599 | |
---|
600 | .filter(".enable, .disable").click( function(event) { |
---|
601 | |
---|
602 | var id = $(this).parents("li.rule").find('.title').html(); |
---|
603 | |
---|
604 | DataLayer.put( 'filter', id, { enabled: !$(this).is('.enable') } ); |
---|
605 | }) |
---|
606 | |
---|
607 | .filter(".enable").button({ |
---|
608 | icons: { |
---|
609 | primary: "ui-icon-circle-check" |
---|
610 | }, |
---|
611 | text: false |
---|
612 | }).end() |
---|
613 | |
---|
614 | .filter(".disable").button({ |
---|
615 | icons: { |
---|
616 | primary: "ui-icon-circle-close" |
---|
617 | }, |
---|
618 | text: false |
---|
619 | }).end().end() |
---|
620 | |
---|
621 | .filter(".close").button({ |
---|
622 | icons: { |
---|
623 | primary: "ui-icon-close" |
---|
624 | }, |
---|
625 | text: false |
---|
626 | }).click( function(event) { |
---|
627 | $(event.target) |
---|
628 | .parents("li.rule").find('.title') |
---|
629 | .each( function(){ |
---|
630 | |
---|
631 | DataLayer.remove( 'filter', $(this).html() ); |
---|
632 | |
---|
633 | }).end().remove(); |
---|
634 | }).end() |
---|
635 | |
---|
636 | .filter(".update").click(function(event){ |
---|
637 | |
---|
638 | var id = ( event.target.href || event.target.parentNode.href ).replace( new RegExp("^.*#"), "" ); |
---|
639 | |
---|
640 | var data = DataLayer.get( 'filter', id ); |
---|
641 | |
---|
642 | if( id === "vacation" ) |
---|
643 | { |
---|
644 | $('[name="vacation"]').val( data.actions[0].parameter ); |
---|
645 | |
---|
646 | list_container.addClass('hidden'); |
---|
647 | vacation_container.removeClass('hidden'); |
---|
648 | return; |
---|
649 | } |
---|
650 | |
---|
651 | showDetails( data ); |
---|
652 | |
---|
653 | list_container.addClass('hidden'); |
---|
654 | details_container.removeClass('hidden'); |
---|
655 | }).end() |
---|
656 | |
---|
657 | .removeClass('ui-button-icon-only'); |
---|
658 | }; |
---|
659 | // ------------------------------------------------------------ |
---|
660 | // ------------------------------------------------------------ |
---|
661 | */ |
---|
662 | |
---|
663 | function block_user_email(email) { |
---|
664 | //var id = "block_"+email; |
---|
665 | var idd = email; |
---|
666 | /** TODO - Mudar quando API abstrair atualizações no cache */ |
---|
667 | DataLayer.remove('filter', false); |
---|
668 | var filters = DataLayer.get('filter'); |
---|
669 | //var filters = DataLayer.get("filter", true); |
---|
670 | for(var index in filters){ |
---|
671 | if(filters[index].name == email) { |
---|
672 | if(confirm(get_lang("This user is already blocked. Would you like to unlock it?"))) { |
---|
673 | DataLayer.remove( 'filter', filters[index].id ); |
---|
674 | DataLayer.commit("filter", false, function(){ |
---|
675 | $.Zebra_Dialog(get_lang("Lock User") + " " + email + " " + get_lang("removed")); |
---|
676 | list_filters(); |
---|
677 | }); |
---|
678 | return true; |
---|
679 | }else |
---|
680 | return true; |
---|
681 | } |
---|
682 | } |
---|
683 | if(confirm(get_lang("Want to block the user") + " " + email + "?")){ |
---|
684 | DataLayer.put( 'filter', idd, |
---|
685 | { name: email, isExact: false, |
---|
686 | criteria:{ 0: {value: email, operator: "=", field: "from"} }, |
---|
687 | actions: { 0: {parameter: "INBOX/Spam", type: "fileinto"}}, |
---|
688 | enabled: true, |
---|
689 | id: email, |
---|
690 | block: true |
---|
691 | }); |
---|
692 | DataLayer.commit("filter", false, function(){ |
---|
693 | $.Zebra_Dialog(get_lang("User") + " " + email + " " + get_lang("blocked")); |
---|
694 | list_filters(); |
---|
695 | }); |
---|
696 | |
---|
697 | } |
---|
698 | } |
---|
699 | |
---|
700 | function list_filters(html){ |
---|
701 | /** TODO - Mudar quando API abstrair atualizações no cache */ |
---|
702 | DataLayer.remove('filter', false); |
---|
703 | var filters = DataLayer.get("filter"); |
---|
704 | var outoffice_active = false; |
---|
705 | var outoffice = false; |
---|
706 | for(var index in filters){ |
---|
707 | DataLayer.put( 'filter', filters[index].id, { enabled: (filters[index].enabled == "true" ? true: false)}); |
---|
708 | if(filters[index].id == "vacation") |
---|
709 | outoffice = true; |
---|
710 | if(filters[index].id == "vacation" && filters[index].enabled == "true"){ |
---|
711 | write_msg(get_lang("Attention, you are in out of office mode."), true); |
---|
712 | outoffice_active = true; |
---|
713 | break; |
---|
714 | } |
---|
715 | } |
---|
716 | DataLayer.commit( 'filter' ); |
---|
717 | if(!outoffice_active){ |
---|
718 | clean_msg(); |
---|
719 | } |
---|
720 | if(html){ |
---|
721 | if( ! $(".filters-windows").length ) |
---|
722 | container = $('.expressomail-module-container').append("<div class='filters-windows'></div>").find(".filters-windows").html( html ).find(".expresso-window-container"); |
---|
723 | list_container = $('.expressomail-module-container').find(".rule-list-container"); |
---|
724 | } |
---|
725 | list_container = $(".expresso-window-filters").dialog({ |
---|
726 | width:700, |
---|
727 | modal: true, |
---|
728 | resizable: false, |
---|
729 | closeOnEscape:true, |
---|
730 | close:function(event, ui) { |
---|
731 | event.stopPropagation(); |
---|
732 | if(list_container.find(".cancel").length) |
---|
733 | list_container.find(".cancel").trigger('click'); |
---|
734 | $(".dialog-head-buttonpane").hide(); |
---|
735 | }, |
---|
736 | open: function () { |
---|
737 | $(".ui-dialog .ui-dialog-titlebar") |
---|
738 | .append('<a href="#" class="ui-dialog-titlebar-minimize ui-corner-all" role="button"><span class="ui-icon ui-icon-minusthick">minimize</span></a>') |
---|
739 | .find('.ui-dialog-titlebar-minimize').click(function() { |
---|
740 | $(".ui-dialog-buttonpane, .ui-dialog-content").toggle(); |
---|
741 | $(".ui-icon-minusthick, .ui-icon-newwin").toggleClass('ui-icon-minusthick').toggleClass('ui-icon-newwin'); |
---|
742 | }); |
---|
743 | $(".dialog-head-buttonpane").show(); |
---|
744 | }, |
---|
745 | autoOpen: false, |
---|
746 | buttons: [{ |
---|
747 | text : get_lang("Close"), |
---|
748 | click : function() { |
---|
749 | $( this ).dialog( "close" ); |
---|
750 | } |
---|
751 | }] |
---|
752 | }); |
---|
753 | $(".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>"); |
---|
754 | $(".dialog-head-buttonpane").css("padding", "5px"). |
---|
755 | 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(); |
---|
756 | |
---|
757 | $(".ui-dialog-buttonpane.ui-widget-content").css("background-color", "#E0EEEE"); |
---|
758 | var list = DataLayer.render( BASE_PATH + 'modules/filters/filter-list.ejs', DataLayer.get("filter:detail", true)); |
---|
759 | list_container.html(list).find(".button").button(); |
---|
760 | |
---|
761 | list_container.find(".rule-list").selectable({ |
---|
762 | selecting: function(event, ui) { |
---|
763 | $(ui.selecting).find(':checkbox').attr('checked', true); |
---|
764 | }, |
---|
765 | unselecting: function(event, ui) { |
---|
766 | $(ui.unselecting).find(':checkbox').attr('checked', false); |
---|
767 | } |
---|
768 | }); |
---|
769 | |
---|
770 | list_container.find( ".menu-control .button" ).filter(".update").button({ |
---|
771 | icons: { |
---|
772 | primary: "ui-icon-pencil" |
---|
773 | }, |
---|
774 | text: false |
---|
775 | }).click(function(){ |
---|
776 | var id = $(this).parents("li.rule").find('.id').val(); |
---|
777 | var filters = DataLayer.get( 'filter', true); |
---|
778 | for(var i =0; i < filters.length; i++){ |
---|
779 | if(filters[i].id == id){ |
---|
780 | filters = filters[i]; |
---|
781 | break; |
---|
782 | } |
---|
783 | } |
---|
784 | DataLayer.render( BASE_PATH + 'modules/filters/edit-filter.ejs', {folders : DataLayer.get("folder", true), delimiter: cyrus_delimiter},function(html){ |
---|
785 | var details_container = $(".expresso-window-filters").html(html); |
---|
786 | if(filters.name != "vacation"){ |
---|
787 | form = container.find("form"); |
---|
788 | criterias = details_container.find( 'fieldset input[name="criteriaType[]"]' ); |
---|
789 | actions = details_container.find( 'fieldset input[name="actionType[]"]' ); |
---|
790 | nameObj = details_container.find( 'input[name="name"]' ); |
---|
791 | isExact = details_container.find( 'input[name="isExact"]' ); |
---|
792 | showDetails(filters); |
---|
793 | var accord = list_container.find(".rule-details-container").accordion({autoHeight: false}); |
---|
794 | list_container.find(".button").button().filter(".forth").click(function(){ |
---|
795 | accord.accordion('activate',1); |
---|
796 | }).end().filter(".back").click(function(){ |
---|
797 | accord.accordion('activate',0); |
---|
798 | }).end().filter(".cancel").click(function(){ |
---|
799 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
800 | }).end().filter(".submit").click(function(){ |
---|
801 | if(nameObj) |
---|
802 | nameObj.attr("disabled", "false"); |
---|
803 | if(valid_save()) |
---|
804 | $(this).submit(); |
---|
805 | else |
---|
806 | return; |
---|
807 | DataLayer.commit( 'filter', false,function(){ |
---|
808 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
809 | }); |
---|
810 | }); |
---|
811 | }else{ |
---|
812 | list_container.find(".vacation-details-container").removeClass("hidden"); |
---|
813 | list_container.find(".rule-details-container").addClass("hidden"); |
---|
814 | list_container.find(".button").button().filter(".back").click(function(){ |
---|
815 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
816 | }).end().filter(".submit").click(function(){ |
---|
817 | $(this).submit(); |
---|
818 | DataLayer.commit( 'filter', false,function(){ |
---|
819 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
820 | }); |
---|
821 | }); |
---|
822 | details_container.find('[name="vacation"]').val(filters.actions[0].parameter); |
---|
823 | } |
---|
824 | }); |
---|
825 | }).end() |
---|
826 | .filter(".enable").button({ |
---|
827 | icons: { |
---|
828 | primary: "ui-icon-circle-close" |
---|
829 | }, |
---|
830 | text: false |
---|
831 | }).click(function(){ |
---|
832 | var id = $(this).parents("li.rule").find('.id').val(); |
---|
833 | DataLayer.put( 'filter', id, { enabled: false }); |
---|
834 | DataLayer.commit("filter", false,function(){ |
---|
835 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
836 | }); |
---|
837 | }).end() |
---|
838 | |
---|
839 | .filter(".disable").button({ |
---|
840 | icons: { |
---|
841 | primary: "ui-icon-circle-check" |
---|
842 | }, |
---|
843 | text: false |
---|
844 | }).click(function(){ |
---|
845 | var id = $(this).parents("li.rule").find('.id').val(); |
---|
846 | DataLayer.put( 'filter', id, { enabled: true }); |
---|
847 | DataLayer.commit("filter", false,function(){ |
---|
848 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
849 | }); |
---|
850 | }).end() |
---|
851 | |
---|
852 | .filter(".close").button({ |
---|
853 | icons: { |
---|
854 | primary: "ui-icon-close" |
---|
855 | }, |
---|
856 | text: false |
---|
857 | }).click(function(event){ |
---|
858 | var filter_name = $(event.target).parents("li.rule").find('.id').val(); |
---|
859 | var filter_screen_name = $(event.target).parents("li.rule").find('.title').html(); |
---|
860 | $.Zebra_Dialog(get_lang("Are you sure to delete the filter") + ": <strong>"+filter_screen_name+"</strong>",{ |
---|
861 | 'type': 'question', |
---|
862 | 'title': get_lang("Exclusion Confirmation"), |
---|
863 | 'buttons': [get_lang('Yes'), get_lang('No')], |
---|
864 | 'onClose': function(caption) { |
---|
865 | if(caption == get_lang('Yes')){ |
---|
866 | /** TODO - Mudar quando API abstrair atualizações no cache */ |
---|
867 | DataLayer.remove('filter', false); |
---|
868 | DataLayer.get('filter'); |
---|
869 | DataLayer.remove( 'filter', filter_name); |
---|
870 | DataLayer.commit("filter", false,function(){ |
---|
871 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
872 | }); |
---|
873 | }else{ |
---|
874 | $(event.target).removeClass("ui-selected").parent().removeClass("ui-selected"); |
---|
875 | } |
---|
876 | } |
---|
877 | }); |
---|
878 | }).end().removeClass("ui-button-icon-only"); |
---|
879 | |
---|
880 | list_container.parent().find(".button.add:first").click(function(){ |
---|
881 | list_container.parent().find(".dialog-head-buttonpane").addClass("hidden"); |
---|
882 | DataLayer.render( BASE_PATH + 'modules/filters/edit-filter.ejs', {folders : DataLayer.get("folder", true), delimiter: cyrus_delimiter},function(html){ |
---|
883 | list_container.html(html); |
---|
884 | var accord = list_container.find(".rule-details-container").accordion({autoHeight: false}); |
---|
885 | list_container.find(".button").button().filter(".forth").click(function(){ |
---|
886 | accord.accordion('activate',1); |
---|
887 | }).end().filter(".back").click(function(){ |
---|
888 | accord.accordion('activate',0); |
---|
889 | }).end().filter(".cancel").click(function(){ |
---|
890 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
891 | }).end().filter(".submit").click(function() { |
---|
892 | if(valid_save()) |
---|
893 | $(this).submit(); |
---|
894 | else |
---|
895 | return; |
---|
896 | DataLayer.commit( 'filter',false,function(){ |
---|
897 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
898 | }); |
---|
899 | }).end().filter('.button.search').click(function() { |
---|
900 | /* Valida se o usuário preencheu as informações */ |
---|
901 | if(valid_save()) |
---|
902 | { |
---|
903 | var criteria_list = list_container.find('[name="criteriaValue[]"]'); |
---|
904 | var criteria_operator_list = list_container.find('[name="criteriaOperator[]"]'); |
---|
905 | var criteria_value = ""; |
---|
906 | var criteria = ""; |
---|
907 | $.each(criteria_list, function(index, value){ |
---|
908 | criteria += $.trim($(criteria_list[index]).val()) + ","; |
---|
909 | }); |
---|
910 | var criteria_ = criteria.split(","); |
---|
911 | var criteria_operator = ""; |
---|
912 | $.each(criteria_operator_list, function(index, value){ |
---|
913 | criteria_operator += $.trim($(criteria_list[index]).val()) != "" ? index + "," : ","; |
---|
914 | criteria_value += $.trim($(criteria_operator_list[index]).val()) + ","; |
---|
915 | }); |
---|
916 | var criteria_operator_ = criteria_operator.split(","); |
---|
917 | var criteria_value_ = criteria_value.split(","); |
---|
918 | var options = ["from", "to", "subject", "body", "size"]; |
---|
919 | var criterias_ = new Array(); |
---|
920 | var j = 0; |
---|
921 | for (i in criteria_) { |
---|
922 | if(criteria_[i] != "") { |
---|
923 | (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]}; |
---|
924 | j++; |
---|
925 | } |
---|
926 | } |
---|
927 | showGridButton = $(this).parent(); |
---|
928 | $.ajax({ |
---|
929 | url: DataLayer.basePath + 'folder/INBOX/message&' + $.param( {"filter": criterias_} ), |
---|
930 | dataType: 'json', |
---|
931 | success: function(data){ |
---|
932 | allMessages = data; |
---|
933 | var parametro = ""; |
---|
934 | (data != false) ? parametro = {"filter": [ "msgNumber", "IN", data ]} : parametro = {"filter": criterias_}; |
---|
935 | |
---|
936 | grid = showGridButton.addClass('hidden') |
---|
937 | .siblings(".fields-search-messages-grid, .fields-search-messages-grid-pager") |
---|
938 | .removeClass('hidden').filter(".fields-search-messages-grid").jqGrid({ |
---|
939 | //url: DataLayer.basePath + 'folder/INBOX/message&' + $.param( {"filter": [ "msgNumber", "IN", data ]} ), |
---|
940 | url: DataLayer.basePath + 'folder/INBOX/message&' + $.param( parametro ), |
---|
941 | datatype: "json", |
---|
942 | mtype: 'GET', |
---|
943 | colNames:['#', ' ', 'De', 'Assunto', 'Data', 'Tamanho'], |
---|
944 | colModel:[ |
---|
945 | {name:'msg_number',index:'msg_number', width:45, hidden:true, sortable:false}, |
---|
946 | {name:'flags',index:'msg_number', width:40, sortable:false, formatter:flags2Class}, |
---|
947 | {name:'from.name',index:'msg_number', width:130, sortable:false}, |
---|
948 | {name:'subject',index:'subject', width:250, sortable:false}, |
---|
949 | {name:'timestamp',index:'timestamp', width:65, align:"center", sortable:false, formatter:date2Time}, |
---|
950 | {name:'size',index:'size', width:50, align:"right", sortable:false, formatter:bytes2Size} |
---|
951 | ], |
---|
952 | jsonReader : { |
---|
953 | root:"rows", |
---|
954 | page: "page", |
---|
955 | total: "total", |
---|
956 | records: "records", |
---|
957 | repeatitems: false, |
---|
958 | id: "0" |
---|
959 | }, |
---|
960 | rowNum:10, |
---|
961 | //rowList:[10,25,50], |
---|
962 | rowList:[10], |
---|
963 | pager: '#fields-search-messages-grid-pager', |
---|
964 | sortname: 'id', |
---|
965 | viewrecords: true, |
---|
966 | sortorder: "desc", |
---|
967 | multiselect: true, |
---|
968 | autowidth: true, |
---|
969 | height:40, |
---|
970 | loadComplete: function(data) { |
---|
971 | // // aplica o contador |
---|
972 | // jQuery('.timable').each(function (i) { |
---|
973 | // jQuery(this).countdown({ |
---|
974 | // since: new Date(parseInt(this.title)), |
---|
975 | // significant: 1, |
---|
976 | // layout: 'há {d<}{dn} {dl} {d>}{h<}{hn} {hl} {h>}{m<}{mn} {ml} {m>}{s<}{sn} {sl}{s>}', |
---|
977 | // description: ' atrás' |
---|
978 | // }); |
---|
979 | // }); |
---|
980 | }, |
---|
981 | onSelectRow: function (id, selected) { |
---|
982 | if( selected ) |
---|
983 | { |
---|
984 | selectedMessages[ id ] = true; |
---|
985 | } |
---|
986 | else |
---|
987 | { |
---|
988 | delete selectedMessages[ id ]; |
---|
989 | } |
---|
990 | }, |
---|
991 | caption: 'Mensagens que atendem aos critérios' |
---|
992 | }); // end jqGrid |
---|
993 | } // end success |
---|
994 | }); // end ajax |
---|
995 | } |
---|
996 | else |
---|
997 | { |
---|
998 | return; |
---|
999 | } |
---|
1000 | }); // end function click |
---|
1001 | }); // end DataLayer.render |
---|
1002 | }); |
---|
1003 | list_container.parent().find(".button.add.vacation").click(function(){ |
---|
1004 | list_container.parent().find(".dialog-head-buttonpane").addClass("hidden"); |
---|
1005 | DataLayer.render( BASE_PATH + 'modules/filters/edit-filter.ejs', {folders : DataLayer.get("folder", true), delimiter: cyrus_delimiter},function(html){ |
---|
1006 | list_container.html(html); |
---|
1007 | list_container.find(".vacation-details-container").removeClass("hidden"); |
---|
1008 | list_container.find(".rule-details-container").addClass("hidden"); |
---|
1009 | list_container.find(".button").button().filter(".back").click(function(){ |
---|
1010 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
1011 | }).end().filter(".submit").click(function(){ |
---|
1012 | $(this).submit(); |
---|
1013 | DataLayer.commit( 'filter',false,function(){ |
---|
1014 | DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {},list_filters); |
---|
1015 | }); |
---|
1016 | }); |
---|
1017 | }); |
---|
1018 | }); |
---|
1019 | } |
---|
1020 | function init_filters(){ |
---|
1021 | var html = DataLayer.render( BASE_PATH + 'modules/filters/init.ejs', {}); |
---|
1022 | list_filters(html); |
---|
1023 | } |
---|