1 /*############################################################################
3 # OpenERP, Open Source Management Solution
4 # Copyright (C) 2011 OpenERP SA (<http://openerp.com>).
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 ############################################################################*/
21 var __lc_buttons = [];
23 openerp.web_livechat = function (openerp) {
25 openerp.web_livechat.Livechat = openerp.web.Widget.extend({
26 template: 'Header-LiveChat',
33 var pwc = new openerp.web.Model("publisher_warranty.contract");
34 pwc.get_func('get_default_livechat_text')().then(function(text) {
35 self.$element.html(text);
36 console.log('receiving text', text);
38 pwc.get_func('is_livechat_enable')().then(function(res) {
39 console.log('result', res);
41 self.$element.click(self.do_load_livechat);
43 self.do_action({type: 'ir.act.url', url: 'http://www.openerp.com/support-or-publisher-warranty-contract'});
48 openerp.webclient.header.do_update.add_last(this.do_update);
51 do_update: function() {
54 self.$element.remove();
59 do_load_livechat: function(evt) {
63 this.$element.unbind('click', this.do_load_livechat);
65 var lc_id = _.uniqueId('livechat_');
66 this.$element.attr('id', lc_id);
68 var pwc = new openerp.web.Model("publisher_warranty.contract");
70 pwc.get_func('is_livechat_enable')().then(function(res) {
71 console.log('res', res);
75 // connect to LiveChat
79 elementId: lc_id, //'livechat_status',
84 online: '<img src="/web_livechat/static/src/img/available.png"/>Support',
85 offline: '<img src="/web_livechat/static/src/img/away.png"/>Support',
92 if (openerp.webclient) {
93 // tracking code from LiveChat
94 var license = '1035052',
98 __lc_load = function (p) {
99 if (typeof __lc_loaded != 'function')
102 l = d.createElement('script'),
103 s = d.getElementsByTagName('script')[0],
105 h = ('https:' == d.location.protocol ? 'https://' : 'http://');
106 l.type = 'text/javascript';
108 l.src = h + 'gis' + p +'.livechatinc.com/gis.cgi?serverType=control'+a+'licenseID='+license+a+'jsonp=__lc_load';
109 if (!(typeof p['server'] !== 'string' || typeof __lc_serv === 'string')) {
110 l.src = h + (__lc_serv = p['server']) + '/licence/'+license+'/script.cgi?lang='+lang+a+'groups='+skill;
111 l.src += (params == '') ? '' : a+'params='+encodeURIComponent(encodeURIComponent(params));
112 s.parentNode.insertBefore(l, s);
114 setTimeout(__lc_load, 1000);
115 if(typeof __lc_serv != 'string'){
116 s.parentNode.insertBefore(l, s);
118 } else __lc_load(Math.ceil(Math.random()*5));
121 // and add widget to webclient
122 openerp.webclient.livechat = new openerp.web_livechat.Livechat(openerp.webclient);
123 openerp.webclient.livechat.prependTo('div.header_corner');