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