rewrite settings, respect disabled_actions config

dev_contacts
PhilW 7 years ago
parent 742c66370e
commit 01bebe2ed4

@ -1,4 +1,6 @@
Roundcube Webmail Swipe Roundcube Webmail Swipe
======================= =======================
* Respect dont_override config
* Respect disabled_actions config
* Created plugin * Created plugin

@ -56,13 +56,13 @@ The following actions are available for left/right swipe:
* `archive` - Archive the message (Requires the Roundcube Archive plugin) * `archive` - Archive the message (Requires the Roundcube Archive plugin)
* `delete` - Delete the message * `delete` - Delete the message
* `flagged` - Mark the message as flagged/unflagged
* `forward` - Forward the message * `forward` - Forward the message
* `move` - Move the message to a chosen folder * `move` - Move the message to a chosen folder
* `read` - Mark the message as read/unread
* `reply` - Reply to the message * `reply` - Reply to the message
* `replyall` - Reply all to the message * `reply-all` - Reply all to the message
* `select` - Select/deselect 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 * `none` - Swipe disabled
The following actions are available for down swipe: The following actions are available for down swipe:

@ -1,54 +1,29 @@
<div id="swipeoptions-menu" class="popupmenu propform" role="dialog" aria-labelledby="aria-label-listoptions" data-options-menuname="messagelistmenu" data-options-menuid="listoptions-menu" data-listselection-class="withselection"> <div id="swipeoptions-menu" class="popupmenu propform" role="dialog" aria-labelledby="aria-label-listoptions" data-options-menuname="messagelistmenu" data-options-menuid="listoptions-menu" data-listselection-class="withselection">
<fieldset class="swipe"> <fieldset class="swipe">
<legend><roundcube:label name="swipe.swipeactions" /></legend> <legend><roundcube:label name="swipe.swipeactions" /></legend>
<roundcube:if condition="!in_array('swipe_actions.messagelist.left', (array)config:dont_override)" />
<div class="form-group row"> <div class="form-group row">
<label for="swipeoptions-left" class="col-form-label col-sm-4"><roundcube:label name="swipe.swipeleft" /></label> <label for="swipeoptions-left" class="col-form-label col-sm-4"><roundcube:label name="swipe.swipeleft" /></label>
<div class="col-sm-8"> <div class="col-sm-8">
<select id="swipeoptions-left" name="swipe_left" class="form-control"> <roundcube:object name="swipeoptionslist" fieldname="swipe_left" id="swipeoptions-left" class="form-control" axis="horizontal" />
<option value="none"><roundcube:label name="none" /></option>
<option value="read"><roundcube:label name="swipe.markasread" /></option>
<option value="flagged"><roundcube:label name="swipe.markasflagged" /></option>
<option value="delete"><roundcube:label name="delete" /></option>
<option value="forward"><roundcube:label name="forward" /></option>
<option value="reply"><roundcube:label name="reply" /></option>
<option value="replyall"><roundcube:label name="replyall" /></option>
<option value="move"><roundcube:label name="moveto" /></option>
<option value="select"><roundcube:label name="select" /></option>
<roundcube:if condition="env:archive_folder" />
<option value="archive"><roundcube:label name="archive.buttontext" /></option>
<roundcube:endif />
</select>
</div> </div>
</div> </div>
<roundcube:endif />
<roundcube:if condition="!in_array('swipe_actions.messagelist.right', (array)config:dont_override)" />
<div class="form-group row"> <div class="form-group row">
<label for="swipeoptions-right" class="col-form-label col-sm-4"><roundcube:label name="swipe.swiperight" /></label> <label for="swipeoptions-right" class="col-form-label col-sm-4"><roundcube:label name="swipe.swiperight" /></label>
<div class="col-sm-8"> <div class="col-sm-8">
<select id="swipeoptions-right" name="swipe_right" class="form-control"> <roundcube:object name="swipeoptionslist" fieldname="swipe_right" id="swipeoptions-right" class="form-control" axis="horizontal" />
<option value="none"><roundcube:label name="none" /></option>
<option value="read"><roundcube:label name="swipe.markasread" /></option>
<option value="flagged"><roundcube:label name="swipe.markasflagged" /></option>
<option value="delete"><roundcube:label name="delete" /></option>
<option value="forward"><roundcube:label name="forward" /></option>
<option value="reply"><roundcube:label name="reply" /></option>
<option value="replyall"><roundcube:label name="replyall" /></option>
<option value="move"><roundcube:label name="moveto" /></option>
<option value="select"><roundcube:label name="select" /></option>
<roundcube:if condition="env:archive_folder" />
<option value="archive"><roundcube:label name="archive.buttontext" /></option>
<roundcube:endif />
</select>
</div> </div>
</div> </div>
<roundcube:endif />
<roundcube:if condition="!in_array('swipe_actions.messagelist.down', (array)config:dont_override)" />
<div class="form-group row"> <div class="form-group row">
<label for="swipeoptions-down" class="col-form-label col-sm-4"><roundcube:label name="swipe.swipedown" /></label> <label for="swipeoptions-down" class="col-form-label col-sm-4"><roundcube:label name="swipe.swipedown" /></label>
<div class="col-sm-8"> <div class="col-sm-8">
<select id="swipeoptions-down" name="swipe_down" class="form-control"> <roundcube:object name="swipeoptionslist" fieldname="swipe_down" id="swipeoptions-down" class="form-control" axis="vertical" />
<option value="none"><roundcube:label name="none" /></option>
<option value="checkmail"><roundcube:label name="checkmail" /></option>
</select>
</div> </div>
</div> </div>
<roundcube:endif />
</fieldset> </fieldset>
</div> </div>

