summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@odoo.com>2017-08-24 15:27:44 +0200
committerChristophe Matthieu <chm@odoo.com>2017-08-30 14:39:17 +0200
commit2728fe1ec1ac7e99819d0f30f29a1814b00c82a4 (patch)
tree89b1325b1ba3e86bc6ac830462c4694bc99553d2 /addons/web/static/src/js/views/basic
parent6cf98c4c87d644928897a76b9985947ab2ebc607 (diff)
[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.
Diffstat (limited to 'addons/web/static/src/js/views/basic')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js13
-rw-r--r--addons/web/static/src/js/views/basic/basic_renderer.js16
2 files changed, 23 insertions, 6 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 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,
diff --git a/addons/web/static/src/js/views/basic/basic_renderer.js b/addons/web/static/src/js/views/basic/basic_renderer.js
index e040a5fa7f0..0e26e2fa19f 100644
--- a/addons/web/static/src/js/views/basic/basic_renderer.js
+++ b/addons/web/static/src/js/views/basic/basic_renderer.js
@@ -10,7 +10,7 @@ odoo.define('web.BasicRenderer', function (require) {
var AbstractRenderer = require('web.AbstractRenderer');
var config = require('web.config');
var core = require('web.core');
-var Domain = require('web.Domain');
+var dom = require('web.dom');
var qweb = core.qweb;
@@ -115,6 +115,20 @@ var BasicRenderer = AbstractRenderer.extend({
return resetWidgets;
});
},
+ /**
+ * Activates the widget and move the cursor to the given offset
+ *
+ * @param {string} id
+ * @param {string} fieldName
+ * @param {integer} offset
+ */
+ focusField: function (id, fieldName, offset) {
+ this.editRecord(id);
+ if (typeof offset === "number") {
+ var field = _.findWhere(this.allFieldWidgets[id], {name: fieldName});
+ dom.setCursor(field.getFocusableElement(), offset);
+ }
+ },
//--------------------------------------------------------------------------
// Private