From f41bd82f66eb25df3c80b4a283a9a5b4d7058972 Mon Sep 17 00:00:00 2001 From: Ankit Sathvara Date: Fri, 7 Jul 2017 11:45:47 +0200 Subject: [ADD] web: Add new widget to toogle a boolean with a slider Purpose ======= Currently, it's not possible to activate a boolean on a non-editable list view without adding 2 buttons linked to a python method. These buttons aren't aligned and the result is not pretty. This commit adds a new widget that allows to toggle a boolean record by record by clicking on the slider. --- addons/web/static/src/js/fields/basic_fields.js | 47 +++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'addons/web/static/src/js/fields/basic_fields.js') diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 1868a29a237..6eb828a9c7e 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1506,6 +1506,52 @@ var FieldBooleanButton = AbstractField.extend({ }, }); +var BooleanToggle = FieldBoolean.extend({ + events: { + 'click': '_onClick' + }, + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @override + * @private + */ + _render: function () { + this._super.apply(this, arguments); + this._renderToggleSwitch(); + }, + + /** + * Display toggle switch + * + * @private + */ + _renderToggleSwitch: function () { + this.$el.addClass("o_boolean_toggle"); + var $div = $('
'); + $div.insertAfter(this.$("input[type=checkbox]")); + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Toggle active value + * + * @private + * @param {MouseEvent} event + */ + _onClick: function (event) { + event.stopPropagation(); + this._setValue(!this.value); + this.$el.closest(".o_data_row").toggleClass('text-muted', this.value); + }, + +}); + var StatInfo = AbstractField.extend({ supportedFieldTypes: ['integer', 'float'], @@ -2258,6 +2304,7 @@ return { FieldBinaryImage: FieldBinaryImage, FieldBoolean: FieldBoolean, FieldBooleanButton: FieldBooleanButton, + BooleanToggle: BooleanToggle, FieldChar: FieldChar, FieldDate: FieldDate, FieldDateTime: FieldDateTime, -- cgit v1.2.3