From c2366d71810ea4a2860f75dbd482dd12649318a8 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 19 Aug 2013 16:21:39 +0200 Subject: [PATCH] Put ChatButton in livechat bzr revid: nicolas.vanhoren@openerp.com-20130819142139-mvh25k95k1wbjtzv --- addons/im/static/src/js/im_common.js | 62 ------------------- addons/im/static/src/xml/im_common.xml | 4 -- addons/im_livechat/loader.js | 6 -- .../static/ext/static/js/livechat.xml | 7 +++ .../static/ext/static/js/livesupport.js | 56 +++++++++++++++++ 5 files changed, 63 insertions(+), 72 deletions(-) create mode 100644 addons/im_livechat/static/ext/static/js/livechat.xml diff --git a/addons/im/static/src/js/im_common.js b/addons/im/static/src/js/im_common.js index 5307cb422fa..e9226e4c056 100644 --- a/addons/im/static/src/js/im_common.js +++ b/addons/im/static/src/js/im_common.js @@ -1,7 +1,5 @@ /* - Dependencies: openerp, underscore, jquery - This file must compile in EcmaScript 3 and work in IE7. Prerequisites to use this module: @@ -17,14 +15,6 @@ function declare($, _, openerp) { var im_common = {}; - // like underscore's noConflit() to easily create an amd wrapper - var tmp_im_common = window.im_common; - im_common.no_conflict = function() { - window.im_common = tmp_im_common; - return im_common; - }; - window.im_common = im_common; - /* All of this must be defined to use this module */ @@ -46,58 +36,6 @@ function declare($, _, openerp) { var ERROR_DELAY = 5000; - im_common.ChatButton = openerp.Widget.extend({ - className: "openerp_style oe_chat_button", - events: { - "click": "click" - }, - init: function(parent, channel, options) { - this._super(parent); - this.channel = channel; - this.options = options; - this.text = options.buttonText; - }, - start: function() { - this.$().append(openerp.qweb.render("chatButton", {widget: this})); - }, - click: function() { - if (! this.manager) { - this.manager = new im_common.ConversationManager(null); - this.activated_def = this.manager.start_polling(); - } - var def = $.Deferred(); - $.when(this.activated_def).then(function() { - def.resolve(); - }, function() { - def.reject(); - }); - setTimeout(function() { - def.reject(); - }, 5000); - def.then(_.bind(this.chat, this), function() { - im_common.notification(_t("It seems the connection to the server is encountering problems, please try again later.")); - }); - }, - chat: function() { - var self = this; - if (this.manager.conversations.length > 0) - return; - im_common.connection.model("im_livechat.channel").call("get_available_user", [this.channel]).then(function(user_id) { - if (! user_id) { - im_common.notification(_t("None of our collaborators seems to be available, please try again later.")); - return; - } - self.manager.ensure_users([user_id]).then(function() { - var conv = self.manager.activate_user(self.manager.get_user(user_id), true); - if (self.options.defaultMessage) { - conv.received_message({message: self.options.defaultMessage, - date: openerp.datetime_to_str(new Date())}); - } - }); - }); - } - }); - im_common.ImUser = openerp.Class.extend(openerp.PropertiesMixin, { init: function(parent, user_rec) { openerp.PropertiesMixin.init.call(this, parent); diff --git a/addons/im/static/src/xml/im_common.xml b/addons/im/static/src/xml/im_common.xml index df5b90cce08..f4acd6762b1 100644 --- a/addons/im/static/src/xml/im_common.xml +++ b/addons/im/static/src/xml/im_common.xml @@ -32,8 +32,4 @@
- - - - \ No newline at end of file diff --git a/addons/im_livechat/loader.js b/addons/im_livechat/loader.js index dcb134adf65..d2580ab272a 100644 --- a/addons/im_livechat/loader.js +++ b/addons/im_livechat/loader.js @@ -31,12 +31,6 @@ require.config({ "jquery.achtung": { deps: ['jquery'], }, - im_common: { - deps: ['jquery', 'openerp', 'underscore', 'qweb2'], - init: function() { - return im_common.no_conflict(); - } - }, }, })(["livesupport", "jquery"], function(livesupport, jQuery) { jQuery.noConflict(); diff --git a/addons/im_livechat/static/ext/static/js/livechat.xml b/addons/im_livechat/static/ext/static/js/livechat.xml new file mode 100644 index 00000000000..1c7b00466d9 --- /dev/null +++ b/addons/im_livechat/static/ext/static/js/livechat.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/addons/im_livechat/static/ext/static/js/livesupport.js b/addons/im_livechat/static/ext/static/js/livesupport.js index c7f136b32d8..d238014bdb0 100644 --- a/addons/im_livechat/static/ext/static/js/livesupport.js +++ b/addons/im_livechat/static/ext/static/js/livesupport.js @@ -34,6 +34,10 @@ define(["openerp", "im_common", "underscore", "require", "jquery", console.log("starting live support customer app"); im_common.connection = new openerp.Session(null, server_url, { override_session: true }); return im_common.connection.session_authenticate(db, login, password); + }).then(function() { + return im_common.connection.rpc('/web/proxy/load', {path: '/im_livechat/static/ext/static/js/livechat.xml'}).then(function(xml) { + openerp.qweb.add_template(xml); + }); }).then(function() { return im_common.connection.rpc('/web/proxy/load', {path: '/im/static/src/xml/im_common.xml'}).then(function(xml) { openerp.qweb.add_template(xml); @@ -63,5 +67,57 @@ define(["openerp", "im_common", "underscore", "require", "jquery", $.achtung({message: message, timeout: 0, showEffects: false, hideEffects: false}); }; + im_common.ChatButton = openerp.Widget.extend({ + className: "openerp_style oe_chat_button", + events: { + "click": "click" + }, + init: function(parent, channel, options) { + this._super(parent); + this.channel = channel; + this.options = options; + this.text = options.buttonText; + }, + start: function() { + this.$().append(openerp.qweb.render("chatButton", {widget: this})); + }, + click: function() { + if (! this.manager) { + this.manager = new im_common.ConversationManager(null); + this.activated_def = this.manager.start_polling(); + } + var def = $.Deferred(); + $.when(this.activated_def).then(function() { + def.resolve(); + }, function() { + def.reject(); + }); + setTimeout(function() { + def.reject(); + }, 5000); + def.then(_.bind(this.chat, this), function() { + im_common.notification(_t("It seems the connection to the server is encountering problems, please try again later.")); + }); + }, + chat: function() { + var self = this; + if (this.manager.conversations.length > 0) + return; + im_common.connection.model("im_livechat.channel").call("get_available_user", [this.channel]).then(function(user_id) { + if (! user_id) { + im_common.notification(_t("None of our collaborators seems to be available, please try again later.")); + return; + } + self.manager.ensure_users([user_id]).then(function() { + var conv = self.manager.activate_user(self.manager.get_user(user_id), true); + if (self.options.defaultMessage) { + conv.received_message({message: self.options.defaultMessage, + date: openerp.datetime_to_str(new Date())}); + } + }); + }); + } + }); + return livesupport; });