From: Michael M Slusarz Date: Wed, 7 Apr 2010 14:51:54 +0000 (-0600) Subject: Move alarms handling into prefs ui widgets X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=6e3c22e26f331bc22d1f565e72e1995ae98becd0;p=horde.git Move alarms handling into prefs ui widgets --- diff --git a/framework/Core/lib/Horde/Core/Prefs/Ui.php b/framework/Core/lib/Horde/Core/Prefs/Ui.php index 82024c03a..06d1a3c8e 100644 --- a/framework/Core/lib/Horde/Core/Prefs/Ui.php +++ b/framework/Core/lib/Horde/Core/Prefs/Ui.php @@ -198,31 +198,6 @@ class Horde_Core_Prefs_Ui /* Run through the action handlers */ foreach ($preflist as $pref) { switch ($this->prefs[$pref]['type']) { - case 'alarm': - $methods = Horde_Alarm::notificationMethods(); - $val = (isset($this->vars->$pref) && is_array($this->vars->$pref)) - ? $this->vars->$pref - : array(); - $value = array(); - - foreach ($val as $method) { - $value[$method] = array(); - if (!empty($methods[$method])) { - foreach (array_keys($methods[$method]) as $param) { - $value[$method][$param] = $this->vars->get($pref . '_' . $param, ''); - if (is_array($methods[$method][$param]) && - $methods[$method][$param]['required'] && - ($value[$method][$param] === '')) { - $notification->push(sprintf(_("You must provide a setting for \"%s\"."), $methods[$method][$param]['desc']), 'horde.error'); - break 3; - } - } - } - } - - $updated |= $prefs->setValue($pref, serialize($value)); - break; - case 'checkbox': $updated |= $prefs->setValue($pref, intval(isset($this->vars->$pref))); break; @@ -380,82 +355,6 @@ class Horde_Core_Prefs_Ui $type = $this->prefs[$pref]['type']; switch ($type) { - case 'alarm': - Horde::addScriptFile('alarmprefs.js', 'horde'); - Horde::addInlineScript(array( - 'HordeAlarmPrefs.pref = ' . Horde_Serialize::serialize($pref, Horde_Serialize::JSON) - )); - - $alarm_pref = unserialize($prefs->getValue($pref)); - $selected = array_keys($alarm_pref); - - $param_list = $select_list = array(); - foreach (Horde_Alarm::notificationMethods() as $method => $params) { - $select_list[] = array( - 'l' => $params['__desc'], - 's' => in_array($method, $selected), - 'v' => $method - ); - - if (count($params > 1)) { - $tmp = array( - 'method' => $method, - 'param' => array() - ); - - foreach ($params as $name => $param) { - if (substr($name, 0, 2) == '__') { - continue; - } - - switch ($param['type']) { - case 'text': - $tmp['param'][] = array( - 'label' => Horde::label($pref . '_' . $name, $param['desc']), - 'name' => $pref . '_' . $name, - 'text' => true, - 'value' => empty($alarm_pref[$method][$name]) ? '' : htmlspecialchars($alarm_pref[$method][$name]) - ); - break; - - case 'bool': - $tmp['param'][] = array( - 'bool' => true, - 'checked' => !empty($alarm_pref[$method][$name]), - 'label' => Horde::label($pref . '_' . $name, $param['desc']), - 'name' => $pref . '_' . $name - ); - break; - - case 'sound': - $current_sound = empty($alarm_pref[$method][$name]) - ? '' - : $alarm_pref[$method][$name]; - $sounds = array(); - foreach (Horde_Themes::soundList() as $key => $val) { - $sounds[] = array( - 'c' => ($current_sound == $key), - 'uri' => htmlspecialchars($val->uri), - 'val' => htmlspecialchars($key) - ); - } - - $tmp['param'][] = array( - 'sound' => true, - 'checked' => !$current_sound, - 'name' => $pref . '_' . $name - ); - break; - } - } - - $param_list[] = $tmp; - } - } - $t->set('param_list', $param_list); - $t->set('select_list', $select_list); - break; - case 'checkbox': $t->set('checked', $prefs->getValue($pref)); break; diff --git a/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php b/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php index 2efd02a18..e05f35084 100644 --- a/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php +++ b/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php @@ -220,4 +220,152 @@ class Horde_Core_Prefs_Ui_Widgets return $out . $t->fetch(HORDE_TEMPLATES . '/prefs/addressbooks.html'); } + /* Alarms selection widget. */ + + /** + * Code to run on init for alarms selection. + */ + static public function alarmInit() + { + Horde::addScriptFile('alarmprefs.js', 'horde'); + } + + /** + * Create code needed for alarm selection. + * + * @param array $data Data items: + *
+     * 'helplink' - (string) [OPTIONAL] Help link.
+     * 'label' - (string) Label.
+     * 'pref' - (string) Preference name.
+     * 
+ * + * @return string HTML UI code. + */ + static public function alarm($data) + { + $pref = $data['pref']; + + Horde::addInlineScript(array( + 'HordeAlarmPrefs.pref = ' . Horde_Serialize::serialize($pref, Horde_Serialize::JSON) + )); + + $alarm_pref = unserialize($prefs->getValue($pref)); + $selected = array_keys($alarm_pref); + + $param_list = $select_list = array(); + foreach (Horde_Alarm::notificationMethods() as $method => $params) { + $select_list[] = array( + 'l' => $params['__desc'], + 's' => in_array($method, $selected), + 'v' => $method + ); + + if (count($params > 1)) { + $tmp = array( + 'method' => $method, + 'param' => array() + ); + + foreach ($params as $name => $param) { + if (substr($name, 0, 2) == '__') { + continue; + } + + switch ($param['type']) { + case 'text': + $tmp['param'][] = array( + 'label' => Horde::label($pref . '_' . $name, $param['desc']), + 'name' => $pref . '_' . $name, + 'text' => true, + 'value' => empty($alarm_pref[$method][$name]) ? '' : htmlspecialchars($alarm_pref[$method][$name]) + ); + break; + + case 'bool': + $tmp['param'][] = array( + 'bool' => true, + 'checked' => !empty($alarm_pref[$method][$name]), + 'label' => Horde::label($pref . '_' . $name, $param['desc']), + 'name' => $pref . '_' . $name + ); + break; + + case 'sound': + $current_sound = empty($alarm_pref[$method][$name]) + ? '' + : $alarm_pref[$method][$name]; + $sounds = array(); + foreach (Horde_Themes::soundList() as $key => $val) { + $sounds[] = array( + 'c' => ($current_sound == $key), + 'uri' => htmlspecialchars($val->uri), + 'val' => htmlspecialchars($key) + ); + } + + $tmp['param'][] = array( + 'sound' => true, + 'checked' => !$current_sound, + 'name' => $pref . '_' . $name + ); + break; + } + } + + $param_list[] = $tmp; + } + } + + $base = $GLOBALS['injector']->createInstance('Horde_Template'); + $base->setOption('gettext', true); + + $t->set('desc', Horde::label($pref, $data['label'])); + if (!empty($data['helplink'])) { + $t->set('helplink', $data['helplink']); + } + $t->set('pref', htmlspecialchars($pref)); + $t->set('param_list', $param_list); + $t->set('select_list', $select_list); + + return $t->fetch(HORDE_TEMPLATES . '/prefs/alarm.html'); + } + + /** + * Process form data. + * + * @param array $data Data items: + *
+     * 'pref' - (string) Preference name.
+     * 
+ * + * @return array TODO + */ + static public function alarmUpdate($ui, $data) + { + $pref = $data['pref']; + $methods = Horde_Alarm::notificationMethods(); + $val = (isset($ui->vars->$pref) && is_array($ui->vars->$pref)) + ? $ui->vars->$pref + : array(); + $value = array(); + + foreach ($val as $method) { + $value[$method] = array(); + if (!empty($methods[$method])) { + foreach (array_keys($methods[$method]) as $param) { + $value[$method][$param] = $ui->vars->get($pref . '_' . $param, ''); + if (is_array($methods[$method][$param]) && + $methods[$method][$param]['required'] && + ($value[$method][$param] === '')) { + $GLOBALS['notification']->push(sprintf(_("You must provide a setting for \"%s\"."), $methods[$method][$param]['desc']), 'horde.error'); + return null; + } + } + } + } + + return $value; + } + } diff --git a/horde/config/prefs.php.dist b/horde/config/prefs.php.dist index ace84085d..60f1b3e25 100644 --- a/horde/config/prefs.php.dist +++ b/horde/config/prefs.php.dist @@ -55,10 +55,6 @@ * following is the list of types, with a description of further keys used * for each type. * - * 'alarm' - * ------- - * TODO - * * 'checkbox' * ---------- * Provides a checkbox (yes/no) entry. diff --git a/kronolith/config/prefs.php.dist b/kronolith/config/prefs.php.dist index 587e74c67..1651c997a 100644 --- a/kronolith/config/prefs.php.dist +++ b/kronolith/config/prefs.php.dist @@ -47,7 +47,7 @@ $prefGroups['notification'] = array( 'desc' => _("Choose how you want to be notified about event changes, event alarms and upcoming events."), 'members' => array( 'event_notification', 'event_notification_exclude_self', - 'daily_agenda', 'event_reminder', 'event_alarms' + 'daily_agenda', 'event_reminder', 'event_alarms_select' ) ); @@ -288,10 +288,12 @@ $_prefs['event_reminder'] = array( ); // alarm methods +$_prefs['event_alarms_select'] = array( + 'type' => 'special' +); + $_prefs['event_alarms'] = array( - 'value' => 'a:1:{s:6:"notify";a:0:{}}', - 'type' => 'alarm', - 'desc' => _("Choose how you want to receive reminders for events with alarms:") + 'value' => 'a:1:{s:6:"notify";a:0:{}}' ); // number of days to generate Free/Busy information for: diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index 15cde7d80..e3b3303cb 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -136,8 +136,12 @@ class Kronolith_Application extends Horde_Registry_Application break; case 'notification': - if (empty($conf['alarms']['driver'])) { + if (empty($conf['alarms']['driver']) || + $prefs->isLocked('event_alarms') || + $prefs->isLocked('event_alarms_select')) { $ui->suppress[]= 'event_alarms'; + } else { + Horde_Core_Prefs_Ui_Widgets::alarminit(); } break; @@ -201,6 +205,12 @@ class Kronolith_Application extends Horde_Registry_Application case 'default_alarm_management': return $this->_defaultAlarmManagement($ui); + case 'event_alarms_select': + return Horde_Core_Prefs_Ui_Widgets::alarm(array( + 'label' => _("Choose how you want to receive reminders for events with alarms:"), + 'pref' => 'event_alarms' + )); + case 'sourceselect': $search = Kronolith::getAddressbookSearchParams(); return Horde_Core_Prefs_Ui_Widgets::addressbooks(array( @@ -227,6 +237,14 @@ class Kronolith_Application extends Horde_Registry_Application $GLOBALS['prefs']->setValue('default_alarm', (int)$ui->vars->alarm_value * (int)$ui->vars->alarm_unit); return true; + case 'event_alarms_select': + $data = Horde_Core_Prefs_Ui_Widgets::alarmUpdate($ui, array('pref' => 'event_alarms')); + if (!is_null($data)) { + $GLOBALS['prefs']->setValue('event_alarms', serialize($data)); + return true; + } + break; + case 'remote_cal_management': return $this->_prefsRemoteCalManagement($ui); diff --git a/nag/config/prefs.php.dist b/nag/config/prefs.php.dist index 0f3f66dae..36bfb0710 100644 --- a/nag/config/prefs.php.dist +++ b/nag/config/prefs.php.dist @@ -37,7 +37,7 @@ $prefGroups['notification'] = array( 'column' => _("Task List and Share Options"), 'label' => _("Notifications"), 'desc' => _("Choose if you want to be notified of task changes and task alarms."), - 'members' => array('task_notification', 'task_alarms'), + 'members' => array('task_notification', 'task_alarms_select'), ); $prefGroups['external'] = array( @@ -155,10 +155,12 @@ $_prefs['task_notification'] = array( ); // alarm methods +$_prefs['task_alarms_select'] = array( + 'type' => 'special' +); + $_prefs['task_alarms'] = array( - 'value' => 'a:1:{s:6:"notify";a:0:{}}', - 'type' => 'alarm', - 'desc' => _("Choose how you want to receive reminders for tasks with alarms:"), + 'value' => 'a:1:{s:6:"notify";a:0:{}}' ); // show data from other applications that can be listed as tasks? diff --git a/nag/lib/Application.php b/nag/lib/Application.php index 9a9761859..8d269335e 100644 --- a/nag/lib/Application.php +++ b/nag/lib/Application.php @@ -102,7 +102,9 @@ class Nag_Application extends Horde_Registry_Application switch ($ui->group) { case 'notification': - if (empty($conf['alarms']['driver'])) { + if (empty($conf['alarms']['driver']) || + $prefs->isLocked('task_alarms') || + $prefs->isLocked('task_alarms_select')) { $ui->suppress[] = 'task_alarms'; } break; @@ -159,6 +161,50 @@ class Nag_Application extends Horde_Registry_Application } /** + * Generate code used to display a special preference. + * + * @param Horde_Core_Prefs_Ui $ui The UI object. + * @param string $item The preference name. + * + * @return string The HTML code to display on the options page. + */ + public function prefsSpecial($ui, $item) + { + switch ($item) { + case 'task_alarms_select': + return Horde_Core_Prefs_Ui_Widgets::alarm(array( + 'label' => _("Choose how you want to receive reminders for tasks with alarms:"), + 'pref' => 'task_alarms' + )); + } + + return ''; + } + + /** + * Special preferences handling on update. + * + * @param Horde_Core_Prefs_Ui $ui The UI object. + * @param string $item The preference name. + * + * @return boolean True if preference was updated. + */ + public function prefsSpecialUpdate($ui, $item) + { + switch ($item) { + case 'task_alarms_select': + $data = Horde_Core_Prefs_Ui_Widgets::alarmUpdate($ui, array('pref' => 'task_alarms')); + if (!is_null($data)) { + $GLOBALS['prefs']->setValue('task_alarms', serialize($data)); + return true; + } + break; + } + + return false; + } + + /** * Generate the menu to use on the prefs page. * * @return Horde_Menu A Horde_Menu object.