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_renderer.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_renderer.js')
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_renderer.js | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_renderer.js b/addons/web/static/src/js/views/basic/basic_renderer.js new file mode 100644 index 00000000000..1db0718545e --- /dev/null +++ b/addons/web/static/src/js/views/basic/basic_renderer.js @@ -0,0 +1,83 @@ +odoo.define('web.BasicRenderer', function (require) { +"use strict"; + +/** + * The BasicRenderer is an abstract class designed to share code between all + * views that uses a BasicModel. The main goal is to keep track of all field + * widgets, and properly destroy them whenever a rerender is done. + * + * When a concrete view extends a BasicRenderer, it should add each field + * widgets in the this.widget list. + */ + +var AbstractRenderer = require('web.AbstractRenderer'); +var config = require('web.config'); +var core = require('web.core'); + +var qweb = core.qweb; + +return AbstractRenderer.extend({ + /** + * @override + */ + init: function (paret, state, params) { + this._super.apply(this, arguments); + this.widgets = []; + this.activeActions = params.activeActions; + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Add a tooltip on a $node, depending on a field description + * + * @param {FieldWidget} widget + * @param {$node} $node + */ + _addFieldTooltip: function (widget, $node) { + // optional argument $node, the jQuery element on which the tooltip + // should be attached if not given, the tooltip is attached on the + // widget's $el + $node = $node.length ? $node : widget.$el; + $node.tooltip({ + delay: { show: 1000, hide: 0 }, + title: function () { + return qweb.render('WidgetLabel.tooltip', { + debug: config.debug, + widget: widget, + }); + } + }); + }, + /** + * Render the view + * + * @override + * @returns {Deferred} + */ + _render: function () { + var oldWidgets = this.widgets; + this.widgets = []; + return this._renderView().then(_.invoke.bind(_, oldWidgets, 'destroy')); + }, + /** + * Actual rendering. Supposed to be overridden by concrete renderers. + * The basic responsabilities of _renderView are: + * - use the xml arch of the view to render a jQuery representation + * - instantiate a widget from the registry for each field in the arch + * + * Note that the 'state' field should contains all necessary information + * for the rendering. The field widgets should be as synchronous as + * possible. + * + * @abstract + * @returns {Deferred} + */ + _renderView: function () { + return $.when(); + }, +}); + +}); |
