From 580287348df6b62b761a94cc00aac9a7090a3d55 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 19 Aug 2013 11:17:41 +0200 Subject: [PATCH] Converted templates + wip bzr revid: nicolas.vanhoren@openerp.com-20130819091741-focrd0tpwjv2vg8s --- addons/im_livechat/loader.js | 3 +- .../static/ext/static/js/livesupport.js | 36 ++++++++++------- .../ext/static/js/livesupport_templates.html | 36 ----------------- .../ext/static/js/livesupport_templates.js | 1 - .../ext/static/js/livesupport_templates.xml | 39 +++++++++++++++++++ 5 files changed, 61 insertions(+), 54 deletions(-) delete mode 100644 addons/im_livechat/static/ext/static/js/livesupport_templates.html delete mode 100644 addons/im_livechat/static/ext/static/js/livesupport_templates.js create mode 100644 addons/im_livechat/static/ext/static/js/livesupport_templates.xml diff --git a/addons/im_livechat/loader.js b/addons/im_livechat/loader.js index f575ea73d77..4fe90110846 100644 --- a/addons/im_livechat/loader.js +++ b/addons/im_livechat/loader.js @@ -29,12 +29,11 @@ require.config({ })(["livesupport", "jquery"], function(livesupport, jQuery) { jQuery.noConflict(); console.log("loaded live support"); - /* livesupport.main({{url | json}}, {{db | json}}, "anonymous", "anonymous", {{channel | json}}, { buttonText: {{buttonText | json}}, inputPlaceholder: {{inputPlaceholder | json}}, defaultMessage: {{(defaultMessage or None) | json}}, auto: window.oe_im_livechat_auto || false, userName: {{userName | json}} || undefined, - });*/ + }); }); diff --git a/addons/im_livechat/static/ext/static/js/livesupport.js b/addons/im_livechat/static/ext/static/js/livesupport.js index 521218af7c6..4e90f4185e0 100644 --- a/addons/im_livechat/static/ext/static/js/livesupport.js +++ b/addons/im_livechat/static/ext/static/js/livesupport.js @@ -3,6 +3,8 @@ define(["openerp", "underscore", "require", "jquery", "jquery.achtung"], function(openerp, _, require, $) { /* jshint es3: true */ "use strict"; + + var _t = openerp._t; var livesupport = {}; @@ -19,24 +21,28 @@ define(["openerp", "underscore", "require", "jquery", var defs = []; options = options || {}; _.defaults(options, { - buttonText: "Chat with one of our collaborators", - inputPlaceholder: "How may I help you?", + buttonText: _t("Chat with one of our collaborators"), + inputPlaceholder: _t("How may I help you?"), defaultMessage: null, auto: false, - userName: "Anonymous" + userName: _t("Anonymous") }); defaultInputPlaceholder = options.inputPlaceholder; userName = options.userName; // TODO : load QwebTemplates - defs.push(add_css("../css/livesupport.css")); - defs.push(add_css("./jquery.achtung.css")); + defs.push(add_css("im_livechat/static/ext/static/css/livesupport.css")); + defs.push(add_css("im_livechat/static/ext/static/lib/jquery-achtung/src/ui.achtung.css")); - $.when.apply($, defs).then(function() { + return $.when.apply($, defs).then(function() { console.log("starting live support customer app"); connection = new openerp.Session(null, server_url, { override_session: true }); return connection.session_authenticate(db, login, password); }).then(function() { - connection.rpc("/im_livechat/available", {db: db, channel: channel}).then(function(activated) { + return connection.rpc('/web/proxy/load', {path: '/im_livechat/static/ext/static/js/livesupport_templates.xml'}).then(function(xml) { + openerp.qweb.add_template(xml); + }); + }).then(function() { + return connection.rpc("/im_livechat/available", {db: db, channel: channel}).then(function(activated) { if (! activated & ! options.auto) return; var button = new livesupport.ChatButton(null, channel, options); @@ -74,7 +80,7 @@ define(["openerp", "underscore", "require", "jquery", this.text = options.buttonText; }, render: function() { - this.$().append(templateEngine.chatButton({widget: this})); + this.$().append(openerp.qweb.render("chatButton", {widget: this})); }, click: function() { if (! this.manager) { @@ -91,7 +97,7 @@ define(["openerp", "underscore", "require", "jquery", def.reject(); }, 5000); def.then(_.bind(this.chat, this), function() { - notification("It seems the connection to the server is encountering problems, please try again later."); + notification(_t("It seems the connection to the server is encountering problems, please try again later.")); }); }, chat: function() { @@ -100,7 +106,7 @@ define(["openerp", "underscore", "require", "jquery", return; connection.model("im_livechat.channel").call("get_available_user", [this.channel]).then(function(user_id) { if (! user_id) { - notification("None of our collaborators seems to be available, please try again later."); + notification(_t("None of our collaborators seems to be available, please try again later.")); return; } self.manager.ensure_users([user_id]).then(function() { @@ -173,7 +179,7 @@ define(["openerp", "underscore", "require", "jquery", var def = $.when(uuid); if (! uuid) { - def = connection.connector.call("/longpolling/im/gen_uuid", {}); + def = connection.rpc("/longpolling/im/gen_uuid", {}); } return def.then(function(uuid) { localStorage["oe_livesupport_uuid"] = uuid; @@ -188,7 +194,7 @@ define(["openerp", "underscore", "require", "jquery", delete self.users_cache[self.my_id]; self.me = me; me.set("name", "You"); - return connection.connector.call("/longpolling/im/activated", {}); + return connection.rpc("/longpolling/im/activated", {}); }).then(function(activated) { if (activated) { self.activated = true; @@ -236,7 +242,7 @@ define(["openerp", "underscore", "require", "jquery", var user_ids = _.map(this.users_cache, function(el) { return el.get("id"); }); - connection.connector.call("/longpolling/im/poll", { + connection.rpc("/longpolling/im/poll", { last: this.last, users_watch: user_ids, db: connection.database, @@ -345,7 +351,7 @@ define(["openerp", "underscore", "require", "jquery", this.inputPlaceholder = defaultInputPlaceholder; }, render: function() { - this.$().append(templateEngine.conversation({widget: this})); + this.$().append(openerp.qweb.render("conversation", {widget: this})); var change_status = function() { this.$().toggleClass("oe_im_chatview_disconnected_status", this.user.get("im_status") === false); this.$(".oe_im_chatview_online").toggle(this.user.get("im_status") === true); @@ -427,7 +433,7 @@ define(["openerp", "underscore", "require", "jquery", }; date = "" + zpad(date.getHours(), 2) + ":" + zpad(date.getMinutes(), 2); - this.last_bubble = $(templateEngine.conversation_bubble({"items": items, "user": user, "time": date})); + this.last_bubble = $(openerp.qweb.render("conversation_bubble", {"items": items, "user": user, "time": date})); $(this.$(".oe_im_chatview_content").children()[0]).append(this.last_bubble); this._go_bottom(); }, diff --git a/addons/im_livechat/static/ext/static/js/livesupport_templates.html b/addons/im_livechat/static/ext/static/js/livesupport_templates.html deleted file mode 100644 index 54cdf450dc1..00000000000 --- a/addons/im_livechat/static/ext/static/js/livesupport_templates.html +++ /dev/null @@ -1,36 +0,0 @@ - -<%def name="conversation"> -
- - ${widget.user.get('name') || 'You'} - -
-
- ${widget.user.get("name") + " is offline. He/She will receive your messages on his/her next connection."} -
-
-
-
- - - -<%def name="conversation_bubble"> -
-
- -
-
${user.get('name') || 'You'}
-
- % _.each(items, function(item) { -
${item}
- % }); -
-
${time}
-
- - -<%def name="chatButton"> - ${widget.text} - \ No newline at end of file diff --git a/addons/im_livechat/static/ext/static/js/livesupport_templates.js b/addons/im_livechat/static/ext/static/js/livesupport_templates.js deleted file mode 100644 index aaabfd38caf..00000000000 --- a/addons/im_livechat/static/ext/static/js/livesupport_templates.js +++ /dev/null @@ -1 +0,0 @@ -window.oe_livesupport_templates_callback("\n<%def name=\"conversation\">\n
\n \n ${widget.user.get('name') || 'You'}\n \n
\n
\n ${widget.user.get(\"name\") + \" is offline. He/She will receive your messages on his/her next connection.\"}\n
\n
\n
\n
\n
\n \n
\n\n\n<%def name=\"conversation_bubble\">\n
\n
\n \n
\n
${user.get('name') || 'You'}
\n
\n % _.each(items, function(item) {\n
${item}
\n % });\n
\n
${time}
\n
\n\n\n<%def name=\"chatButton\">\n ${widget.text}\n"); diff --git a/addons/im_livechat/static/ext/static/js/livesupport_templates.xml b/addons/im_livechat/static/ext/static/js/livesupport_templates.xml new file mode 100644 index 00000000000..a9076d9b878 --- /dev/null +++ b/addons/im_livechat/static/ext/static/js/livesupport_templates.xml @@ -0,0 +1,39 @@ + + + + +
+ + + +
+
+ +
+
+
+
+ +
+ + +
+
+ +
+
+
+ +
+
+
+
+
+
+ + + + +
\ No newline at end of file