From 35f63b35d5058f961a0f11a06b102b3308be84a7 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 4 Sep 2014 13:03:48 +0000 Subject: [PATCH] * Calendar: fixed freetime search to correctly read and set times from edit window - fixed et2_date.set_value() to understand nummeric timestamps in usertime used on server-side (needed timezone offset) - added new parameter-type for et2_date.set_value() string starting with + or - to add or subtract given number of seconds from current time (to not have to code that in applications) --- calendar/inc/class.calendar_uiforms.inc.php | 10 +++++++++ calendar/js/app.js | 13 ++++-------- etemplate/js/et2_widget_date.js | 23 ++++++++++++++++++--- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/calendar/inc/class.calendar_uiforms.inc.php b/calendar/inc/class.calendar_uiforms.inc.php index 061f0a04f8..c7ac6308da 100644 --- a/calendar/inc/class.calendar_uiforms.inc.php +++ b/calendar/inc/class.calendar_uiforms.inc.php @@ -1920,6 +1920,16 @@ class calendar_uiforms extends calendar_ui $response = egw_json_response::get(); //$response->addAlert(__METHOD__.'('.array2string($edit_content).')'); + // convert start/end date-time values to timestamps + foreach(array('start', 'end') as $name) + { + if (!empty($edit_content[$name])) + { + $date = new egw_time($edit_content[$name]); + $edit_content[$name] = $date->format('ts'); + } + } + if ($edit_content['duration']) { $edit_content['end'] = $edit_content['start'] + $edit_content['duration']; diff --git a/calendar/js/app.js b/calendar/js/app.js index be25053d13..542e76aecd 100644 --- a/calendar/js/app.js +++ b/calendar/js/app.js @@ -838,14 +838,8 @@ app.classes.calendar = AppJS.extend( var sTime = this.et2.getWidgetById(selectedId+'start'); - var eTime = this.et2.getWidgetById(selectedId+'[end]'); - //Catches the start time from freetime content - var str = sTime.get_value(); - - var end = parseInt(str) + parseInt(content['duration']); - //check the parent window is still open before to try to access it - if (window.opener) + if (window.opener && sTime) { var editWindowObj = window.opener.etemplate2.getByApplication('calendar')[0]; if (typeof editWindowObj != "undefined") @@ -854,8 +848,9 @@ app.classes.calendar = AppJS.extend( var endTime = editWindowObj.widgetContainer.getWidgetById('end'); if (startTime && endTime) { - startTime.set_value(str); - endTime.set_value(end); + startTime.set_value(sTime.get_value()); + endTime.set_value(sTime.get_value()); + endTime.set_value('+'+content['duration']); } } } diff --git a/etemplate/js/et2_widget_date.js b/etemplate/js/et2_widget_date.js index 9bc490eee2..e0bacfe796 100644 --- a/etemplate/js/et2_widget_date.js +++ b/etemplate/js/et2_widget_date.js @@ -106,6 +106,15 @@ var et2_date = et2_inputWidget.extend( } }, + /** + * Setting date + * + * @param {string|number|Date} _value supported are the following formats: + * - Date object with usertime as UTC value + * - string like Date.toJSON() + * - string or number with timestamp in usertime like server-side uses it + * - string starting with + or - to add/substract given number of seconds from current value, "+600" to add 10 minutes + */ set_value: function(_value) { var old_value = this._oldValue; if(_value === null || _value === "" || _value === undefined || @@ -211,9 +220,17 @@ var et2_date = et2_inputWidget.extend( } else if (typeof _value == 'object' && _value.valueOf) { this.date = _value; } else if (typeof _value == 'number' || !isNaN(_value)) { - // Timestamp - // JS dates use milliseconds - this.date.setTime(parseInt(_value)*1000); + // string starting with + or - --> add/substract number of seconds from current value + if (typeof _value == 'string' && (_value[0] == '+' || _value[0] == '-')) + { + this.date.setTime(this.date.getTime()+1000*parseInt(_value)); + } + else + { + // Timestamp in usertime need to be corrected with timezoneoffset as we internally use UTC for egw usertime + // JS dates use milliseconds + this.date.setTime(1000*(parseInt(_value)-60*this.date.getTimezoneOffset())); + } } // Update input - popups do, but framework doesn't