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