X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=plugins%2Fmanagesieve%2Fmanagesieve.js;h=a8bfaf203c5047a832b8febf4c206abbad23ea9d;hb=76507f7c63a660742e76889ad6e3919f3dde3bb0;hp=7ff1acf73389f9d10c8c2f70ad2b4ccab720611e;hpb=b68022ca3782d5eb5a1a7ef6f8cf7abe1dc15bd6;p=roundcube.git
diff --git a/plugins/managesieve/managesieve.js b/plugins/managesieve/managesieve.js
index 7ff1acf..a8bfaf2 100644
--- a/plugins/managesieve/managesieve.js
+++ b/plugins/managesieve/managesieve.js
@@ -1,381 +1,769 @@
-/* Sieve Filters (tab) */
+/* (Manage)Sieve Filters */
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();
- }
+ // 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');
+ }
+
+ 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-add', 'plugin.managesieve-setadd', !rcmail.env.sieveconnerror);
+ }
+
+ var i, p = rcmail, setcnt, set = rcmail.env.currentset;
+
+ if (rcmail.gui_objects.filterslist) {
+ rcmail.filters_list = new rcube_list_widget(rcmail.gui_objects.filterslist,
+ {multiselect:false, draggable:true, keyboard:false});
+ rcmail.filters_list.addEventListener('select', function(o){ p.managesieve_select(o); });
+ rcmail.filters_list.addEventListener('dragstart', function(o){ p.managesieve_dragstart(o); });
+ 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(o){ p.managesieve_setselect(o); });
+ 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', setcnt);
+ rcmail.enable_command('plugin.managesieve-setdel', setcnt > 1);
+ }
+ }
+ if (rcmail.gui_objects.sieveform && rcmail.env.rule_disabled)
+ $('#disabled').attr('checked', true);
});
+};
+
+/*********************************************************/
+/********* Managesieve UI 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.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_act = function()
+{
+ 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);
+};
+
+// Filter selection
+rcube_webmail.prototype.managesieve_select = function(list)
+{
+ 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)
+{
+ var i, rows = this.filters_list.rows;
+
+ for (i=0; i o.id)
+ rows[i].uid = rows[i].uid-1;
+ }
- /*********************************************************/
- /********* Managesieve filters methods *********/
- /*********************************************************/
+ break;
- rcube_webmail.prototype.managesieve_add = function()
- {
- this.load_managesieveframe();
- this.filters_list.clear_selection();
- };
+ // Update filter row
+ case 'update':
+ var i, row = $('#rcmrow'+o.id);
- rcube_webmail.prototype.managesieve_del = function()
- {
- var id = this.filters_list.get_single_selection();
+ if (o.name)
+ $('td', row).html(o.name);
+ if (o.disabled)
+ row.addClass('disabled');
+ else
+ row.removeClass('disabled');
- if (confirm(this.get_label('managesieve.filterconfirmdelete')))
- this.http_request('plugin.managesieve',
- '_act=delete&_fid='+this.filters_list.rows[id].uid, true);
- };
+ $('#disabled', $('iframe').contents()).prop('checked', o.disabled);
- 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);
- };
+ break;
- 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);
- };
+ // Add filter row to the list
+ case 'add':
+ var list = this.filters_list,
+ row = $(' |
');
- 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;
- }
- }
- };
+ break;
- // operations on filters form
- rcube_webmail.prototype.managesieve_ruleadd = function(id)
- {
- this.http_post('plugin.managesieve', '_act=ruleadd&_rid='+id);
- };
+ // Delete set row
+ case 'setdel':
+ var id = this.managesieve_setid(o.name);
- 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);
- }
- };
+ this.filtersets_list.remove_row(id);
+ this.filters_list.clear();
+ this.show_contentframe(false);
+ this.enable_command('plugin.managesieve-setdel', 'plugin.managesieve-setact', 'plugin.managesieve-setget', false);
- 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'));
- }
- };
+ delete this.env.filtersets[id];
- rcube_webmail.prototype.managesieve_actionadd = function(id)
- {
- this.http_post('plugin.managesieve', '_act=actionadd&_aid='+id);
- };
+ break;
- 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);
- }
- };
+ // Create set row
+ case 'setadd':
+ var id = 'S' + new Date().getTime(),
+ list = this.filtersets_list,
+ row = $(' |
');
- 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'));
- }
- };
+ $('td', row).html(o.name);
+ row.attr('id', 'rcmrow'+id);
- // 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');
+ }
+ else {
+ $(button).addClass('disabled');
+ }
+ }
+};
+
+function rule_header_select(id)
+{
+ 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';
+ }
+
+ obj.style.width = obj.value == '...' ? '40px' : '';
+};
+
+function rule_op_select(id)
+{
+ var obj = document.getElementById('rule_op' + id),
+ target = document.getElementById('rule_target' + id);
+
+ target.style.display = obj.value == 'exists' || obj.value == 'notexists' ? 'none' : 'inline';
+};
+
+function rule_trans_select(id)
+{
+ var obj = document.getElementById('rule_trans_op' + id),
+ target = document.getElementById('rule_trans_type' + id);
+
+ target.style.display = obj.value != 'content' ? 'none' : 'inline';
+};
+
+function rule_mod_select(id)
+{
+ var obj = document.getElementById('rule_mod_op' + id),
+ target = document.getElementById('rule_mod_type' + id);
+
+ target.style.display = obj.value != 'address' && obj.value != 'envelope' ? 'none' : 'inline';
+};
+
+function rule_join_radio(value)
+{
+ $('#rules').css('display', value == 'any' ? 'none' : 'block');
+};
+
+function rule_adv_switch(id, elem)
+{
+ var elem = $(elem), enabled = elem.hasClass('hide'), adv = $('#rule_advanced'+id);
+
+ if (enabled) {
+ adv.hide();
+ elem.removeClass('hide').addClass('show');
+ }
+ else {
+ adv.show();
+ elem.removeClass('show').addClass('hide');
+ }
+}
- for (i=0; i0 || buttons.length>1)
- {
- $(button).removeClass('disabled');
- button.removeAttribute('disabled');
- }
- else
- {
- $(button).addClass('disabled');
- button.setAttribute('disabled', true);
- }
- }
+function action_type_select(id)
+{
+ var obj = document.getElementById('action_type' + id),
+ enabled = {},
+ elems = {
+ mailbox: document.getElementById('action_mailbox' + id),
+ target: document.getElementById('action_target' + id),
+ target_area: document.getElementById('action_target_area' + id),
+ flags: document.getElementById('action_flags' + id),
+ vacation: document.getElementById('action_vacation' + id)
+ };
+
+ if (obj.value == 'fileinto' || obj.value == 'fileinto_copy') {
+ enabled.mailbox = 1;
+ }
+ else if (obj.value == 'redirect' || obj.value == 'redirect_copy') {
+ enabled.target = 1;
+ }
+ else if (obj.value.match(/^reject|ereject$/)) {
+ enabled.target_area = 1;
+ }
+ else if (obj.value.match(/^(add|set|remove)flag$/)) {
+ enabled.flags = 1;
+ }
+ else if (obj.value == 'vacation') {
+ enabled.vacation = 1;
+ }
+
+ for (var x in elems) {
+ elems[x].style.display = !enabled[x] ? 'none' : 'inline';
+ }
+};
+
+// Register onmouse(leave/enter) events for tips on specified form element
+rcube_webmail.prototype.managesieve_tip_register = function(tips)
+{
+ var n, framed = parent.rcmail,
+ tip = framed ? parent.rcmail.env.ms_tip_layer : rcmail.env.ms_tip_layer;
+
+ for (var n in tips) {
+ $('#'+tips[n][0])
+ .bind('mouseenter', {str: tips[n][1]},
+ function(e) {
+ var offset = $(this).offset(),
+ left = offset.left,
+ top = offset.top - 12;
+
+ if (framed) {
+ offset = $((rcmail.env.task == 'mail' ? '#sievefilterform > 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) { 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 = '';
+
+ 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 = $('