niv-openerp
2013-02-04 18:12:21 +01:00
parent a0d4b3d099
commit 72eb57f02e
4 changed files with 53 additions and 6 deletions
@@ -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 {
@@ -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],
@@ -29,4 +29,8 @@
</div>
<div class="oe_im_chatview_time">${time}</div>
</div>
</%def>
<%def name="chatButton">
${widget.text}
</%def>
@@ -1 +1 @@
window.oe_livesupport_templates_callback("\n<%def name=\"conversation\">\n <div class=\"oe_im_chatview_header\">\n <img src=\"${toUrl('../img/green.png')}\" class=\"oe_im_chatview_online\"/>\n ${widget.user.get('name') || 'You'}\n <button class=\"oe_im_chatview_close\">\u00d7</button>\n </div>\n <div class=\"oe_im_chatview_disconnected\">\n ${widget.user.get(\"name\") + \" is offline. He/She will receive your messages on his/her next connection.\"}\n </div>\n <div class=\"oe_im_chatview_content\">\n <div></div>\n </div>\n <div class=\"oe_im_chatview_footer\">\n <input class=\"oe_im_chatview_input\" placeholder=\"Say something...\" />\n </div>\n</%def>\n\n<%def name=\"conversation_bubble\">\n <div class=\"oe_im_chatview_bubble\">\n <div class=\"oe_im_chatview_clip\">\n <img class=\"oe_im_chatview_avatar\" src=\"${user.get('image_url')}\"/>\n </div>\n <div class=\"oe_im_chatview_from\">${user.get('name') || 'You'}</div>\n <div class=\"oe_im_chatview_bubble_list\">\n % _.each(items, function(item) {\n <div class=\"oe_im_chatview_bubble_item\">${item}</div>\n % });\n </div>\n <div class=\"oe_im_chatview_time\">${time}</div>\n </div>\n</%def>");
window.oe_livesupport_templates_callback("\n<%def name=\"conversation\">\n <div class=\"oe_im_chatview_header\">\n <img src=\"${toUrl('../img/green.png')}\" class=\"oe_im_chatview_online\"/>\n ${widget.user.get('name') || 'You'}\n <button class=\"oe_im_chatview_close\">\u00d7</button>\n </div>\n <div class=\"oe_im_chatview_disconnected\">\n ${widget.user.get(\"name\") + \" is offline. He/She will receive your messages on his/her next connection.\"}\n </div>\n <div class=\"oe_im_chatview_content\">\n <div></div>\n </div>\n <div class=\"oe_im_chatview_footer\">\n <input class=\"oe_im_chatview_input\" placeholder=\"Say something...\" />\n </div>\n</%def>\n\n<%def name=\"conversation_bubble\">\n <div class=\"oe_im_chatview_bubble\">\n <div class=\"oe_im_chatview_clip\">\n <img class=\"oe_im_chatview_avatar\" src=\"${user.get('image_url')}\"/>\n </div>\n <div class=\"oe_im_chatview_from\">${user.get('name') || 'You'}</div>\n <div class=\"oe_im_chatview_bubble_list\">\n % _.each(items, function(item) {\n <div class=\"oe_im_chatview_bubble_item\">${item}</div>\n % });\n </div>\n <div class=\"oe_im_chatview_time\">${time}</div>\n </div>\n</%def>\n\n<%def name=\"chatButton\">\n ${widget.text}\n</%def>");