From 611fc6cc4f8a18dbe1eaf6df258e2a8d2a9a75ad Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 10 Jul 2012 12:35:57 +0200 Subject: [PATCH] [FIX] handling of resize event during edition so form fields don't get all fubar bzr revid: xmo@openerp.com-20120710103557-584hsyats0fdzpo1 --- .../web/static/src/js/view_list_editable.js | 48 +++++++++++++++---- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index f759c274287..1fb99966eeb 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -13,6 +13,10 @@ openerp.web.list_editable = function (instance) { this._super.apply(this, arguments); this.editor = this.makeEditor(); + // Stores records of {field, cell}, allows for re-rendering fields + // depending on cell state during and after resize events + this.fields_for_resize = []; + instance.web.bus.on('resize', this, this.resizeFields); $(this.groups).bind({ 'edit': function (e, id, dataset) { @@ -27,6 +31,10 @@ openerp.web.list_editable = function (instance) { } }) }, + destroy: function () { + instance.web.bus.off('resize', this, this.resizeFields); + this._super(); + }, /** * Handles the activation of a record in editable mode (making a record * editable), called *after* the record has become editable. @@ -146,6 +154,7 @@ openerp.web.list_editable = function (instance) { var cells = this.getCellsFor($recordRow); return this.ensureSaved().pipe(function () { + self.fields_for_resize.splice(0, self.fields_for_resize.length); return self.withEvent('edit', { record: record.attributes, cancel: false @@ -158,17 +167,11 @@ openerp.web.list_editable = function (instance) { field.set({invisible: true}); return; } - var $cell = $(cell); - var position = $cell.position(); - field.$element.css({ - top: position.top, - left: position.left, - width: $cell.outerWidth(), - minHeight: $cell.outerHeight() - }); + self.fields_for_resize.push({field: field, cell: cell}); }).pipe(function () { $recordRow.addClass('oe_edition'); + self.resizeFields(); return record.attributes; }); }); @@ -181,6 +184,35 @@ openerp.web.list_editable = function (instance) { }); return cells; }, + /** + * If currently editing a row, resizes all registered form fields based + * on the corresponding row cell + */ + resizeFields: function () { + if (!this.editor.isEditing()) { return; } + for(var i=0, len=this.fields_for_resize.length; i