diff options
| author | Xavier Morel <xmo@openerp.com> | 2012-07-10 12:35:57 +0200 |
|---|---|---|
| committer | Xavier Morel <xmo@openerp.com> | 2012-07-10 12:35:57 +0200 |
| commit | 611fc6cc4f8a18dbe1eaf6df258e2a8d2a9a75ad (patch) | |
| tree | 81400cc4ca140b7f2b6f33637f792ff3fe909967 /addons/web/static | |
| parent | 9568c463b3444db0bb3633e826c7a039f7e38802 (diff) | |
[FIX] handling of resize event during edition so form fields don't get all fubar
bzr revid: xmo@openerp.com-20120710103557-584hsyats0fdzpo1
Diffstat (limited to 'addons/web/static')
| -rw-r--r-- | addons/web/static/src/js/view_list_editable.js | 48 |
1 files 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; }); }); @@ -182,6 +185,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<len; ++i) { + var item = this.fields_for_resize[i]; + this.resizeField(item.field, item.cell); + } + }, + /** + * Resizes a field's root element based on the corresponding cell of + * a listview row + * + * @param {instance.web.form.AbstractField} field + * @param {jQuery} cell + */ + resizeField: function (field, cell) { + var $cell = $(cell); + var position = $cell.position(); + + field.$element.css({ + top: position.top, + left: position.left, + width: $cell.outerWidth(), + minHeight: $cell.outerHeight() + }); + }, + /** * @return {jQuery.Deferred} */ saveEdition: function () { |
