a few more improvements

dev_contacts
PhilW 6 years ago
parent 8460d1b177
commit d0cc2b48c5

@ -314,28 +314,6 @@ rcube_webmail.prototype.swipe = {
if (swipedata.axis) if (swipedata.axis)
swipeevents.clearswipe(e); swipeevents.clearswipe(e);
}); });
},
save_options: function(dialog) {
var post = {};
$.each(['left', 'right', 'down'], function() {
var option_input = $('.swipeoptions-' + this, dialog).find('select,input').first();
if ($(option_input).is('input[type="radio"]')) {
selector = 'input[name="swipe_' + this + '"]:checked';
}
else if ($(option_input).is('select')) {
selector = 'select[name="swipe_' + this + '"]';
}
if ($(selector, dialog).val() != rcmail.env.swipe_actions[this]) {
rcmail.env.swipe_actions[this] = $(selector, dialog).val();
post['swipe_' + this] = rcmail.env.swipe_actions[this];
}
});
if (!$.isEmptyObject(post))
rcmail.http_post('plugin.swipe.save_settings', post);
} }
}; };
@ -371,10 +349,31 @@ $(document).ready(function() {
} }
}); });
rcmail.show_popup_dialog(dialog, rcmail.get_label('swipeoptions', 'swipe'), [ var save_func = function(e) {
{ text: rcmail.get_label('save'), 'class': 'mainaction save', click: function(e, ui, dialog) { rcmail.swipe.save_options(this); (rcmail.is_framed() ? parent.$ : $)(dialog || this).dialog('close'); } }, var post = {};
{ text: rcmail.get_label('cancel'), 'class': 'cancel', click: function(e, ui, dialog) { (rcmail.is_framed() ? parent.$ : $)(dialog || this).dialog('close'); } } $.each(['left', 'right', 'down'], function() {
]); var option_input = $('.swipeoptions-' + this, dialog).find('select,input').first();
if ($(option_input).is('input[type="radio"]')) {
selector = 'input[name="swipe_' + this + '"]:checked';
}
else if ($(option_input).is('select')) {
selector = 'select[name="swipe_' + this + '"]';
}
if ($(selector, dialog).val() != rcmail.env.swipe_actions[this]) {
rcmail.env.swipe_actions[this] = $(selector, dialog).val();
post['swipe_' + this] = rcmail.env.swipe_actions[this];
}
});
if (!$.isEmptyObject(post))
rcmail.http_post('plugin.swipe.save_settings', post);
return true;
};
rcmail.simple_dialog(dialog, rcmail.get_label('swipeoptions', 'swipe'), save_func);
}, !rcmail.env.swipe_list.draggable); }, !rcmail.env.swipe_list.draggable);
// down swipe on list container // down swipe on list container

