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