From bae6b3686f9947d568841e1a1a3108ffe9a33514 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 5 Sep 2014 10:35:08 +0000 Subject: [PATCH] date widget has now api to set or get year, month, date, hours, minutes or time(stamp) and using that in calendar app.js for date manipulation --- calendar/js/app.js | 6 +- etemplate/js/et2_widget_date.js | 107 ++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 2 deletions(-) diff --git a/calendar/js/app.js b/calendar/js/app.js index 542e76aecd..27b10721ed 100644 --- a/calendar/js/app.js +++ b/calendar/js/app.js @@ -1310,8 +1310,10 @@ app.classes.calendar = AppJS.extend( else { jQuery('#calendar-edit_alarm > tbody :nth-child(1)').show(); - start.date.setHours(0); - time.set_value(start.get_value() - 60 * def_alarm); + start.set_hours(0); + start.set_minutes(0); + time.set_value(start.get_value()); + time.set_value('-'+(60 * def_alarm)); event.set_value(_secs_to_label(60 * def_alarm)); } } diff --git a/etemplate/js/et2_widget_date.js b/etemplate/js/et2_widget_date.js index e0bacfe796..ea702d9a38 100644 --- a/etemplate/js/et2_widget_date.js +++ b/etemplate/js/et2_widget_date.js @@ -106,6 +106,113 @@ var et2_date = et2_inputWidget.extend( } }, + /** + * Set (full) year of current date + * + * @param {number} _value 4-digit year + */ + set_year: function(_value) + { + this.date.setUTCFullYear(_value); + this.set_value(this.date); + }, + /** + * Set month (1..12) of current date + * + * @param {number} _value 1..12 + */ + set_month: function(_value) + { + this.date.setUTCMonth(_value-1); + this.set_value(this.date); + }, + /** + * Set day of current date + * + * @param {number} _value 1..31 + */ + set_date: function(_value) + { + this.date.setUTCDate(_value); + this.set_value(this.date); + }, + /** + * Set hour (0..23) of current date + * + * @param {number} _value 0..23 + */ + set_hours: function(_value) + { + this.date.setUTCHours(_value); + this.set_value(this.date); + }, + /** + * Set minute (0..59) of current date + * + * @param {number} _value 0..59 + */ + set_minutes: function(_value) + { + this.date.setUTCMinutes(_value); + this.set_value(this.date); + }, + /** + * Get (full) year of current date + * + * @return {number|null} 4-digit year or null for empty + */ + get_year: function() + { + return this.input_date.val() == "" ? null : this.date.getUTCFullYear(); + }, + /** + * Get month (1..12) of current date + * + * @return {number|null} 1..12 or null for empty + */ + get_month: function() + { + return this.input_date.val() == "" ? null : this.date.getUTCMonth()+1; + }, + /** + * Get day of current date + * + * @return {number|null} 1..31 or null for empty + */ + get_date: function() + { + return this.input_date.val() == "" ? null : this.date.getUTCDate(); + }, + /** + * Get hour (0..23) of current date + * + * @return {number|null} 0..23 or null for empty + */ + get_hours: function() + { + return this.input_date.val() == "" ? null : this.date.getUTCHours(); + }, + /** + * Get minute (0..59) of current date + * + * @return {number|null} 0..59 or null for empty + */ + get_minutes: function() + { + return this.input_date.val() == "" ? null : this.date.getUTCMinutes(); + }, + /** + * Get timestamp + * + * You can use set_value to set a timestamp. + * + * @return {number|null} timestamp (seconds since 1970-01-01 + */ + get_time: function() + { + return this.input_date.val() == "" ? null : this.date.getTime(); + }, + /** * Setting date *