[FIX] pad: improve pad bootstrap, prevent creating useless empty pads, avoid edition warning in read-only mode for new pads, translate messages

Added a small method to detect the proper server configuration,
and make it degrade gracefully if the method is not present.
This avoids having to force a pad URL generation in order to
test the config (possibly creating useless pads).
Add a user-friendly message when the pad has not yet been
initialized for a given record, in read-only mode.

bzr revid: odo@openerp.com-20140314131849-rnjvk1pqpiyvtc1c
This commit is contained in:
Olivier Dony 2014-03-14 14:18:49 +01:00
parent b93ae13482
commit a9f98e4990
3 changed files with 62 additions and 39 deletions

View File

@ -14,6 +14,10 @@ _logger = logging.getLogger(__name__)
class pad_common(osv.osv_memory): class pad_common(osv.osv_memory):
_name = 'pad.common' _name = 'pad.common'
def pad_is_configured(self, cr, uid, context=None):
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
return bool(user.company_id.pad_server)
def pad_generate_url(self, cr, uid, context=None): def pad_generate_url(self, cr, uid, context=None):
company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id; company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id;

View File

@ -71,6 +71,7 @@
.oe_pad_loading{ .oe_pad_loading{
text-align: center; text-align: center;
opacity: 0.75; opacity: 0.75;
font-style: italic;
} }
.etherpad_readonly ul, .etherpad_readonly ol { .etherpad_readonly ul, .etherpad_readonly ol {

View File

@ -1,63 +1,81 @@
openerp.pad = function(instance) { openerp.pad = function(instance) {
var _t = instance.web._t;
instance.web.form.FieldPad = instance.web.form.AbstractField.extend(instance.web.form.ReinitializeWidgetMixin, { instance.web.form.FieldPad = instance.web.form.AbstractField.extend(instance.web.form.ReinitializeWidgetMixin, {
template: 'FieldPad', template: 'FieldPad',
content: "", content: "",
init: function() { init: function() {
var self = this;
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.set("configured", true); this._configured_deferred = this.view.dataset.call('pad_is_configured').done(function(data) {
this.on("change:configured", this, this.switch_configured); self.set("configured", !!data);
}).fail(function(data, event) {
event.preventDefault();
self.set("configured", true);
});
}, },
initialize_content: function() { initialize_content: function() {
var self = this; var self = this;
this.switch_configured();
this.$('.oe_pad_switch').click(function() { this.$('.oe_pad_switch').click(function() {
self.$el.toggleClass('oe_pad_fullscreen'); self.$el.toggleClass('oe_pad_fullscreen');
self.view.$el.find('.oe_chatter').toggle(); 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(); this.render_value();
}, },
switch_configured: function() {
this.$(".oe_unconfigured").toggle(! this.get("configured"));
this.$(".oe_configured").toggle(this.get("configured"));
},
render_value: function() { render_value: function() {
var self = this; var self = this;
if (this.get("configured") && ! this.get("value")) { this._configured_deferred.always(function() {
self.view.dataset.call('pad_generate_url', { if (! self.get('configured')) {
context: { return;
model: self.view.model, };
field_name: self.name, var value = self.get('value');
object_id: self.view.datarecord.id if (self.get('effective_readonly')) {
}, if (_.str.startsWith(value, 'http')) {
}).done(function(data) { this.pad_loading_request = self.view.dataset.call('pad_get_content', {url: value}).done(function(data) {
if (! data.url) { self.$('.oe_pad_content').removeClass('oe_pad_loading').html('<div class="oe_pad_readonly"><div>');
self.set("configured", false); self.$('.oe_pad_readonly').html(data);
}).fail(function() {
self.$('.oe_pad_content').text(_t('Unable to load pad'));
});
} else { } 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 {
this.$('.oe_pad_content').html(""); var def = $.when();
var value = this.get('value'); if (! value || !_.str.startsWith(value, 'http')) {
if (this.pad_loading_request) { def = self.view.dataset.call('pad_generate_url', {
this.pad_loading_request.abort(); context: {
} model: self.view.model,
if (_.str.startsWith(value, 'http')) { field_name: self.name,
if (! this.get('effective_readonly')) { object_id: self.view.datarecord.id
var content = '<iframe width="100%" height="100%" frameborder="0" src="' + value + '?showChat=false&userName=' + this.session.username + '"></iframe>'; },
this.$('.oe_pad_content').html(content); }).done(function(data) {
this._dirty_flag = true; if (! data.url) {
} else { self.set("configured", false);
this.content = '<div class="oe_pad_loading">... Loading pad ...</div>'; } else {
this.pad_loading_request = self.view.dataset.call('pad_get_content', {url: value}).done(function(data) { self.set("value", data.url);
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);
}
}); });
} }
} });
}, },
}); });