[IMP] lazy loading of dashboards
authorGéry Debongnie <ged@odoo.com>
Thu, 21 Aug 2014 09:01:13 +0000 (11:01 +0200)
committerGéry Debongnie <ged@odoo.com>
Thu, 21 Aug 2014 09:48:37 +0000 (11:48 +0200)
The widget AddToDashboard used to make an ajax call every time the
search view is loaded.  This is often useless and can be annoying when
that request is long.  With this patch, the request is only done when
the user click on the widget AddToDashboard

addons/board/static/src/js/dashboard.js

index bdd0c6a..f31a277 100644 (file)
@@ -329,15 +329,19 @@ instance.web.form.tags.add('board', 'instance.web.form.DashBoard');
 instance.board.AddToDashboard = instance.web.search.Input.extend({
     template: 'SearchView.addtodashboard',
     _in_drawer: true,
+    init: function (parent) {
+        this._super(parent);
+        this.is_loaded = null;
+    },
     start: function () {
         var self = this;
         this.$el
-            .on('click', 'h4', this.proxy('show_option'))
+            .on('click', 'h4', this.proxy('load_and_show_option'))
             .on('submit', 'form', function (e) {
                 e.preventDefault();
                 self.add_dashboard();
             });
-        return this.load_data().done(this.proxy("render_data"));
+        return $.when();
     },
     load_data:function(){
         var board = new instance.web.Model('board.board');
@@ -406,12 +410,18 @@ instance.board.AddToDashboard = instance.web.search.Input.extend({
             }
         });
     },
-    show_option:function(){
+    load_and_show_option: function(){
+        if (!this.is_loaded) {
+            this.is_loaded = this.load_data().done(this.proxy("render_data"));
+        }
+        this.is_loaded.done(this.proxy('show_option'));
+    },
+    show_option: function () {
         this.$el.toggleClass('oe_opened');
         if (! this.$el.hasClass('oe_opened'))
             return;
         this.$("input").val(this.view.fields_view.name || "" );
-    }
+    },
 });