From f438bba101dadbaf79e49c17928bee3c45f70514 Mon Sep 17 00:00:00 2001 From: PhilW Date: Sun, 20 Jan 2019 19:15:26 +0000 Subject: [PATCH] add options menu to addressbook task --- skins/elastic/swipe.less | 27 +++++++++++++++++++++++++++ swipe.js | 36 ++++++++++++++++++++++++------------ swipe.php | 31 ++++++++++++++++++++++++++----- 3 files changed, 77 insertions(+), 17 deletions(-) diff --git a/skins/elastic/swipe.less b/skins/elastic/swipe.less index 07776d6..f130072 100644 --- a/skins/elastic/swipe.less +++ b/skins/elastic/swipe.less @@ -206,4 +206,31 @@ .swipe-active:not(#swipe-action), .swipe-active > td { background-color: @color-layout-list-background; +} + +.toolbar a.button.swipe { + display: none; +} + +html.layout-small, +html.layout-phone { + .toolbar { + a.button { + &.swipe { + display: inline-block; + + &:before { + content: @fa-var-hand-point-up; + } + } + } + } +} + +fieldset.swipe-menu { + margin: .25em; + + legend { + display: none; + } } \ No newline at end of file diff --git a/swipe.js b/swipe.js index 2f68f73..afe3722 100644 --- a/swipe.js +++ b/swipe.js @@ -314,6 +314,21 @@ rcube_webmail.prototype.swipe = { if (swipedata.axis) swipeevents.clearswipe(e); }); + }, + + setup_options: function() { + $.each(rcmail.env.swipe_actions, function(direction, action) { + var option_input = $('.swipeoptions-' + direction).find('select,input'); + if (option_input.is('input[type="radio"]')) { + option_input.filter('[value="' + action + '"]').prop('checked', true); + } + else if (option_input.is('select') && option_input.first().children('option').length > 0) { + option_input.val(action); + } + else { + $('.swipeoptions-' + direction).hide(); + } + }); } }; @@ -378,6 +393,14 @@ $(document).ready(function() { return false; } }); + + rcmail.register_command('plugin.swipe.options', function() { + rcmail.show_popup_dialog($('#swipeoptions').clone(), rcmail.get_label('swipeactions', 'swipe'), [ + { text: rcmail.get_label('save'), 'class': 'mainaction save', click: function(e, ui, dialog) { rcmail.set_list_options(); (rcmail.is_framed() ? parent.$ : $)(dialog || this).dialog('close'); } }, + { text: rcmail.get_label('cancel'), 'class': 'cancel', click: function(e, ui, dialog) { (rcmail.is_framed() ? parent.$ : $)(dialog || this).dialog('close'); } } + ]); + rcmail.swipe.setup_options(); + }, true); } }); @@ -461,18 +484,7 @@ $(document).ready(function() { // done in menu-open not beforemenu-open because of Elastic's Bootstrap popovers rcmail.addEventListener('menu-open', function(p) { if (p.name == rcmail.env.swipe_menuname && $('.swipe-menu').is(':visible')) { - $.each(rcmail.env.swipe_actions, function(direction, action) { - var option_input = $('.swipeoptions-' + direction).find('select,input'); - if (option_input.is('input[type="radio"]')) { - option_input.filter('[value="' + action + '"]').prop('checked', true); - } - else if (option_input.is('select') && option_input.first().children('option').length > 0) { - option_input.val(action); - } - else { - $('.swipeoptions-' + direction).hide(); - } - }); + rcmail.swipe.setup_options(); } }); }); \ No newline at end of file diff --git a/swipe.php b/swipe.php index ed0ce64..6759141 100644 --- a/swipe.php +++ b/swipe.php @@ -84,22 +84,43 @@ class swipe extends rcube_plugin 'down' => $config['down'] )); - $this->add_hook('template_container', array($this, 'options_menu')); $this->include_stylesheet($this->local_skin_path() . '/swipe.css'); $this->include_script('swipe.js'); - $this->rcube->output->add_label('swipe.markasflagged', 'swipe.markasunflagged', 'swipe.markasread', 'swipe.markasunread', - 'refresh', 'moveto', 'reply', 'replyall', 'forward', 'select', 'swipe.deselect', 'compose'); + $this->rcube->output->add_label('swipe.swipeactions', 'swipe.markasflagged', 'swipe.markasunflagged', 'swipe.markasread', + 'swipe.markasunread', 'refresh', 'moveto', 'reply', 'replyall', 'forward', 'select', 'swipe.deselect', 'compose'); $this->rcube->output->add_handler('swipeoptionslist', array($this, 'options_list')); + + if ($this->rcube->task == 'mail') { + $this->add_hook('template_container', array($this, 'options_menu')); + } + elseif ($this->rcube->task == 'addressbook') { + $this->add_button(array( + 'command' => 'plugin.swipe.options', + 'type' => 'link', + 'class' => 'button swipe', + 'title' => 'swipe.swipeactions', + 'innerclass' => 'inner', + 'label' => 'swipe.swipeactions' + ), 'toolbar'); + $this->add_hook('render_page', array($this, 'options_menu')); + } } } } public function options_menu($args) { - if ($args['name'] == 'listoptions') { + if ($args['name'] == 'listoptions' || ($this->rcube->task == 'addressbook' && $args['write'])) { // add additional menus from skins folder to list options menu $html = $this->rcube->output->just_parse("menu_file\" skinpath=\"plugins/swipe\" />"); - $args['content'] .= $html; + + if ($this->rcube->task == 'addressbook') { + $html = html::div(array('id' => 'swipeoptions', 'class' => 'popupmenu'), $html); + $args['content'] = str_replace('', $html . '', $args['content']); + } + else { + $args['content'] .= $html; + } return $args; }