summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields/basic_fields.js
diff options
context:
space:
mode:
authorAnkit Sathvara <asa@odoo.com>2017-07-07 11:45:47 +0200
committerYannick Tivisse <yti@odoo.com>2017-07-07 16:18:23 +0200
commitf41bd82f66eb25df3c80b4a283a9a5b4d7058972 (patch)
tree33a30ad6a06e9f53e965e02d1cb26077413fb008 /addons/web/static/src/js/fields/basic_fields.js
parentc9f0352ac6ca6cb5d4426ce8362b26fd18902f2e (diff)
[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.
Diffstat (limited to 'addons/web/static/src/js/fields/basic_fields.js')
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js47
1 files changed, 47 insertions, 0 deletions
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 class="slider"></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,