From 72eb57f02e750b684717f7dc64dd1cda19e508ec Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 4 Feb 2013 18:12:21 +0100 Subject: [PATCH] wip bzr revid: nicolas.vanhoren@openerp.com-20130204171221-q6es5fomqbcwzmn0 --- .../static/ext/static/css/livesupport.css | 22 +++++++++++++ .../static/ext/static/js/livesupport.js | 31 ++++++++++++++++--- .../ext/static/js/livesupport_templates.html | 4 +++ .../ext/static/js/livesupport_templates.js | 2 +- 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/addons/live_support/static/ext/static/css/livesupport.css b/addons/live_support/static/ext/static/css/livesupport.css index cb4d340134c..3c72981653e 100644 --- a/addons/live_support/static/ext/static/css/livesupport.css +++ b/addons/live_support/static/ext/static/css/livesupport.css @@ -9,6 +9,28 @@ text-shadow: 0 1px 1px rgba(255, 255, 255, 0.5); } +/* button */ + +.oe_chat_button { + position: fixed; + bottom: 0px; + right: 15px; + display: inline-block; + min-width: 100px; + background-color: rgba(60, 60, 60, 0.6); + font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; + font-size: 14px; + font-weight: bold; + padding: 10px; + color: white; + text-shadow: rgb(59, 76, 88) 1px 1px 0px; + border: 1px solid rgb(80, 80, 80); + border-bottom: 0px; + border-top-left-radius: 5px; + border-top-right-radius: 5px; + cursor: pointer; +} + /* conversations */ .oe_im_chatview { diff --git a/addons/live_support/static/ext/static/js/livesupport.js b/addons/live_support/static/ext/static/js/livesupport.js index f8282674540..214ba6230d5 100644 --- a/addons/live_support/static/ext/static/js/livesupport.js +++ b/addons/live_support/static/ext/static/js/livesupport.js @@ -6,7 +6,11 @@ define(["nova", "jquery", "underscore", "oeclient", "require"], function(nova, $ templateEngine.extendEnvironment({"toUrl": _.bind(require.toUrl, require)}); var connection; - livesupport.main = function(server_url, db, login, password) { + livesupport.main = function(server_url, db, login, password, options) { + options = options || {}; + _.defaults(options, { + buttonText: "Chat with one of our collaborators", + }); var templates_def = $.ajax({ url: require.toUrl("./livesupport_templates.js"), jsonp: false, @@ -25,6 +29,25 @@ define(["nova", "jquery", "underscore", "oeclient", "require"], function(nova, $ $.when(templates_def, css_def).then(function() { console.log("starting client"); connection = new oeclient.Connection(new oeclient.JsonpRPCConnector(server_url), db, login, password); + new livesupport.ChatButton(null, options.buttonText).appendTo($("body")); + }); + }; + + var ERROR_DELAY = 5000; + + livesupport.ChatButton = nova.Widget.$extend({ + className: "openerp_style oe_chat_button", + events: { + "click": "click", + }, + __init__: function(parent, text) { + this.$super(parent); + this.text = text; + }, + render: function() { + this.$().append(templateEngine.chatButton({widget: this})); + }, + click: function() { connection.getModel("live_support.channel").call("get_available_user", [1]).then(function(result) { if (! result) { console.log("no available user"); @@ -38,10 +61,8 @@ define(["nova", "jquery", "underscore", "oeclient", "require"], function(nova, $ }); }); }); - }); - }; - - var ERROR_DELAY = 5000; + }, + }); livesupport.ImUser = nova.Class.$extend({ __include__: [nova.DynamicProperties], diff --git a/addons/live_support/static/ext/static/js/livesupport_templates.html b/addons/live_support/static/ext/static/js/livesupport_templates.html index 96eecd2c21a..aa3b24ad491 100644 --- a/addons/live_support/static/ext/static/js/livesupport_templates.html +++ b/addons/live_support/static/ext/static/js/livesupport_templates.html @@ -29,4 +29,8 @@
${time}
+ + +<%def name="chatButton"> + ${widget.text} \ No newline at end of file diff --git a/addons/live_support/static/ext/static/js/livesupport_templates.js b/addons/live_support/static/ext/static/js/livesupport_templates.js index 0e26101ba97..c671a6f1edc 100644 --- a/addons/live_support/static/ext/static/js/livesupport_templates.js +++ b/addons/live_support/static/ext/static/js/livesupport_templates.js @@ -1 +1 @@ -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"); +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");