diff options
| author | Christophe Matthieu <chm@odoo.com> | 2017-08-31 14:39:52 +0200 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2017-08-31 16:26:11 +0200 |
| commit | 95c2bd33a2e4bc5995b77c64c961e97db809e7f2 (patch) | |
| tree | 27c6d4104ae973ad293f0b8e5742f231f8362ff1 /addons/web/static/src/js/views | |
| parent | 6f60a9a1792f4390c883bc1dff5f595c84183e12 (diff) | |
[IMP] web: lazy load nvd3, ace and fullCalendar lib to reduce asset size
Diffstat (limited to 'addons/web/static/src/js/views')
| -rw-r--r-- | addons/web/static/src/js/views/abstract_view.js | 51 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/calendar/calendar_view.js | 2 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/graph/graph_view.js | 8 |
3 files changed, 21 insertions, 40 deletions
diff --git a/addons/web/static/src/js/views/abstract_view.js b/addons/web/static/src/js/views/abstract_view.js index 644ba8ac985..873fcc27b0d 100644 --- a/addons/web/static/src/js/views/abstract_view.js +++ b/addons/web/static/src/js/views/abstract_view.js @@ -23,13 +23,12 @@ odoo.define('web.AbstractView', function (require) { * in most case discarded. */ +var ajax = require('web.ajax'); var Class = require('web.Class'); var Context = require('web.Context'); -var ajax = require('web.ajax'); var AbstractModel = require('web.AbstractModel'); var AbstractRenderer = require('web.AbstractRenderer'); var AbstractController = require('web.AbstractController'); -var Context = require('web.Context'); var AbstractView = Class.extend({ // name displayed in view switchers @@ -51,8 +50,6 @@ var AbstractView = Class.extend({ Model: AbstractModel, Renderer: AbstractRenderer, Controller: AbstractController, - js_libs: [], - css_libs: [], }, /** @@ -125,7 +122,15 @@ var AbstractView = Class.extend({ //-------------------------------------------------------------------------- /** - * Main method of the view class. + * Main method of the view class. Create a controller, and make sure that + * data and libraries are loaded. + * + * There is a unusual thing going in this method with parents: we create + * renderer/model with parent as parent, then we have to reassign them at + * the end to make sure that we have the proper relationships. This is + * necessary to solve the problem that the controller need the model and the + * renderer to be instantiated, but the model need a parent to be able to + * load itself, and the renderer needs the data in its constructor. * * @param {Widget} parent The parent of the resulting Controller (most * likely a view manager) @@ -133,7 +138,7 @@ var AbstractView = Class.extend({ */ getController: function (parent) { var self = this; - return $.when(this._loadData(parent), this._loadLibs()).then(function () { + return $.when(this._loadData(parent), ajax.loadLibs(this)).then(function () { var model = self.getModel(); var state = model.get(arguments[0]); var renderer = self.getRenderer(parent, state); @@ -203,40 +208,6 @@ var AbstractView = Class.extend({ return model.load(this.loadParams); }, /** - * Makes sure that the js_libs and css_libs are properly loaded. Note that - * the ajax loadJS and loadCSS methods don't do anything if the given file - * is already loaded. - * - * @private - * @returns {Deferred} - */ - _loadLibs: function () { - var defs = []; - var jsDefs; - _.each(this.config.js_libs, function (urls) { - if (typeof(urls) === 'string') { - // js_libs is an array of urls: those urls can be loaded in - // parallel - defs.push(ajax.loadJS(urls)); - } else { - // js_libs is an array of arrays of urls: those arrays of urls - // must be loaded sequentially, but the urls inside each - // sub-array can be loaded in parallel - defs.push($.when.apply($, jsDefs).then(function () { - jsDefs = []; - _.each(urls, function (url) { - jsDefs.push(ajax.loadJS(url)); - }); - return $.when.apply($, jsDefs); - })); - } - }); - _.each(this.config.css_libs, function (url) { - defs.push(ajax.loadCSS(url)); - }); - return $.when.apply($, defs); - }, - /** * Loads the subviews for x2many fields when they are not inline * * @private diff --git a/addons/web/static/src/js/views/calendar/calendar_view.js b/addons/web/static/src/js/views/calendar/calendar_view.js index 71a6c30b756..47c16300508 100644 --- a/addons/web/static/src/js/views/calendar/calendar_view.js +++ b/addons/web/static/src/js/views/calendar/calendar_view.js @@ -21,6 +21,8 @@ var fieldsToGather = [ var CalendarView = AbstractView.extend({ display_name: _lt('Calendar'), icon: 'fa-calendar', + jsLibs: ['/web/static/lib/fullcalendar/js/fullcalendar.js'], + cssLibs: ['/web/static/lib/fullcalendar/css/fullcalendar.css'], config: { Model: CalendarModel, Controller: CalendarController, diff --git a/addons/web/static/src/js/views/graph/graph_view.js b/addons/web/static/src/js/views/graph/graph_view.js index 423d52ca64c..a5ad21e1816 100644 --- a/addons/web/static/src/js/views/graph/graph_view.js +++ b/addons/web/static/src/js/views/graph/graph_view.js @@ -19,6 +19,14 @@ var _lt = core._lt; var GraphView = AbstractView.extend({ display_name: _lt('Graph'), icon: 'fa-bar-chart', + cssLibs: [ + '/web/static/lib/nvd3/nv.d3.css' + ], + jsLibs: [ + '/web/static/lib/nvd3/d3.v3.js', + '/web/static/lib/nvd3/nv.d3.js', + '/web/static/src/js/libs/nvd3.js' + ], config: { Model: GraphModel, Controller: Controller, |
