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