various improvements, add support for radio buttons

dev_contacts
PhilW 6 years ago
parent e171d2dea1
commit 0d819ea65e

@ -1,6 +1,7 @@
Roundcube Webmail Swipe
=======================
* Allow menu to use select or radio buttons
* Add support for markasjunk plugin
* Support for pointer events
* Add hooks for other plugins to interact with

@ -1,11 +1,13 @@
<div id="swipeoptions-menu" class="popupmenu propform" role="dialog" aria-labelledby="aria-label-listoptions" data-options-menuname="messagelistmenu" data-options-menuid="listoptions-menu" data-listselection-class="withselection">
<roundcube:object name="swipeenv" param="menuname" val="messagelistmenu" />
<roundcube:object name="swipeenv" param="listselection_class" val="withselection" />
<div id="swipeoptions-menu" class="popupmenu propform" role="dialog" aria-labelledby="aria-label-listoptions" data-options-menuid="listoptions-menu">
<fieldset class="swipe">
<legend><roundcube:label name="swipe.swipeactions" /></legend>
<roundcube:if condition="!in_array('swipe_actions.messagelist.left', (array)config:dont_override)" />
<div class="form-group row swipeoptions-left">
<label for="swipeoptions-left" class="col-form-label col-sm-4"><roundcube:label name="swipe.swipeleft" /></label>
<div class="col-sm-8">
<roundcube:object name="swipeoptionslist" fieldname="swipe_left" id="swipeoptions-left" source="messagelist" axis="horizontal" />
<roundcube:object name="swipeoptionslist" type="select" source="messagelist" axis="horizontal" direction="left" />
</div>
</div>
<roundcube:endif />
@ -13,7 +15,7 @@
<div class="form-group row swipeoptions-right">
<label for="swipeoptions-right" class="col-form-label col-sm-4"><roundcube:label name="swipe.swiperight" /></label>
<div class="col-sm-8">
<roundcube:object name="swipeoptionslist" fieldname="swipe_right" id="swipeoptions-right" source="messagelist" axis="horizontal" />
<roundcube:object name="swipeoptionslist" type="select" source="messagelist" axis="horizontal" direction="right" />
</div>
</div>
<roundcube:endif />
@ -21,7 +23,7 @@
<div class="form-group row swipeoptions-down">
<label for="swipeoptions-down" class="col-form-label col-sm-4"><roundcube:label name="swipe.swipedown" /></label>
<div class="col-sm-8">
<roundcube:object name="swipeoptionslist" fieldname="swipe_down" id="swipeoptions-down" source="messagelist" axis="vertical" />
<roundcube:object name="swipeoptionslist" type="select" source="messagelist" axis="vertical" direction="down" />
</div>
</div>
<roundcube:endif />

