diff --git a/CHANGELOG b/CHANGELOG index 6837752..bea69ce 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Roundcube Webmail Swipe ======================= + * Add hooks for other plugins to interact with * 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 077d792..1bfb650 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,28 @@ The following actions are available for down swipe: * `checkmail` - Check for new messages in the current folder * `none` - Swipe disabled +Interaction with other plugins +------------------------------ +The `swipe_actions_list` triggered when listing the available actions on the +list options menu. +*Arguments:* + * actions + * axis + +*Return values:* + * actions + +The `swipe-action` JS event is triggered when a swipe action is performed. +Return `false` to abort the action or return a JSON object like this to assign +an action: +```js +{ + 'class': '', + 'text': '', + 'callback': function(p) { } +}; +``` + [rcplugrepo]: https://plugins.roundcube.net/packages/johndoh/swipe [releases]: https://github.com/johndoh/roundcube-swipe/releases [gpl]: https://www.gnu.org/licenses/gpl.html \ No newline at end of file diff --git a/swipe.js b/swipe.js index 6fdbaae..e52db9e 100644 --- a/swipe.js +++ b/swipe.js @@ -32,26 +32,26 @@ rcube_webmail.prototype.swipe_list_selection = function(uid, show, prev_sel) { // make the system think no preview pane exists while we do some fake message selects // to enable/disable relevant commands for current selection var prev_contentframe = rcmail.env.contentframe, i; - rcmail.env.contentframe = null; + this.env.contentframe = null; if (show) { - if (rcmail.message_list.selection.length == 0 || !rcmail.message_list.in_selection(uid)) { - prev_sel = prev_sel ? prev_sel : rcmail.message_list.get_selection(); - rcmail.message_list.clear_selection(); - rcmail.message_list.highlight_row(uid, true); + if (this.message_list.selection.length == 0 || !this.message_list.in_selection(uid)) { + prev_sel = prev_sel ? prev_sel : this.message_list.get_selection(); + this.message_list.clear_selection(); + this.message_list.highlight_row(uid, true); } } else if (prev_sel) { - rcmail.message_list.clear_selection(); + this.message_list.clear_selection(); for (i in prev_sel) rcmail[this.list_object].highlight_row(prev_sel[i], true); } else { - rcmail.message_list.clear_selection(); + this.message_list.clear_selection(); } - rcmail.env.contentframe = prev_contentframe; + this.env.contentframe = prev_contentframe; return prev_sel; }; @@ -61,42 +61,42 @@ rcube_webmail.prototype.swipe_action_callback = function(command, type, props) { return; if (type == 'mark') { - rcmail.mark_message(command, props.uid); + this.mark_message(command, props.uid); } else if (type == 'compose') { - rcmail.enable_command(command, true); - rcmail.env.uid = props.uid; - rcmail.command(command, '', props.obj, props.originalEvent); + this.enable_command(command, true); + this.env.uid = props.uid; + this.command(command, '', props.obj, props.originalEvent); } else if (type == 'select') { - rcmail.message_list.highlight_row(props.uid, true); + this.message_list.highlight_row(props.uid, true); var select_class = ''; if (select_class = $('#swipeoptions-menu').data('listselection-class')) { - if (command == 'deselect' && rcmail.message_list.get_selection().length == 0) - $(rcmail.gui_objects.messagelist).removeClass(select_class); + if (command == 'deselect' && this.message_list.get_selection().length == 0) + $(this.gui_objects.messagelist).removeClass(select_class); else - $(rcmail.gui_objects.messagelist).addClass(select_class); + $(this.gui_objects.messagelist).addClass(select_class); } } else { - var prev_sel = rcmail.swipe_list_selection(props.uid, true); + var prev_sel = this.swipe_list_selection(props.uid, true); // enable command - var prev_command = rcmail.commands[command]; - rcmail.enable_command(command, true); + var prev_command = this.commands[command]; + this.enable_command(command, true); // some actions require a button click in the UI to trigger things like popovers // rather than a direct command call - $('#' + rcmail.buttons[command][0].id).trigger('click'); + $('#' + this.buttons[command][0].id).trigger('click'); if (props.delay_disable) { return {'prev_command': prev_command, 'prev_sel': prev_sel}; } else { // restore original state - rcmail.enable_command(command, prev_command); - rcmail.swipe_list_selection(props.uid, false, prev_sel); + this.enable_command(command, prev_command); + this.swipe_list_selection(props.uid, false, prev_sel); } } }; @@ -108,27 +108,36 @@ rcube_webmail.prototype.swipe_select_action = function(direction, obj) { 'callback': null }; - if (rcmail.env.swipe_actions[direction] == 'archive' && rcmail.env.archive_folder) { + ret = this.triggerEvent('swipe-action', {'direction': direction, 'obj': obj}); + if (ret !== undefined) { + // abort if one of the handlers returned false + if (ret === false) + return action; + else + return ret; + } + + if (this.env.swipe_actions[direction] == 'archive' && this.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') { + else if (this.env.swipe_actions[direction] == 'checkmail') { action.class = 'checkmail'; action.text = 'refresh'; action.callback = function(p) { rcmail.command('checkmail'); }; } - else if (rcmail.env.swipe_actions[direction] == 'delete') { + else if (this.env.swipe_actions[direction] == 'delete') { action.class = 'delete'; action.text = 'delete'; action.callback = function(p) { rcmail.swipe_action_callback('delete', null, p); }; } - else if (rcmail.env.swipe_actions[direction] == 'forward') { + else if (this.env.swipe_actions[direction] == 'forward') { action.class = 'forward'; action.text = 'forward'; action.callback = function(p) { rcmail.swipe_action_callback('forward', 'compose', p); }; } - else if (rcmail.env.swipe_actions[direction] == 'move') { + else if (this.env.swipe_actions[direction] == 'move') { action.class = 'move'; action.text = 'moveto'; action.callback = function(p) { @@ -146,17 +155,17 @@ rcube_webmail.prototype.swipe_select_action = function(direction, obj) { }; }; } - else if (rcmail.env.swipe_actions[direction] == 'reply') { + else if (this.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') { + else if (this.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') { + else if (this.env.swipe_actions[direction] == 'swipe-read') { if (obj.hasClass('unread')) { action.class = 'read'; action.text = 'swipe.markasread'; @@ -168,7 +177,7 @@ 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] == 'swipe-flagged') { + else if (this.env.swipe_actions[direction] == 'swipe-flagged') { if (obj.hasClass('flagged')) { action.class = 'unflagged'; action.text = 'swipe.markasunflagged'; @@ -180,7 +189,7 @@ rcube_webmail.prototype.swipe_select_action = function(direction, obj) { action.callback = function(p) { rcmail.swipe_action_callback('flagged', 'mark', p); }; } } - else if (rcmail.env.swipe_actions[direction] == 'swipe-select') { + else if (this.env.swipe_actions[direction] == 'swipe-select') { if (obj.hasClass('selected')) { action.class = 'deselect'; action.text = 'swipe.deselect'; diff --git a/swipe.php b/swipe.php index c86c769..1ad120e 100644 --- a/swipe.php +++ b/swipe.php @@ -85,11 +85,15 @@ class swipe extends rcube_plugin public function options_list($args) { $disabled_actions = (array) rcube::get_instance()->config->get('disabled_actions'); + $swipe_actions = $this->actions[$args['axis']]; $args['name'] = $args['fieldname']; + // Allow other plugins to interact with the action list + $data = rcube::get_instance()->plugins->exec_hook('swipe_actions_list', array('actions' => $swipe_actions, 'axis' => $args['axis'])); + $select = new html_select($args); $select->add($this->gettext('none'), 'none'); - foreach ($this->actions[$args['axis']] as $action => $text) { + foreach ($data['actions'] 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']) {