summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/widgets
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@odoo.com>2017-05-15 16:18:28 +0200
committerChristophe Matthieu <chm@odoo.com>2017-05-15 16:19:47 +0200
commit5f13b7f019a0aa56dabd426bb33b3be93f2954b0 (patch)
treed74fbb063c67a73df5d751e7e82a41d9f9d99222 /addons/web/static/src/js/widgets
parent932e8874004da7b0222cd1846eac090819d3ab07 (diff)
[IMP] web: update datepicker syntax with the new guidelines
Diffstat (limited to 'addons/web/static/src/js/widgets')
-rw-r--r--addons/web/static/src/js/widgets/date_picker.js135
-rw-r--r--addons/web/static/src/js/widgets/domain_selector.js4
2 files changed, 99 insertions, 40 deletions
diff --git a/addons/web/static/src/js/widgets/date_picker.js b/addons/web/static/src/js/widgets/date_picker.js
index 06dccc85d4a..353a5dc78f2 100644
--- a/addons/web/static/src/js/widgets/date_picker.js
+++ b/addons/web/static/src/js/widgets/date_picker.js
@@ -12,10 +12,13 @@ var DateWidget = Widget.extend({
template: "web.datepicker",
type_of_date: "date",
events: {
- 'dp.change': 'change_datetime',
- 'dp.show': 'set_datetime_default',
- 'change .o_datepicker_input': 'change_datetime',
+ 'dp.change': 'changeDatetime',
+ 'dp.show': '_onShow',
+ 'change .o_datepicker_input': 'changeDatetime',
},
+ /**
+ * @override
+ */
init: function(parent, options) {
this._super.apply(this, arguments);
@@ -41,6 +44,9 @@ var DateWidget = Widget.extend({
keyBinds: null,
});
},
+ /**
+ * @override
+ */
start: function() {
this.$input = this.$('input.o_datepicker_input');
this.$input.focus(function(e) {
@@ -49,67 +55,120 @@ var DateWidget = Widget.extend({
this.$input.datetimepicker(this.options);
this.picker = this.$input.data('DateTimePicker');
this.$input.click(this.picker.toggle.bind(this.picker));
- this.set_readonly(false);
+ this._setReadonly(false);
},
- set_value: function(value) {
- this.set({'value': value});
- var formatted_value = value ? this.format_client(value) : null;
- this.$input.val(formatted_value);
- if (this.picker) {
- this.picker.date(value || null);
+ /**
+ * @override
+ */
+ destroy: function() {
+ this.picker.destroy();
+ this._super.apply(this, arguments);
+ },
+
+ //--------------------------------------------------------------------------
+ // Public
+ //--------------------------------------------------------------------------
+
+ /**
+ * set datetime value
+ */
+ changeDatetime: function () {
+ if(this.isValid()) {
+ this._setValueFromUi();
+ this.trigger("datetime_changed");
}
},
- get_value: function() {
+ /**
+ * @returns {Moment|false}
+ */
+ getValue: function () {
var value = this.get('value');
return value && value.clone();
},
- set_value_from_ui: function() {
- var value = this.$input.val() || false;
- this.set_value(this.parse_client(value));
- },
- set_readonly: function(readonly) {
- this.readonly = readonly;
- this.$input.prop('readonly', this.readonly);
- },
- is_valid: function() {
+ /**
+ * @returns {boolean}
+ */
+ isValid: function () {
var value = this.$input.val();
if(value === "") {
return true;
} else {
try {
- this.parse_client(value);
+ this._parseClient(value);
return true;
} catch(e) {
return false;
}
}
},
- parse_client: function(v) {
- return field_utils.parse[this.type_of_date](v, null, {timezone: false});
+ /**
+ * @param {Moment|false}
+ */
+ setValue: function (value) {
+ this.set({'value': value});
+ var formatted_value = value ? this._formatClient(value) : null;
+ this.$input.val(formatted_value);
+ if (this.picker) {
+ this.picker.date(value || null);
+ }
},
- format_client: function(v) {
+
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ * @param {Moment}
+ * @returns {string}
+ */
+ _formatClient: function (v) {
return field_utils.format[this.type_of_date](v, null, {timezone: false});
},
- set_datetime_default: function() {
+ /**
+ * @private
+ * @param {string|false}
+ * @returns {Moment}
+ */
+ _parseClient: function (v) {
+ return field_utils.parse[this.type_of_date](v, null, {timezone: false});
+ },
+ /**
+ * @private
+ * @param {boolean}
+ */
+ _setReadonly: function (readonly) {
+ this.readonly = readonly;
+ this.$input.prop('readonly', this.readonly);
+ },
+ /**
+ * set the value from the input value
+ *
+ * @private
+ */
+ _setValueFromUi: function() {
+ var value = this.$input.val() || false;
+ this.setValue(this._parseClient(value));
+ },
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * set the date of the picker by the current date or the today date
+ *
+ * @private
+ */
+ _onShow: function () {
//when opening datetimepicker the date and time by default should be the one from
//the input field if any or the current day otherwise
var value = moment().second(0);
- if(this.$input.val().length !== 0 && this.is_valid()) {
- value = this.parse_client(this.$input.val());
+ if(this.$input.val().length !== 0 && this.isValid()) {
+ value = this._parseClient(this.$input.val());
}
-
this.picker.date(value);
},
- change_datetime: function() {
- if(this.is_valid()) {
- this.set_value_from_ui();
- this.trigger("datetime_changed");
- }
- },
- destroy: function() {
- this.picker.destroy();
- this._super.apply(this, arguments);
- },
});
var DateTimeWidget = DateWidget.extend({
diff --git a/addons/web/static/src/js/widgets/domain_selector.js b/addons/web/static/src/js/widgets/domain_selector.js
index 8bbebb3cdf9..74572e81b39 100644
--- a/addons/web/static/src/js/widgets/domain_selector.js
+++ b/addons/web/static/src/js/widgets/domain_selector.js
@@ -660,9 +660,9 @@ var DomainLeaf = DomainNode.extend({
this.valueWidget = new (selectedField.type === "datetime" ? datepicker.DateTimeWidget : datepicker.DateWidget)(this);
wDefs.push(this.valueWidget.appendTo("<div/>").then((function () {
this.valueWidget.$el.addClass("o_domain_leaf_value_input");
- this.valueWidget.set_value(moment(this.value));
+ this.valueWidget.setValue(moment(this.value));
this.valueWidget.on("datetime_changed", this, function () {
- this._changeValue(this.valueWidget.get_value());
+ this._changeValue(this.valueWidget.getValue());
});
}).bind(this)));
}