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