Extended calendar folder management feature for kolab driver
This commit is contained in:
parent
b7e8092558
commit
1cd956f708
8 changed files with 316 additions and 68 deletions
|
@ -420,7 +420,7 @@ class calendar extends rcube_plugin
|
||||||
function calendar_action()
|
function calendar_action()
|
||||||
{
|
{
|
||||||
$action = get_input_value('action', RCUBE_INPUT_GPC);
|
$action = get_input_value('action', RCUBE_INPUT_GPC);
|
||||||
$cal = get_input_value('c', RCUBE_INPUT_POST);
|
$cal = get_input_value('c', RCUBE_INPUT_GPC);
|
||||||
$success = $reload = false;
|
$success = $reload = false;
|
||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
|
|
|
@ -1276,10 +1276,10 @@ function rcube_calendar_ui(settings)
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
dataType: 'html',
|
dataType: 'html',
|
||||||
url: rcmail.url('calendar'),
|
url: rcmail.url('calendar'),
|
||||||
data: { action:(calendar.id ? 'form-edit' : 'form-new'), calendar:{ id:calendar.id } },
|
data: { action:(calendar.id ? 'form-edit' : 'form-new'), c:{ id:calendar.id } },
|
||||||
success: function(data){
|
success: function(data) {
|
||||||
$dialog.html(data);
|
$dialog.html(data);
|
||||||
form = $('#calendarform > form');
|
form = $('form', $('#calendarform')); // '#calendarform > form' doesn't work here
|
||||||
name = $('#calendar-name').prop('disabled', !calendar.editable).val(calendar.editname || calendar.name);
|
name = $('#calendar-name').prop('disabled', !calendar.editable).val(calendar.editname || calendar.name);
|
||||||
color = $('#calendar-color').val(calendar.color).miniColors({ value: calendar.color });
|
color = $('#calendar-color').val(calendar.color).miniColors({ value: calendar.color });
|
||||||
name.select();
|
name.select();
|
||||||
|
@ -1291,7 +1291,7 @@ function rcube_calendar_ui(settings)
|
||||||
|
|
||||||
buttons[rcmail.gettext('save', 'calendar')] = function() {
|
buttons[rcmail.gettext('save', 'calendar')] = function() {
|
||||||
// form is not loaded
|
// form is not loaded
|
||||||
if (!form)
|
if (!form || !form.length)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: do some input validation
|
// TODO: do some input validation
|
||||||
|
|
|
@ -291,6 +291,7 @@ abstract class calendar_driver
|
||||||
* @param string E-mail address of attendee
|
* @param string E-mail address of attendee
|
||||||
* @param integer Requested period start date/time as unix timestamp
|
* @param integer Requested period start date/time as unix timestamp
|
||||||
* @param integer Requested period end date/time as unix timestamp
|
* @param integer Requested period end date/time as unix timestamp
|
||||||
|
*
|
||||||
* @return array List of busy timeslots within the requested range
|
* @return array List of busy timeslots within the requested range
|
||||||
*/
|
*/
|
||||||
public function get_freebusy_list($email, $start, $end)
|
public function get_freebusy_list($email, $start, $end)
|
||||||
|
@ -300,16 +301,16 @@ abstract class calendar_driver
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback function to append additional elements to the calendar create/edit form
|
* Callback function to produce driver-specific calendar create/edit form
|
||||||
*
|
*
|
||||||
* @param string Request action 'form-edit|form-new'
|
* @param string Request action 'form-edit|form-new'
|
||||||
* @param array Calendar properties (e.g. id)
|
* @param array Calendar properties (e.g. id, color)
|
||||||
* @param string HTML code for default edit form
|
*
|
||||||
* @return string HTML to be appended to form
|
* @return string HTML content of the form
|
||||||
*/
|
*/
|
||||||
public function calendar_form($action, $calendar, $html)
|
public function calendar_form($action, $calendar)
|
||||||
{
|
{
|
||||||
return $html;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -140,17 +140,15 @@ class kolab_driver extends calendar_driver
|
||||||
*/
|
*/
|
||||||
public function create_calendar($prop)
|
public function create_calendar($prop)
|
||||||
{
|
{
|
||||||
$folder = rcube_charset_convert($prop['name'], RCMAIL_CHARSET, 'UTF7-IMAP');
|
$folder = $this->folder_update($prop);
|
||||||
|
|
||||||
// add namespace prefix (when needed)
|
if ($folder === false) {
|
||||||
$this->rc->imap_init();
|
return false;
|
||||||
$folder = $this->rc->imap->mod_mailbox($folder, 'in');
|
}
|
||||||
|
|
||||||
// create ID
|
// create ID
|
||||||
$id = rcube_kolab::folder_id($folder);
|
$id = rcube_kolab::folder_id($folder);
|
||||||
|
|
||||||
// create IMAP folder
|
|
||||||
if (rcube_kolab::folder_create($folder, 'event')) {
|
|
||||||
// save color in user prefs (temp. solution)
|
// save color in user prefs (temp. solution)
|
||||||
$prefs['kolab_calendars'] = $this->rc->config->get('kolab_calendars', array());
|
$prefs['kolab_calendars'] = $this->rc->config->get('kolab_calendars', array());
|
||||||
$prefs['kolab_calendars'][$id]['color'] = $prop['color'];
|
$prefs['kolab_calendars'][$id]['color'] = $prop['color'];
|
||||||
|
@ -160,9 +158,6 @@ class kolab_driver extends calendar_driver
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update properties of an existing calendar
|
* Update properties of an existing calendar
|
||||||
|
@ -172,20 +167,16 @@ class kolab_driver extends calendar_driver
|
||||||
public function edit_calendar($prop)
|
public function edit_calendar($prop)
|
||||||
{
|
{
|
||||||
if ($prop['id'] && ($cal = $this->calendars[$prop['id']])) {
|
if ($prop['id'] && ($cal = $this->calendars[$prop['id']])) {
|
||||||
$newfolder = rcube_charset_convert($prop['name'], RCMAIL_CHARSET, 'UTF7-IMAP');
|
|
||||||
$oldfolder = $cal->get_realname();
|
$oldfolder = $cal->get_realname();
|
||||||
// add namespace prefix (when needed)
|
$newfolder = $this->folder_update($prop);
|
||||||
$this->rc->imap_init();
|
|
||||||
$newfolder = $this->rc->imap->mod_mailbox($newfolder, 'in');
|
|
||||||
|
|
||||||
if (!$cal->readonly && $newfolder != $oldfolder)
|
if ($newfolder === false) {
|
||||||
$result = rcube_kolab::folder_rename($oldfolder, $newfolder);
|
return false;
|
||||||
else
|
}
|
||||||
$result = true;
|
|
||||||
|
|
||||||
if ($result) {
|
|
||||||
// create ID
|
// create ID
|
||||||
$id = $newfolder ? rcube_kolab::folder_id($newfolder) : $prop['id'];
|
$id = rcube_kolab::folder_id($newfolder);
|
||||||
|
|
||||||
// save color in user prefs (temp. solution)
|
// save color in user prefs (temp. solution)
|
||||||
$prefs['kolab_calendars'] = $this->rc->config->get('kolab_calendars', array());
|
$prefs['kolab_calendars'] = $this->rc->config->get('kolab_calendars', array());
|
||||||
unset($prefs['kolab_calendars'][$prop['id']]);
|
unset($prefs['kolab_calendars'][$prop['id']]);
|
||||||
|
@ -193,13 +184,72 @@ class kolab_driver extends calendar_driver
|
||||||
|
|
||||||
$this->rc->user->save_prefs($prefs);
|
$this->rc->user->save_prefs($prefs);
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename or Create a new IMAP folder
|
||||||
|
*
|
||||||
|
* @param array Hash array with calendar properties
|
||||||
|
*
|
||||||
|
* @return mixed New folder name or False on failure
|
||||||
|
*/
|
||||||
|
private function folder_update($prop)
|
||||||
|
{
|
||||||
|
$folder = rcube_charset_convert($prop['name'], RCMAIL_CHARSET, 'UTF7-IMAP');
|
||||||
|
$oldfolder = $prop['oldname']; // UTF7
|
||||||
|
$parent = $prop['parent']; // UTF7
|
||||||
|
$delimiter = $_SESSION['imap_delimiter'];
|
||||||
|
|
||||||
|
// sanity checks (from steps/settings/save_folder.inc)
|
||||||
|
if (!strlen($folder)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (strlen($folder) > 128) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// these characters are problematic e.g. when used in LIST/LSUB
|
||||||
|
foreach (array($delimiter, '%', '*') as $char) {
|
||||||
|
if (strpos($folder, $delimiter) !== false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @TODO: $options
|
||||||
|
$options = array();
|
||||||
|
if ($options['protected'] || $options['norename']) {
|
||||||
|
$folder = $oldfolder;
|
||||||
|
}
|
||||||
|
else if (strlen($parent)) {
|
||||||
|
$folder = $parent . $delimiter . $folder;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// add namespace prefix (when needed)
|
||||||
|
$this->rc->imap_init();
|
||||||
|
$folder = $this->rc->imap->mod_mailbox($folder, 'in');
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the folder name
|
||||||
|
if (strlen($oldfolder)) {
|
||||||
|
if ($oldfolder != $folder)
|
||||||
|
$result = rcube_kolab::folder_rename($oldfolder, $folder);
|
||||||
|
else
|
||||||
|
$result = true;
|
||||||
|
}
|
||||||
|
// create new folder
|
||||||
|
else {
|
||||||
|
$result = rcube_kolab::folder_create($folder, 'event', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result ? $folder : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the given calendar with all its contents
|
* Delete the given calendar with all its contents
|
||||||
*
|
*
|
||||||
|
@ -772,4 +822,167 @@ class kolab_driver extends calendar_driver
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback function to produce driver-specific calendar create/edit form
|
||||||
|
*
|
||||||
|
* @param string Request action 'form-edit|form-new'
|
||||||
|
* @param array Calendar properties (e.g. id, color)
|
||||||
|
*
|
||||||
|
* @return string HTML content of the form
|
||||||
|
*/
|
||||||
|
public function calendar_form($action, $calendar)
|
||||||
|
{
|
||||||
|
// Remove any scripts/css/js
|
||||||
|
$this->rc->output->reset();
|
||||||
|
// Produce form content
|
||||||
|
$content = $this->calendar_form_content($calendar);
|
||||||
|
// Parse form template, write to output buffer
|
||||||
|
// This way other plugins (e.g. acl) will be able to add scripts/style to the content
|
||||||
|
ob_start();
|
||||||
|
$this->rc->output->parse('calendar.calendarform-kolab', false, true);
|
||||||
|
$html = ob_get_clean();
|
||||||
|
|
||||||
|
return str_replace('%FORM_CONTENT%', $content, $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produces calendar edit/create form content
|
||||||
|
*
|
||||||
|
* @return string HTML content of the form
|
||||||
|
*/
|
||||||
|
private function calendar_form_content($calendar)
|
||||||
|
{
|
||||||
|
if ($calendar['id'] && ($cal = $this->calendars[$calendar['id']])) {
|
||||||
|
$folder = $cal->get_realname(); // UTF7
|
||||||
|
$color = $cal->get_color();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$folder = '';
|
||||||
|
$color = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$hidden_fields[] = array('name' => 'oldname', 'value' => $folder);
|
||||||
|
|
||||||
|
$delim = $_SESSION['imap_delimiter'];
|
||||||
|
$form = array();
|
||||||
|
|
||||||
|
if (strlen($folder)) {
|
||||||
|
$path_imap = explode($delim, $folder);
|
||||||
|
$name = rcube_charset_convert(array_pop($path_imap), 'UTF7-IMAP');
|
||||||
|
$path_imap = implode($path_imap, $delim);
|
||||||
|
|
||||||
|
$this->rc->imap_connect();
|
||||||
|
$options = $this->rc->imap->mailbox_info($folder);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$path_imap = '';
|
||||||
|
$name = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// General tab
|
||||||
|
$form['props'] = array(
|
||||||
|
'name' => $this->rc->gettext('properties'),
|
||||||
|
);
|
||||||
|
|
||||||
|
// calendar name
|
||||||
|
$foldername = new html_inputfield(array('name' => 'name', 'id' => 'calendar-name', 'size' => 20));
|
||||||
|
|
||||||
|
$form['props']['fieldsets']['location'] = array(
|
||||||
|
'name' => $this->rc->gettext('location'),
|
||||||
|
'content' => array(
|
||||||
|
'name' => array(
|
||||||
|
'label' => $this->cal->gettext('name'),
|
||||||
|
'value' => $foldername->show($name),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!empty($options) && ($options['norename'] || $options['namespace'] != 'personal')) {
|
||||||
|
// prevent user from moving folder
|
||||||
|
$hidden_fields[] = array('name' => 'parent', 'value' => $path_imap);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$select = rcube_kolab::folder_selector('event', array('name' => 'parent'));
|
||||||
|
|
||||||
|
$form['props']['fieldsets']['location']['content']['path'] = array(
|
||||||
|
'label' => $this->cal->gettext('parentcalendar'),
|
||||||
|
'value' => $select->show($path_imap),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// calendar color
|
||||||
|
$color = new html_inputfield(array('name' => 'color', 'id' => 'calendar-color', 'size' => 6));
|
||||||
|
|
||||||
|
$form['props']['fieldsets']['settings'] = array(
|
||||||
|
'name' => $this->rc->gettext('settings'),
|
||||||
|
'content' => array(
|
||||||
|
'color' => array(
|
||||||
|
'label' => $this->cal->gettext('color'),
|
||||||
|
'value' => $color->show($calendar['color']),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Allow plugins to modify the form content (e.g. with ACL form)
|
||||||
|
$plugin = $this->rc->plugins->exec_hook('calendar_form_kolab',
|
||||||
|
array('form' => $form, 'options' => $options, 'name' => $folder));
|
||||||
|
|
||||||
|
$form = $plugin['form'];
|
||||||
|
$out = '';
|
||||||
|
|
||||||
|
if (is_array($hidden_fields)) {
|
||||||
|
foreach ($hidden_fields as $field) {
|
||||||
|
$hiddenfield = new html_hiddenfield($field);
|
||||||
|
$out .= $hiddenfield->show() . "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create form output
|
||||||
|
foreach ($form as $tab) {
|
||||||
|
if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) {
|
||||||
|
$content = '';
|
||||||
|
foreach ($tab['fieldsets'] as $fieldset) {
|
||||||
|
$subcontent = $this->get_form_part($fieldset);
|
||||||
|
if ($subcontent) {
|
||||||
|
$content .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $subcontent) ."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$content = $this->get_form_part($tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($content) {
|
||||||
|
$out .= html::tag('fieldset', null, html::tag('legend', null, Q($tab['name'])) . $content) ."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function used in calendar_form_content(). Creates a part of the form.
|
||||||
|
*/
|
||||||
|
private function get_form_part($form)
|
||||||
|
{
|
||||||
|
$content = '';
|
||||||
|
|
||||||
|
if (is_array($form['content']) && !empty($form['content'])) {
|
||||||
|
$table = new html_table(array('cols' => 2));
|
||||||
|
foreach ($form['content'] as $col => $colprop) {
|
||||||
|
$colprop['id'] = '_'.$col;
|
||||||
|
$label = !empty($colprop['label']) ? $colprop['label'] : rcube_label($col);
|
||||||
|
|
||||||
|
$table->add('title', sprintf('<label for="%s">%s</label>', $colprop['id'], Q($label)));
|
||||||
|
$table->add(null, $colprop['value']);
|
||||||
|
}
|
||||||
|
$content = $table->show();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$content = $form['content'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -529,26 +529,17 @@ class calendar_ui
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for calendar form template object.
|
* Handler for calendar form template.
|
||||||
* Will get additional form fields from driver class
|
* The form content could be overriden by the driver
|
||||||
*/
|
*/
|
||||||
function calendar_editform($action, $calendar = array())
|
function calendar_editform($action, $calendar = array())
|
||||||
{
|
{
|
||||||
// compose default calendar form
|
$html = $this->calendar->driver->calendar_form($action, $calendar);
|
||||||
$input_name = new html_inputfield(array('name' => 'name', 'id' => 'calendar-name', 'size' => 20));
|
|
||||||
$html = html::div('form-section',
|
|
||||||
html::label('calendar-name', $this->calendar->gettext('name')) .
|
|
||||||
$input_name->show($calendar['name']));
|
|
||||||
|
|
||||||
$input_color = new html_inputfield(array('name' => 'color', 'id' => 'calendar-color', 'size' => 6));
|
if (!$html)
|
||||||
$html .= html::div('form-section',
|
$html = $this->rc->output->parse('calendar.calendarform', false, false);
|
||||||
html::label('calendar-color', $this->calendar->gettext('color')) .
|
|
||||||
$input_color->show($calendar['color']));
|
|
||||||
|
|
||||||
// allow driver to extend the form
|
return $html;
|
||||||
$html = $this->calendar->driver->calendar_form($action, $calendar, $html);
|
|
||||||
|
|
||||||
return html::tag('form', array('action' => "#", 'method' => "get"), $html);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$labels = array();
|
$labels = array();
|
||||||
|
|
||||||
// preferences
|
// preferences
|
||||||
|
@ -56,6 +57,7 @@ $labels['alarms'] = 'Reminder';
|
||||||
$labels['generated'] = 'generated at';
|
$labels['generated'] = 'generated at';
|
||||||
$labels['selectdate'] = 'Select date';
|
$labels['selectdate'] = 'Select date';
|
||||||
$labels['printdescriptions'] = 'Print descriptions';
|
$labels['printdescriptions'] = 'Print descriptions';
|
||||||
|
$labels['parentcalendar'] = 'Superior calendar';
|
||||||
|
|
||||||
// alarm/reminder settings
|
// alarm/reminder settings
|
||||||
$labels['alarmemail'] = 'Send Email';
|
$labels['alarmemail'] = 'Send Email';
|
||||||
|
|
|
@ -843,6 +843,28 @@ a.alarm-action-snooze:after {
|
||||||
height: 160px;
|
height: 160px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#calendar-details {
|
||||||
|
left: 5px;
|
||||||
|
position: absolute;
|
||||||
|
right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#calendar-details div.tabsbar {
|
||||||
|
top: 0;
|
||||||
|
left: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#calendar-details fieldset {
|
||||||
|
background-color: #F2F2F2;
|
||||||
|
}
|
||||||
|
|
||||||
|
#calendar-details table td.title {
|
||||||
|
font-weight: bold;
|
||||||
|
white-space: nowrap;
|
||||||
|
color: #666;
|
||||||
|
padding-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* fullcalendar style overrides */
|
/* fullcalendar style overrides */
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
<html>
|
||||||
|
<head></head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="calendar-details">
|
||||||
|
<form action="#" id="calendarpropform">
|
||||||
|
%FORM_CONTENT%
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
rcube_init_tabs('calendar-details > form');
|
||||||
|
$('#calendarform').dialog({
|
||||||
|
height: Math.min(400, $('#calendar-details').height()+90),
|
||||||
|
width: Math.min(500, $('#calendar-details').width()+50),
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Reference in a new issue