replace swipe_actions_list hook with swipe_actions, improve extensibility

release-0.1
PhilW 6 years ago
parent 7d7d5eb71f
commit ae74720cb7

@ -106,13 +106,28 @@ to dont_override:
Interaction with other plugins Interaction with other plugins
------------------------------ ------------------------------
The `swipe_actions_list` hook is triggered when listing the available actions The `swipe_actions` hook is triggered when the plugin starts up
on the list options menu. on the list options menu.
*Arguments:* *Arguments:*
* actions * list_type - the name of list the swipe actions are being performed on, e.g. messagelist, used when selecting/saving config
* direction * actions - an array of actions for this list in the format:
```
$args['actions'] = array(
'list_name' => '*JS list object name*',
'selection_id' => '*JS element identifier e.g. UID*',
'vertical' => array(
'*action_name*' => array('label' => '*display name*'),
...
),
'horizontal' => array(
'*action_name*' => array('label' => '*display name*'),
...
)
);
```
*Return values:* *Return values:*
* list_type
* actions * actions
The `swipe-action` JS event is triggered when a swipe action is performed. The `swipe-action` JS event is triggered when a swipe action is performed.

@ -46,8 +46,8 @@ rcube_webmail.prototype.swipe = {
if (!props.uid) if (!props.uid)
return; return;
var prev_uid = rcmail.env[rcmail.env.task == 'addressbook' ? 'cid' : 'uid']; var prev_uid = rcmail.env[rcmail.env.swipe_selection_id];
rcmail.env[rcmail.env.task == 'addressbook' ? 'cid' : 'uid'] = props.uid; rcmail.env[rcmail.env.swipe_selection_id] = props.uid;
var type = null; var type = null;
if (matches = command.match(/([a-z0-9_-]+)\/([a-z0-9-_]+)/)) { if (matches = command.match(/([a-z0-9_-]+)\/([a-z0-9-_]+)/)) {
@ -77,7 +77,7 @@ rcube_webmail.prototype.swipe = {
rcmail.enable_command(command, prev_command); rcmail.enable_command(command, prev_command);
} }
rcmail.env[rcmail.env.task == 'addressbook' ? 'cid' : 'uid'] = prev_uid; rcmail.env[rcmail.env.swipe_selection_id] = prev_uid;
}, },
select_action: function(direction, obj) { select_action: function(direction, obj) {
@ -356,7 +356,7 @@ rcube_webmail.prototype.swipe = {
$(document).ready(function() { $(document).ready(function() {
if (window.rcmail && ((bw.touch && !bw.ie) || bw.pointer)) { if (window.rcmail && ((bw.touch && !bw.ie) || bw.pointer)) {
rcmail.addEventListener('init', function() { rcmail.addEventListener('init', function() {
rcmail.env.swipe_list = rcmail.task == 'addressbook' ? rcmail.contact_list : rcmail.message_list; rcmail.env.swipe_list = rcmail[rcmail.env.swipe_list_name];
var list_container = $(rcmail.env.swipe_list.list).parent(); var list_container = $(rcmail.env.swipe_list.list).parent();
if (rcmail.env.swipe_list.draggable || !list_container[0].addEventListener) if (rcmail.env.swipe_list.draggable || !list_container[0].addEventListener)
@ -435,14 +435,12 @@ $(document).ready(function() {
// prevent accidental list scroll when swipe active // prevent accidental list scroll when swipe active
rcmail.swipe.parent.on('scroll', function() { rcmail.swipe.set_scroll_css(); }).trigger('scroll'); rcmail.swipe.parent.on('scroll', function() { rcmail.swipe.set_scroll_css(); }).trigger('scroll');
if (rcmail.env.task == 'addressbook') { rcmail.contact_list.addEventListener('getselection', function(p) {
rcmail.contact_list.addEventListener('getselection', function(p) { if (rcmail.swipe.active && rcmail.env[rcmail.env.swipe_selection_id]) {
if (rcmail.swipe.active && rcmail.env.cid) { p.res = [rcmail.env[rcmail.env.swipe_selection_id]];
p.res = [rcmail.env.cid]; return false;
return false; }
} });
});
}
}); });
// right/left/down swipe on list // right/left/down swipe on list

@ -27,7 +27,7 @@
*/ */
class swipe extends rcube_plugin class swipe extends rcube_plugin
{ {
public $task = 'mail|addressbook'; public $task = '^((?!login).)*$';
private $menu_file = null; private $menu_file = null;
private $dont_override = array(); private $dont_override = array();
private $disabled_actions = array(); private $disabled_actions = array();
@ -35,6 +35,8 @@ class swipe extends rcube_plugin
private $config = array(); private $config = array();
private $actions = array( private $actions = array(
'messagelist' => array( 'messagelist' => array(
'list_name' => 'message_list',
'selection_id' => 'uid',
'vertical' => array( 'vertical' => array(
'checkmail' => array('label' => 'checkmail') 'checkmail' => array('label' => 'checkmail')
), ),
@ -52,6 +54,8 @@ class swipe extends rcube_plugin
) )
), ),
'contactlist' => array( 'contactlist' => array(
'list_name' => 'contact_list',
'selection_id' => 'cid',
'vertical' => array(), 'vertical' => array(),
'horizontal' => array( 'horizontal' => array(
'vcard_attachments' => array('label' => 'vcard_attachments.forwardvcard', 'plugin' => true), 'vcard_attachments' => array('label' => 'vcard_attachments.forwardvcard', 'plugin' => true),
@ -59,7 +63,8 @@ class swipe extends rcube_plugin
'delete' => array('label' => 'delete'), 'delete' => array('label' => 'delete'),
'swipe-select' => array('label' => 'select') 'swipe-select' => array('label' => 'select')
) )
) ),
'none' => null
); );
private $rcube; private $rcube;
private $list_type; private $list_type;
@ -67,9 +72,19 @@ class swipe extends rcube_plugin
public function init() public function init()
{ {
$this->rcube = rcube::get_instance(); $this->rcube = rcube::get_instance();
$this->list_type = $this->rcube->task == 'addressbook' ? 'contactlist' : 'messagelist';
$this->add_texts('localization/'); $this->add_texts('localization/');
switch ($this->rcube->task) {
case 'addressbook':
$this->list_type = 'contactlist';
break;
case 'mail':
$this->list_type = 'messagelist';
break;
default:
$this->list_type = 'none';
}
$this->add_hook('ready', array($this, 'setup')); $this->add_hook('ready', array($this, 'setup'));
$this->register_action('plugin.swipe.save_settings', array($this, 'save_settings')); $this->register_action('plugin.swipe.save_settings', array($this, 'save_settings'));
} }
@ -85,12 +100,24 @@ class swipe extends rcube_plugin
$this->menu_file = '/' . $this->local_skin_path() . '/includes/menu.html'; $this->menu_file = '/' . $this->local_skin_path() . '/includes/menu.html';
$filepath = slashify($this->home) . $this->menu_file; $filepath = slashify($this->home) . $this->menu_file;
if (is_file($filepath) && is_readable($filepath)) { if (is_file($filepath) && is_readable($filepath)) {
// Allow other plugins to interact with the actions list
$data = rcube::get_instance()->plugins->exec_hook('swipe_actions', array('list_type' => $this->list_type, 'actions' => $this->actions[$this->list_type]));
$this->list_type = $data['list_type'];
$this->actions[$this->list_type] = $data['actions'];
if (sizeof($this->actions[$this->list_type]) == 0) {
// no swipe actions found, disable the plugin
return;
}
$config = $this->config[$this->list_type]; $config = $this->config[$this->list_type];
$this->rcube->output->set_env('swipe_actions', array( $this->rcube->output->set_env('swipe_actions', array(
'left' => $config['left'], 'left' => $config['left'],
'right' => $config['right'], 'right' => $config['right'],
'down' => $config['down'] 'down' => $config['down']
)); ));
$this->rcube->output->set_env('swipe_list_name', $this->actions[$this->list_type]['list_name']);
$this->rcube->output->set_env('swipe_selection_id',$this->actions[$this->list_type]['selection_id']);
$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');
@ -124,11 +151,8 @@ class swipe extends rcube_plugin
$args['id'] = 'swipeoptions-' . $args['direction']; $args['id'] = 'swipeoptions-' . $args['direction'];
$args['name'] = 'swipe_' . $args['direction']; $args['name'] = 'swipe_' . $args['direction'];
// Allow other plugins to interact with the action list
$data = rcube::get_instance()->plugins->exec_hook('swipe_actions_list', array('actions' => $swipe_actions, 'direction' => $args['direction']));
$options = array(); $options = array();
foreach ($data['actions'] as $action => $info) { foreach ($swipe_actions as $action => $info) {
if (!$this->_allowed_action($args['direction'], $action, $info)) { if (!$this->_allowed_action($args['direction'], $action, $info)) {
continue; continue;
} }
@ -168,6 +192,10 @@ class swipe extends rcube_plugin
{ {
$this->_load_config(); $this->_load_config();
// Allow other plugins to interact with the actions list
$data = rcube::get_instance()->plugins->exec_hook('swipe_actions', array('list_type' => $this->list_type, 'actions' => $this->actions[$this->list_type]));
$this->list_type = $data['list_type'];
$save = false; $save = false;
foreach (array('left', 'right', 'down') as $direction) { foreach (array('left', 'right', 'down') as $direction) {
if (($prop = rcube_utils::get_input_value('swipe_' . $direction, rcube_utils::INPUT_POST)) && $this->_allowed_action($direction)) { if (($prop = rcube_utils::get_input_value('swipe_' . $direction, rcube_utils::INPUT_POST)) && $this->_allowed_action($direction)) {
@ -189,7 +217,9 @@ class swipe extends rcube_plugin
// initialize internal config // initialize internal config
foreach (array_keys($this->actions) as $list) { foreach (array_keys($this->actions) as $list) {
$this->config[$list] = array('left' => 'none', 'right' => 'none', 'down' => 'none'); if ($list != 'none') {
$this->config[$list] = array('left' => 'none', 'right' => 'none', 'down' => 'none');
}
} }
// get user config // get user config

Loading…
Cancel
Save