From b8c4b42250b9caf2ac4fef32cc85dab05ccc3b08 Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Mon, 3 Dec 2018 11:05:52 +0000 Subject: [IMP] web: state_selection widget readonly if field readonly The current implementation of the state_selection widget always makes it editable even if the field is readonly. We improved this behavior by removing the handle of click on the widget when the field is readonly, but keeping it even if the view is not in edit mode, because it used for example in project to change state even when view is not editable. closes odoo/odoo#29218 --- addons/web/static/src/js/fields/basic_fields.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (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 aac91081c3c..4d266db409d 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1960,11 +1960,10 @@ var StateSelectionWidget = AbstractField.extend({ * @override */ _render: function () { - var self = this; var states = this._prepareDropdownValues(); // Adapt "FormSelection" // Like priority, default on the first possible value if no value is given. - var currentState = _.findWhere(states, {name: self.value}) || states[0]; + var currentState = _.findWhere(states, {name: this.value}) || states[0]; this.$('.o_status') .removeClass('o_status_red o_status_green') .addClass(currentState.state_class) @@ -1979,6 +1978,10 @@ var StateSelectionWidget = AbstractField.extend({ var $dropdown = this.$('.dropdown-menu'); $dropdown.children().remove(); // remove old items $items.appendTo($dropdown); + + // Disable edition if the field is readonly + var isReadonly = this.record.evalModifiers(this.attrs.modifiers).readonly; + this.$('a[data-toggle=dropdown]').toggleClass('disabled', isReadonly || false); }, //-------------------------------------------------------------------------- -- cgit v1.2.3