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
------------------------------
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.
*Arguments:*
* actions
* direction
* list_type - the name of list the swipe actions are being performed on, e.g. messagelist, used when selecting/saving config
* 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:*
* list_type
* actions
The `swipe-action` JS event is triggered when a swipe action is performed.

@ -46,8 +46,8 @@ rcube_webmail.prototype.swipe = {
if (!props.uid)
return;
var prev_uid = rcmail.env[rcmail.env.task == 'addressbook' ? 'cid' : 'uid'];
rcmail.env[rcmail.env.task == 'addressbook' ? 'cid' : 'uid'] = props.uid;
var prev_uid = rcmail.env[rcmail.env.swipe_selection_id];
rcmail.env[rcmail.env.swipe_selection_id] = props.uid;
var type = null;
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.env[rcmail.env.task == 'addressbook' ? 'cid' : 'uid'] = prev_uid;
rcmail.env[rcmail.env.swipe_selection_id] = prev_uid;
},
select_action: function(direction, obj) {
@ -356,7 +356,7 @@ rcube_webmail.prototype.swipe = {
$(document).ready(function() {
if (window.rcmail && ((bw.touch && !bw.ie) || bw.pointer)) {
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();
if (rcmail.env.swipe_list.draggable || !list_container[0].addEventListener)
@ -435,14 +435,12 @@ $(document).ready(function() {
// prevent accidental list scroll when swipe active
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) {
if (rcmail.swipe.active && rcmail.env.cid) {
p.res = [rcmail.env.cid];
return false;
}
});
}
rcmail.contact_list.addEventListener('getselection', function(p) {
if (rcmail.swipe.active && rcmail.env[rcmail.env.swipe_selection_id]) {
p.res = [rcmail.env[rcmail.env.swipe_selection_id]];
return false;
}
});
});
// right/left/down swipe on list

@ -27,7 +27,7 @@
*/
class swipe extends rcube_plugin
{
public $task = 'mail|addressbook';
public $task = '^((?!login).)*$';
private $menu_file = null;
private $dont_override = array();
private $disabled_actions = array();
@ -35,6 +35,8 @@ class swipe extends rcube_plugin
private $config = array();
private $actions = array(
'messagelist' => array(
'list_name' => 'message_list',
'selection_id' => 'uid',
'vertical' => array(
'checkmail' => array('label' => 'checkmail')
),
@ -52,6 +54,8 @@ class swipe extends rcube_plugin
)
),
'contactlist' => array(
'list_name' => 'contact_list',
'selection_id' => 'cid',
'vertical' => array(),
'horizontal' => array(
'vcard_attachments' => array('label' => 'vcard_attachments.forwardvcard', 'plugin' => true),
@ -59,7 +63,8 @@ class swipe extends rcube_plugin
'delete' => array('label' => 'delete'),
'swipe-select' => array('label' => 'select')
)
)
),
'none' => null
);
private $rcube;
private $list_type;
@ -67,9 +72,19 @@ class swipe extends rcube_plugin
public function init()
{
$this->rcube = rcube::get_instance();
$this->list_type = $this->rcube->task == 'addressbook' ? 'contactlist' : 'messagelist';
$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->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';
$filepath = slashify($this->home) . $this->menu_file;
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];
$this->rcube->output->set_env('swipe_actions', array(
'left' => $config['left'],
'right' => $config['right'],
'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_script('swipe.js');
@ -124,11 +151,8 @@ class swipe extends rcube_plugin
$args['id'] = 'swipeoptions-' . $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();
foreach ($data['actions'] as $action => $info) {
foreach ($swipe_actions as $action => $info) {
if (!$this->_allowed_action($args['direction'], $action, $info)) {
continue;
}
@ -168,6 +192,10 @@ class swipe extends rcube_plugin
{
$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;
foreach (array('left', 'right', 'down') as $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
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

Loading…
Cancel
Save