merge web_livechat lazy loading

bzr revid: chs@openerp.com-20111209163522-b4jy7pzpjdj7xpkx
This commit is contained in:
Christophe Simonis 2011-12-09 17:35:22 +01:00
commit 2cc0b2e79f
2 changed files with 42 additions and 13 deletions

View File

@ -44,7 +44,7 @@ class publisher_warranty_contract(osv.osv):
@cache(skiparg=3)
def get_default_livechat_text(self, cr, uid):
return '<a href="http://www.openerp.com/support-or-publisher-warranty-contract" target="_blank"><img src="/web_livechat/static/src/img/busy.png"/>Support</a>'
return '<a href="#" target="_blank"><img src="/web_livechat/static/src/img/busy.png"/>Support</a>'
publisher_warranty_contract()

View File

@ -33,7 +33,16 @@ openerp.web_livechat.Livechat = openerp.web.Widget.extend({
var pwc = new openerp.web.Model(self.session, "publisher_warranty.contract");
pwc.get_func('get_default_livechat_text')().then(function(text) {
self.$element.html(text);
console.log('receiving text', text);
self.do_update();
pwc.get_func('is_livechat_enable')().then(function(res) {
console.log('result', res);
if(res) {
self.$element.click(self.do_load_livechat);
} else {
self.do_action({type: 'ir.act.url', url: 'http://www.openerp.com/support-or-publisher-warranty-contract'});
}
})
});
openerp.webclient.header.do_update.add_last(this.do_update);
@ -45,7 +54,14 @@ openerp.web_livechat.Livechat = openerp.web.Widget.extend({
self.$element.remove();
return;
}
},
do_load_livechat: function(evt) {
evt.preventDefault();
var self = this;
this.$element.unbind('click', this.do_load_livechat);
var lc_id = _.uniqueId('livechat_');
this.$element.attr('id', lc_id);
@ -56,6 +72,8 @@ openerp.web_livechat.Livechat = openerp.web.Widget.extend({
if(!res) {
//return;
}
// connect to LiveChat
__lc_load();
__lc_buttons.push({
elementId: lc_id, //'livechat_status',
@ -77,17 +95,28 @@ if (openerp.webclient) {
params = '',
lang = 'en',
skill = '0';
__lc_load = function (p) { if (typeof __lc_loaded != 'function')
if (p) { var d = document, l = d.createElement('script'), s =
d.getElementsByTagName('script')[0], a = unescape('%26'),
h = ('https:' == d.location.protocol ? 'https://' : 'http://'); l.type = 'text/javascript'; l.async = true;
l.src = h + 'gis' + p +'.livechatinc.com/gis.cgi?serverType=control'+a+'licenseID='+license+a+'jsonp=__lc_load';
if (!(typeof p['server'] !== 'string' || typeof __lc_serv === 'string')) {
l.src = h + (__lc_serv = p['server']) + '/licence/'+license+'/script.cgi?lang='+lang+a+'groups='+skill;
l.src += (params == '') ? '' : a+'params='+encodeURIComponent(encodeURIComponent(params)); s.parentNode.insertBefore(l, s);
} else setTimeout(__lc_load, 1000); if(typeof __lc_serv != 'string'){ s.parentNode.insertBefore(l, s);}
} else __lc_load(Math.ceil(Math.random()*5)); }
__lc_load();
__lc_load = function (p) {
if (typeof __lc_loaded != 'function')
if (p) {
var d = document,
l = d.createElement('script'),
s = d.getElementsByTagName('script')[0],
a = unescape('%26'),
h = ('https:' == d.location.protocol ? 'https://' : 'http://');
l.type = 'text/javascript';
l.async = true;
l.src = h + 'gis' + p +'.livechatinc.com/gis.cgi?serverType=control'+a+'licenseID='+license+a+'jsonp=__lc_load';
if (!(typeof p['server'] !== 'string' || typeof __lc_serv === 'string')) {
l.src = h + (__lc_serv = p['server']) + '/licence/'+license+'/script.cgi?lang='+lang+a+'groups='+skill;
l.src += (params == '') ? '' : a+'params='+encodeURIComponent(encodeURIComponent(params));
s.parentNode.insertBefore(l, s);
} else
setTimeout(__lc_load, 1000);
if(typeof __lc_serv != 'string'){
s.parentNode.insertBefore(l, s);
}
} else __lc_load(Math.ceil(Math.random()*5));
}
// and add widget to webclient
openerp.webclient.livechat = new openerp.web_livechat.Livechat(openerp.webclient);