From 490361b83ef1f2edf1871a8ae18e3494cb921e24 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 28 Jan 2013 15:35:24 +0100 Subject: [PATCH] Test version that can send messages bzr revid: nicolas.vanhoren@openerp.com-20130128143524-cm02ppafma96tkol --- .../static/ext/static/js/livesupport.js | 25 +++++++++++++++---- .../static/ext/static/js/oeclient.js | 19 ++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/addons/live_support/static/ext/static/js/livesupport.js b/addons/live_support/static/ext/static/js/livesupport.js index f017064b44d..87cc4070a72 100644 --- a/addons/live_support/static/ext/static/js/livesupport.js +++ b/addons/live_support/static/ext/static/js/livesupport.js @@ -16,8 +16,23 @@ define(["nova", "jquery", "underscore", "oeclient", "require"], function(nova, $ }).then(function(content) { return templateEngine.loadFileContent(content); }).then(function() { + console.log("starting client"); connection = new oeclient.Connection(new oeclient.JsonpRPCConnector(server_url), db, login, password); - console.log("hello"); + connection.getModel("res.users").search_read([["login", "in", ["demo", "admin"]]]).then(function(result) { + var admin, demo; + if (result[0].login === "admin") { + admin = result[0]; + demo = result[1]; + } else { + admin = result[1]; + demo = result[0]; + } + admin = new livesupport.ImUser(null, admin); + demo = new livesupport.ImUser(null, demo); + var manager = new livesupport.ConversationManager(null); + manager.set_me(admin); + manager.activate_user(demo); + }); }); }; @@ -49,7 +64,7 @@ define(["nova", "jquery", "underscore", "oeclient", "require"], function(nova, $ livesupport.ConversationManager = nova.Class.$extend({ __include__: [nova.DynamicProperties], - init: function(parent) { + __init__: function(parent) { nova.DynamicProperties.__init__.call(this, parent); this.set("right_offset", 0); this.conversations = []; @@ -137,8 +152,8 @@ define(["nova", "jquery", "underscore", "oeclient", "require"], function(nova, $ "click .oe_im_chatview_close": "destroy", "click .oe_im_chatview_header": "show_hide", }, - init: function(parent, user, me) { - this._super(parent); + __init__: function(parent, user, me) { + this.$super(parent); this.me = me; this.user = user; this.user.add_watcher(); @@ -184,7 +199,7 @@ define(["nova", "jquery", "underscore", "oeclient", "require"], function(nova, $ var mes = this.$("input").val(); this.$("input").val(""); var send_it = _.bind(function() { - var model = new connection.getModel("im.message"); + var model = connection.getModel("im.message"); return model.call("post", [mes, this.user.get('id')], {context: {}}); }, this); var tries = 0; diff --git a/addons/live_support/static/ext/static/js/oeclient.js b/addons/live_support/static/ext/static/js/oeclient.js index c309282edef..5f476c02ff8 100644 --- a/addons/live_support/static/ext/static/js/oeclient.js +++ b/addons/live_support/static/ext/static/js/oeclient.js @@ -149,6 +149,25 @@ define(["underscore", "jquery", "nova"], function(_, $, nova) { ]); }, this)); }, + search_read: function(domain, fields, offset, limit, order, context) { + return this.call("search", [domain || [], offset || 0, limit || false, order || false, context || {}]).then(_.bind(function(record_ids) { + if (! record_ids) { + return []; + } + return this.call("read", [record_ids, fields || [], context || {}]).then(function(records) { + var index = {}; + _.each(records, function(r) { + index[r.id] = r; + }); + var res = []; + _.each(record_ids, function(id) { + if (index[id]) + res.push(index[id]); + }); + return res; + }); + }, this)); + }, }); return oeclient;