forked from Techsystech/web
[FIX]: Remove needless comments in __openerp__.py
[FIX]: Cleanup user provided timepicker options initialization and handling11.0
parent
05838eafc6
commit
ce89284d73
|
@ -12,10 +12,9 @@ definition. It can be use as a replacement for the standard float_time widget.
|
||||||
If you use the widget with a field record, the input field has the following default
|
If you use the widget with a field record, the input field has the following default
|
||||||
timepicker options:
|
timepicker options:
|
||||||
|
|
||||||
* By default direct user input is disabled
|
* By default the possible selection is based on 15 minute interval (step: 15)
|
||||||
* By default the possible selection is based on 15 minute interval
|
* By default 24 hour mode with H:i format (timeFormat: 'H:i')
|
||||||
* By default 24 hour mode with H:i format
|
* By default scroll selection starts at current time (scrollDefault: 'now')
|
||||||
* Scroll selection defaults to current server time
|
|
||||||
|
|
||||||
The widget uses the jquery.timepicker plugin by Jon Thornton
|
The widget uses the jquery.timepicker plugin by Jon Thornton
|
||||||
|
|
||||||
|
@ -24,22 +23,21 @@ Usage
|
||||||
=====
|
=====
|
||||||
|
|
||||||
This module defines a new widget type for form views input fileds.
|
This module defines a new widget type for form views input fileds.
|
||||||
|
|
||||||
Set the attribute ``widget=timepicker`` in a ``field`` tag in a form view.
|
Set the attribute ``widget=timepicker`` in a ``field`` tag in a form view.
|
||||||
|
|
||||||
You can pass all options through the "timepicker" field in the options::
|
You can pass custom options through the "timepicker" field in the options attribute:
|
||||||
|
|
||||||
...
|
...
|
||||||
<field name="mytimefieldname" `widget=timepicker`` data-options="{'step': '30', 'disableTextInput': false}"/>
|
<field name="mytimefieldname" `widget=timepicker`` options="{'step': '30', 'disableTextInput': false}"/>
|
||||||
...
|
...
|
||||||
|
|
||||||
See the available options at https://github.com/jonthornton/jquery-timepicker#timepicker-plugin-for-jquery
|
See the available options at https://github.com/jonthornton/jquery-timepicker#timepicker-plugin-for-jquery.
|
||||||
|
|
||||||
|
|
||||||
ToDo
|
Known issues / Roadmap
|
||||||
====
|
======================
|
||||||
|
|
||||||
Sanity check on options available in field defintion as override options for timepicker widget.
|
* Absolutely no sanity check or validation on options.
|
||||||
|
|
||||||
|
|
||||||
Credits
|
Credits
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
'category': 'Web',
|
'category': 'Web',
|
||||||
'website': 'https://github.com/OCA/Web',
|
'website': 'https://github.com/OCA/Web',
|
||||||
|
|
||||||
# any module necessary for this one to work correctly
|
|
||||||
'depends': [
|
'depends': [
|
||||||
'web'
|
'web'
|
||||||
],
|
],
|
||||||
|
@ -25,12 +24,9 @@
|
||||||
'qweb': [
|
'qweb': [
|
||||||
'static/src/xml/web_widget_timepicker.xml'
|
'static/src/xml/web_widget_timepicker.xml'
|
||||||
],
|
],
|
||||||
|
|
||||||
# always loaded
|
|
||||||
'data': [
|
'data': [
|
||||||
'views/web_widget_timepicker_assets.xml'
|
'views/web_widget_timepicker_assets.xml'
|
||||||
],
|
],
|
||||||
|
|
||||||
# Installation options
|
|
||||||
"installable": True,
|
"installable": True,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,11 @@
|
||||||
odoo.define('web_widget_timepicker.form_widgets', function (require) {
|
odoo.define('web_widget_timepicker', function (require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var core = require('web.core');
|
var core = require('web.core');
|
||||||
var formats = require('web.formats');
|
var formats = require('web.formats');
|
||||||
var common = require('web.form_common');
|
var common = require('web.form_common');
|
||||||
|
|
||||||
// Snippet from http://stackoverflow.com/questions/9036429/convert-object-string-to-json
|
var TimePickerField = common.AbstractField.extend(common.ReinitializeFieldMixin, {
|
||||||
function cleanup_str2json(str) {
|
|
||||||
return (str.length > 0 && str !== undefined) ? str
|
|
||||||
// wrap keys without quote with valid double quote
|
|
||||||
.replace(/([\$\w]+)\s*:/g, function(_, $1){return '"'+$1+'":'})
|
|
||||||
// replacing single quote wrapped ones to double quote
|
|
||||||
.replace(/'([^']+)'/g, function(_, $1){return '"'+$1+'"'}) : undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
var TimePicker = common.AbstractField.extend(common.ReinitializeFieldMixin, {
|
|
||||||
is_field_number: true,
|
is_field_number: true,
|
||||||
template: "TimePickerField",
|
template: "TimePickerField",
|
||||||
internal_format: 'float_time',
|
internal_format: 'float_time',
|
||||||
|
@ -27,9 +18,7 @@ odoo.define('web_widget_timepicker.form_widgets', function (require) {
|
||||||
|
|
||||||
this.internal_set_value(0);
|
this.internal_set_value(0);
|
||||||
|
|
||||||
this.options = _.defaults( {}, {
|
this.options = _.defaults( this.options, {
|
||||||
disableTextInput: true,
|
|
||||||
forceRoundTime: true,
|
|
||||||
step: 15,
|
step: 15,
|
||||||
selectOnBlur: true,
|
selectOnBlur: true,
|
||||||
timeFormat: 'H:i',
|
timeFormat: 'H:i',
|
||||||
|
@ -38,24 +27,7 @@ odoo.define('web_widget_timepicker.form_widgets', function (require) {
|
||||||
},
|
},
|
||||||
initialize_content: function() {
|
initialize_content: function() {
|
||||||
if(!this.get("effective_readonly")) {
|
if(!this.get("effective_readonly")) {
|
||||||
var custom_options;
|
this.$el.find('input').timepicker(this.options);
|
||||||
|
|
||||||
if( this.node.attrs['data-options'] !== undefined && this.node.attrs['data-options'].length > 0) {
|
|
||||||
// First try to use jquery data function to create object
|
|
||||||
custom_options = $(this.node).data('options');
|
|
||||||
|
|
||||||
if(typeof custom_options !== 'object') {
|
|
||||||
// No garantee that the input data-options string is valid JSON format so try to cleanup
|
|
||||||
custom_options = JSON.parse(cleanup_str2json(this.node.attrs['data-options']));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(typeof custom_options === 'object') {
|
|
||||||
this.$el.find('input').timepicker($.extend({}, this.options, custom_options ));
|
|
||||||
} else {
|
|
||||||
this.$el.find('input').timepicker(this.options);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setupFocus(this.$('input'));
|
this.setupFocus(this.$('input'));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -109,7 +81,9 @@ odoo.define('web_widget_timepicker.form_widgets', function (require) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
core.form_widget_registry.add('timepicker', TimePicker);
|
core.form_widget_registry.add('timepicker', TimePickerField);
|
||||||
|
|
||||||
return TimePicker;
|
return {
|
||||||
|
TimePickerField: TimePickerField,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue