X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=plugins%2Fmanagesieve%2Fmanagesieve.js;h=1c6f2def642deeb1018da2d3c06eae8ca274ea0b;hb=5058e04171cbe6d82a65fc9d869ddef90e829e36;hp=04977eb1a9a841d84c038343b817de5b44f80f01;hpb=07e1de2dcd3f3ff8910a3680493f035b3c693cf0;p=roundcube.git diff --git a/plugins/managesieve/managesieve.js b/plugins/managesieve/managesieve.js index 04977eb..1c6f2de 100644 --- a/plugins/managesieve/managesieve.js +++ b/plugins/managesieve/managesieve.js @@ -1,56 +1,100 @@ -/* Sieve Filters (tab) */ +/* (Manage)Sieve Filters */ if (window.rcmail) { rcmail.addEventListener('init', function(evt) { + // add managesieve-create command to message_commands array, + // so it's state will be updated on message selection/unselection + if (rcmail.env.task == 'mail') { + if (rcmail.env.action != 'show') + rcmail.env.message_commands.push('managesieve-create'); + else + rcmail.enable_command('managesieve-create', true); + } + else { + var tab = $('').attr('id', 'settingstabpluginmanagesieve').addClass('tablink'), + button = $('').attr('href', rcmail.env.comm_path+'&_action=plugin.managesieve') + .attr('title', rcmail.gettext('managesieve.managefilters')) + .html(rcmail.gettext('managesieve.filters')) + .appendTo(tab); + + // add tab + rcmail.add_element(tab, 'tabs'); + } - var tab = $('').attr('id', 'settingstabpluginmanagesieve').addClass('tablink'); - var button = $('').attr('href', rcmail.env.comm_path+'&_action=plugin.managesieve') - .attr('title', rcmail.gettext('managesieve.managefilters')) - .html(rcmail.gettext('managesieve.filters')) - .appendTo(tab); - - // add button and register commands - rcmail.add_element(tab, 'tabs'); - rcmail.register_command('plugin.managesieve-save', function() { rcmail.managesieve_save() }, true); - rcmail.register_command('plugin.managesieve-add', function() { rcmail.managesieve_add() }, true); - rcmail.register_command('plugin.managesieve-del', function() { rcmail.managesieve_del() }, true); - rcmail.register_command('plugin.managesieve-up', function() { rcmail.managesieve_up() }, true); - rcmail.register_command('plugin.managesieve-down', function() { rcmail.managesieve_down() }, true); - rcmail.register_command('plugin.managesieve-set', function() { rcmail.managesieve_set() }, true); - rcmail.register_command('plugin.managesieve-setadd', function() { rcmail.managesieve_setadd() }, true); - rcmail.register_command('plugin.managesieve-setdel', function() { rcmail.managesieve_setdel() }, true); - rcmail.register_command('plugin.managesieve-setact', function() { rcmail.managesieve_setact() }, true); - rcmail.register_command('plugin.managesieve-setget', function() { rcmail.managesieve_setget() }, true); - - if (rcmail.env.action == 'plugin.managesieve') { + if (rcmail.env.task == 'mail' || rcmail.env.action.indexOf('plugin.managesieve') != -1) { + // Create layer for form tips + if (!rcmail.env.framed) { + rcmail.env.ms_tip_layer = $('
'); + rcmail.env.ms_tip_layer.appendTo(document.body); + } + } + + // register commands + rcmail.register_command('plugin.managesieve-save', function() { rcmail.managesieve_save() }); + rcmail.register_command('plugin.managesieve-act', function() { rcmail.managesieve_act() }); + rcmail.register_command('plugin.managesieve-add', function() { rcmail.managesieve_add() }); + rcmail.register_command('plugin.managesieve-del', function() { rcmail.managesieve_del() }); + rcmail.register_command('plugin.managesieve-move', function() { rcmail.managesieve_move() }); + rcmail.register_command('plugin.managesieve-setadd', function() { rcmail.managesieve_setadd() }); + rcmail.register_command('plugin.managesieve-setdel', function() { rcmail.managesieve_setdel() }); + rcmail.register_command('plugin.managesieve-setact', function() { rcmail.managesieve_setact() }); + rcmail.register_command('plugin.managesieve-setget', function() { rcmail.managesieve_setget() }); + + if (rcmail.env.action == 'plugin.managesieve' || rcmail.env.action == 'plugin.managesieve-save') { if (rcmail.gui_objects.sieveform) { rcmail.enable_command('plugin.managesieve-save', true); + + // small resize for header element + $('select[name="_header[]"]', rcmail.gui_objects.sieveform).each(function() { + if (this.value == '...') this.style.width = '40px'; + }); + + // resize dialog window + if (rcmail.env.action == 'plugin.managesieve' && rcmail.env.task == 'mail') { + parent.rcmail.managesieve_dialog_resize(rcmail.gui_objects.sieveform); + } + + $('input[type="text"]:first', rcmail.gui_objects.sieveform).focus(); } else { - rcmail.enable_command('plugin.managesieve-del', 'plugin.managesieve-up', - 'plugin.managesieve-down', false); rcmail.enable_command('plugin.managesieve-add', 'plugin.managesieve-setadd', !rcmail.env.sieveconnerror); } - // Create layer for form tips - if (!rcmail.env.framed) { - rcmail.env.ms_tip_layer = $('
'); - rcmail.env.ms_tip_layer.appendTo(document.body); - } + var i, p = rcmail, setcnt, set = rcmail.env.currentset; if (rcmail.gui_objects.filterslist) { - var p = rcmail; - rcmail.filters_list = new rcube_list_widget(rcmail.gui_objects.filterslist, {multiselect:false, draggable:false, keyboard:false}); - rcmail.filters_list.addEventListener('select', function(o){ p.managesieve_select(o); }); + rcmail.filters_list = new rcube_list_widget(rcmail.gui_objects.filterslist, + {multiselect:false, draggable:true, keyboard:false}); + rcmail.filters_list.addEventListener('select', function(e) { p.managesieve_select(e); }); + rcmail.filters_list.addEventListener('dragstart', function(e) { p.managesieve_dragstart(e); }); + rcmail.filters_list.addEventListener('dragend', function(e) { p.managesieve_dragend(e); }); + rcmail.filters_list.row_init = function (row) { + row.obj.onmouseover = function() { p.managesieve_focus_filter(row); }; + row.obj.onmouseout = function() { p.managesieve_unfocus_filter(row); }; + }; rcmail.filters_list.init(); rcmail.filters_list.focus(); + } + + if (rcmail.gui_objects.filtersetslist) { + rcmail.filtersets_list = new rcube_list_widget(rcmail.gui_objects.filtersetslist, {multiselect:false, draggable:false, keyboard:false}); + rcmail.filtersets_list.addEventListener('select', function(e) { p.managesieve_setselect(e); }); + rcmail.filtersets_list.init(); + rcmail.filtersets_list.focus(); + + if (set != null) { + set = rcmail.managesieve_setid(set); + rcmail.filtersets_list.shift_start = set; + rcmail.filtersets_list.highlight_row(set, false); + } + setcnt = rcmail.filtersets_list.rowcount; rcmail.enable_command('plugin.managesieve-set', true); - rcmail.enable_command('plugin.managesieve-setact', 'plugin.managesieve-setget', rcmail.gui_objects.filtersetslist.length); - rcmail.enable_command('plugin.managesieve-setdel', rcmail.gui_objects.filtersetslist.length > 1); + rcmail.enable_command('plugin.managesieve-setact', 'plugin.managesieve-setget', setcnt); + rcmail.enable_command('plugin.managesieve-setdel', setcnt > 1); - $('#'+rcmail.buttons['plugin.managesieve-setact'][0].id).attr('title', rcmail.gettext('managesieve.filterset' - + (rcmail.gui_objects.filtersetslist.value == rcmail.env.active_set ? 'deact' : 'act'))); + // Fix dragging filters over sets list + $('tr', rcmail.gui_objects.filtersetslist).each(function (i, e) { p.managesieve_fixdragend(e); }); } } if (rcmail.gui_objects.sieveform && rcmail.env.rule_disabled) @@ -59,7 +103,7 @@ if (window.rcmail) { }; /*********************************************************/ -/********* Managesieve filters methods *********/ +/********* Managesieve UI methods *********/ /*********************************************************/ rcube_webmail.prototype.managesieve_add = function() @@ -71,23 +115,41 @@ rcube_webmail.prototype.managesieve_add = function() rcube_webmail.prototype.managesieve_del = function() { var id = this.filters_list.get_single_selection(); - if (confirm(this.get_label('managesieve.filterdeleteconfirm'))) - this.http_request('plugin.managesieve', - '_act=delete&_fid='+this.filters_list.rows[id].uid, true); + if (confirm(this.get_label('managesieve.filterdeleteconfirm'))) { + var lock = this.set_busy(true, 'loading'); + this.http_post('plugin.managesieve', + '_act=delete&_fid='+this.filters_list.rows[id].uid, lock); + } }; -rcube_webmail.prototype.managesieve_up = function() +rcube_webmail.prototype.managesieve_act = function() { - var id = this.filters_list.get_single_selection(); - this.http_request('plugin.managesieve', - '_act=up&_fid='+this.filters_list.rows[id].uid, true); + var id = this.filters_list.get_single_selection(), + lock = this.set_busy(true, 'loading'); + + this.http_post('plugin.managesieve', + '_act=act&_fid='+this.filters_list.rows[id].uid, lock); }; -rcube_webmail.prototype.managesieve_down = function() +// Filter selection +rcube_webmail.prototype.managesieve_select = function(list) { - var id = this.filters_list.get_single_selection(); - this.http_request('plugin.managesieve', - '_act=down&_fid='+this.filters_list.rows[id].uid, true); + var id = list.get_single_selection(); + if (id != null) + this.load_managesieveframe(list.rows[id].uid); +}; + +// Set selection +rcube_webmail.prototype.managesieve_setselect = function(list) +{ + this.show_contentframe(false); + this.filters_list.clear(true); + this.enable_command('plugin.managesieve-setdel', list.rowcount > 1); + this.enable_command( 'plugin.managesieve-setact', 'plugin.managesieve-setget', true); + + var id = list.get_single_selection(); + if (id != null) + this.managesieve_list(this.env.filtersets[id]); }; rcube_webmail.prototype.managesieve_rowid = function(id) @@ -97,196 +159,291 @@ rcube_webmail.prototype.managesieve_rowid = function(id) for (i=0; i id) + if (rows[i] != null && rows[i].uid > o.id) rows[i].uid = rows[i].uid-1; } + break; - case 'down': - var from, fromstatus, status, rows = this.filters_list.rows; + // Update filter row + case 'update': + var i, row = $('#rcmrow'+o.id); + + if (o.name) + $('td', row).html(o.name); + if (o.disabled) + row.addClass('disabled'); + else + row.removeClass('disabled'); + + $('#disabled', $('iframe').contents()).prop('checked', o.disabled); - // we need only to replace filter names... - for (var i=0; i'); + + $('td', row).html(o.name); + row.attr('id', 'rcmrow'+o.id); + if (o.disabled) + row.addClass('disabled'); + + list.insert_row(row.get(0)); + list.highlight_row(o.id); + + this.enable_command('plugin.managesieve-del', 'plugin.managesieve-act', true); - // we need only to replace filter names... - for (var i=0; i'); + + $('td', row).html(o.name); + row.attr('id', 'rcmrow'+id); + + this.env.filtersets[id] = o.name; + list.insert_row(row.get(0)); + + // move row into its position on the list + if (o.index != list.rowcount-1) { + row.detach(); + var elem = $('tr:visible', list.list).get(o.index); + row.insertBefore(elem); + } + + list.select(id); + + // Fix dragging filters over sets list + this.managesieve_fixdragend(row); + + break; } - this.gui_objects.sieveform.submit(); + + this.set_busy(false); }; // load filter frame rcube_webmail.prototype.load_managesieveframe = function(id) { - if (typeof(id) != 'undefined' && id != null) { - this.enable_command('plugin.managesieve-del', true); - this.filters_listbuttons(); - } - else - this.enable_command('plugin.managesieve-up', 'plugin.managesieve-down', 'plugin.managesieve-del', false); + var has_id = typeof(id) != 'undefined' && id != null; + this.enable_command('plugin.managesieve-act', 'plugin.managesieve-del', has_id); if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) { target = window.frames[this.env.contentframe]; var msgid = this.set_busy(true, 'loading'); - target.location.href = this.env.comm_path+'&_action=plugin.managesieve&_framed=1&_fid='+id+'&_unlock='+msgid; + target.location.href = this.env.comm_path+'&_action=plugin.managesieve&_framed=1' + +(id ? '&_fid='+id : '')+'&_unlock='+msgid; } }; -// enable/disable Up/Down buttons -rcube_webmail.prototype.filters_listbuttons = function() +// load filter frame +rcube_webmail.prototype.managesieve_dragstart = function(list) { - var id = this.filters_list.get_single_selection(), - rows = this.filters_list.rows; + var id = this.filters_list.get_single_selection(); - for (var i=0; i0 || buttons.length>1) { $(button).removeClass('disabled'); - button.removeAttribute('disabled'); } else { $(button).addClass('disabled'); - button.setAttribute('disabled', true); } } }; -// Set change -rcube_webmail.prototype.managesieve_set = function() +function rule_header_select(id) { - var script = $(this.gui_objects.filtersetslist).val(); - location.href = this.env.comm_path+'&_action=plugin.managesieve&_set='+script; -}; + var obj = document.getElementById('header' + id), + size = document.getElementById('rule_size' + id), + op = document.getElementById('rule_op' + id), + target = document.getElementById('rule_target' + id), + header = document.getElementById('custom_header' + id), + mod = document.getElementById('rule_mod' + id), + trans = document.getElementById('rule_trans' + id), + comp = document.getElementById('rule_comp' + id); + + if (obj.value == 'size') { + size.style.display = 'inline'; + op.style.display = 'none'; + target.style.display = 'none'; + header.style.display = 'none'; + mod.style.display = 'none'; + trans.style.display = 'none'; + comp.style.display = 'none'; + } + else { + header.style.display = obj.value != '...' ? 'none' : 'inline'; + size.style.display = 'none'; + op.style.display = 'inline'; + comp.style.display = ''; + rule_op_select(id); + mod.style.display = obj.value == 'body' ? 'none' : 'block'; + trans.style.display = obj.value == 'body' ? 'block' : 'none'; + } -// Script download -rcube_webmail.prototype.managesieve_setget = function() -{ - var script = $(this.gui_objects.filtersetslist).val(); - location.href = this.env.comm_path+'&_action=plugin.managesieve&_act=setget&_set='+script; + obj.style.width = obj.value == '...' ? '40px' : ''; }; -// Set activate -rcube_webmail.prototype.managesieve_setact = function() +function rule_op_select(id) { - if (!this.gui_objects.filtersetslist) - return false; + var obj = document.getElementById('rule_op' + id), + target = document.getElementById('rule_target' + id); - var script = this.gui_objects.filtersetslist.value, - action = (script == rcmail.env.active_set ? 'deact' : 'setact'); - - this.http_post('plugin.managesieve', '_act='+action+'&_set='+script); + target.style.display = obj.value == 'exists' || obj.value == 'notexists' ? 'none' : 'inline'; }; -// Set activate flag in sets list after set activation -rcube_webmail.prototype.managesieve_reset = function() +function rule_trans_select(id) { - if (!this.gui_objects.filtersetslist) - return false; - - var list = this.gui_objects.filtersetslist, - opts = list.getElementsByTagName('option'), - label = ' (' + this.get_label('managesieve.active') + ')', - regx = new RegExp(RegExp.escape(label)+'$'); - - for (var x=0; x iframe' : '#filter-box'), parent.document).offset(); top += offset.top; left += offset.left; } tip.html(e.data.str) top -= tip.height(); - + tip.css({left: left, top: top}).show(); }) - .bind('mouseleave', - function(e) { - var tip = parent.rcmail && parent.rcmail.env.ms_tip_layer ? - parent.rcmail.env.ms_tip_layer : rcmail.env.ms_tip_layer; - tip.hide(); - }); + .bind('mouseleave', function(e) { tip.hide(); }); } }; + +/*********************************************************/ +/********* Mail UI methods *********/ +/*********************************************************/ + +rcube_webmail.prototype.managesieve_create = function() +{ + if (!rcmail.env.sieve_headers || !rcmail.env.sieve_headers.length) + return; + + var i, html, buttons = {}, dialog = $("#sievefilterform"); + + // create dialog window + if (!dialog.length) { + dialog = $('
'); + $('body').append(dialog); + } + + // build dialog window content + html = '
'+this.gettext('managesieve.usedata')+'
    '; + for (i in rcmail.env.sieve_headers) + html += '
  • ' + +' '+rcmail.env.sieve_headers[i][1]+'
  • '; + html += '
'; + + dialog.html(html); + + // [Next Step] button action + buttons[this.gettext('managesieve.nextstep')] = function () { + // check if there's at least one checkbox checked + var hdrs = $('input[name="headers[]"]:checked', dialog); + if (!hdrs.length) { + alert(rcmail.gettext('managesieve.nodata')); + return; + } + + // build frame URL + var url = rcmail.get_task_url('mail'); + url = rcmail.add_url(url, '_action', 'plugin.managesieve'); + url = rcmail.add_url(url, '_framed', 1); + + hdrs.map(function() { + var val = rcmail.env.sieve_headers[this.value]; + url = rcmail.add_url(url, 'r['+this.value+']', val[0]+':'+val[1]); + }); + + // load form in the iframe + var frame = $('