From 2728fe1ec1ac7e99819d0f30f29a1814b00c82a4 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 24 Aug 2017 15:27:44 +0200 Subject: [IMP] web: onchange x2many with virtual id in create command When an onchange modifies an x2many field, the line on which the user works remains in editable mode and the cursor is returned to the same position. The second argument of create command is a reference used to reactivate the edited line. --- addons/web/static/src/js/views/basic/basic_model.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') 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 0d95c292070..537fa11fdb9 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -92,10 +92,10 @@ var session = require('web.session'); var _t = core._t; var x2ManyCommands = { - // (0, _, {values}) + // (0, virtualID, {values}) CREATE: 0, - create: function (values) { - return [x2ManyCommands.CREATE, false, values]; + create: function (virtualID, values) { + return [x2ManyCommands.CREATE, virtualID || false, values]; }, // (1, id, {values}) UPDATE: 1, @@ -391,6 +391,7 @@ var BasicModel = AbstractModel.extend({ limit: element.limit, model: element.model, offset: element.offset, + ref: element.ref, res_ids: element.res_ids.slice(0), specialData: _.extend({}, element.specialData), type: 'record', @@ -1213,6 +1214,7 @@ var BasicModel = AbstractModel.extend({ modelName: list.model, parentID: list.id, viewType: list.viewType, + ref: command[1], }; if (command[0] === 1) { params.res_id = command[1]; @@ -2415,7 +2417,7 @@ var BasicModel = AbstractModel.extend({ commands[fieldName].push(x2ManyCommands.replace_with(realIDs)); _.each(relRecordCreated, function (relRecord) { var changes = self._generateChanges(relRecord, options); - commands[fieldName].push(x2ManyCommands.create(changes)); + commands[fieldName].push(x2ManyCommands.create(relRecord.ref, changes)); }); // generate update commands for records that have been // updated (it may happen with editable lists) @@ -2451,7 +2453,7 @@ var BasicModel = AbstractModel.extend({ // this is a new id relRecord = _.findWhere(relRecordAdded, {res_id: list.res_ids[i]}); changes = this._generateChanges(relRecord, options); - commands[fieldName].push(x2ManyCommands.create(changes)); + commands[fieldName].push(x2ManyCommands.create(relRecord.ref, changes)); } } if (options.changesOnly && !didChange && addedIds.length === 0 && removedIds.length === 0) { @@ -2824,6 +2826,7 @@ var BasicModel = AbstractModel.extend({ orderedBy: params.orderedBy || [], parentID: params.parentID, rawContext: params.rawContext, + ref: params.ref || res_id, relationField: params.relationField, res_id: res_id, res_ids: res_ids, -- cgit v1.2.3