Set user prefered default alarm for regular and wholeday events

This commit is contained in:
Hadi Nategh 2014-06-05 16:07:59 +00:00
parent 60a32879d4
commit 0b109288f4
2 changed files with 51 additions and 53 deletions

View File

@ -149,6 +149,17 @@ class calendar_uiforms extends calendar_ui
{
$participants[$this->user] = $participant_types['u'][$this->user] = calendar_so::combine_status('A',1,'CHAIR');
}
$def_alarm = $this->cal_prefs['default-alarm'] != -1?$this->cal_prefs['default-alarm']:$this->cal_prefs['custom-default-alarm'] * 60;
$offset = $def_alarm != 0 ? $def_alarm : 600;
$prefAlarm = array(
'default' => 1,
'offset' => $offset ,
'time' => $start - $offset,
'all' => false,
'owner' => $owner,
'id' => 1,
);
return array(
'participant_types' => $participant_types,
'participants' => $participants,
@ -158,11 +169,11 @@ class calendar_uiforms extends calendar_ui
'tzid' => $this->bo->common_prefs['tz'],
'priority' => 2, // normal
'public'=> $this->cal_prefs['default_private'] ? 0 : 1,
'alarm' => array(),
'alarm' => array(1 => $prefAlarm),
'recur_exception' => array(),
);
}
/**
* Process the edited event and evtl. call edit to redisplay it
*
@ -237,6 +248,24 @@ class calendar_uiforms extends calendar_ui
{
$content['end'] = $content['start'] + $content['duration'];
}
// Set the default alarm for a new whole day event
if ($content['whole_day'] && $content['alarm'][1]['default'])
{
$default_alarm = $this->cal_prefs['default-alarm-wholeday'] != -1?$this->cal_prefs['default-alarm-wholeday']:
$this->cal_prefs['custom-default-alarm-wholeday'] * 60;
$offset = $default_alarm != 0 ? $default_alarm : 600;
$prefAlarm = array(
'default' => 1,
'offset' => $offset ,
'time' => $this->bo->date2ts($content['start']) - $offset,
'all' => false,
'owner' => $owner,
'id' => 1,
);
$content['alarm'][1] = $prefAlarm;
}
$event = $content;
unset($event['new_alarm']);
unset($event['alarm']['delete_alarm']);
@ -1132,6 +1161,7 @@ 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'),
@ -1274,27 +1304,6 @@ class calendar_uiforms extends calendar_ui
}
}
}
// Set alarm sel_options
$alarm_options = array();
$default_alarm = $this->cal_prefs['default-alarm'] != -1?$this->cal_prefs['default-alarm']:$this->cal_prefs['custom-default-alarm'] * 60;
if (!empty($event['whole_day']) && $event['whole_day'])
{
$default_alarm = $this->cal_prefs['default-alarm-wholeday'] != -1?$this->cal_prefs['default-alarm-wholeday']:
$this->cal_prefs['custom-default-alarm-wholeday'] * 60;
}
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. If there's no preference chooses 10 min
$event['new_alarm']['options'] = $default_alarm ? $default_alarm: 600;
$etpl = new etemplate_new();
if (!$etpl->read($preserv['template']))

View File

@ -1207,20 +1207,18 @@ app.classes.calendar = AppJS.extend(
*/
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;
}
var alarm = this.et2.getWidgetById('alarm');
var def_alarm_wd = this.egw.preference('default-alarm-wholeday', 'calendar')?
this.egw.preference('default-alarm-wholeday', 'calendar')
:parseInt(this.egw.preference('custom-default-alarm-wholeday', 'calendar')) * 60;
var def_alarm = this.egw.preference('default-alarm', 'calendar') != 0 ?
this.egw.preference('default-alarm', 'calendar')
:parseInt(this.egw.preference('custom-default-alarm', 'calendar')) * 60;
var content = this.et2.getArrayMgr('content').data;
var start = this.et2.getWidgetById('start');
var self= this;
var time = alarm.cells[1][0].widget;
var event = alarm.cells[1][1].widget;
// Convert a seconds of time to a translated label
var _secs_to_label = function (_secs)
{
@ -1233,27 +1231,18 @@ app.classes.calendar = AppJS.extend(
{
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 (_widget.get_value() == "true" && typeof content['alarm'][1]['default'] != 'undefined')
{
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);
start.date.setHours(0);
time.set_value(start.get_value() - def_alarm_wd);
event.set_value(_secs_to_label(def_alarm_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);
time.set_value(start.get_value() - def_alarm);
event.set_value(_secs_to_label(def_alarm));
}
}
}
});