[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._super.apply(this, arguments);
|
||||||
|
|
||||||
this.editor = this.makeEditor();
|
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({
|
$(this.groups).bind({
|
||||||
'edit': function (e, id, dataset) {
|
'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
|
* Handles the activation of a record in editable mode (making a record
|
||||||
* editable), called *after* the record has become editable.
|
* editable), called *after* the record has become editable.
|
||||||
|
@ -146,6 +154,7 @@ openerp.web.list_editable = function (instance) {
|
||||||
var cells = this.getCellsFor($recordRow);
|
var cells = this.getCellsFor($recordRow);
|
||||||
|
|
||||||
return this.ensureSaved().pipe(function () {
|
return this.ensureSaved().pipe(function () {
|
||||||
|
self.fields_for_resize.splice(0, self.fields_for_resize.length);
|
||||||
return self.withEvent('edit', {
|
return self.withEvent('edit', {
|
||||||
record: record.attributes,
|
record: record.attributes,
|
||||||
cancel: false
|
cancel: false
|
||||||
|
@ -158,17 +167,11 @@ openerp.web.list_editable = function (instance) {
|
||||||
field.set({invisible: true});
|
field.set({invisible: true});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var $cell = $(cell);
|
|
||||||
var position = $cell.position();
|
|
||||||
|
|
||||||
field.$element.css({
|
self.fields_for_resize.push({field: field, cell: cell});
|
||||||
top: position.top,
|
|
||||||
left: position.left,
|
|
||||||
width: $cell.outerWidth(),
|
|
||||||
minHeight: $cell.outerHeight()
|
|
||||||
});
|
|
||||||
}).pipe(function () {
|
}).pipe(function () {
|
||||||
$recordRow.addClass('oe_edition');
|
$recordRow.addClass('oe_edition');
|
||||||
|
self.resizeFields();
|
||||||
return record.attributes;
|
return record.attributes;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -181,6 +184,35 @@ openerp.web.list_editable = function (instance) {
|
||||||
});
|
});
|
||||||
return cells;
|
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}
|
* @return {jQuery.Deferred}
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue