working 2-lines inclusion

bzr revid: nicolas.vanhoren@openerp.com-20130205134711-h0g2pw9f9b1nyh7j
This commit is contained in:
niv-openerp 2013-02-05 14:47:11 +01:00
parent f5f3fc7584
commit cbcbe926a4
4 changed files with 51 additions and 21 deletions

View File

@ -19,11 +19,35 @@
#
##############################################################################
import openerp
import openerp.addons.web_im.im as im
import json
import random
import jinja2
from osv import osv, fields
env = jinja2.Environment(
loader=jinja2.PackageLoader('openerp.addons.live_support', "."),
autoescape=False
)
env.filters["json"] = json.dumps
class ImportController(openerp.addons.web.http.Controller):
_cp_path = '/live_support'
@openerp.addons.web.http.httprequest
def loader(self, req, **kwargs):
db = kwargs["db"]
channel = int(kwargs["channel"])
req.session._db = db
req.session._uid = None
req.session._login = "anonymous"
req.session._password = "anonymous"
info = req.session.model('live_support.channel').get_info_for_chat_src()
info["db"] = db
info["channel"] = channel
return env.get_template("loader.js").render(info)
class live_support_channel(osv.osv):
_name = 'live_support.channel'
_columns = {
@ -41,6 +65,11 @@ class live_support_channel(osv.osv):
return False
return random.choice(users).id
def get_info_for_chat_src(self, cr, uid, context=None):
url = self.pool.get('ir.config_parameter').get_param(cr, openerp.SUPERUSER_ID, 'web.base.url')
return {"url": url}
class im_user(osv.osv):
_inherit = 'im.user'
_columns = {

View File

@ -0,0 +1,15 @@
require.config({
context: "oelivesupport",
baseUrl: {{url | json}} + "/live_support/static/ext/static/js",
shim: {
underscore: {
init: function() {
return _.noConflict();
},
},
},
})(["livesupport", "jquery"], function(livesupport, jQuery) {
jQuery.noConflict();
livesupport.main({{url | json}}, {{db | json}}, "anonymous", "anonymous", {{channel | json}});
});

View File

@ -6,7 +6,7 @@ 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, options) {
livesupport.main = function(server_url, db, login, password, channel, options) {
options = options || {};
_.defaults(options, {
buttonText: "Chat with one of our collaborators",
@ -29,7 +29,7 @@ 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"));
new livesupport.ChatButton(null, channel, options.buttonText).appendTo($("body"));
});
};
@ -40,8 +40,9 @@ define(["nova", "jquery", "underscore", "oeclient", "require"], function(nova, $
events: {
"click": "click",
},
__init__: function(parent, text) {
__init__: function(parent, channel, text) {
this.$super(parent);
this.channel = channel;
this.text = text;
},
render: function() {
@ -69,7 +70,7 @@ define(["nova", "jquery", "underscore", "oeclient", "require"], function(nova, $
var self = this;
if (this.manager.conversations.length > 0)
return;
connection.getModel("live_support.channel").call("get_available_user", [1]).then(function(user_id) {
connection.getModel("live_support.channel").call("get_available_user", [this.channel]).then(function(user_id) {
if (! user_id) {
window.alert("None of our collaborators seems to be available, please try again later.");
return;

View File

@ -1,23 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<script src="http://localhost:8069/live_support/static/ext/static/js/require.js"></script>
<script>
require.config({
context: "oelivesupport",
baseUrl: "http://localhost:8069/live_support/static/ext/static/js",
shim: {
underscore: {
init: function() {
return _.noConflict();
},
},
},
})(["livesupport", "jquery"], function(livesupport, jQuery) {
jQuery.noConflict();
livesupport.main("http://localhost", "test", "anonymous", "anonymous");
});
</script>
<script type="text/javascript" src="http://localhost/live_support/static/ext/static/js/require.js"></script>
<script type="text/javascript" src="http://localhost/live_support/loader?db=test&channel=1"></script>
</head>
<body style="height:100%; margin:0; padding:0;">
<iframe src="http://openerp.com" height="100%" width=100%"></iframe>