@ -46,7 +46,7 @@ rcube_webmail.prototype.swipe = {
rcmail.message_list.highlight_row(props.uid, true);
var select_class = '';
if (select_class = $('#swipeoptions-menu').data('listselection-class')) {
if (select_class = rcmail.env.swipe_listselection_class) {
if (command == 'deselect' && rcmail.message_list.get_selection().length == 0)
$(rcmail.gui_objects.messagelist).removeClass(select_class);
else
@ -409,30 +409,23 @@ $(document).ready(function() {
rcmail.swipe.init(swipe_config);
});
// add swipe options to list options menu
rcmail.addEventListener('menu-open', function(p) {
if (p.name == $('#swipeoptions-menu').data('options-menuname')) {
if (!rcmail.message_list.draggable) {
// set form values
$.each(['left', 'right', 'down'], function() {
$('select[name="swipe_' + this + '"]:visible').val(rcmail.env.swipe_actions[this]);
});
$('fieldset.swipe').show();
}
else {
$('fieldset.swipe').hide();
}
}
});
// save swipe options
rcmail.set_list_options_core = rcmail.set_list_options;
rcmail.set_list_options = function(cols, sort_col, sort_order, threads, layout) {
var post = {};
$.each(['left', 'right', 'down'], function() {
if ($('select[name="swipe_' + this + '"]:visible').val() != rcmail.env.swipe_actions[this]) {
rcmail.env.swipe_actions[this] = $('select[name="swipe_' + this + '"]:visible').val();
var fieldtype = rcmail.env['swipe_input_' + this];
if (fieldtype == 'radio') {
selector = 'input[name="swipe_' + this + '"]:checked';
}
else if (fieldtype == 'select') {
selector = 'select[name="swipe_' + this + '"]';
selector += $(selector).length > 1 ? ':visible' : '';
}
if ($(selector).val() != rcmail.env.swipe_actions[this]) {
rcmail.env.swipe_actions[this] = $(selector).val();
post['swipe_' + this] = rcmail.env.swipe_actions[this];
}
});
@ -446,4 +439,31 @@ $(document).ready(function() {
if ($('#swipeoptions-menu > fieldset').find('select').length > 0)
$('#swipeoptions-menu > fieldset').appendTo('#' + $('#swipeoptions-menu').data('options-menuid'));
}
// add swipe options to list options menu
rcmail.addEventListener('menu-open', function(p) {
if (p.name == rcmail.env.swipe_menuname) {
if (!rcmail.message_list.draggable) {
// set form values
$.each(['left', 'right', 'down'], function() {
var fieldtype = rcmail.env['swipe_input_' + this];
if (fieldtype == 'radio') {
selector = '#swipeoptions-' + this + '-' + rcmail.env.swipe_actions[this];
selector += $(selector).length > 1 ? ':visible' : '';
$(selector).prop('checked', true);
}
else if (fieldtype == 'select') {
selector = 'select[name="swipe_' + this + '"]';
selector += $(selector).length > 1 ? ':visible' : '';
$(selector).val(rcmail.env.swipe_actions[this]);
}
});
$('fieldset.swipe').show();
}
else {
$('fieldset.swipe').hide();
}
}
});
});

@ -73,6 +73,7 @@ class swipe extends rcube_plugin
$this->include_script('swipe.js');
$this->rcube->output->add_label('none', 'refresh', 'moveto', 'reply', 'replyall', 'forward', 'select');
$this->rcube->output->add_handler('swipeoptionslist', array($this, 'options_list'));
$this->rcube->output->add_handler('swipeenv', array($this, 'set_env'));
}
}
}
@ -95,7 +96,9 @@ class swipe extends rcube_plugin
$disabled_actions = (array) rcube::get_instance()->config->get('disabled_actions');
$laoded_plugins = $this->api->loaded_plugins();
$swipe_actions = $this->actions[$args['source']][$args['axis']];
$args['name'] = $args['fieldname'];
$args['id'] = 'swipeoptions-' . $args['direction'];
$args['name'] = 'swipe_' . $args['direction'];
$this->rcube->output->set_env('swipe_input_' . $args['direction'], $args['type']);
// Allow other plugins to interact with the action list
$data = rcube::get_instance()->plugins->exec_hook('swipe_actions_list', array('actions' => $swipe_actions, 'source' => $args['source'], 'axis' => $args['axis']));
@ -113,12 +116,41 @@ class swipe extends rcube_plugin
$options[$action] = $this->gettext($text);
}
asort($options);
$options = array('none' => $this->gettext('none')) + $options;
switch ($args['type']) {
case 'radio':
foreach ($options as $val => $text) {
$fieldid = $args['id'] . '-' . $val;
$radio = new html_radiobutton(array('name' => $args['name'], 'id' => $fieldid, 'class' => $val, 'value' => $val));
$radio = $radio->show($this->config[$args['direction']]);
if (isset($args['innertag']))
$text = html::tag($args['innertag'], null, $text);
$radio = html::label($fieldid, $radio . $text);
if (isset($args['outertag']))
$radio = html::tag($args['outertag'], null, $radio);
$field .= $radio;
}
break;
case 'select':
$select = new html_select($args);
$select->add($this->gettext('none'), 'none');
$select->add(array_values($options), array_keys($options));
$field = $select->show($this->config[$args['direction']]);
return $select->show();
break;
}
return $field;
}
public function set_env($args)
{
$this->rcube->output->set_env('swipe_' . $args['param'], $args['val']);
}
public function save_settings()

Loading…
Cancel
Save