Add alarm notifications.
authorJan Schneider <jan@horde.org>
Fri, 20 Nov 2009 23:47:52 +0000 (00:47 +0100)
committerJan Schneider <jan@horde.org>
Fri, 20 Nov 2009 23:48:12 +0000 (00:48 +0100)
kronolith/js/kronolith.js
kronolith/lib/Kronolith.php

index de7081c..226b7e6 100644 (file)
@@ -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);
     },
index 7654757..2eb16d0 100644 (file)
@@ -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('&amp;', '&', 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