[MERGE] Forward port of saas-2 fixes up to rev 9152 rev-id odo@openerp.com-2014031414...
authorOlivier Dony <odo@openerp.com>
Fri, 14 Mar 2014 14:39:11 +0000 (15:39 +0100)
committerOlivier Dony <odo@openerp.com>
Fri, 14 Mar 2014 14:39:11 +0000 (15:39 +0100)
bzr revid: odo@openerp.com-20140314143911-c2mxesg31xezeyr9

1  2 
addons/pad/static/src/css/etherpad.css
addons/pad/static/src/js/pad.js
addons/share/wizard/share_wizard.py

@@@ -10,55 -16,66 +16,67 @@@ openerp.pad = function(instance) 
          },
          initialize_content: function() {
              var self = this;
-             this.switch_configured();
              this.$('.oe_pad_switch').click(function() {
                  self.$el.toggleClass('oe_pad_fullscreen');
 +                self.$el.find('.oe_pad_switch').toggleClass('fa-expand fa-compress');
                  self.view.$el.find('.oe_chatter').toggle();
              });
+             this._configured_deferred.always(function() {
+                 var configured = self.get('configured');
+                 self.$(".oe_unconfigured").toggle(!configured);
+                 self.$(".oe_configured").toggle(configured);
+             });
              this.render_value();
          },
-         switch_configured: function() {
-             this.$(".oe_unconfigured").toggle(! this.get("configured"));
-             this.$(".oe_configured").toggle(this.get("configured"));
-         },
          render_value: function() {
-             var self  = this;
-             if (this.get("configured") && ! this.get("value")) {
-                 self.view.dataset.call('pad_generate_url', {
-                     context: {
-                         model: self.view.model,
-                         field_name: self.name,
-                         object_id: self.view.datarecord.id
-                     },
-                 }).done(function(data) {
-                     if (! data.url) {
-                         self.set("configured", false);
+             var self = this;
+             this._configured_deferred.always(function() {
+                 if (! self.get('configured')) {
+                     return;
+                 };
+                 var value = self.get('value');
+                 if (self.get('effective_readonly')) {
+                     if (_.str.startsWith(value, 'http')) {
+                         this.pad_loading_request = self.view.dataset.call('pad_get_content', {url: value}).done(function(data) {
+                             self.$('.oe_pad_content').removeClass('oe_pad_loading').html('<div class="oe_pad_readonly"><div>');
+                             self.$('.oe_pad_readonly').html(data);
+                         }).fail(function() {
+                             self.$('.oe_pad_content').text(_t('Unable to load pad'));
+                         });
                      } else {
-                         self.set("value", data.url);
+                         self.$('.oe_pad_content').addClass('oe_pad_loading').show().text(_t("This pad will be initialized on first edit"));
+                     }
+                 }
+                 else {
+                     var def = $.when();
+                     if (! value || !_.str.startsWith(value, 'http')) {
+                         def = self.view.dataset.call('pad_generate_url', {
+                             context: {
+                                 model: self.view.model,
+                                 field_name: self.name,
+                                 object_id: self.view.datarecord.id
+                             },
+                         }).done(function(data) {
+                             if (! data.url) {
+                                 self.set("configured", false);
+                             } else {
+                                 self.set("value", data.url);
+                             }
+                         });
                      }
-                 });
-             }
-             this.$('.oe_pad_content').html("");
-             var value = this.get('value');
-             if (this.pad_loading_request) {
-                 this.pad_loading_request.abort();
-             }
-             if (_.str.startsWith(value, 'http')) {
-                 if (! this.get('effective_readonly')) {
-                     var content = '<iframe width="100%" height="100%" frameborder="0" src="' + value + '?showChat=false&userName=' + this.session.username + '"></iframe>';
-                     this.$('.oe_pad_content').html(content);
-                     this._dirty_flag = true;
-                 } else {
-                     this.content = '<div class="oe_pad_loading">... Loading pad ...</div>';
-                     this.pad_loading_request = self.view.dataset.call('pad_get_content', {url: value}).done(function(data) {
-                         self.$('.oe_pad_content').html('<div class="oe_pad_readonly"><div>');
-                         self.$('.oe_pad_readonly').html(data);
-                     }).fail(function() {
-                         self.$('.oe_pad_content').text('Unable to load pad');
+                     def.then(function() {
+                         value = self.get('value');
+                         if (_.str.startsWith(value, 'http')) {
+                             var content = '<iframe width="100%" height="100%" frameborder="0" src="' + value + '?showChat=false&userName=' + self.session.username + '"></iframe>';
+                             self.$('.oe_pad_content').html(content);
+                             self._dirty_flag = true;
+                         }
+                         else {
+                             self.$('.oe_pad_content').text(value);
+                         }
                      });
                  }
-             }
+             });
          },
      });
  
Simple merge