[FIX] handling of resize event during edition so form fields don't get all fubar
bzr revid: xmo@openerp.com-20120710103557-584hsyats0fdzpo1
This commit is contained in:
parent
9568c463b3
commit
611fc6cc4f
|
@ -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<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}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue