[FIX] ensure only one row at a time is edited, integrate dataset index in row markup to create a more solid mapping between records and table rows in ListView.List (than checking the number of ancestors, which — it turns out — is a bit brittle when adding new rows at the front of the table
bzr revid: xmo@openerp.com-20110606134336-mmk00344x7gicd0z
This commit is contained in:
parent
587131e3ee
commit
ea92194cc6
|
@ -65,9 +65,28 @@ openerp.base.list.editable = function (openerp) {
|
|||
if (!this.options.editable) {
|
||||
return old_list_row_clicked.call(this, event);
|
||||
}
|
||||
this.render_row_as_form(event.currentTarget);
|
||||
this.edit_record();
|
||||
},
|
||||
/**
|
||||
* Checks if a record is being edited, and if so cancels it
|
||||
*/
|
||||
cancel_pending_edition: function () {
|
||||
if (!this.edition) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.edition_index !== null) {
|
||||
this.reload_record(this.edition_index);
|
||||
}
|
||||
this.edition_form.stop();
|
||||
this.edition_form.$element.remove();
|
||||
delete this.edition_form;
|
||||
delete this.edition_index;
|
||||
delete this.edition;
|
||||
},
|
||||
render_row_as_form: function (row) {
|
||||
this.cancel_pending_edition();
|
||||
|
||||
var self = this;
|
||||
var $new_row = $('<tr>', {
|
||||
id: _.uniqueId('oe-editable-row-'),
|
||||
|
@ -99,6 +118,8 @@ openerp.base.list.editable = function (openerp) {
|
|||
} else if (this.options.editable) {
|
||||
this.$current.append($new_row);
|
||||
}
|
||||
this.edition = true;
|
||||
this.edition_index = this.dataset.index;
|
||||
this.edition_form = _.extend(new openerp.base.FormView(
|
||||
null, this.group.view.session, $new_row.attr('id'),
|
||||
this.dataset, false), {
|
||||
|
@ -133,6 +154,8 @@ openerp.base.list.editable = function (openerp) {
|
|||
self.reload_record(self.dataset.index, true).then(function () {
|
||||
self.edition_form.stop();
|
||||
delete self.edition_form;
|
||||
delete self.edition_index;
|
||||
delete self.edition;
|
||||
if (!edit_next) {
|
||||
return;
|
||||
}
|
||||
|
@ -141,9 +164,6 @@ openerp.base.list.editable = function (openerp) {
|
|||
return;
|
||||
}
|
||||
self.dataset.next();
|
||||
self.render_row_as_form(
|
||||
self.$current.children().eq(
|
||||
self.dataset.index));
|
||||
});
|
||||
}, this.options.editable === 'top');
|
||||
},
|
||||
|
@ -151,12 +171,16 @@ openerp.base.list.editable = function (openerp) {
|
|||
* Cancels the edition of the row for the current dataset index
|
||||
*/
|
||||
cancel_edition: function () {
|
||||
if (this.dataset.index !== null) {
|
||||
this.reload_record(this.dataset.index);
|
||||
}
|
||||
this.edition_form.stop();
|
||||
this.edition_form.$element.remove();
|
||||
delete this.edition_form;
|
||||
this.cancel_pending_edition();
|
||||
},
|
||||
/**
|
||||
* Edits record currently selected via dataset
|
||||
*/
|
||||
edit_record: function () {
|
||||
this.render_row_as_form(
|
||||
this.$current.children(
|
||||
_.sprintf('[data-index=%d]',
|
||||
this.dataset.index)));
|
||||
},
|
||||
new_record: function () {
|
||||
this.dataset.index = null;
|
||||
|
|
|
@ -607,7 +607,7 @@ openerp.base.ListView.List = Class.extend( /** @lends openerp.base.ListView.List
|
|||
this.$current.find('th.oe-record-selector input:checked')
|
||||
.closest('tr').each(function () {
|
||||
var record = {};
|
||||
_(rows[$(this).prevAll().length].data).each(function (obj, key) {
|
||||
_(rows[$(this).data('index')].data).each(function (obj, key) {
|
||||
record[key] = obj.value;
|
||||
});
|
||||
result.ids.push(record.id);
|
||||
|
@ -622,7 +622,7 @@ openerp.base.ListView.List = Class.extend( /** @lends openerp.base.ListView.List
|
|||
* @returns {Number} the position of the row in this.rows
|
||||
*/
|
||||
row_position: function (row) {
|
||||
return $(row).prevAll().length;
|
||||
return $(row).data('index');
|
||||
},
|
||||
/**
|
||||
* Returns the identifier of the object displayed in the provided table
|
||||
|
@ -721,7 +721,8 @@ openerp.base.ListView.List = Class.extend( /** @lends openerp.base.ListView.List
|
|||
columns: this.columns,
|
||||
options: this.options,
|
||||
row: this.rows[record_index],
|
||||
row_parity: (record_index % 2 === 0) ? 'even' : 'odd'
|
||||
row_parity: (record_index % 2 === 0) ? 'even' : 'odd',
|
||||
row_index: record_index
|
||||
});
|
||||
}
|
||||
// drag and drop
|
||||
|
|
|
@ -288,7 +288,8 @@
|
|||
</t-if>
|
||||
</t>
|
||||
</t>
|
||||
<tr t-name="ListView.row" t-att-style="style" t-att-class="row_parity">
|
||||
<tr t-name="ListView.row" t-att-style="style" t-att-class="row_parity"
|
||||
t-att-data-index="row_index">
|
||||
<t t-foreach="columns" t-as="column">
|
||||
<td t-if="column.meta">
|
||||
|
||||
|
|
Loading…
Reference in New Issue