Browse Source

[FIX]: Remove needless comments in __openerp__.py

[FIX]: Cleanup user provided timepicker options initialization and handling
pull/357/head
docmfried 9 years ago
parent
commit
720a5eb08d
  1. 20
      web_widget_timepicker/README.rst
  2. 4
      web_widget_timepicker/__openerp__.py
  3. 42
      web_widget_timepicker/static/src/js/web_widget_timepicker.js

20
web_widget_timepicker/README.rst

@ -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
timepicker options:
* By default direct user input is disabled
* By default the possible selection is based on 15 minute interval
* By default 24 hour mode with H:i format
* Scroll selection defaults to current server time
* By default the possible selection is based on 15 minute interval (step: 15)
* By default 24 hour mode with H:i format (timeFormat: 'H:i')
* By default scroll selection starts at current time (scrollDefault: 'now')
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.
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

4
web_widget_timepicker/__openerp__.py

@ -10,7 +10,6 @@
'category': 'Web',
'website': 'https://github.com/OCA/Web',
# any module necessary for this one to work correctly
'depends': [
'web'
],
@ -25,12 +24,9 @@
'qweb': [
'static/src/xml/web_widget_timepicker.xml'
],
# always loaded
'data': [
'views/web_widget_timepicker_assets.xml'
],
# Installation options
"installable": True,
}

42
web_widget_timepicker/static/src/js/web_widget_timepicker.js

@ -1,20 +1,11 @@
odoo.define('web_widget_timepicker.form_widgets', function (require) {
odoo.define('web_widget_timepicker', function (require) {
"use strict";
var core = require('web.core');
var formats = require('web.formats');
var common = require('web.form_common');
// Snippet from http://stackoverflow.com/questions/9036429/convert-object-string-to-json
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, {
var TimePickerField = common.AbstractField.extend(common.ReinitializeFieldMixin, {
is_field_number: true,
template: "TimePickerField",
internal_format: 'float_time',
@ -27,9 +18,7 @@ odoo.define('web_widget_timepicker.form_widgets', function (require) {
this.internal_set_value(0);
this.options = _.defaults( {}, {
disableTextInput: true,
forceRoundTime: true,
this.options = _.defaults( this.options, {
step: 15,
selectOnBlur: true,
timeFormat: 'H:i',
@ -38,24 +27,7 @@ odoo.define('web_widget_timepicker.form_widgets', function (require) {
},
initialize_content: function() {
if(!this.get("effective_readonly")) {
var custom_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.$el.find('input').timepicker(this.options);
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…
Cancel
Save