Improve categories handling: categories from event objects are automatically added to the user's list of categories; color assignments are currently saved in user prefs
This commit is contained in:
parent
7ef15d9c7a
commit
7b623f293e
5 changed files with 36 additions and 21 deletions
|
@ -394,7 +394,7 @@ class calendar extends rcube_plugin
|
|||
|
||||
|
||||
// category definitions
|
||||
if (!$this->driver->categoriesimmutable) {
|
||||
if (!$this->driver->nocategories) {
|
||||
$p['blocks']['categories']['name'] = $this->gettext('categories');
|
||||
|
||||
$categories = (array) $this->driver->list_categories();
|
||||
|
@ -403,9 +403,10 @@ class calendar extends rcube_plugin
|
|||
$key = md5($name);
|
||||
$field_class = 'rcmfd_category_' . str_replace(' ', '_', $name);
|
||||
$category_remove = new html_inputfield(array('type' => 'button', 'value' => 'X', 'class' => 'button', 'onclick' => '$(this).parent().remove()', 'title' => $this->gettext('remove_category')));
|
||||
$category_name = new html_inputfield(array('name' => "_categories[$key]", 'class' => $field_class, 'size' => 30));
|
||||
$category_name = new html_inputfield(array('name' => "_categories[$key]", 'class' => $field_class, 'size' => 30, 'disabled' => $this->driver->categoriesimmutable));
|
||||
$category_color = new html_inputfield(array('name' => "_colors[$key]", 'class' => "$field_class colors", 'size' => 6));
|
||||
$categories_list .= html::div(null, $category_name->show($name) . ' ' . $category_color->show($color) . ' ' . $category_remove->show());
|
||||
$hidden = $this->driver->categoriesimmutable ? html::tag('input', array('type' => 'hidden', 'name' => "_categories[$key]", 'value' => $name)) : '';
|
||||
$categories_list .= html::div(null, $hidden . $category_name->show($name) . ' ' . $category_color->show($color) . ' ' . $category_remove->show());
|
||||
}
|
||||
|
||||
$p['blocks']['categories']['options']['category_' . $name] = array(
|
||||
|
@ -470,7 +471,7 @@ class calendar extends rcube_plugin
|
|||
);
|
||||
|
||||
// categories
|
||||
if (!$this->driver->categoriesimmutable) {
|
||||
if (!$this->driver->nocategories) {
|
||||
$old_categories = $new_categories = array();
|
||||
foreach ($this->driver->list_categories() as $name => $color) {
|
||||
$old_categories[md5($name)] = $name;
|
||||
|
@ -953,7 +954,7 @@ class calendar extends rcube_plugin
|
|||
'end' => gmdate('c', $this->fromGMT($event['end'])), // so shift timestamps to users's timezone and render a date string
|
||||
'description' => strval($event['description']),
|
||||
'location' => strval($event['location']),
|
||||
'className' => ($addcss ? 'fc-event-cal-'.asciiwords($event['calendar'], true).' ' : '') . 'fc-event-cat-' . asciiwords($event['categories'], true),
|
||||
'className' => ($addcss ? 'fc-event-cal-'.asciiwords($event['calendar'], true).' ' : '') . 'fc-event-cat-' . asciiwords(strtolower($event['categories']), true),
|
||||
'allDay' => ($event['allday'] == 1),
|
||||
) + $event;
|
||||
}
|
||||
|
|
|
@ -450,6 +450,11 @@ function rcube_calendar_ui(settings)
|
|||
// enable/disable alarm property according to backend support
|
||||
$('#edit-alarms')[(calendar.alarms ? 'show' : 'hide')]();
|
||||
|
||||
// check categories drop-down: add value if not exists
|
||||
if (event.categories && !categories.find("option[value='"+event.categories+"']").length) {
|
||||
$('<option>').attr('value', event.categories).text(event.categories).appendTo(categories).prop('selected', true);
|
||||
}
|
||||
|
||||
// set recurrence form
|
||||
var recurrence, interval, rrtimes, rrenddate;
|
||||
var load_recurrence_tab = function()
|
||||
|
|
|
@ -31,6 +31,7 @@ class kolab_calendar
|
|||
public $readonly = true;
|
||||
public $attachments = true;
|
||||
public $alarms = false;
|
||||
public $categories = array();
|
||||
|
||||
private $cal;
|
||||
private $storage;
|
||||
|
@ -220,6 +221,10 @@ class kolab_calendar
|
|||
|
||||
$events = array();
|
||||
foreach ($this->events as $id => $event) {
|
||||
// remember seen categories
|
||||
if ($event['categories'])
|
||||
$this->categories[$event['categories']]++;
|
||||
|
||||
// filter events by search query
|
||||
if (!empty($search)) {
|
||||
$hit = false;
|
||||
|
@ -571,6 +576,9 @@ class kolab_calendar
|
|||
$_attendees .= $rec['organizer']['display-name'] . ' ' . $rec['organizer']['smtp-address'] . ' ';
|
||||
}
|
||||
|
||||
// Roundcube only supports one category assignment
|
||||
$categories = explode(',', $rec['categories']);
|
||||
|
||||
return array(
|
||||
'id' => $rec['uid'],
|
||||
'uid' => $rec['uid'],
|
||||
|
@ -583,7 +591,7 @@ class kolab_calendar
|
|||
'recurrence' => $rrule,
|
||||
'alarms' => $alarm_value . $alarm_unit,
|
||||
'_alarm' => intval($rec['alarm']),
|
||||
'categories' => $rec['categories'],
|
||||
'categories' => $categories[0],
|
||||
'attachments' => $attachments,
|
||||
'attendees' => $attendees,
|
||||
'_attendees' => $_attendees,
|
||||
|
|
|
@ -680,12 +680,21 @@ class kolab_driver extends calendar_driver
|
|||
if ($calendars && is_string($calendars))
|
||||
$calendars = explode(',', $calendars);
|
||||
|
||||
$events = array();
|
||||
$events = $categories = array();
|
||||
foreach ($this->calendars as $cid => $calendar) {
|
||||
if ($calendars && !in_array($cid, $calendars))
|
||||
continue;
|
||||
|
||||
$events = array_merge($events, $this->calendars[$cid]->list_events($start, $end, $search, $virtual));
|
||||
$categories += $this->calendars[$cid]->categories;
|
||||
}
|
||||
|
||||
// add new categories to user prefs
|
||||
$old_categories = $this->rc->config->get('calendar_categories', array());
|
||||
if ($newcats = array_diff(array_map('strtolower', array_keys($categories)), array_map('strtolower', array_keys($old_categories)))) {
|
||||
foreach ($newcats as $category)
|
||||
$old_categories[$category] = ''; // no color set yet
|
||||
$this->rc->user->save_prefs(array('calendar_categories' => $old_categories));
|
||||
}
|
||||
|
||||
return $events;
|
||||
|
@ -835,19 +844,8 @@ class kolab_driver extends calendar_driver
|
|||
*/
|
||||
public function list_categories()
|
||||
{
|
||||
# fixed list according to http://www.kolab.org/doc/kolabformat-2.0rc7-html/c300.html
|
||||
return array(
|
||||
'important' => 'cc0000',
|
||||
'business' => '333333',
|
||||
'personal' => '333333',
|
||||
'vacation' => '333333',
|
||||
'must-attend' => '333333',
|
||||
'travel-required' => '333333',
|
||||
'needs-preparation' => '333333',
|
||||
'birthday' => '333333',
|
||||
'anniversary' => '333333',
|
||||
'phone-call' => '333333',
|
||||
);
|
||||
// FIXME: complete list with categories saved in config objects (KEP:12)
|
||||
return $this->rc->config->get('calendar_categories', array());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -93,7 +93,10 @@ class calendar_ui
|
|||
$css = "\n";
|
||||
|
||||
foreach ((array)$categories as $class => $color) {
|
||||
$class = 'cat-' . asciiwords($class, true);
|
||||
if (empty($color))
|
||||
continue;
|
||||
|
||||
$class = 'cat-' . asciiwords(strtolower($class), true);
|
||||
$css .= ".$class { color: #$color }\n";
|
||||
if ($mode > 0) {
|
||||
if ($mode == 2) {
|
||||
|
|
Loading…
Add table
Reference in a new issue