From efe8de0b5b3dcc305cb8b353fd4dce8913052005 Mon Sep 17 00:00:00 2001 From: alec Date: Sun, 4 Sep 2011 06:44:18 +0000 Subject: - Added possibility to create a filter based on selected message "in-place" git-svn-id: https://svn.roundcube.net/trunk@5155 208e9e7b-5314-0410-a742-e7e81cd9613c --- plugins/managesieve/Changelog | 2 + plugins/managesieve/localization/en_US.inc | 6 +- plugins/managesieve/localization/pl_PL.inc | 4 + plugins/managesieve/managesieve.js | 184 ++++++++++++++++----- plugins/managesieve/managesieve.php | 150 ++++++++++++++++- plugins/managesieve/skins/default/filter.png | Bin 0 -> 547 bytes plugins/managesieve/skins/default/managesieve.css | 17 +- .../managesieve/skins/default/managesieve_mail.css | 63 +++++++ .../skins/default/templates/filteredit.html | 7 +- 9 files changed, 380 insertions(+), 53 deletions(-) create mode 100644 plugins/managesieve/skins/default/filter.png create mode 100644 plugins/managesieve/skins/default/managesieve_mail.css diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog index 4472ccf21..7c056fb76 100644 --- a/plugins/managesieve/Changelog +++ b/plugins/managesieve/Changelog @@ -1,3 +1,5 @@ +- Added possibility to create a filter based on selected message "in-place" + * version 4.3 [2011-07-28] ----------------------------------------------------------- - Fixed handling of error in Net_Sieve::listScripts() diff --git a/plugins/managesieve/localization/en_US.inc b/plugins/managesieve/localization/en_US.inc index f08357ed9..559e9a06c 100644 --- a/plugins/managesieve/localization/en_US.inc +++ b/plugins/managesieve/localization/en_US.inc @@ -77,6 +77,9 @@ $labels['flagdeleted'] = 'Deleted'; $labels['flaganswered'] = 'Answered'; $labels['flagflagged'] = 'Flagged'; $labels['flagdraft'] = 'Draft'; +$labels['filtercreate'] = 'Create filter'; +$labels['usedata'] = 'Use following data in the filter:'; +$labels['nextstep'] = 'Next Step'; $messages = array(); $messages['filterunknownerror'] = 'Unknown server error'; @@ -100,6 +103,7 @@ $messages['setdeleteconfirm'] = 'Are you sure, you want to delete selected filte $messages['setcreateerror'] = 'Unable to create filters set. Server error occured'; $messages['setcreated'] = 'Filters set created successfully'; $messages['emptyname'] = 'Unable to create filters set. Empty set name'; -$messages['nametoolong'] = 'Unable to create filters set. Name too long' +$messages['nametoolong'] = 'Unable to create filters set. Name too long'; +$messages['nodata'] = 'At least one position must be selected!'; ?> diff --git a/plugins/managesieve/localization/pl_PL.inc b/plugins/managesieve/localization/pl_PL.inc index 290dd1a46..4b088f0a6 100644 --- a/plugins/managesieve/localization/pl_PL.inc +++ b/plugins/managesieve/localization/pl_PL.inc @@ -78,6 +78,9 @@ $labels['flagdeleted'] = 'Usunięta'; $labels['flaganswered'] = 'Z odpowiedzią'; $labels['flagflagged'] = 'Oflagowana'; $labels['flagdraft'] = 'Szkic'; +$labels['filtercreate'] = 'Utwóż filtr'; +$labels['usedata'] = 'Użyj następujących danych do utworzenia filtra:'; +$labels['nextstep'] = 'Następny krok'; $messages = array(); $messages['filterunknownerror'] = 'Nieznany błąd serwera'; @@ -102,5 +105,6 @@ $messages['setcreateerror'] = 'Nie można utworzyć zbioru filtrów. Błąd serw $messages['setcreated'] = 'Zbiór filtrów został utworzony pomyślnie'; $messages['emptyname'] = 'Nie można utworzyć zbioru filtrów. Pusta nazwa zbioru'; $messages['nametoolong'] = 'Nie można utworzyć zbioru filtrów. Nazwa zbyt długa' +$messages['nodata'] = 'Należy wybrać co najmniej jedną pozycję!'; ?> diff --git a/plugins/managesieve/managesieve.js b/plugins/managesieve/managesieve.js index ec6247aff..9efbfe6b4 100644 --- a/plugins/managesieve/managesieve.js +++ b/plugins/managesieve/managesieve.js @@ -1,43 +1,59 @@ -/* 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-add', function() { rcmail.managesieve_add() }); + rcmail.register_command('plugin.managesieve-del', function() { rcmail.managesieve_del() }); + rcmail.register_command('plugin.managesieve-up', function() { rcmail.managesieve_up() }); + rcmail.register_command('plugin.managesieve-down', function() { rcmail.managesieve_down() }); + rcmail.register_command('plugin.managesieve-set', function() { rcmail.managesieve_set() }); + 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); + // 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); - } - 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}); @@ -479,17 +495,19 @@ rcube_webmail.prototype.managesieve_reload = function(set) // 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(), - tip = rcmail.env.framed ? parent.rcmail.env.ms_tip_layer : rcmail.env.ms_tip_layer, left = offset.left, top = offset.top - 12; - if (rcmail.env.framed) { - offset = $(parent.document.getElementById('filter-box')).offset(); + if (framed) { + offset = $((rcmail.env.task == 'mail' ? '#sievefilterform > iframe' : '#filter-box'), parent.document).offset(); top += offset.top; left += offset.left; } @@ -499,12 +517,7 @@ rcube_webmail.prototype.managesieve_tip_register = function(tips) 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(); }); } }; @@ -579,3 +592,98 @@ function action_type_select(id) elems[x].style.display = !enabled[x] ? 'none' : 'inline'; } }; + +/*********************************************************/ +/********* 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 = $('