@ -108,7 +108,12 @@ rcube_webmail.prototype.swipe_select_action = function(direction, obj) {
'callback': null '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.class = 'checkmail';
action.text = 'refresh'; action.text = 'refresh';
action.callback = function(p) { rcmail.command('checkmail'); }; action.callback = function(p) { rcmail.command('checkmail'); };
@ -118,18 +123,6 @@ rcube_webmail.prototype.swipe_select_action = function(direction, obj) {
action.text = 'delete'; action.text = 'delete';
action.callback = function(p) { rcmail.swipe_action_callback('delete', null, p); }; 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') { else if (rcmail.env.swipe_actions[direction] == 'forward') {
action.class = 'forward'; action.class = 'forward';
action.text = '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')) { if (obj.hasClass('unread')) {
action.class = 'read'; action.class = 'read';
action.text = 'swipe.markasread'; 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); }; action.callback = function(p) { rcmail.swipe_action_callback('unread', 'mark', p); };
} }
} }
else if (rcmail.env.swipe_actions[direction] == 'reply') { else if (rcmail.env.swipe_actions[direction] == 'swipe-flagged') {
action.class = 'reply'; if (obj.hasClass('flagged')) {
action.text = 'reply'; action.class = 'unflagged';
action.callback = function(p) { rcmail.swipe_action_callback('reply', 'compose', p); }; action.text = 'swipe.markasunflagged';
action.callback = function(p) { rcmail.swipe_action_callback('unflagged', 'mark', p); };
} }
else if (rcmail.env.swipe_actions[direction] == 'replyall') { else {
action.class = 'replyall'; action.class = 'flagged';
action.text = 'replyall'; action.text = 'swipe.markasflagged';
action.callback = function(p) { rcmail.swipe_action_callback('reply-all', 'compose', p); }; 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')) { if (obj.hasClass('selected')) {
action.class = 'deselect'; action.class = 'deselect';
action.text = 'swipe.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); }; 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; return action;
}; };
@ -391,6 +391,7 @@ $(document).ready(function() {
rcmail.set_list_options_core(cols, sort_col, sort_order, threads, layout); rcmail.set_list_options_core(cols, sort_col, sort_order, threads, layout);
} }
if ($('#swipeoptions-menu > fieldset').find('select').length > 0)
$('#swipeoptions-menu > fieldset').appendTo('#' + $('#swipeoptions-menu').data('options-menuid')); $('#swipeoptions-menu > fieldset').appendTo('#' + $('#swipeoptions-menu').data('options-menuid'));
} }
}); });

@ -30,6 +30,20 @@ class swipe extends rcube_plugin
public $task = 'mail'; public $task = 'mail';
private $menu_file = ''; private $menu_file = '';
private $config = array('left' => 'none', 'right' => 'none', 'down' => 'none'); 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() public function init()
{ {
@ -48,6 +62,7 @@ class swipe extends rcube_plugin
$this->include_stylesheet($this->local_skin_path() . '/swipe.css'); $this->include_stylesheet($this->local_skin_path() . '/swipe.css');
$this->include_script('swipe.js'); $this->include_script('swipe.js');
$this->add_hook('render_page', array($this, 'options_menu')); $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')); $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); $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() public function save_settings()
{ {
$config = array(); $config = array();
@ -86,6 +121,7 @@ class swipe extends rcube_plugin
private function _load_config() private function _load_config()
{ {
$config = rcube::get_instance()->config->get('swipe_actions', array()); $config = rcube::get_instance()->config->get('swipe_actions', array());
return array_key_exists('messagelist', $config) ? $config['messagelist'] : $this->config; return array_key_exists('messagelist', $config) ? $config['messagelist'] : $this->config;
} }
} }

Loading…
Cancel
Save