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