Implemented user search
bzr revid: nicolas.vanhoren@openerp.com-20121127103052-nb09c5x0e1t485za
This commit is contained in:
parent
a77339ccf0
commit
986f9d26f3
|
@ -7,7 +7,7 @@ openerp.web_im = function(instance) {
|
|||
this.update_promise.then(function() {
|
||||
var im = new instance.web_im.InstantMessaging(self);
|
||||
im.appendTo(instance.client.$el);
|
||||
var button = new instance.web.IMTopButton(self);
|
||||
var button = new instance.web.ImTopButton(self);
|
||||
button.im = im;
|
||||
button.appendTo(instance.webclient.$el.find('.oe_systray'));
|
||||
});
|
||||
|
@ -15,8 +15,8 @@ openerp.web_im = function(instance) {
|
|||
},
|
||||
});
|
||||
|
||||
instance.web.IMTopButton = instance.web.Widget.extend({
|
||||
template:'IMTopButton',
|
||||
instance.web.ImTopButton = instance.web.Widget.extend({
|
||||
template:'ImTopButton',
|
||||
events: {
|
||||
"click button": "clicked",
|
||||
},
|
||||
|
@ -27,28 +27,24 @@ openerp.web_im = function(instance) {
|
|||
|
||||
instance.web_im.InstantMessaging = instance.web.Widget.extend({
|
||||
template: "InstantMessaging",
|
||||
events: {
|
||||
"keydown .oe_im_input": "search_users",
|
||||
},
|
||||
init: function(parent) {
|
||||
this._super(parent);
|
||||
this.shown = false;
|
||||
this.set("right_offset", 0);
|
||||
this.last = null;
|
||||
this.users = [];
|
||||
},
|
||||
start: function() {
|
||||
var self = this;
|
||||
this.$el.css("right", -this.$el.outerWidth());
|
||||
self.poll();
|
||||
self.last = null;
|
||||
$(window).scroll(_.bind(this.calc_box, this));
|
||||
$(window).resize(_.bind(this.calc_box, this));
|
||||
self.calc_box();
|
||||
self.$(".oe_im_input").keypress(function(e) {
|
||||
if(e.which != 13) {
|
||||
return;
|
||||
}
|
||||
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()});
|
||||
}).focus();
|
||||
this.calc_box();
|
||||
|
||||
this.poll();
|
||||
this.search_users();
|
||||
},
|
||||
calc_box: function() {
|
||||
var $topbar = instance.client.$(".oe_topbar");
|
||||
|
@ -57,6 +53,31 @@ openerp.web_im = function(instance) {
|
|||
this.$el.css("top", top);
|
||||
this.$el.css("bottom", 0);
|
||||
},
|
||||
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()});
|
||||
},
|
||||
switch_display: function() {
|
||||
var fct = _.bind(function() {
|
||||
this.set("right_offset", $(window).width() - this.$el.offset().left);
|
||||
|
@ -94,4 +115,12 @@ openerp.web_im = function(instance) {
|
|||
}
|
||||
});
|
||||
|
||||
instance.web_im.ImUser = instance.web.Widget.extend({
|
||||
"template": "ImUser",
|
||||
init: function(parent, user_rec) {
|
||||
this._super(parent);
|
||||
this.user_rec = user_rec;
|
||||
},
|
||||
});
|
||||
|
||||
}
|
|
@ -4,13 +4,19 @@
|
|||
<templates xml:space="preserve">
|
||||
<t t-name="InstantMessaging">
|
||||
<div class="oe_im">
|
||||
<div class="oe_im_content"></div>
|
||||
<input class="oe_im_input" type="text"/>
|
||||
<div class="oe_im_content"></div>
|
||||
<div class="oe_im_users"></div>
|
||||
</div>
|
||||
</t>
|
||||
<t t-name="IMTopButton">
|
||||
<t t-name="ImTopButton">
|
||||
<div title='Display im' class="oe_topbar_item oe_topbar_imbutton">
|
||||
<button></button>
|
||||
</div>
|
||||
</t>
|
||||
<t t-name="ImUser">
|
||||
<div class="oe_im_user">
|
||||
<t t-esc="widget.user_rec.name"/>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
Loading…
Reference in New Issue