From bccd75796e8ff3c9dee23dd3f9a8ce75274e3289 Mon Sep 17 00:00:00 2001 From: Martin Trigaux <mat@openerp.com> Date: Fri, 20 Jun 2014 14:04:52 +0200 Subject: [PATCH] [IMP] web: allow fields in list view to use the attrs readonly to dynamically show and hide the fields --- addons/web/static/src/css/base.css | 18 +++++++++++++++--- addons/web/static/src/css/base.sass | 13 +++++++++++-- addons/web/static/src/js/view_form.js | 7 +++++-- addons/web/static/src/js/view_list_editable.js | 17 +++++++---------- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 7c2bc81b9e3f..2b08a7c06f4b 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -2815,11 +2815,11 @@ .openerp .oe_list_editable .oe_list_content td.oe_list_field_cell { padding: 4px 6px 3px; } -.openerp .oe_list.oe_list_editable.oe_editing .oe_edition .oe_list_field_cell:not(.oe_readonly) { +.openerp .oe_list.oe_list_editable.oe_editing .oe_edition .oe_list_field_cell { color: transparent; text-shadow: none; } -.openerp .oe_list.oe_list_editable.oe_editing .oe_edition .oe_list_field_cell:not(.oe_readonly) * { +.openerp .oe_list.oe_list_editable.oe_editing .oe_edition .oe_list_field_cell * { visibility: hidden; } .openerp .oe_list.oe_list_editable.oe_editing .oe_m2o_drop_down_button { @@ -2835,6 +2835,13 @@ min-width: 0; max-width: none; } +.openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_list_field_handle { + color: transparent; +} +.openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_readonly { + padding: 4px 6px 3px; + text-align: left; +} .openerp .oe_list.oe_list_editable.oe_editing .oe_form_field input, .openerp .oe_list.oe_list_editable.oe_editing .oe_form_field textarea { height: 27px; -moz-border-radius: 0; @@ -2846,9 +2853,14 @@ .openerp .oe_list.oe_list_editable.oe_editing .oe_form_field input, .openerp .oe_list.oe_list_editable.oe_editing .oe_form_field textarea, .openerp .oe_list.oe_list_editable.oe_editing .oe_form_field select { min-width: 0; } -.openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_form_field_float input, .openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_form_view_integer input { +.openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_form_field_float.oe_readonly, .openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_form_view_integer.oe_readonly { + padding: 6px 0px 0px; text-align: right; + max-width: 100px; +} +.openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_form_field_float input, .openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_form_view_integer input { width: 100% !important; + text-align: right; } .openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_form_field_datetime input.oe_datepicker_master, .openerp .oe_list.oe_list_editable.oe_editing .oe_form_field.oe_form_field_date input.oe_datepicker_master { width: 100% !important; diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index 1c02018da9d8..bdb358af6a0f 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -2218,7 +2218,7 @@ $sheet-padding: 16px .oe_list_editable .oe_list_content td.oe_list_field_cell padding: 4px 6px 3px .oe_list.oe_list_editable.oe_editing - .oe_edition .oe_list_field_cell:not(.oe_readonly) + .oe_edition .oe_list_field_cell * visibility: hidden color: transparent @@ -2230,6 +2230,11 @@ $sheet-padding: 16px .oe_input_icon margin-top: 5px .oe_form_field + &.oe_list_field_handle + color: transparent + &.oe_readonly + padding: 4px 6px 3px + text-align: left min-width: 0 max-width: none input, textarea @@ -2240,9 +2245,13 @@ $sheet-padding: 16px input, textarea, select min-width: 0 &.oe_form_field_float,&.oe_form_view_integer - input + &.oe_readonly + padding: 6px 0px 0px text-align: right + max-width: 100px + input width: 100% !important + text-align: right &.oe_form_field_datetime,&.oe_form_field_date input.oe_datepicker_master width: 100% !important diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index fec7ce106075..cbaf9e6f11e4 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2600,7 +2600,9 @@ instance.web.form.FieldDatetime = instance.web.form.AbstractField.extend(instanc }, set_dimensions: function (height, width) { this._super(height, width); - this.datewidget.$input.css('height', height); + if (!this.get("effective_readonly")) { + this.datewidget.$input.css('height', height); + } } }); @@ -3395,7 +3397,8 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc }, set_dimensions: function (height, width) { this._super(height, width); - this.$input.css('height', height); + if (!this.get("effective_readonly") && this.$input) + this.$input.css('height', height); } }); diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index 7d2e44263ce9..f3ee5dbb7ade 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -282,9 +282,7 @@ openerp.web.list_editable = function (instance) { if (!this.editor.is_editing()) { return; } for(var i=0, len=this.fields_for_resize.length; i<len; ++i) { var item = this.fields_for_resize[i]; - if (!item.field.get('effective_invisible')) { - this.resize_field(item.field, item.cell); - } + this.resize_field(item.field, item.cell); } }, /** @@ -303,6 +301,11 @@ openerp.web.list_editable = function (instance) { at: 'left top', of: $cell }); + if (field.get('effective_readonly')) { + field.$el.addClass('oe_readonly'); + } + if(field.widget == "handle") + field.$el.addClass('oe_list_field_handle'); }, /** * @return {jQuery.Deferred} @@ -448,13 +451,7 @@ openerp.web.list_editable = function (instance) { setup_events: function () { var self = this; _.each(this.editor.form.fields, function(field, field_name) { - var set_invisible = function() { - field.set({'force_invisible': field.get('effective_readonly')}); - }; - field.on("change:effective_readonly", self, set_invisible); - set_invisible(); - field.on('change:effective_invisible', self, function () { - if (field.get('effective_invisible')) { return; } + field.on("change:effective_readonly", self, function(){ var item = _(self.fields_for_resize).find(function (item) { return item.field === field; }); -- GitLab