Allow user to enable/disable alarms per calendar

This commit is contained in:
Thomas Bruederli 2011-07-31 14:40:52 +02:00
parent 2797716362
commit f7c12cb456
10 changed files with 47 additions and 15 deletions

View file

@ -1422,9 +1422,9 @@ function rcube_calendar_ui(settings)
var $dialog = $("#calendarform").dialog('close');
if (!calendar)
calendar = { name:'', color:'cc0000', editable:true };
calendar = { name:'', color:'cc0000', editable:true, showalarms:true };
var form, name, color;
var form, name, color, alarms;
$dialog.html(rcmail.get_label('loading'));
$.ajax({
@ -1439,6 +1439,7 @@ function rcube_calendar_ui(settings)
me.dialog_resize('#calendarform', form.height(), form.width());
name = $('#calendar-name').prop('disabled', !calendar.editable).val(calendar.editname || calendar.name);
color = $('#calendar-color').val(calendar.color).miniColors({ value: calendar.color });
alarms = $('#calendar-showalarms').prop('checked', calendar.showalarms).get(0);
name.select();
}
});

View file

@ -91,8 +91,9 @@ abstract class calendar_driver
* Create a new calendar assigned to the current user
*
* @param array Hash array with calendar properties
* name: Calendar name
* color: The color of the calendar
* name: Calendar name
* color: The color of the calendar
* showalarms: True if alarms are enabled
* @return mixed ID of the calendar on success, False on error
*/
abstract function create_calendar($prop);
@ -101,9 +102,10 @@ abstract class calendar_driver
* Update properties of an existing calendar
*
* @param array Hash array with calendar properties
* id: Calendar Identifier
* name: Calendar name
* color: The color of the calendar
* id: Calendar Identifier
* name: Calendar name
* color: The color of the calendar
* showalarms: True if alarms are enabled (if supported)
* @return boolean True on success, Fales on failure
*/
abstract function edit_calendar($prop);

View file

