From ef558a777feb667206449a66207288d7bc0b6bf8 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Sat, 21 Nov 2009 00:47:52 +0100 Subject: [PATCH] Add alarm notifications. --- kronolith/js/kronolith.js | 52 +++++++++++++++++++++++++++++++++++++++++++-- kronolith/lib/Kronolith.php | 11 +++++++--- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/kronolith/js/kronolith.js b/kronolith/js/kronolith.js index de7081cea..226b7e68a 100644 --- a/kronolith/js/kronolith.js +++ b/kronolith/js/kronolith.js @@ -28,6 +28,7 @@ KronolithCore = { date: new Date(), tasktype: 'incomplete', growls: 0, + alarms: [], doActionOpts: { onException: function(r, e) { KronolithCore.debug('onException', e); }, @@ -120,12 +121,58 @@ KronolithCore = { this.logout(Kronolith.conf.timeout_url); return true; + case 'horde.alarm': + // Only show one instance of an alarm growl. + if (this.alarms.indexOf(m.alarm.id) != -1) { + break; + } + message = m.alarm.title.escapeHTML(); + if (!Object.isUndefined(m.alarm.url)) { + message = new Element('a', { 'href': m.alarm.url }) + .insert(message); + } + var select = new Element('select'); + $H(Kronolith.conf.snooze).each(function(snooze) { + select.insert(new Element('option', { 'value': snooze.key }).insert(snooze.value)); + }); + message = new Element('div') + .insert(message) + .insert(' ') + .insert(select); + var growl = this.Growler.growl(message, { + className: 'horde-alarm', + life: 8, + log: false, + sticky: true, + created: function() { + if (m.type == 'horde.alarm') { + this.alarms.push(m.alarm.id); + } + }.bind(this), + destroyed: function() { + if (m.type == 'horde.alarm') { + this.alarms = this.alarms.without(m.alarm.id); + } + }.bind(this) + }); + select.observe('change', function() { + if (select.getValue()) { + new Ajax.Request( + Kronolith.conf.URI_SNOOZE, + { 'parameters': { 'alarm': m.alarm.id, + 'snooze': select.getValue() }, + 'onSuccess': function() { + this.Growler.ungrowl(growl); + }.bind(this)}); + } + }.bind(this)); + break; + case 'horde.error': case 'horde.warning': - //case 'horde.alarm': case 'horde.message': case 'horde.success': - this.Growler.growl(m.message, { + this.Growler.growl(m.message.escapeHTML(), { className: m.type.replace('.', '-'), life: 8, log: true, @@ -140,6 +187,7 @@ KronolithCore = { } notify.update(Kronolith.text.alerts.interpolate({ 'count': ++this.growls })); notify.up().show(); + break; } }, this); }, diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 76547574a..2eb16d02e 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -123,7 +123,7 @@ class Kronolith $code['conf'] = array( 'URI_AJAX' => Horde::url($kronolith_webroot . '/ajax.php', true, -1), 'URI_IMG' => $registry->getImageDir() . '/', - //'URI_VIEW' => Horde_Util::addParameter(Horde::url($imp_webroot . '/view.php', true, -1), array('actionID' => 'view_source', 'id' => 0), null, false), + 'URI_SNOOZE' => Horde::url($registry->get('webroot', 'horde') . '/services/snooze.php', true, -1), 'SESSION_ID' => defined('SID') ? SID : '', 'prefs_url' => str_replace('&', '&', Horde::getServiceLink('options', 'kronolith')), 'name' => $registry->get('name'), @@ -147,8 +147,13 @@ class Kronolith Horde_Date_Recurrence::RECUR_YEARLY_DATE => 'Yearly', Horde_Date_Recurrence::RECUR_YEARLY_DAY => 'Yearly', Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY => 'Yearly'), - // Turn debugging on? - 'debug' => !empty($conf['js']['debug']), + 'snooze' => array('' => _("Snooze..."), + '-1' => _("Dismiss"), + '5' => _("5 minutes"), + '15' => _("15 minutes"), + '60' => _("1 hour"), + '360' => _("6 hours"), + '1440' => _("1 day")), ); // Calendars -- 2.11.0