From 01bebe2ed4c51d0cf097f4fd5731cec4104ed054 Mon Sep 17 00:00:00 2001 From: PhilW Date: Sat, 27 Jan 2018 17:57:20 +0000 Subject: [PATCH] rewrite settings, respect disabled_actions config --- CHANGELOG | 4 ++- README.md | 8 ++--- skins/elastic/menu.html | 79 ++++++++++++++--------------------------- swipe.js | 61 +++++++++++++++---------------- swipe.php | 36 +++++++++++++++++++ 5 files changed, 101 insertions(+), 87 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a02332c..6837752 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,6 @@ Roundcube Webmail Swipe ======================= - * Created plugin \ No newline at end of file + * Respect dont_override config + * Respect disabled_actions config + * Created plugin \ No newline at end of file diff --git a/README.md b/README.md index e57c33a..077d792 100644 --- a/README.md +++ b/README.md @@ -56,13 +56,13 @@ The following actions are available for left/right swipe: * `archive` - Archive the message (Requires the Roundcube Archive plugin) * `delete` - Delete the message -* `flagged` - Mark the message as flagged/unflagged * `forward` - Forward the message * `move` - Move the message to a chosen folder -* `read` - Mark the message as read/unread * `reply` - Reply to the message -* `replyall` - Reply all to the message -* `select` - Select/deselect the message +* `reply-all` - Reply all to the message +* `swipe-flagged` - Mark the message as flagged/unflagged +* `swipe-read` - Mark the message as read/unread +* `swipe-select` - Select/deselect the message * `none` - Swipe disabled The following actions are available for down swipe: diff --git a/skins/elastic/menu.html b/skins/elastic/menu.html index 05dbd5e..b720710 100644 --- a/skins/elastic/menu.html +++ b/skins/elastic/menu.html @@ -1,54 +1,29 @@ \ No newline at end of file diff --git a/swipe.js b/swipe.js index a15d052..6fdbaae 100644 --- a/swipe.js +++ b/swipe.js @@ -108,7 +108,12 @@ rcube_webmail.prototype.swipe_select_action = function(direction, obj) { 'callback': null }; - if (rcmail.env.swipe_actions[direction] == 'checkmail') { + if (rcmail.env.swipe_actions[direction] == 'archive' && rcmail.env.archive_folder) { + action.class = 'archive'; + action.text = 'archive.buttontext'; + action.callback = function(p) { rcmail.swipe_action_callback('plugin.archive', null, p); }; + } + else if (rcmail.env.swipe_actions[direction] == 'checkmail') { action.class = 'checkmail'; action.text = 'refresh'; action.callback = function(p) { rcmail.command('checkmail'); }; @@ -118,18 +123,6 @@ rcube_webmail.prototype.swipe_select_action = function(direction, obj) { action.text = 'delete'; action.callback = function(p) { rcmail.swipe_action_callback('delete', null, p); }; } - else if (rcmail.env.swipe_actions[direction] == 'flagged') { - if (obj.hasClass('flagged')) { - action.class = 'unflagged'; - action.text = 'swipe.markasunflagged'; - action.callback = function(p) { rcmail.swipe_action_callback('unflagged', 'mark', p); }; - } - else { - action.class = 'flagged'; - action.text = 'swipe.markasflagged'; - action.callback = function(p) { rcmail.swipe_action_callback('flagged', 'mark', p); }; - } - } else if (rcmail.env.swipe_actions[direction] == 'forward') { action.class = 'forward'; action.text = 'forward'; @@ -153,7 +146,17 @@ rcube_webmail.prototype.swipe_select_action = function(direction, obj) { }; }; } - else if (rcmail.env.swipe_actions[direction] == 'read') { + else if (rcmail.env.swipe_actions[direction] == 'reply') { + action.class = 'reply'; + action.text = 'reply'; + action.callback = function(p) { rcmail.swipe_action_callback('reply', 'compose', p); }; + } + else if (rcmail.env.swipe_actions[direction] == 'reply-all') { + action.class = 'replyall'; + action.text = 'replyall'; + action.callback = function(p) { rcmail.swipe_action_callback('reply-all', 'compose', p); }; + } + else if (rcmail.env.swipe_actions[direction] == 'swipe-read') { if (obj.hasClass('unread')) { action.class = 'read'; action.text = 'swipe.markasread'; @@ -165,17 +168,19 @@ rcube_webmail.prototype.swipe_select_action = function(direction, obj) { action.callback = function(p) { rcmail.swipe_action_callback('unread', 'mark', p); }; } } - else if (rcmail.env.swipe_actions[direction] == 'reply') { - action.class = 'reply'; - action.text = 'reply'; - action.callback = function(p) { rcmail.swipe_action_callback('reply', 'compose', p); }; - } - else if (rcmail.env.swipe_actions[direction] == 'replyall') { - action.class = 'replyall'; - action.text = 'replyall'; - action.callback = function(p) { rcmail.swipe_action_callback('reply-all', 'compose', p); }; + else if (rcmail.env.swipe_actions[direction] == 'swipe-flagged') { + if (obj.hasClass('flagged')) { + action.class = 'unflagged'; + action.text = 'swipe.markasunflagged'; + action.callback = function(p) { rcmail.swipe_action_callback('unflagged', 'mark', p); }; + } + else { + action.class = 'flagged'; + action.text = 'swipe.markasflagged'; + action.callback = function(p) { rcmail.swipe_action_callback('flagged', 'mark', p); }; + } } - else if (rcmail.env.swipe_actions[direction] == 'select') { + else if (rcmail.env.swipe_actions[direction] == 'swipe-select') { if (obj.hasClass('selected')) { action.class = 'deselect'; action.text = 'swipe.deselect'; @@ -187,11 +192,6 @@ rcube_webmail.prototype.swipe_select_action = function(direction, obj) { action.callback = function(p) { rcmail.swipe_action_callback('select', 'select', p); }; } } - else if (rcmail.env.swipe_actions[direction] == 'archive' && rcmail.env.archive_folder) { - action.class = 'archive'; - action.text = 'archive.buttontext'; - action.callback = function(p) { rcmail.swipe_action_callback('plugin.archive', null, p); }; - } return action; }; @@ -391,6 +391,7 @@ $(document).ready(function() { rcmail.set_list_options_core(cols, sort_col, sort_order, threads, layout); } - $('#swipeoptions-menu > fieldset').appendTo('#' + $('#swipeoptions-menu').data('options-menuid')); + if ($('#swipeoptions-menu > fieldset').find('select').length > 0) + $('#swipeoptions-menu > fieldset').appendTo('#' + $('#swipeoptions-menu').data('options-menuid')); } }); \ No newline at end of file diff --git a/swipe.php b/swipe.php index 072c1b7..c86c769 100644 --- a/swipe.php +++ b/swipe.php @@ -30,6 +30,20 @@ class swipe extends rcube_plugin public $task = 'mail'; private $menu_file = ''; private $config = array('left' => 'none', 'right' => 'none', 'down' => 'none'); + private $actions = array( + 'vertical' => array('checkmail' => 'checkmail'), + 'horizontal' => array( + 'swipe-read' => 'swipe.markasread', + 'swipe-flagged' => 'swipe.markasflagged', + 'delete' => 'delete', + 'forward' => 'forward', + 'reply' => 'reply', + 'reply-all' => 'replyall', + 'move' => 'moveto', + 'swipe-select' => 'select', + 'archive' => 'archive.buttontext' + ) + ); public function init() { @@ -48,6 +62,7 @@ class swipe extends rcube_plugin $this->include_stylesheet($this->local_skin_path() . '/swipe.css'); $this->include_script('swipe.js'); $this->add_hook('render_page', array($this, 'options_menu')); + $this->api->output->add_handler('swipeoptionslist', array($this, 'options_list')); } $this->register_action('plugin.swipe.save_settings', array($this, 'save_settings')); @@ -67,6 +82,26 @@ class swipe extends rcube_plugin $this->api->output->add_footer($html); } + public function options_list($args) + { + $disabled_actions = (array) rcube::get_instance()->config->get('disabled_actions'); + $args['name'] = $args['fieldname']; + + $select = new html_select($args); + $select->add($this->gettext('none'), 'none'); + foreach ($this->actions[$args['axis']] as $action => $text) { + // Skip the action if it is in disabled_actions config option + // Skip the archive option if the plugin is not active and configured + if (in_array($action, $disabled_actions) || in_array('mail.' . $action, $disabled_actions) || $action == 'archive' && !$this->api->output->env['archive_folder']) { + continue; + } + + $select->add($this->gettext($text), $action); + } + + return $select->show(); + } + public function save_settings() { $config = array(); @@ -86,6 +121,7 @@ class swipe extends rcube_plugin private function _load_config() { $config = rcube::get_instance()->config->get('swipe_actions', array()); + return array_key_exists('messagelist', $config) ? $config['messagelist'] : $this->config; } }