Add subtype 'confidential' to event and task folders; refactored subtype selector handling in JS (#3451)

This commit is contained in:
Thomas Bruederli 2014-09-23 11:37:45 +02:00
parent e4f8757b28
commit f0b205cb2e
3 changed files with 33 additions and 38 deletions

View file

@ -50,47 +50,23 @@ window.rcmail && rcmail.env.action == 'folders' && rcmail.addEventListener('init
}); });
window.rcmail && rcmail.env.action != 'folders' && $(document).ready(function() { window.rcmail && rcmail.env.action != 'folders' && $(document).ready(function() {
// IE doesn't allow setting OPTION's display/visibility
// We'll need to remove SELECT's options, see below
if (bw.ie) {
rcmail.env.subtype_html = $('#_subtype').html();
}
// Add onchange handler for folder type SELECT, and call it on form init // Add onchange handler for folder type SELECT, and call it on form init
$('#_ctype').change(function() { $('#_ctype').change(function() {
var type = $(this).val(), var type = $(this).val(),
sub = $('#_subtype'), sub = $('#_subtype'),
subtype = sub.val(); subtypes = rcmail.env.kolab_folder_subtypes[type] || {};
// For IE we need to revert the whole SELECT to the original state // reset subtype selector
if (bw.ie) { sub.html('<option value=""></option>');
sub.html(rcmail.env.subtype_html).val(subtype);
}
// For non-mail folders we must hide mail-specific subtypes // append available subtypes for the given folder type
$('option', sub).each(function() { $.each(subtypes, function(val, label) {
var opt = $(this), val = opt.val(); $('<option>').attr('value', val).text(label).appendTo(sub);
if (val == '')
return;
// there's no mail.default
if (val == 'default' && type != 'mail') {
opt.show();
return;
};
if (type == 'mail' && val != 'default')
opt.show();
else if (bw.ie)
opt.remove();
else
opt.hide();
}); });
// And re-set subtype // And re-set subtype
if (type != 'mail' && subtype != '' && subtype != 'default') { sub.val(rcmail.env.kolab_folder_subtype);
sub.val(''); });
}
}).change();
}); });
function kolab_folders_filter(filter) function kolab_folders_filter(filter)

View file

@ -27,7 +27,17 @@ class kolab_folders extends rcube_plugin
public $task = '?(?!login).*'; public $task = '?(?!login).*';
public $types = array('mail', 'event', 'journal', 'task', 'note', 'contact', 'configuration', 'file', 'freebusy'); public $types = array('mail', 'event', 'journal', 'task', 'note', 'contact', 'configuration', 'file', 'freebusy');
public $mail_types = array('inbox', 'drafts', 'sentitems', 'outbox', 'wastebasket', 'junkemail'); public $subtypes = array(
'mail' => array('inbox', 'drafts', 'sentitems', 'outbox', 'wastebasket', 'junkemail'),
'event' => array('default', 'confidential'),
'task' => array('default', 'confidential'),
'journal' => array('default'),
'note' => array('default'),
'contact' => array('default'),
'configuration' => array('default'),
'file' => array('default'),
'freebusy' => array('default'),
);
public $act_types = array('event', 'task'); public $act_types = array('event', 'task');
private $rc; private $rc;
@ -248,6 +258,7 @@ class kolab_folders extends rcube_plugin
// build type SELECT fields // build type SELECT fields
$type_select = new html_select(array('name' => '_ctype', 'id' => '_ctype')); $type_select = new html_select(array('name' => '_ctype', 'id' => '_ctype'));
$sub_select = new html_select(array('name' => '_subtype', 'id' => '_subtype')); $sub_select = new html_select(array('name' => '_subtype', 'id' => '_subtype'));
$sub_select->add('', '');
foreach ($this->types as $type) { foreach ($this->types as $type) {
$type_select->add($this->gettext('foldertype'.$type), $type); $type_select->add($this->gettext('foldertype'.$type), $type);
@ -257,10 +268,14 @@ class kolab_folders extends rcube_plugin
$type_select->add($ctype, $ctype); $type_select->add($ctype, $ctype);
} }
$sub_select->add('', ''); $sub_types = array();
$sub_select->add($this->gettext('default'), 'default'); foreach ($this->subtypes as $ftype => $subtypes) {
foreach ($this->mail_types as $type) { $sub_types[$ftype] = array_combine($subtypes, array_map(array($this, 'gettext'), $subtypes));
$sub_select->add($this->gettext($type), $type);
// fill options for the current folder type
if ($ftype == $ctype || $ftype == $new_ctype) {
$sub_select->add(array_values($sub_types[$ftype]), $subtypes);
}
} }
$args['form']['props']['fieldsets']['settings']['content']['foldertype'] = array( $args['form']['props']['fieldsets']['settings']['content']['foldertype'] = array(
@ -269,6 +284,9 @@ class kolab_folders extends rcube_plugin
. $sub_select->show(isset($new_subtype) ? $new_subtype : $subtype), . $sub_select->show(isset($new_subtype) ? $new_subtype : $subtype),
); );
$this->rc->output->set_env('kolab_folder_subtypes', $sub_types);
$this->rc->output->set_env('kolab_folder_subtype', isset($new_subtype) ? $new_subtype : $subtype);
return $args; return $args;
} }
@ -312,7 +330,7 @@ class kolab_folders extends rcube_plugin
} }
} }
// Subtype sanity-checks // Subtype sanity-checks
else if ($subtype && ($ctype != 'mail' || !in_array($subtype, $this->mail_types))) { else if ($subtype && (!($subtypes = $this->subtypes[$ctype]) || !in_array($subtype, $subtypes))) {
$subtype = ''; $subtype = '';
} }

View file

@ -28,6 +28,7 @@ $labels['sentitems'] = 'Sent';
$labels['outbox'] = 'Outbox'; $labels['outbox'] = 'Outbox';
$labels['wastebasket'] = 'Trash'; $labels['wastebasket'] = 'Trash';
$labels['junkemail'] = 'Junk'; $labels['junkemail'] = 'Junk';
$labels['confidential'] = 'Confidential';
$messages['defaultfolderexists'] = 'There is already default folder of specified type'; $messages['defaultfolderexists'] = 'There is already default folder of specified type';