diff options
| author | Géry Debongnie <ged@odoo.com> | 2017-02-27 19:39:41 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | 206453c83689ad0dc6ceec3686153ab79bf88660 (patch) | |
| tree | 4cffbfbcb5ca9467abf35f595caa24fbe7761a6b /addons/web/static/src/js/views/basic | |
| parent | f79399bf7720e7a69b95fe2c548208b56b94ce29 (diff) | |
[FIX] web: various fixes with one2many/formviewdialogs
We share the basic model record between views, and we have to make sure
that everything is properly coordinated. The main issue solved by this
commit is the fact that we can now edit a one2many record, then close
the dialog, then edit it again and finally cancel the changes, which
bring us to the previous step.
Also, we had to slightly improve the AbstractView API
Diffstat (limited to 'addons/web/static/src/js/views/basic')
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 27 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_view.js | 14 |
2 files changed, 41 insertions, 0 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 785cf79775b..bc36f454914 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -403,6 +403,7 @@ var BasicModel = AbstractModel.extend({ * of all fields by default * @param {Object} params.fields contains the description of each field * @param {string} [params.type] 'record' or 'list' + * @param {string} [params.recordID] an ID for an existing resource. * @returns {Deferred -> string} resolves to a local id, or handle */ load: function (params) { @@ -733,11 +734,22 @@ var BasicModel = AbstractModel.extend({ * @param {string} record_id local resource * @param {Object} [options] * @param {boolean} [options.reload=true] if true, data will be reloaded + * @param {boolean} [options.localSave=false] if true, the record will only + * be 'locally' saved: its changes will move from the _changes key to the + * data key * @returns {Deferred} */ save: function (record_id, options) { var self = this; options = options || {}; + if (options.localSave) { + var record = self.localData[record_id]; + if (record._changes) { + _.extend(record.data, record._changes); + record._changes = null; + } + return $.when(); + } var shouldReload = 'reload' in options ? options.reload : true; return this.mutex.exec(function () { var record = self.localData[record_id]; @@ -800,6 +812,21 @@ var BasicModel = AbstractModel.extend({ }); }, /** + * Set and return the fieldattrs on a record element. + * It is mostly useful for the cases where a record element is shared + * between various views, such as a one2many with a tree and a form view. + * + * @param {string} recordID a valid element ID + * @param {Object} attrs the new field attrs + * @return {Object} the previous field attrs + */ + setFieldAttrs: function (recordID, attrs) { + var record = this.localData[recordID]; + var result = record.fieldAttrs; + record.fieldAttrs = attrs; + return result; + }, + /** * For list resources, this changes the orderedBy key, then performs the * sort directly, in javascript. This is used for sorting static datasets, * such as a one2many in a form view. For dynamic datasets, such as a list diff --git a/addons/web/static/src/js/views/basic/basic_view.js b/addons/web/static/src/js/views/basic/basic_view.js index 947a3ad26b6..aea0b88dcf3 100644 --- a/addons/web/static/src/js/views/basic/basic_view.js +++ b/addons/web/static/src/js/views/basic/basic_view.js @@ -99,6 +99,7 @@ var BasicView = AbstractView.extend({ this.loadParams.fieldNames = fieldNames; this.loadParams.fields = fields; this.loadParams.limit = parseInt(arch.attrs.limit, 10) || params.limit; + this.recordID = params.recordID; }, //-------------------------------------------------------------------------- @@ -106,6 +107,19 @@ var BasicView = AbstractView.extend({ //-------------------------------------------------------------------------- /** + * In some cases, we already have a preloaded record + * + * @override + * @private + * @returns {Deferred} + */ + _loadData: function () { + if (this.recordID) { + return $.when(this.recordID); + } + return this._super.apply(this, arguments); + }, + /** * Visit all nodes in the arch field and process each fields * * @param {Object} arch |
