Fix displaying the url to the alarm's object.
authorJan Schneider <jan@horde.org>
Tue, 2 Mar 2010 22:59:20 +0000 (23:59 +0100)
committerJan Schneider <jan@horde.org>
Tue, 2 Mar 2010 23:02:34 +0000 (00:02 +0100)
Hide alarm notification if clicking the object link.
Add a separate button for dismissing the alarm.

kronolith/js/kronolith.js
kronolith/lib/Ajax/Application.php
kronolith/lib/Event.php
kronolith/lib/Kronolith.php

index 99f5bab..61df8f5 100644 (file)
@@ -131,29 +131,36 @@ KronolithCore = {
             case 'horde.alarm':
                 var alarm = m.flags.alarm;
                 // Only show one instance of an alarm growl.
-                if (this.alarms.indexOf(alarm.id) != -1) {
+                if (this.alarms.include(alarm.id)) {
                     break;
                 }
 
                 this.alarms.push(alarm.id);
 
                 message = alarm.title.escapeHTML();
-                if (!Object.isUndefined(alarm.ajax)) {
-                    message = new Element('a')
-                        .insert(message)
-                        .observe('click', function() { this.go(alarm.ajax); }.bind(this));
-                } else if (!Object.isUndefined(alarm.url)) {
-                    message = new Element('a', { href: alarm.url })
-                        .insert(message);
+                if (!Object.isUndefined(alarm.params) &&
+                    !Object.isUndefined(alarm.params.notify)) {
+                    if (!Object.isUndefined(alarm.params.notify.ajax)) {
+                        message = new Element('a')
+                            .insert(message)
+                            .observe('click', function() {
+                                this.Growler.ungrowl(growl);
+                                this.go(alarm.params.notify.ajax);
+                            }.bind(this));
+                    } else if (!Object.isUndefined(alarm.params.notify.url)) {
+                        message = new Element('a', { href: alarm.params.notify.url })
+                            .insert(message);
+                    }
                 }
                 message = new Element('div')
                     .insert(message);
                 if (alarm.user) {
-                    var select = new Element('select');
-                        $H(Kronolith.conf.snooze).each(function(snooze) {
-                            select.insert(new Element('option', { value: snooze.key }).insert(snooze.value));
-                        });
-                    message.insert(' ').insert(select);
+                    var select = '<select>';
+                    $H(Kronolith.conf.snooze).each(function(snooze) {
+                        select += '<option value="' + snooze.key + '">' + snooze.value + '</option>';
+                    });
+                    select += '</select>';
+                    message.insert('<br /><br />' + Kronolith.text.snooze.interpolate({ time: select, dismiss_start: '<input type="button" value="', dismiss_end: '" class="button ko" />' }));
                 }
                 var growl = this.Growler.growl(message, {
                     className: 'horde-alarm',
@@ -171,15 +178,22 @@ KronolithCore = {
                 }.bindAsEventListener(this));
 
                 if (alarm.user) {
-                    select.observe('change', function() {
-                        if (select.getValue()) {
+                    message.down('select').observe('change', function(e) {
+                        if (e.element().getValue()) {
                             this.Growler.ungrowl(growl);
                             new Ajax.Request(
                                 Kronolith.conf.URI_SNOOZE,
                                 { parameters: { alarm: alarm.id,
-                                                snooze: select.getValue() } });
+                                                snooze: e.element().getValue() } });
                         }
-                    }.bind(this));
+                    }.bindAsEventListener(this));
+                    message.down('input[type=button]').observe('click', function(e) {
+                        this.Growler.ungrowl(growl);
+                        new Ajax.Request(
+                            Kronolith.conf.URI_SNOOZE,
+                            { parameters: { alarm: alarm.id,
+                                            snooze: -1 } });
+                    }.bindAsEventListener(this));
                 }
                 break;
 
@@ -3680,6 +3694,25 @@ KronolithCore = {
 
         this.setTitle(ev.t);
         RedBox.showHtml($('kronolithEventDialog').show());
+
+        /* Hide alarm message for this event. */
+        if (r.msgs) {
+            r.msgs = r.msgs.reject(function(msg) {
+                if (msg.type != 'horde.alarm') {
+                    return false;
+                }
+                var alarm = msg.flags.alarm;
+                if (alarm.params && alarm.params.notify &&
+                    alarm.params.notify.show &&
+                    alarm.params.notify.show.calendar &&
+                    alarm.params.notify.show.event &&
+                    alarm.params.notify.show.calendar == ev.c &&
+                    alarm.params.notify.show.event == ev.id) {
+                    return true;
+                }
+                return false;
+            });
+        }
     },
 
     /**
index a978306..69dd033 100644 (file)
@@ -415,6 +415,7 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
      */
     public function ListTopTags()
     {
+        $this->notify = false;
         $tagger = new Kronolith_Tagger();
         $result = new stdClass;
         $result->tags = array();
index 6503114..bff33ca 100644 (file)
@@ -1128,6 +1128,7 @@ abstract class Kronolith_Event
                 '__app' => $GLOBALS['registry']->getApp(),
                 'event' => $this->id,
                 'calendar' => $this->calendar);
+            $methods['notify']['ajax'] = 'event:' . $this->calendarType . '|' . $this->calendar . ':' . $this->id . ':' . $start->dateString();
             if (!empty($methods['notify']['sound'])) {
                 if ($methods['notify']['sound'] == 'on') {
                     // Handle boolean sound preferences.
index 33efecf..413d4f9 100644 (file)
@@ -216,8 +216,7 @@ class Kronolith
                              Horde_Date_Recurrence::RECUR_YEARLY_DATE => 'Yearly',
                              Horde_Date_Recurrence::RECUR_YEARLY_DAY => 'Yearly',
                              Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY => 'Yearly'),
-            'snooze' => array('0' => _("Snooze..."),
-                              '-1' => _("Dismiss"),
+            'snooze' => array('0' => _("select..."),
                               '5' => _("5 minutes"),
                               '15' => _("15 minutes"),
                               '60' => _("1 hour"),
@@ -328,6 +327,7 @@ class Kronolith
             'ajax_timeout' => _("There has been no contact with the calendar server for several minutes. The server may be temporarily unavailable or network problems may be interrupting your session. You will not see any updates until the connection is restored."),
             'ajax_recover' => _("The connection to the calendar server has been restored."),
             'alarm' => _("Alarm:"),
+            'snooze' => sprintf(_("You can snooze it for %s or %s dismiss %s it entirely"), '#{time}', '#{dismiss_start}', '#{dismiss_end}'),
             'noalerts' => _("No Notifications"),
             'alerts' => sprintf(_("%s notifications"), '#{count}'),
             'hidelog' => _("Hide Notifications"),