diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 156f6ff4590..4a3b92cc895 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -53,7 +53,7 @@ openerp.mail = function(session) { }); /* display user, fetch comments */ this.display_current_user(); - if (this.records) return this.display_comments(this.records); + if (this.params.records) return this.display_comments(this.params.records); else return this.init_comments(); }, @@ -306,7 +306,10 @@ openerp.mail = function(session) { */ init: function (parent, params) { this._super(parent); + this.params = params || {}; this.params.limit = params.limit || 20; + this.params.search = {}; + this.params.domain = []; this.sorted_comments = {}; /* DataSets */ this.ds_msg = new session.web.DataSet(this, 'mail.message'); @@ -324,7 +327,7 @@ openerp.mail = function(session) { self.searchview.on_search.add(self.do_searchview_search); }); /* fetch comments */ - var comments_ready = this.fetch_comments(); + var comments_ready = this.init_comments(); return (search_view_ready && comments_ready); }, @@ -358,10 +361,27 @@ openerp.mail = function(session) { contexts: contexts || [], group_by_seq: groupbys || [] }, function (results) { - self.search['context'] = results.context; - self.search['domain'] = results.domain; - self.search['groupby'] = results.group_by; - self.fetch_comments(self.search['domain'], self.search['context']); + self.params.search['context'] = results.context; + self.params.search['domain'] = results.domain; + self.params.search['groupby'] = results.group_by; + self.init_comments(self.params.search['domain'], self.params.search['context']); + }); + }, + + /** + * Initializes Wall and calls fetch_comments + * @param {Array} domains + * @param {Array} contexts + * @param {Array} groupbys + * @param {Number} limit number of messages to fetch + */ + init_comments: function(domain, context, offset, limit) { + var self = this; + this.params.domain = []; + this.sorted_comments = {}; + this.$element.find('div.oe_mail_wall_threads').empty(); + return this.fetch_comments(domain, context, offset, limit).then(function () { + self.$element.find('button.oe_mail_wall_button_more').bind('click', function () { self.do_more(); }); }); }, @@ -383,10 +403,9 @@ openerp.mail = function(session) { * @param {Array} records records to show in threads */ display_comments: function (records) { - this.$element.find('div.oe_mail_wall_threads').empty(); - this.sort_comments(records, this.sorted_comments); + var sorted_comments = this.sort_comments(records, this.sorted_comments); var self = this; - _(this.sorted_comments).each(function (rec_models, model) { // each model + _(sorted_comments).each(function (rec_models, model) { // each model _(rec_models).each(function (record_id, id) { // each record var template = 'WallThreadContainer'; var render_res = session.web.qweb.render(template, { @@ -394,23 +413,24 @@ openerp.mail = function(session) { 'record_id': id, }); $('