summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_model.js
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-04-06 09:59:05 +0200
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commite7dfa4af775a93b291ccd570c05970f2ac2b9187 (patch)
treedc8589b6310f3a8cb7f2963fef50b18572c69018 /addons/web/static/src/js/views/basic/basic_model.js
parent39ab5712ed58ccbc16736cc08d594fe50fedde39 (diff)
[FIX] web: add support for editable=top/bottom in o2m
Before this commit, we lost the functionality of editing records top or bottom. However, it as almost ready, but we needed to change the way commands are generated, to respect the actual order in the UI. Also, the mock server needed to be updated, to make sure he also save the new ids in the correct order.
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_model.js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js37
1 files changed, 21 insertions, 16 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js
index 1f8d5ce94c6..c95325dbb87 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -1058,7 +1058,7 @@ var BasicModel = AbstractModel.extend({
return this.notifyChanges(id, command.data);
}));
} else {
- defs.push(this.addDefaultRecord(list.id));
+ defs.push(this.addDefaultRecord(list.id, {position: command.position}));
}
break;
case 'UPDATE':
@@ -1715,20 +1715,29 @@ var BasicModel = AbstractModel.extend({
var removedIds = _.difference(list.res_ids, relIds);
var addedIds = _.difference(relIds, list.res_ids);
var keptIds = _.intersection(list.res_ids, relIds);
+
// the didChange variable keeps track of the fact that at
// least one id was updated
var didChange = false;
- var command, i, relRecord;
- for (i = 0; i < keptIds.length; i++) {
- relRecord = _.findWhere(relData, {res_id: keptIds[i]});
- if (!_.isEmpty(relRecord._changes)) {
- var changes = this._generateChanges(relRecord);
- command = x2ManyCommands.update(relRecord.res_id, changes);
- didChange = true;
- } else {
- command = x2ManyCommands.link_to(keptIds[i]);
+ var command, relRecord;
+ for (var i = 0; i < relIds.length; i++) {
+ if (_.contains(keptIds, relIds[i])) {
+ // this is an id that already existed
+ relRecord = _.findWhere(relData, {res_id: relIds[i]});
+ if (!_.isEmpty(relRecord._changes)) {
+ var changes = this._generateChanges(relRecord);
+ command = x2ManyCommands.update(relRecord.res_id, changes);
+ didChange = true;
+ } else {
+ command = x2ManyCommands.link_to(relIds[i]);
+ }
+ commands[fieldName].push(command);
+ } else if (_.contains(addedIds, relIds[i])) {
+ // this is a new id
+ relRecord = _.findWhere(relData, {res_id: relIds[i]});
+ relRecord = this.get(relRecord.id, {raw: true});
+ commands[fieldName].push(x2ManyCommands.create(_.omit(relRecord.data, 'id')));
}
- commands[fieldName].push(command);
}
if (changesOnly && !didChange && addedIds.length === 0 && removedIds.length === 0) {
// in this situation, we have no changed ids, no added
@@ -1736,11 +1745,7 @@ var BasicModel = AbstractModel.extend({
// last changes
commands[fieldName] = [];
}
- for (i = 0; i < addedIds.length; i++) {
- relRecord = _.findWhere(relData, {res_id: addedIds[i]});
- relRecord = this.get(relRecord.id, {raw: true});
- commands[fieldName].push(x2ManyCommands.create(_.omit(relRecord.data, 'id')));
- }
+ // add delete commands
for (i = 0; i < removedIds.length; i++) {
commands[fieldName].push(x2ManyCommands.delete(removedIds[i]));
}