@ -36,28 +36,28 @@ class swipe extends rcube_plugin
private $actions = array( private $actions = array(
'messagelist' => array( 'messagelist' => array(
'vertical' => array( 'vertical' => array(
'checkmail' => 'checkmail' 'checkmail' => array('label' => 'checkmail')
), ),
'horizontal' => array( 'horizontal' => array(
'archive' => 'archive.buttontext', 'archive' => array('label' => 'archive.buttontext', 'plugin' => true, 'condition' => 'env:archive_folder'),
'delete' => 'delete', 'delete' => array('label' => 'delete'),
'forward' => 'forward', 'forward' => array('label' => 'forward'),
'markasjunk' => 'markasjunk.markasjunk', 'markasjunk' => array('label' => 'markasjunk.markasjunk', 'plugin' => true),
'move' => 'moveto', 'move' => array('label' => 'moveto'),
'reply' => 'reply', 'reply' => array('label' => 'reply'),
'reply-all' => 'replyall', 'reply-all' => array('label' => 'replyall'),
'swipe-flagged' => 'swipe.markasflagged', 'swipe-flagged' => array('label' => 'swipe.markasflagged'),
'swipe-read' => 'swipe.markasread', 'swipe-read' => array('label' => 'swipe.markasread'),
'swipe-select' => 'select' 'swipe-select' => array('label' => 'select')
) )
), ),
'contactlist' => array( 'contactlist' => array(
'vertical' => array(), 'vertical' => array(),
'horizontal' => array( 'horizontal' => array(
'vcard_attachments' => 'vcard_attachments.forwardvcard', 'vcard_attachments' => array('label' => 'vcard_attachments.forwardvcard', 'plugin' => true),
'compose' => 'compose', 'compose' => array('label' => 'compose'),
'delete' => 'delete', 'delete' => array('label' => 'delete'),
'swipe-select' => 'select' 'swipe-select' => array('label' => 'select')
) )
) )
); );
@ -76,42 +76,44 @@ class swipe extends rcube_plugin
public function setup() public function setup()
{ {
if ($this->rcube->action != '') {
return;
}
$this->_load_config(); $this->_load_config();
if ($this->rcube->output->type == 'html' && $this->rcube->action == '') { $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)) { $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->include_stylesheet($this->local_skin_path() . '/swipe.css');
$this->include_script('swipe.js');
$this->rcube->output->add_label('swipe.swipeoptions', '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->_allowed_action('*')) { $this->include_stylesheet($this->local_skin_path() . '/swipe.css');
// add swipe actions link to the menu $this->include_script('swipe.js');
$this->add_button(array( $this->rcube->output->add_label('swipe.swipeoptions', 'swipe.markasflagged', 'swipe.markasunflagged', 'swipe.markasread',
'command' => 'plugin.swipe.options', 'swipe.markasunread', 'refresh', 'moveto', 'reply', 'replyall', 'forward', 'select', 'swipe.deselect', 'compose');
'type' => 'link', $this->rcube->output->add_handler('swipeoptionslist', array($this, 'options_list'));
'class' => 'button swipe disabled', }
'classact' => 'button swipe',
'title' => 'swipe.swipeoptions', if ($this->_allowed_action('*')) {
'innerclass' => 'inner', // add swipe actions link to the menu
'label' => 'swipe.swipeoptions' $this->add_button(array(
), 'listcontrols'); 'command' => 'plugin.swipe.options',
'type' => 'link',
// add swipe actions popup menu 'class' => 'button swipe disabled',
$html = $this->rcube->output->just_parse("<roundcube:include file=\"$this->menu_file\" skinpath=\"plugins/swipe\" />"); 'classact' => 'button swipe',
$this->rcube->output->add_footer($html); 'title' => 'swipe.swipeoptions',
} 'innerclass' => 'inner',
'label' => 'swipe.swipeoptions'
), 'listcontrols');
// add swipe actions popup menu
$html = $this->rcube->output->just_parse("<roundcube:include file=\"$this->menu_file\" skinpath=\"plugins/swipe\" />");
$this->rcube->output->add_footer($html);
} }
} }
@ -126,12 +128,12 @@ class swipe extends rcube_plugin
$data = rcube::get_instance()->plugins->exec_hook('swipe_actions_list', array('actions' => $swipe_actions, 'direction' => $args['direction'])); $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 => $text) { foreach ($data['actions'] as $action => $info) {
if (!$this->_allowed_action($args['direction'], $action)) { if (!$this->_allowed_action($args['direction'], $action, $info)) {
continue; continue;
} }
$options[$action] = $this->gettext($text); $options[$action] = $this->gettext($info['label']);
} }
asort($options); asort($options);
@ -164,6 +166,8 @@ class swipe extends rcube_plugin
public function save_settings() public function save_settings()
{ {
$this->_load_config();
$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)) {
@ -193,15 +197,18 @@ class swipe extends rcube_plugin
// remove disabled actions // remove disabled actions
foreach ($config as $list => $opts) { foreach ($config as $list => $opts) {
foreach ($opts as $dirction => $action) { foreach ($opts as $direction => $action) {
if ($this->_allowed_action($dirction, $action)) { $axis = $direction == 'down' ? 'vertical' : 'horizontal';
$this->config[$list][$dirction] = $action; $opts = !empty($this->actions[$list][$axis][$action]) ? $this->actions[$list][$axis][$action] : null;
if ($this->_allowed_action($direction, $action, $opts)) {
$this->config[$list][$direction] = $action;
} }
} }
} }
} }
private function _allowed_action($direction, $action = '') private function _allowed_action($direction, $action = '', $opts = null)
{ {
$result = true; $result = true;
@ -214,15 +221,42 @@ class swipe extends rcube_plugin
else if (in_array($action, $this->disabled_actions) || in_array($this->rcube->task . $action, $this->disabled_actions)) { else if (in_array($action, $this->disabled_actions) || in_array($this->rcube->task . $action, $this->disabled_actions)) {
$result = false; $result = false;
} }
else if (in_array($action, array('markasjunk', 'vcard_attachments')) && !in_array($action, $this->laoded_plugins)) { else if (isset($opts['plugin']) && !in_array($action, $this->laoded_plugins)) {
// check plugin is enabled // check plugin is enabled
$result = false; $result = false;
} }
else if ($action == 'archive' && !$this->rcube->output->env['archive_folder']) {
// archive plugin // check for special conditions
if ($result && !empty($opts['condition']) && !$this->_eval_expression($opts['condition'])) {
$result = false; $result = false;
} }
return $result; return $result;
} }
private function _eval_expression($expression)
{
// from rcmail_output_html::eval_expression()
$expression = preg_replace(
array(
'/session:([a-z0-9_]+)/i',
'/config:([a-z0-9_]+)(:([a-z0-9_]+))?/i',
'/env:([a-z0-9_]+)/i',
'/request:([a-z0-9_]+)/i',
'/cookie:([a-z0-9_]+)/i',
'/browser:([a-z0-9_]+)/i',
),
array(
"\$_SESSION['\\1']",
"\$this->rcube->config->get('\\1',rcube_utils::get_boolean('\\3'))",
"\$this->rcube->output->env['\\1']",
"rcube_utils::get_input_value('\\1', rcube_utils::INPUT_GPC)",
"\$_COOKIE['\\1']",
"\$this->rcmail->output->browser->{'\\1'}",
),
$expression
);
return eval("return ($expression);");
}
} }

Loading…
Cancel
Save