Put ChatButton in livechat
bzr revid: nicolas.vanhoren@openerp.com-20130819142139-mvh25k95k1wbjtzv
This commit is contained in:
parent
910ae6cba9
commit
c2366d7181
|
@ -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);
|
||||
|
|
|
@ -32,8 +32,4 @@
|
|||
<div class="oe_im_chatview_time"><t t-esc="time"/></div>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-name="chatButton">
|
||||
<t t-esc="widget.text"/>
|
||||
</t>
|
||||
</templates>
|
|
@ -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();
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<templates>
|
||||
<t t-name="chatButton">
|
||||
<t t-esc="widget.text"/>
|
||||
</t>
|
||||
</templates>
|
|
@ -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;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue