| | |
| | | /* (Manage)Sieve Filters */ |
| | | /** |
| | | * (Manage)Sieve Filters plugin |
| | | * |
| | | * @licstart The following is the entire license notice for the |
| | | * JavaScript code in this file. |
| | | * |
| | | * Copyright (c) 2012-2014, The Roundcube Dev Team |
| | | * |
| | | * The JavaScript code in this page is free software: you can redistribute it |
| | | * and/or modify it under the terms of the GNU General Public License |
| | | * as published by the Free Software Foundation, either version 3 of |
| | | * the License, or (at your option) any later version. |
| | | * |
| | | * @licend The above is the entire license notice |
| | | * for the JavaScript code in this file. |
| | | */ |
| | | |
| | | if (window.rcmail) { |
| | | rcmail.addEventListener('init', function(evt) { |
| | |
| | | rcmail.env.message_commands.push('managesieve-create'); |
| | | else |
| | | rcmail.enable_command('managesieve-create', true); |
| | | } |
| | | else { |
| | | var tab = $('<span>').attr('id', 'settingstabpluginmanagesieve').addClass('tablink filter'), |
| | | button = $('<a>').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.startsWith('plugin.managesieve')) { |
| | |
| | | $('textarea[data-type="list"]', rcmail.gui_objects.sieveform).each(function() { |
| | | smart_field_init(this); |
| | | }); |
| | | |
| | | // enable date pickers on date fields |
| | | if ($.datepicker && rcmail.env.date_format) { |
| | | $.datepicker.setDefaults({ |
| | | dateFormat: rcmail.env.date_format, |
| | | changeMonth: true, |
| | | showOtherMonths: true, |
| | | selectOtherMonths: true, |
| | | onSelect: function(dateText) { $(this).focus().val(dateText) } |
| | | }); |
| | | $('input.datepicker').datepicker(); |
| | | } |
| | | } |
| | | else { |
| | | rcmail.enable_command('plugin.managesieve-add', 'plugin.managesieve-setadd', !rcmail.env.sieveconnerror); |
| | |
| | | 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(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(); |
| | | |
| | | rcmail.filters_list |
| | | .addEventListener('select', function(e) { p.managesieve_select(e); }) |
| | | .addEventListener('dragstart', function(e) { p.managesieve_dragstart(e); }) |
| | | .addEventListener('dragend', function(e) { p.managesieve_dragend(e); }) |
| | | .addEventListener('initrow', function(row) { |
| | | row.obj.onmouseover = function() { p.managesieve_focus_filter(row); }; |
| | | row.obj.onmouseout = function() { p.managesieve_unfocus_filter(row); }; |
| | | }) |
| | | .init().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(); |
| | | 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); }) |
| | | .init().focus(); |
| | | |
| | | if (set != null) { |
| | | set = rcmail.managesieve_setid(set); |
| | |
| | | |
| | | // Delete filter row |
| | | case 'del': |
| | | var i = 0, list = this.filters_list; |
| | | var id = o.id, list = this.filters_list; |
| | | |
| | | list.remove_row(this.managesieve_rowid(o.id)); |
| | | list.clear_selection(); |
| | |
| | | return; |
| | | } |
| | | |
| | | // modify ID and remove all attached events |
| | | $(this).attr('id', 'rcmrow'+(i++)).unbind(); |
| | | var rowid = this.id.substr(6); |
| | | |
| | | // remove all attached events |
| | | $(this).unbind(); |
| | | |
| | | // update row id |
| | | if (rowid > id) |
| | | $(this).attr('id', 'rcmrow' + (rowid-1)); |
| | | }); |
| | | list.init(); |
| | | |
| | |
| | | // Form submition |
| | | rcube_webmail.prototype.managesieve_save = function() |
| | | { |
| | | if (this.env.action == 'plugin.managesieve-vacation') { |
| | | var data = $(this.gui_objects.sieveform).serialize(); |
| | | this.http_post('plugin.managesieve-vacation', data, this.display_message(this.get_label('managesieve.vacation.saving'), 'loading')); |
| | | return; |
| | | } |
| | | |
| | | if (parent.rcmail && parent.rcmail.filters_list && this.gui_objects.sieveform.name != 'filtersetform') { |
| | | var id = parent.rcmail.filters_list.get_single_selection(); |
| | | if (id != null) |
| | |
| | | row.className = 'actionrow'; |
| | | row.setAttribute('id', 'actionrow'+id); |
| | | row.innerHTML = content; |
| | | |
| | | // initialize smart list inputs |
| | | $('textarea[data-type="list"]', row).each(function() { |
| | | smart_field_init(this); |
| | | }); |
| | | |
| | | this.managesieve_formbuttons(div); |
| | | } |
| | |
| | | /********* Mail UI methods *********/ |
| | | /*********************************************************/ |
| | | |
| | | rcube_webmail.prototype.managesieve_create = function() |
| | | rcube_webmail.prototype.managesieve_create = function(force) |
| | | { |
| | | if (!rcmail.env.sieve_headers || !rcmail.env.sieve_headers.length) |
| | | if (!force && this.env.action != 'show' && !$('#'+this.env.contentframe).is(':visible')) { |
| | | var uid = this.message_list.get_single_selection(), |
| | | lock = this.set_busy(true, 'loading'); |
| | | |
| | | this.http_post('plugin.managesieve-action', {_uid: uid}, lock); |
| | | return; |
| | | } |
| | | |
| | | if (!this.env.sieve_headers || !this.env.sieve_headers.length) |
| | | return; |
| | | |
| | | var i, html, buttons = {}, dialog = $("#sievefilterform"); |
| | |
| | | |
| | | // build dialog window content |
| | | html = '<fieldset><legend>'+this.gettext('managesieve.usedata')+'</legend><ul>'; |
| | | for (i in rcmail.env.sieve_headers) |
| | | for (i in this.env.sieve_headers) |
| | | html += '<li><input type="checkbox" name="headers[]" id="sievehdr'+i+'" value="'+i+'" checked="checked" />' |
| | | +'<label for="sievehdr'+i+'">'+rcmail.env.sieve_headers[i][0]+':</label> '+rcmail.env.sieve_headers[i][1]+'</li>'; |
| | | +'<label for="sievehdr'+i+'">'+this.env.sieve_headers[i][0]+':</label> '+this.env.sieve_headers[i][1]+'</li>'; |
| | | html += '</ul></fieldset>'; |
| | | |
| | | dialog.html(html); |
| | |
| | | // show dialog window |
| | | dialog.dialog({ |
| | | modal: false, |
| | | resizable: !bw.ie6, |
| | | closeOnEscape: (!bw.ie6 && !bw.ie7), // disable for performance reasons |
| | | resizable: true, |
| | | closeOnEscape: !bw.ie7, // disable for performance reasons |
| | | title: this.gettext('managesieve.newfilter'), |
| | | close: function() { rcmail.managesieve_dialog_close(); }, |
| | | buttons: buttons, |