2013-01-16 13:43:48 +00:00
|
|
|
|
2013-08-19 12:33:32 +00:00
|
|
|
/*
|
|
|
|
This file must compile in EcmaScript 3 and work in IE7.
|
|
|
|
*/
|
|
|
|
|
2013-08-19 14:09:08 +00:00
|
|
|
define(["openerp", "im_common", "underscore", "require", "jquery",
|
|
|
|
"jquery.achtung"], function(openerp, im_common, _, require, $) {
|
2013-08-14 14:31:15 +00:00
|
|
|
/* jshint es3: true */
|
|
|
|
"use strict";
|
2013-08-19 09:17:41 +00:00
|
|
|
|
|
|
|
var _t = openerp._t;
|
2013-08-14 14:31:15 +00:00
|
|
|
|
2013-01-16 14:08:21 +00:00
|
|
|
var livesupport = {};
|
2013-01-16 13:43:48 +00:00
|
|
|
|
2013-02-05 13:47:11 +00:00
|
|
|
livesupport.main = function(server_url, db, login, password, channel, options) {
|
2013-02-12 13:38:26 +00:00
|
|
|
var defs = [];
|
2013-02-04 17:12:21 +00:00
|
|
|
options = options || {};
|
|
|
|
_.defaults(options, {
|
2013-08-19 09:17:41 +00:00
|
|
|
buttonText: _t("Chat with one of our collaborators"),
|
|
|
|
inputPlaceholder: _t("How may I help you?"),
|
2013-02-07 15:04:01 +00:00
|
|
|
defaultMessage: null,
|
2013-02-11 13:47:23 +00:00
|
|
|
auto: false,
|
2013-08-19 09:17:41 +00:00
|
|
|
userName: _t("Anonymous")
|
2013-02-04 17:12:21 +00:00
|
|
|
});
|
2013-08-19 14:09:08 +00:00
|
|
|
|
|
|
|
im_common.notification = notification;
|
|
|
|
im_common.to_url = require.toUrl;
|
|
|
|
im_common.defaultInputPlaceholder = options.inputPlaceholder;
|
|
|
|
im_common.userName = options.userName;
|
|
|
|
defs.push(add_css("im/static/src/css/im_common.css"));
|
2013-08-19 09:17:41 +00:00
|
|
|
defs.push(add_css("im_livechat/static/ext/static/lib/jquery-achtung/src/ui.achtung.css"));
|
2013-01-28 16:23:52 +00:00
|
|
|
|
2013-08-19 09:17:41 +00:00
|
|
|
return $.when.apply($, defs).then(function() {
|
2013-02-05 14:01:43 +00:00
|
|
|
console.log("starting live support customer app");
|
2013-08-19 14:09:08 +00:00
|
|
|
im_common.connection = new openerp.Session(null, server_url, { override_session: true });
|
|
|
|
return im_common.connection.session_authenticate(db, login, password);
|
2013-08-14 14:31:15 +00:00
|
|
|
}).then(function() {
|
2013-08-19 14:09:08 +00:00
|
|
|
return im_common.connection.rpc('/web/proxy/load', {path: '/im/static/src/xml/im_common.xml'}).then(function(xml) {
|
2013-08-19 09:17:41 +00:00
|
|
|
openerp.qweb.add_template(xml);
|
|
|
|
});
|
|
|
|
}).then(function() {
|
2013-08-19 14:09:08 +00:00
|
|
|
return im_common.connection.rpc("/im_livechat/available", {db: db, channel: channel}).then(function(activated) {
|
2013-02-12 13:38:26 +00:00
|
|
|
if (! activated & ! options.auto)
|
2013-02-05 14:01:43 +00:00
|
|
|
return;
|
2013-08-19 14:09:08 +00:00
|
|
|
var button = new im_common.ChatButton(null, channel, options);
|
2013-02-11 13:47:23 +00:00
|
|
|
button.appendTo($("body"));
|
|
|
|
if (options.auto)
|
|
|
|
button.click();
|
2013-02-05 14:01:43 +00:00
|
|
|
});
|
2013-02-04 17:12:21 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-02-12 13:38:26 +00:00
|
|
|
var add_css = function(relative_file_name) {
|
|
|
|
var css_def = $.Deferred();
|
2013-08-19 14:09:08 +00:00
|
|
|
$('<link rel="stylesheet" href="' + im_common.to_url(relative_file_name) + '"></link>')
|
2013-02-12 13:38:26 +00:00
|
|
|
.appendTo($("head")).ready(function() {
|
|
|
|
css_def.resolve();
|
|
|
|
});
|
|
|
|
return css_def.promise();
|
|
|
|
};
|
|
|
|
|
|
|
|
var notification = function(message) {
|
|
|
|
$.achtung({message: message, timeout: 0, showEffects: false, hideEffects: false});
|
|
|
|
};
|
|
|
|
|
2013-08-14 14:31:15 +00:00
|
|
|
return livesupport;
|
2013-01-16 14:08:21 +00:00
|
|
|
});
|