Read and save alarm methods.
authorJan Schneider <jan@horde.org>
Mon, 1 Mar 2010 11:46:43 +0000 (12:46 +0100)
committerJan Schneider <jan@horde.org>
Mon, 1 Mar 2010 11:46:43 +0000 (12:46 +0100)
framework/Alarm/lib/Horde/Alarm.php
kronolith/index.php
kronolith/js/kronolith.js
kronolith/lib/Event.php
kronolith/templates/index/edit.inc

index 8ede608..48ce573 100644 (file)
@@ -488,7 +488,7 @@ class Horde_Alarm
         if (!isset($methods)) {
             $methods = array(
                 'notify' => array(
-                    '__desc' => _("Inline Notification"),
+                    '__desc' => _("Inline"),
                     'sound' => array(
                         'type' => 'sound',
                         'desc' => _("Play a sound?"),
@@ -496,7 +496,7 @@ class Horde_Alarm
                     )
                 ),
                 'mail' => array(
-                    '__desc' => _("Email Notification"),
+                    '__desc' => _("Email"),
                     'email' => array(
                         'type' => 'text',
                         'desc' => _("Email address (optional)"),
index a557e53..ae8dba2 100644 (file)
@@ -24,6 +24,49 @@ if ($help_link) {
 $today = new Horde_Date($_SERVER['REQUEST_TIME']);
 $_SESSION['horde_prefs']['nomenu'] = true;
 
+$alarm_methods = $alarm_params = '';
+foreach (Horde_Alarm::notificationMethods() as $method => $params) {
+    $alarm_methods .= ' <input type="checkbox" name="event_alarms[]" id="kronolithEventAlarm' . $method . '" value="' . $method . '" /> <label for="kronolithEventAlarm' . $method . '">' . $params['__desc'] . '</label>';
+    if (count($params) < 2) {
+        continue;
+    }
+    $alarm_params .= ' <div id="kronolithEventAlarm' . $method . 'Params" style="display:none">';
+    foreach ($params as $name => $param) {
+        if (substr($name, 0, 2) == '__') {
+            continue;
+        }
+        $alarm_params .= ' <label for="kronolithEventAlarmParam' . $name
+            . '">' . $param['desc'] . '</label> ';
+        $name_att = 'name="event_alarms_' . $name . '"';
+        $att = 'id="kronolithEventAlarmParam' . $name . '" ' . $name_att;
+        switch ($param['type']) {
+        case 'text':
+            $alarm_params .= '<input type="text" ' . $att . ' />';
+            break;
+        case 'boolean':
+            $alarm_params .= '<input type="checkbox" ' . $att . ' />';
+            break;
+        case 'sound':
+            $alarm_params .= '<ul class="sound-list"><li><input type="radio" ' . $att
+                . ' value="" checked="checked" /> ' . _("No Sound") . '</li>';
+            foreach (glob($registry->get('themesfs', 'horde') . '/sounds/*.wav') as $sound) {
+                $sound = htmlspecialchars(basename($sound));
+                $alarm_params .= '<li><input type="radio" id="kronolithEventAlarmParam'
+                    . $name . str_replace('.wav', '', $sound) . '" ' . $name_att
+                    . ' value="' .  $sound
+                    . '" /> <embed autostart="false" src="'
+                    . $registry->get('themesuri', 'horde') . '/sounds/'
+                    . $sound . '" /> ' . $sound . '</li>';
+            }
+            $alarm_params .= '</ul>';
+            break;
+        }
+        $alarm_params .= '<br />';
+    }
+    $alarm_params = substr($alarm_params, 0, - 6);
+    $alarm_params .= '</div>';
+}
+
 Kronolith::header();
 echo "<body class=\"kronolithAjax\">\n";
 require KRONOLITH_TEMPLATES . '/index/index.inc';
index 87ac960..256e6de 100644 (file)
@@ -2654,6 +2654,10 @@ KronolithCore = {
                 this.toggleAllDay();
                 return;
 
+            case 'kronolithEventAlarmDefaultOn':
+                this.disableAlarmMethods();
+                return;
+
             case 'kronolithEventLinkNone':
             case 'kronolithEventLinkDaily':
             case 'kronolithEventLinkWeekly':
@@ -3124,6 +3128,16 @@ KronolithCore = {
                 elt.disable();
                 e.stop();
                 return;
+            } else if (elt.tagName == 'INPUT' && elt.name == 'event_alarms[]') {
+                $('kronolithEventAlarmDefaultOff').setValue(1);
+                if ($(elt.id + 'Params')) {
+                    if (elt.getValue()) {
+                        $(elt.id + 'Params').show();
+                    } else {
+                        $(elt.id + 'Params').hide();
+                    }
+                }
+                return;
             }
 
             var calClass = elt.retrieve('calendarclass');
@@ -3370,6 +3384,7 @@ KronolithCore = {
         this.toggleAllDay(false);
         this.openTab($('kronolithEventForm').down('.tabset a.kronolithTabLink'));
         $('kronolithEventForm').enable();
+        this.disableAlarmMethods();
         $('kronolithEventForm').reset();
         if (Kronolith.conf.maps.driver) {
             $('kronolithEventMapLink').hide();
@@ -3533,6 +3548,27 @@ KronolithCore = {
                     throw $break;
                 }
             });
+            if (ev.m) {
+                $('kronolithEventAlarmDefaultOff').checked = true;
+                $H(ev.m).each(function(method) {
+                    $('kronolithEventAlarm' + method.key).setValue(1);
+                    $('kronolithEventAlarm' + method.key + 'Params').show();
+                    $H(method.value).each(function(param) {
+                        var input = $('kronolithEventAlarmParam' + param.key);
+                        if (input.type == 'radio') {
+                            input.up('form').select('input[type=radio]').each(function(radio) {
+                                if (radio.name == input.name &&
+                                    radio.value == param.value) {
+                                    radio.setValue(1);
+                                    throw $break;
+                                }
+                            });
+                        } else {
+                            input.setValue(param.value);
+                        }
+                    });
+                });
+            }
         } else {
             $('kronolithEventAlarmOff').setValue(true);
         }
@@ -3711,6 +3747,20 @@ KronolithCore = {
     },
 
     /**
+     * Disables all custom alarm methods in the event form.
+     */
+    disableAlarmMethods: function() {
+        $('kronolithEventTabReminder').select('input').each(function(input) {
+            if (input.name == 'event_alarms[]') {
+                input.setValue(0);
+                if ($(input.id + 'Params')) {
+                    $(input.id + 'Params').hide();
+                }
+            }
+        });
+    },
+
+    /**
      * Toggles the recurrence fields of the event edit form.
      *
      * @param string recur  The recurrence part of the field name, i.e. 'None',
index 8437627..6503114 100644 (file)
@@ -1274,6 +1274,9 @@ abstract class Kronolith_Event
                 }
                 $json->at = $attendees;
             }
+            if ($this->methods) {
+                $json->m = $this->methods;
+            }
         }
 
         return $json;
index b0e5684..bc2d172 100644 (file)
 </div>
 
 <div id="kronolithEventTabReminder" class="kronolithTabsOption" style="display:none">
-  <?php printf(_("%s Don't set %s or %s set %s before the event %s and %s alert me via %s"),
+  <?php printf(_("%s Don't set %s or %s set %s before the event %s and alert me via %s the usual method(s) %s or %s the method(s) %s"),
   '<label for="kronolithEventAlarmOff"><input type="radio" name="alarm" id="kronolithEventAlarmOff" value="0" checked="checked" />', '</label>',
   '<label for="kronolithEventAlarmOn"><input type="radio" name="alarm" id="kronolithEventAlarmOn" value="1" />', '</label>
   <input type="text" name="alarm_value" id="kronolithEventAlarmValue" size="3" value="15" class="kronolithEventValue" />
-  <label for="kronolithEventAlarmUnit">
-    <select name="alarm_unit" id="kronolithEventAlarmUnit">
-      <option value="1">' . _("minutes") . '</option>
-      <option value="60">' . _("hours") . '</option>
-      <option value="1440">' . _("days") . '</option>
-      <option value="10080">' . _("weeks") . '</option>
-    </select>',
+  <select name="alarm_unit" id="kronolithEventAlarmUnit">
+    <option value="1">' . _("minutes") . '</option>
+    <option value="60">' . _("hours") . '</option>
+    <option value="1440">' . _("days") . '</option>
+    <option value="10080">' . _("weeks") . '</option>
+  </select>
+  <label for="kronolithEventAlarmValue">',
   '</label>',
-  '<label for="kronolithEventAlarmMethod">',
-    '<select name="event_alarms" id="kronolithEventAlarmMethod">
-      <option value="">' . _("E-mail") . '</option>
-      <option value="">' . _("SAPO Messenger") . '</option>
-      <option value="" disabled="disabled">' . _("SMS") . '</option>
-    </select>
-  </label>') ?>
+  '<input type="radio" name="alarm_change_method" id="kronolithEventAlarmDefaultOn" value="0" checked="checked" />
+  <label for="kronolithEventAlarmDefaultOn">', '</label>',
+  '<input type="radio" name="alarm_change_method" id="kronolithEventAlarmDefaultOff" value="1" />
+  <label for="kronolithEventAlarmDefaultOff">',
+  '</label>' . $alarm_methods . $alarm_params) ?>
 </div>
 
 <div id="kronolithEventTabRecur" class="kronolithTabsOption" style="display:none">