[ADD] suggestion js and xml files

bzr revid: mat@openerp.com-20130329080140-t99dzeaiwikwjpsm
This commit is contained in:
Martin Trigaux 2013-03-29 09:01:40 +01:00
parent 5a112d8fa2
commit 3af8beb2b9
2 changed files with 121 additions and 0 deletions

View File

@ -0,0 +1,86 @@
openerp.mail.suggestions = function(session, mail) {
var _t = session.web._t;
var QWeb = session.web.qweb
var suggestions = session.suggestions = {};
suggestions.Sidebar = session.web.Widget.extend({
template: "mail.suggestions",
init: function (parent, action) {
var self = this;
this._super(parent, action);
this.res_user = new session.web.DataSetSearch(this, 'res.users');
},
});
var removed_suggested_group = session.removed_suggested_group = [];
suggestions.Groups = session.web.Widget.extend({
init: function (parent, action) {
console.log("init");
var self = this;
this._super(parent, action);
this.deferred = $.Deferred();
this.mail_group = new session.web.DataSetSearch(this, 'mail.group');
this.suggestions = [];
},
start: function() {
var self = this;
var args = arguments;
var res = self.get_suggested_group();
return $.when(res).done(function() {});
},
get_suggested_group: function () {
var self = this;
var group = self.mail_group.call('get_suggested_thread', {'removed_suggested_threads':removed_suggested_group}).then(function(res) {
if(res.length<=0) {self.$(".oe_user_profile_group").hide();}
_(res).each(function(result) {
result['image']=self.session.url('/web/binary/image', {model: 'mail.group', field: 'image_small', id: result.id});
});
self.suggestions = res
});
return $.when(group).done(function() {
self.$el.html( QWeb.render("mail.suggestions.groups", {'widget': self}) );
self.bind_events();
});
},
bind_events: function() {
var self = this;
this.$el.one('click', '.oe_remove_suggested_group', {data:this}, self.remove_suggested_group);
self.$el.one('click', '.oe_join_group', { data:self }, self.join_group);
},
join_group:function(event) {
var self = this;
console.log("join");
return event.data.data.mail_group.call('message_subscribe_users', [[$(self).attr('id')],[event.data.data.session.uid]]).then(function(res) {
event.data.data.get_suggested_group();
});
},
remove_suggested_group: function(event) {
var self = this;
console.log("remove");
removed_suggested_group.push($(self).attr('id'));
event.data.data.get_suggested_group();
},
});
mail.Wall.include({
start: function(options) {
this._super(options);
var self = this;
var sidebar = new suggestions.Sidebar(self);
sidebar.appendTo(self.$el.find('.oe_mail_wall_aside')).then( function() {
});
var sug_groups = new suggestions.Groups(self);
// sug_groups.replace(self.$el.find('.oe_suggestions_groups'));
$.when(sug_groups.start()).done(function() {
//self.$el.find('.oe_suggestions_groups').html(sug_groups.$el.html());
sug_groups.replace( self.$el.find('.oe_suggestions_groups') );
});
}
});
};

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<template>
<t t-name="mail.suggestions">
<div class="oe_suggestions_groups">No groups</div>
</t>
<!-- Suggested groups -->
<div t-name="mail.suggestions.groups" class="oe_sidebar_group">
<p class="oe_user_display">Suggested Groups</p>
<div class="oe_suggest_groups">
<t t-foreach="widget.suggestions" t-as="result">
<div class="oe_suggested_groups">
<div class="oe_group_images">
<a t-attf-href="#model=mail.group&amp;id=#{result.id}">
<img class="oe_group_image_content" t-attf-src="{result.image}"/>
</a>
</div>
<div class="oe_group">
<a class="oe_group_name" t-attf-href="#model=mail.group&amp;id=#{result.id}">
<t t-esc="result.name"/>
</a>
<a href="#" class="oe_remove_suggested_group" rol="button" t-attf-id="{result.id}">
<span class="oe_kanban_action oe_kanban_action_a">X</span>
</a>
<br/>
<button type="button" t-att-id="result.id" class="oe_join_group">Join Group</button>
</div>
</div>
</t>
</div>
</div>
</template>