@ -81,6 +81,7 @@ class database_driver extends calendar_driver
$this->rc->user->ID
);
while ($result && ($arr = $this->rc->db->fetch_assoc($result))) {
$arr['showalarms'] = intval($arr['showalarms']);
$this->calendars[$arr['calendar_id']] = $arr;
$calendar_ids[] = $this->rc->db->quote($arr['calendar_id']);
}
@ -114,11 +115,12 @@ class database_driver extends calendar_driver
{
$result = $this->rc->db->query(
"INSERT INTO " . $this->db_calendars . "
(user_id, name, color)
(user_id, name, color, showalarms)
VALUES (?, ?, ?)",
$this->rc->user->ID,
$prop['name'],
$prop['color']
$prop['color'],
$prop['showalarms']?1:0
);
if ($result)
@ -136,11 +138,12 @@ class database_driver extends calendar_driver
{
$query = $this->rc->db->query(
"UPDATE " . $this->db_calendars . "
SET name=?, color=?
SET name=?, color=?, showalarms=?
WHERE calendar_id=?
AND user_id=?",
$prop['name'],
$prop['color'],
$prop['showalarms']?1:0,
$prop['id'],
$this->rc->user->ID
);
@ -187,7 +190,7 @@ class database_driver extends calendar_driver
$query = $this->rc->db->query(sprintf(
"INSERT INTO " . $this->db_events . "
(calendar_id, created, changed, uid, start, end, all_day, recurrence, title, description, location, categories, free_busy, priority, sensitivity, attendees, alarms, notifyat)
VALUES (?, %s, %s, ?, %s, %s, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
VALUES (?, %s, %s, ?, %s, %s, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
$this->rc->db->now(),
$this->rc->db->now(),
$this->rc->db->fromunixtime($event['start']),
@ -738,8 +741,13 @@ class database_driver extends calendar_driver
else if (is_string($calendars))
$calendars = explode(',', $calendars);
// only allow to select from calendars of this use
$calendar_ids = array_map(array($this->rc->db, 'quote'), array_intersect($calendars, array_keys($this->calendars)));
// only allow to select from calendars with activated alarms
$calendar_ids = array();
foreach ($calendars as $cid) {
if ($this->calendars[$cid] && $this->calendars[$cid]['showalarms'])
$calendar_ids[] = $cid;
}
$calendar_ids = array_map(array($this->rc->db, 'quote'), $calendar_ids);
$alarms = array();
if (!empty($calendar_ids)) {

View file

@ -17,6 +17,7 @@ CREATE TABLE `calendars` (
`user_id` int(10) UNSIGNED NOT NULL DEFAULT '0',
`name` varchar(255) NOT NULL,
`color` varchar(8) NOT NULL,
`showalarms` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY(`calendar_id`),
CONSTRAINT `fk_calendars_user_id` FOREIGN KEY (`user_id`)
REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE

View file

@ -26,6 +26,7 @@ CREATE TABLE calendars (
REFERENCES users (user_id) ON UPDATE CASCADE ON DELETE CASCADE,
name varchar(255) NOT NULL,
color varchar(8) NOT NULL,
showalarms smallint NOT NULL DEFAULT 1,
PRIMARY KEY (calendar_id)
);

View file

@ -18,6 +18,7 @@ CREATE TABLE calendars (
user_id integer NOT NULL default '0',
name varchar(255) NOT NULL default '',
color varchar(255) NOT NULL default '',
showalarms tinyint(1) NOT NULL default '1',
CONSTRAINT fk_calendars_user_id FOREIGN KEY (user_id)
REFERENCES users(user_id)
);

View file

@ -72,6 +72,11 @@ class kolab_calendar
$this->readonly = false;
}
}
// user-specific alarms settings win
$prefs = $this->cal->rc->config->get('kolab_calendars', array());
if (isset($prefs[$this->id]['showalarms']))
$this->alarms = $prefs[$this->id]['showalarms'];
}
}
@ -150,7 +155,6 @@ class kolab_calendar
return 'cc0000';
}
/**
* Return the corresponding Kolab_Folder instance
*/
@ -559,6 +563,7 @@ class kolab_calendar
'allday' => $allday,
'recurrence' => $rrule,
'alarms' => $alarm_value . $alarm_unit,
'_alarm' => intval($rec['alarm']),
'categories' => $rec['categories'],
'attachments' => $attachments,
'attendees' => $attendees,

View file

@ -122,6 +122,7 @@ class kolab_driver extends calendar_driver
'editname' => $cal->get_foldername(),
'color' => $cal->get_color(),
'readonly' => $cal->readonly,
'showalarms' => $cal->alarms,
'class_name' => $cal->get_namespace(),
);
}
@ -178,10 +179,11 @@ class kolab_driver extends calendar_driver
// create ID
$id = rcube_kolab::folder_id($newfolder);
// save color in user prefs (temp. solution)
// save color and alarms in user prefs (temp. solution)
$prefs['kolab_calendars'] = $this->rc->config->get('kolab_calendars', array());
unset($prefs['kolab_calendars'][$prop['id']]);
$prefs['kolab_calendars'][$id]['color'] = $prop['color'];
$prefs['kolab_calendars'][$id]['showalarms'] = $prop['showalarms'] ? true : false;
$this->rc->user->save_prefs($prefs);
return true;
@ -932,6 +934,7 @@ class kolab_driver extends calendar_driver
'name' => $this->rc->gettext('settings'),
'content' => array(
'color' => $formfields['color'],
'showalarms' => $formfields['showalarms'],
),
);

View file

@ -569,6 +569,15 @@ class calendar_ui
),
);
if ($this->calendar->driver->alarms) {
$checkbox = new html_checkbox(array('name' => 'showalarms', 'id' => 'calendar-showalarms', 'value' => 1));
$formfields['showalarms'] = array(
'label' => $this->calendar->gettext('showalarms'),
'value' => $checkbox->show($calendar['showalarms']?1:0),
'id' => 'calendar-showalarms',
);
}
// allow driver to extend or replace the form content
return html::tag('form', array('action' => "#", 'method' => "get", 'id' => 'calendarpropform'),
$this->calendar->driver->calendar_form($action, $calendar, $formfields)

View file

@ -65,6 +65,7 @@ $labels['searchearlierdates'] = '« Search for earlier events';
$labels['searchlaterdates'] = 'Search for later events »';
// alarm/reminder settings
$labels['showalarms'] = 'Show alarms';
$labels['alarmemail'] = 'Send Email';
$labels['alarmdisplay'] = 'Show message';
$labels['alarmdisplayoption'] = 'Message';