From b063901fde648fb85c789f36e8aaa4bbed698e69 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Wed, 28 May 2014 15:04:06 +0000 Subject: [PATCH] Set alarm's default value according to user preferences for both regular and wholeday events --- calendar/inc/class.calendar_uiforms.inc.php | 21 +++++++- calendar/js/app.js | 59 +++++++++++++++++++++ calendar/templates/default/edit.xet | 2 +- 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/calendar/inc/class.calendar_uiforms.inc.php b/calendar/inc/class.calendar_uiforms.inc.php index b97003f8d4..cea393b7f9 100644 --- a/calendar/inc/class.calendar_uiforms.inc.php +++ b/calendar/inc/class.calendar_uiforms.inc.php @@ -1125,7 +1125,6 @@ class calendar_uiforms extends calendar_ui 'status' => $this->bo->verbose_status, 'duration' => $this->durations, 'role' => $this->bo->roles, - 'new_alarm[options]' => $this->bo->alarms+array(0 => lang('Custom')), 'before_after'=>array(0 => lang('Before'), 1 => lang('After')), 'action' => array( 'copy' => array('label' => 'Copy', 'title' => 'Copy this event'), @@ -1268,6 +1267,24 @@ class calendar_uiforms extends calendar_ui } } } + // Set alarm sel_options + $alarm_options = array(); + $default_alarm = $this->cal_prefs['default-alarm']; + if (!empty($event['whole_day']) && $event['whole_day']) $default_alarm = $this->cal_prefs['default-alarm-wholeday']; + if (!array_key_exists($default_alarm, $this->bo->alarms) && $default_alarm > 0) + { + $alarm_options = $this->bo->alarms + array($default_alarm => calendar_bo::secs2label ($default_alarm)); + } + else + { + $alarm_options = $this->bo->alarms; + } + $sel_options += array( + 'new_alarm[options]' => $alarm_options + array(0 => lang('Custom')) + ); + // set default preference value + $event['new_alarm']['options'] = $default_alarm; + $etpl = new etemplate_new(); if (!$etpl->read($preserv['template'])) { @@ -1415,7 +1432,7 @@ class calendar_uiforms extends calendar_ui } $content['participants']['status_date'] = $preserv['actual_date']; $preserv = array_merge($preserv,$content); - + $event['new_alarm']['options'] = $content['new_alarm']['options']; if ($event['alarm']) { // makes keys of the alarm-array starting with 1 diff --git a/calendar/js/app.js b/calendar/js/app.js index dbe3a29f2f..ea91015b77 100644 --- a/calendar/js/app.js +++ b/calendar/js/app.js @@ -1196,5 +1196,64 @@ app.classes.calendar = AppJS.extend( alarm_date.set_value(date); } } + }, + + /** + * Set alarm options based on WD/Regular event user preferences + * Gets fired by wholeday checkbox + * + * @param {egw object} _egw + * @param {widget object} _widget whole_day checkbox + */ + set_alarmOptions_WD: function (_egw,_widget) + { + var alarm_options = this.et2.getWidgetById('new_alarm[options]'); + var sel_options = alarm_options.options.select_options; + var def_wd = this.egw.preference('default-alarm-wholeday', 'calendar'); + var def_alarm = this.egw.preference('default-alarm', 'calendar'); + var self = this; + // Search a needle inside an object. Return true if there's one, otherwise false + var _is_in_options = function (_needle, _object) + { + for(var key in _object) + { + if (_needle == _object[key].value) return true; + } + return false; + } + // Convert a seconds of time to a translated label + var _secs_to_label = function (_secs) + { + var label=''; + if (_secs <= 3600) + { + label = self.egw.lang('%1 minutes', _secs/60); + } + else if(_secs <= 86400) + { + label = self.egw.lang('%1 hours', _secs/3600); + } + else + { + label = self.egw.lang('%1 days', _secs/86400); + } + return label; + } + + if (_widget.get_value() == "true") + { + if (!_is_in_options(def_wd, sel_options)) + { + sel_options [sel_options.length] = {value:def_wd,label:_secs_to_label(def_wd)}; + alarm_options.set_select_options(sel_options); + } + alarm_options.set_value(def_wd); + } + else + { + sel_options = this.et2.getArrayMgr('sel_options').data.new_alarm.options; + alarm_options.set_select_options(sel_options); + alarm_options.set_value(def_alarm); + } } }); diff --git a/calendar/templates/default/edit.xet b/calendar/templates/default/edit.xet index be3f3a9122..fc211590b5 100644 --- a/calendar/templates/default/edit.xet +++ b/calendar/templates/default/edit.xet @@ -287,7 +287,7 @@ - +