From a393c37c4fdda083dc2afd525b489fe78a38ce0e Mon Sep 17 00:00:00 2001 From: alecpl Date: Thu, 21 May 2009 07:14:47 +0000 Subject: - managesieve plugin --- plugins/managesieve/managesieve.js | 381 +++++++++++++++++++++++++++++++++++++ 1 file changed, 381 insertions(+) create mode 100644 plugins/managesieve/managesieve.js (limited to 'plugins/managesieve/managesieve.js') diff --git a/plugins/managesieve/managesieve.js b/plugins/managesieve/managesieve.js new file mode 100644 index 000000000..09139d6c5 --- /dev/null +++ b/plugins/managesieve/managesieve.js @@ -0,0 +1,381 @@ +/* Sieve Filters (tab) */ + +if (window.rcmail) { + rcmail.addEventListener('init', function(evt) { + // + 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')) + .bind('click', function(e){ return rcmail.command('plugin.managesieve', this) }) + .appendTo(tab); + + // add button and register commands + rcmail.add_element(tab, 'tabs'); + rcmail.register_command('plugin.managesieve', function() { rcmail.goto_url('plugin.managesieve') }, true); + 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); + + if (rcmail.env.action == 'plugin.managesieve') + { + if (rcmail.gui_objects.sieveform) + rcmail.enable_command('plugin.managesieve-save', true); + else { + rcmail.enable_command('plugin.managesieve-del', 'plugin.managesieve-up', 'plugin.managesieve-down', false); + rcmail.enable_command('plugin.managesieve-add', !rcmail.env.sieveconnerror); + } + + 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.init(); + rcmail.filters_list.focus(); + } + } + }); + + /*********************************************************/ + /********* Managesieve filters methods *********/ + /*********************************************************/ + + rcube_webmail.prototype.managesieve_add = function() + { + this.load_managesieveframe(); + this.filters_list.clear_selection(); + }; + + rcube_webmail.prototype.managesieve_del = function() + { + var id = this.filters_list.get_single_selection(); + + if (confirm(this.get_label('managesieve.filterconfirmdelete'))) + this.http_request('plugin.managesieve', + '_act=delete&_fid='+this.filters_list.rows[id].uid, true); + }; + + rcube_webmail.prototype.managesieve_up = function() + { + var id = this.filters_list.get_single_selection(); + this.http_request('plugin.managesieve', + '_act=up&_fid='+this.filters_list.rows[id].uid, true); + }; + + rcube_webmail.prototype.managesieve_down = function() + { + var id = this.filters_list.get_single_selection(); + this.http_request('plugin.managesieve', + '_act=down&_fid='+this.filters_list.rows[id].uid, true); + }; + + rcube_webmail.prototype.managesieve_rowid = function(id) + { + var rows = this.filters_list.rows; + + for (var i=0; i id) + rows[i].uid = rows[i].uid-1; + } + break; + + case 'down': + var rows = this.filters_list.rows; + var from; + + // we need only to replace filter names... + for (var i=0; i0; i--) + { + if (rows[i] == null) { // removed row + } else if (i == id) { + this.enable_command('plugin.managesieve-down', false); + break; + } else { + this.enable_command('plugin.managesieve-down', true); + break; + } + } + }; + + // operations on filters form + rcube_webmail.prototype.managesieve_ruleadd = function(id) + { + this.http_post('plugin.managesieve', '_act=ruleadd&_rid='+id); + }; + + rcube_webmail.prototype.managesieve_rulefill = function(content, id, after) + { + if (content != '') + { + // create new element + var div = document.getElementById('rules'); + var row = document.createElement('div'); + + this.managesieve_insertrow(div, row, after); + // fill row after inserting (for IE) + row.setAttribute('id', 'rulerow'+id); + row.className = 'rulerow'; + row.innerHTML = content; + + this.managesieve_formbuttons(div); + } + }; + + rcube_webmail.prototype.managesieve_ruledel = function(id) + { + if (confirm(this.get_label('managesieve.ruledeleteconfirm'))) + { + var row = document.getElementById('rulerow'+id); + row.parentNode.removeChild(row); + this.managesieve_formbuttons(document.getElementById('rules')); + } + }; + + rcube_webmail.prototype.managesieve_actionadd = function(id) + { + this.http_post('plugin.managesieve', '_act=actionadd&_aid='+id); + }; + + rcube_webmail.prototype.managesieve_actionfill = function(content, id, after) + { + if (content != '') + { + var div = document.getElementById('actions'); + var row = document.createElement('div'); + + this.managesieve_insertrow(div, row, after); + // fill row after inserting (for IE) + row.className = 'actionrow'; + row.setAttribute('id', 'actionrow'+id); + row.innerHTML = content; + + this.managesieve_formbuttons(div); + } + }; + + rcube_webmail.prototype.managesieve_actiondel = function(id) + { + if (confirm(this.get_label('managesieve.actiondeleteconfirm'))) + { + var row = document.getElementById('actionrow'+id); + row.parentNode.removeChild(row); + this.managesieve_formbuttons(document.getElementById('actions')); + } + }; + + // insert rule/action row in specified place on the list + rcube_webmail.prototype.managesieve_insertrow = function(div, row, after) + { + for (var i=0; i0 || buttons.length>1) + { + $(button).removeClass('disabled'); + button.removeAttribute('disabled'); + } + else + { + $(button).addClass('disabled'); + button.setAttribute('disabled', true); + } + } + } +} -- cgit v1.2.3