2012-11-15 17:49:02 +00:00
|
|
|
|
2012-11-27 10:02:41 +00:00
|
|
|
openerp.web_im = function(instance) {
|
2012-11-15 17:49:02 +00:00
|
|
|
|
2012-11-26 12:38:53 +00:00
|
|
|
instance.web.UserMenu.include({
|
|
|
|
do_update: function(){
|
|
|
|
var self = this;
|
|
|
|
this.update_promise.then(function() {
|
2012-11-27 10:02:41 +00:00
|
|
|
var im = new instance.web_im.InstantMessaging(self);
|
|
|
|
im.appendTo(instance.client.$el);
|
2012-11-27 10:30:52 +00:00
|
|
|
var button = new instance.web.ImTopButton(self);
|
2012-11-27 10:02:41 +00:00
|
|
|
button.im = im;
|
2012-11-26 12:38:53 +00:00
|
|
|
button.appendTo(instance.webclient.$el.find('.oe_systray'));
|
|
|
|
});
|
|
|
|
return this._super.apply(this, arguments);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-11-27 10:30:52 +00:00
|
|
|
instance.web.ImTopButton = instance.web.Widget.extend({
|
|
|
|
template:'ImTopButton',
|
2012-11-26 12:38:53 +00:00
|
|
|
events: {
|
|
|
|
"click button": "clicked",
|
|
|
|
},
|
|
|
|
clicked: function() {
|
2012-11-27 10:02:41 +00:00
|
|
|
this.im.switch_display();
|
2012-11-26 12:38:53 +00:00
|
|
|
},
|
2012-11-15 17:49:02 +00:00
|
|
|
});
|
|
|
|
|
2012-11-27 10:02:41 +00:00
|
|
|
instance.web_im.InstantMessaging = instance.web.Widget.extend({
|
|
|
|
template: "InstantMessaging",
|
2012-11-27 10:30:52 +00:00
|
|
|
events: {
|
|
|
|
"keydown .oe_im_input": "search_users",
|
|
|
|
},
|
2012-11-26 12:38:53 +00:00
|
|
|
init: function(parent) {
|
|
|
|
this._super(parent);
|
|
|
|
this.shown = false;
|
2012-11-26 12:55:48 +00:00
|
|
|
this.set("right_offset", 0);
|
2012-11-27 10:30:52 +00:00
|
|
|
this.last = null;
|
|
|
|
this.users = [];
|
2012-11-26 12:38:53 +00:00
|
|
|
},
|
2012-11-15 17:49:02 +00:00
|
|
|
start: function() {
|
2012-11-26 12:38:53 +00:00
|
|
|
this.$el.css("right", -this.$el.outerWidth());
|
|
|
|
$(window).scroll(_.bind(this.calc_box, this));
|
|
|
|
$(window).resize(_.bind(this.calc_box, this));
|
2012-11-27 10:30:52 +00:00
|
|
|
this.calc_box();
|
|
|
|
|
|
|
|
this.poll();
|
|
|
|
this.search_users();
|
2012-11-15 17:49:02 +00:00
|
|
|
},
|
2012-11-26 12:38:53 +00:00
|
|
|
calc_box: function() {
|
|
|
|
var $topbar = instance.client.$(".oe_topbar");
|
|
|
|
var top = $topbar.offset().top + $topbar.height();
|
|
|
|
top = Math.max(top - $(window).scrollTop(), 0);
|
|
|
|
this.$el.css("top", top);
|
|
|
|
this.$el.css("bottom", 0);
|
|
|
|
},
|
2012-11-27 10:30:52 +00:00
|
|
|
search_users: function(e) {
|
|
|
|
if(e && e.which !== 13) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var users = new instance.web.Model("res.users");
|
|
|
|
var self = this;
|
|
|
|
return users.query(["name"]).filter([["name", "ilike", this.$(".oe_im_input").val()]]).limit(20).all().then(function(result) {
|
|
|
|
_.each(self.users, function(user) {
|
|
|
|
user.destroy();
|
|
|
|
});
|
|
|
|
self.users = [];
|
|
|
|
_.each(result, function(user) {
|
|
|
|
var widget = new instance.web_im.ImUser(self, user);
|
|
|
|
widget.appendTo(self.$(".oe_im_users"));
|
|
|
|
self.users.push(widget);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
send_message: function() {
|
|
|
|
// old code
|
|
|
|
var mes = self.$(".oe_im_input").val();
|
|
|
|
self.$(".oe_im_input").val("");
|
|
|
|
var model = new instance.web.Model("im.message");
|
|
|
|
model.call("post", [mes], {context: new instance.web.CompoundContext()});
|
|
|
|
},
|
2012-11-26 12:38:53 +00:00
|
|
|
switch_display: function() {
|
2012-11-26 12:55:48 +00:00
|
|
|
var fct = _.bind(function() {
|
|
|
|
this.set("right_offset", $(window).width() - this.$el.offset().left);
|
|
|
|
}, this);
|
|
|
|
var opt = {
|
|
|
|
step: fct,
|
|
|
|
complete: fct,
|
|
|
|
};
|
2012-11-26 12:38:53 +00:00
|
|
|
if (this.shown) {
|
|
|
|
this.$el.animate({
|
|
|
|
right: -this.$el.outerWidth(),
|
2012-11-26 12:55:48 +00:00
|
|
|
}, opt);
|
2012-11-26 12:38:53 +00:00
|
|
|
} else {
|
|
|
|
this.$el.animate({
|
|
|
|
right: 0,
|
2012-11-26 12:55:48 +00:00
|
|
|
}, opt);
|
2012-11-26 12:38:53 +00:00
|
|
|
}
|
|
|
|
this.shown = ! this.shown;
|
|
|
|
},
|
2012-11-15 17:49:02 +00:00
|
|
|
poll: function() {
|
|
|
|
var self = this;
|
2012-11-27 10:02:41 +00:00
|
|
|
this.rpc("/im/poll", {
|
2012-11-22 15:23:02 +00:00
|
|
|
last: this.last,
|
|
|
|
context: new instance.web.CompoundContext()
|
|
|
|
}, {shadow: true}).then(function(result) {
|
2012-11-15 17:49:02 +00:00
|
|
|
self.last = result.last;
|
|
|
|
_.each(result.res, function(mes) {
|
2012-11-27 10:02:41 +00:00
|
|
|
$("<div>").text(mes).appendTo(self.$(".oe_im_content"));
|
2012-11-15 17:49:02 +00:00
|
|
|
});
|
2012-11-16 09:43:10 +00:00
|
|
|
self.poll();
|
2012-11-15 17:49:02 +00:00
|
|
|
}, function(unused, e) {
|
|
|
|
e.preventDefault();
|
2012-11-16 09:43:10 +00:00
|
|
|
setTimeout(_.bind(self.poll, self), 5000);
|
2012-11-15 17:49:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-11-27 10:30:52 +00:00
|
|
|
instance.web_im.ImUser = instance.web.Widget.extend({
|
|
|
|
"template": "ImUser",
|
|
|
|
init: function(parent, user_rec) {
|
|
|
|
this._super(parent);
|
|
|
|
this.user_rec = user_rec;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-11-15 17:49:02 +00:00
|
|
|
}
|