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