diff options
| author | Géry Debongnie <ged@odoo.com> | 2017-04-23 21:03:52 +0200 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2017-04-24 11:02:12 +0200 |
| commit | 54a90ca91910ea4345cf4261b80ea1cb7cfbae9d (patch) | |
| tree | e096c4b21f2eaa6f2f9336ccc65972c1456899b8 /addons/web/static/src/js/fields | |
| parent | a765ff503d3d60eb1dbc3a2c175b60fcafdcd083 (diff) | |
[FIX] hr_holidays,web: proper use of toggle_boolean in list view
hr_holiday was the only module that used a widget=toggle_boolean on a
button in a list view. That behaviour was implemented as a column
widget in the previous list view, and was not reimplemented in the new
views. The feature is useful, but this was not done properly: it is
better to use a widget on a field (that was the intent) instead of doing
a weird hack like it was done.
With this commit, we update hr_holidays to use the ToggleBoolean widget,
which is supposed to work on every views.
Also, we fix the toggleboolean widget (it was not properly rendering
tooltips, and changes were not saved in readonly list view).
Note that it as the side effect of being better from the point of rpcs:
before, the list view had to reload itself. Also, another advantage is
that models do not need to implement custom methods (such as
toggle_payslip_status) just to toggle a boolean...
Diffstat (limited to 'addons/web/static/src/js/fields')
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 1477d017852..33728565cf5 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1668,29 +1668,59 @@ var FieldProgressBar = AbstractField.extend({ }); /** - This widget is intended to be used on boolean fields. It toggles a button - switching between a green bullet / gray bullet. + * This widget is intended to be used on boolean fields. It toggles a button + * switching between a green bullet / gray bullet. */ var FieldToggleBoolean = AbstractField.extend({ template: "toggle_button", events: { - 'click': 'set_toggle_button' + 'click': '_onToggleButton' }, supportedFieldTypes: ['boolean'], + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * A boolean field is always set since false is a valid value. + * + * @override + */ + isSet: function () { + return true; + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @override + * @private + */ _render: function () { var class_name = this.value ? 'o_toggle_button_success' : 'text-muted'; this.$('i').attr('class', ('fa fa-circle ' + class_name)); + var title = this.value ? this.attrs.options.active : this.attrs.options.inactive; + this.$el.attr('title', title); }, - set_toggle_button: function () { - var toggle_value = !this.value; - this._setValue(toggle_value); - if (this.mode === 'edit') { - this._render(); - } - }, - isSet: function () { - return true; + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Toggle the button + * + * @private + * @param {MouseEvent} event + */ + _onToggleButton: function (event) { + event.stopPropagation(); + this._setValue(!this.value); }, + }); var JournalDashboardGraph = AbstractField.extend({ |
