diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-04-12 10:44:06 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-12 10:44:06 +0200 |
| commit | 3638cade098fe8531b1f34a0481aadd090f1ea09 (patch) | |
| tree | 35e9bc3bcf8be0b52b6ddb929fa7a9d2894c5da4 /addons/web/static/src/js/views/basic/basic_view.js | |
| parent | f1168d06c0415092c4adc9c2c6917ac5e67a1420 (diff) | |
| parent | e2e0353ce576f3c38814ae39ca4ab18ff0b6785f (diff) | |
[MERGE] web,*: redesign all JS views
This branch introduces a full redesign of all JS views. We started
basically from scratch. The goal was to unify all the various views
under a common framework, to make them testable, to make then usable
in different conditions (in studio, or in the frontend), and to make
our lives easier.
Some important points are:
- we have a brand new testing framework (still QUnit based)
- kanban view (formerly in web_kanban) moved to the web addon
- calendar view (formerly in web_calendar) moved to web as well
- tree view was removed
- each view is now separated into 3 parts: the renderer, the model,
the controller (so, actually a kind of MVC)
- we introduced new coding guidelines (camelCase, 80 chars width, ...)
- all new code should be documented
We hope that this code is the start of a new era for the Odoo web
client, we want to have a high quality codebase, well documented, well
tested, well designed.
Work done by the framework team: mostly aab, ged, chm, dmo, qsm, mge,
fwi, adr
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_view.js')
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_view.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_view.js b/addons/web/static/src/js/views/basic/basic_view.js new file mode 100644 index 00000000000..d850b2b7a2f --- /dev/null +++ b/addons/web/static/src/js/views/basic/basic_view.js @@ -0,0 +1,82 @@ +odoo.define('web.BasicView', function (require) { +"use strict"; + +/** + * The BasicView is an abstract class designed to share code between views that + * want to use a basicModel. As of now, it is the form view, the list view and + * the kanban view. + * + * The main focus of this class is to process the arch and extract field + * attributes, as well as some other useful informations. + */ + +var AbstractView = require('web.AbstractView'); +var BasicController = require('web.BasicController'); +var BasicModel = require('web.BasicModel'); + +var BasicView = AbstractView.extend({ + config: _.extend({}, AbstractView.prototype.config, { + Model: BasicModel, + Controller: BasicController, + }), + /** + * process the fields_view to find all fields appearing in the views. + * list those fields' name in this.fields_name, which will be the list + * of fields read when data is fetched. + * this.fields is the list of all field's description (the result of + * the fields_get), where the fields appearing in the fields_view are + * augmented with their attrs and some flags if they require a + * particular handling. + * + * @param {Object} viewInfo + * @param {Object} params + */ + init: function (viewInfo, params) { + this._super.apply(this, arguments); + + this.controllerParams.confirmOnDelete = true; + this.controllerParams.archiveEnabled = 'active' in viewInfo.fields; + this.controllerParams.hasButtons = + 'action_buttons' in params ? params.action_buttons : true; + + this.loadParams.fieldsInfo = viewInfo.fieldsInfo; + this.loadParams.fields = viewInfo.fields; + this.loadParams.limit = parseInt(viewInfo.arch.attrs.limit, 10) || params.limit; + this.loadParams.viewType = this.viewType; + this.recordID = params.recordID; + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * In some cases, we already have a preloaded record + * + * @override + * @private + * @returns {Deferred} + */ + _loadData: function () { + if (this.recordID) { + var record = this.model.get(this.recordID); + var viewType = this.viewType; + var viewFields = Object.keys(record.fieldsInfo[viewType]); + var fieldNames = _.difference(viewFields, Object.keys(record.data)); + if (fieldNames.length && !this.model.isNew(record.id)) { + return this.model.reload(this.recordID, { + fieldNames: fieldNames, + keepChanges: true, + viewType: viewType, + }); + } else { + return $.when(this.recordID); + } + } + return this._super.apply(this, arguments); + }, +}); + +return BasicView; + +}); |
