Thomas Bruederli
2014-04-27 b34d67907566663ab46b487b99817673ce4e32e5
plugins/managesieve/managesieve.js
@@ -1,4 +1,19 @@
/* (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) {
@@ -50,6 +65,18 @@
        $('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);
@@ -60,22 +87,25 @@
      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);
@@ -226,7 +256,7 @@
    // 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();
@@ -241,8 +271,14 @@
          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();
@@ -437,6 +473,12 @@
// 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)
@@ -795,9 +837,17 @@
/*********           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");
@@ -810,9 +860,9 @@
  // 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);
@@ -852,8 +902,8 @@
  // 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,