From 43e49d754f7fd0b0e0dad1cf54591236d00e3365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 30 Mar 2012 17:11:47 +0200 Subject: [PATCH] [REF] Wall widget: refactored and cleaned code. Better management of domains. Removed 'You have loaded all discussion'. bzr revid: tde@openerp.com-20120330151147-d09fl1ps97vex8cz --- addons/mail/static/src/css/mail.css | 11 +-- addons/mail/static/src/js/mail.js | 127 +++++++++++++++------------- addons/mail/static/src/xml/mail.xml | 1 - 3 files changed, 75 insertions(+), 64 deletions(-) diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index 9630838a98f..638fc1ea111 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -2,22 +2,22 @@ /* Wall */ /* ------------------------------ */ -.oe_mail_wall { +div.oe_mail_wall { overflow: auto; padding: 5px; } -.oe_mail_wall_search { +div.oe_mail_wall_search { width: 55%; } /* 2 columns view */ -.oe_mail_wall_left { +div.oe_mail_wall_left { float: left; width: 65%; } -.oe_mail_wall_right { +div.oe_mail_wall_right { float: right; width: 34%; } @@ -36,8 +36,9 @@ margin-left: 40px; } -.oe_mail_wall_more { +div.oe_mail_wall_more { text-align: center; + display: none; } /* ------------------------------ */ diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 97ae0ea5f75..69ac42e1546 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -544,49 +544,60 @@ openerp.mail = function(session) { this._super(parent); this.params = params || {}; this.params.limit = params.limit || 50; + this.params.limit = 2; + this.params.domain = params.domain || []; + this.params.context = params.context || {}; + this.params.search = {'domain': [], 'context': {}, 'groupby': {}} this.params.search_view_id = params.search_view_id || false; this.params.thread_level = params.thread_level || 1; - this.params.search = {}; - this.params.domain = []; this.sorted_comments = {'models': {}}; + this.comments_structure = {'models': {}}; this.display_show_more = true; - /* DataSets */ + // datasets this.ds_msg = new session.web.DataSet(this, 'mail.message'); this.ds_groups = new session.web.DataSet(this, 'mail.group'); this.ds_thread = new session.web.DataSet(this, 'mail.thread'); this.ds_users = new session.web.DataSet(this, 'res.users'); }, - start: function() { - var self = this; + start: function () { this._super.apply(this, arguments); - /* events and buttons */ - this.$element.find('button.oe_mail_wall_button_comment').bind('click', function () { self.do_comment(); }); - this.$element.find('button.oe_mail_wall_button_more').bind('click', function () { self.do_more(); }); - this.$element.find('p.oe_mail_wall_nomore').hide(); - /* load mail.message search view */ - var search_view_loaded = this.load_search_view(this.params.search_view_id, {}, false); - var search_view_ready = $.when(search_view_loaded).then(function () { - self.searchview.on_search.add(self.do_searchview_search); - }); - /* fetch comments */ - var comments_ready = this.init_comments(this.params.domain, {}, 0, this.params.limit); + var self = this; + // add events + this.add_event_handlers(); + // load mail.message search view + var search_view_ready = this.load_search_view(this.params.search_view_id, {}, false); + // fetch first threads + var comments_ready = this.init_and_fetch_comments(this.params.limit, 0); return (search_view_ready && comments_ready); }, stop: function () { this._super.apply(this, arguments); }, + + /** Add events */ + add_event_handlers: function () { + var self = this; + // post a comment + this.$element.find('button.oe_mail_wall_button_comment').click(function () { self.do_comment(); }); + // display more threads + this.$element.find('button.oe_mail_wall_button_more').click(function () { self.do_more(); }); + }, /** * Loads the mail.message search view * @param {Number} view_id id of the search view to load * @param {Object} defaults ?? - * @param {Boolean} hidden ?? + * @param {Boolean} hidden some kind of trick we do not care here */ load_search_view: function (view_id, defaults, hidden) { + var self = this; this.searchview = new session.web.SearchView(this, this.ds_msg, view_id || false, defaults || {}, hidden || false); - return this.searchview.appendTo(this.$element.find('div.oe_mail_wall_search')); + var search_view_loaded = this.searchview.appendTo(this.$element.find('div.oe_mail_wall_search')); + return $.when(search_view_loaded).then(function () { + self.searchview.on_search.add(self.do_searchview_search); + }); }, /** @@ -604,45 +615,46 @@ openerp.mail = function(session) { contexts: contexts || [], group_by_seq: groupbys || [] }, function (results) { - 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'], 0, self.params.limit); + //self.params.search['context'] = results.context; + //self.params.search['domain'] = results.domain; + //self.params.search['groupby'] = results.group_by; + return self.init_and_fetch_comments(self.params.limit, 0, results.domain, results.context); }); }, /** - * Initializes Wall and calls fetch_comments - * @param {Array} domains - * @param {Array} contexts - * @param {Array} groupbys - * @param {Number} limit number of messages to fetch + * Initializes the wall and calls fetch_comments + * @param {Number} limit: number of notifications to fetch + * @param {Number} offset: offset in notifications search + * @param {Array} domain + * @param {Array} context */ - init_comments: function(domain, context, offset, limit) { - this.params.domain = []; + init_and_fetch_comments: function(limit, offset, domain, context) { + this.params.search['domain'] = _.union(this.params.domain, domain || []); + this.params.search['context'] = _.extend(this.params.context, context || {}); this.display_show_more = true; this.sorted_comments = {'models': {}}; this.$element.find('div.oe_mail_wall_threads').empty(); - return this.fetch_comments(domain, context, offset, limit); + return this.fetch_comments(limit, offset); }, /** - * Fetches Wall comments (mail.thread.get_pushed_messages) - * @param {Array} domains - * @param {Array} contexts - * @param {Array} groupbys - * @param {Number} limit number of messages to fetch + * Fetches wall messages + * @param {Number} limit: number of notifications to fetch + * @param {Number} offset: offset in notifications search + * @param {Array} domain + * @param {Array} context */ - fetch_comments: function (domain, context, offset, limit) { + fetch_comments: function (limit, offset, additional_domain, additional_context) { var self = this; + if (additional_domain) var fetch_domain = _.union(this.params.search['domain'], additional_domain); + else var fetch_domain = this.params.search['domain']; + if (additional_context) var fetch_context = _.extend(this.params.search['context'], additional_context); + else var fetch_context = this.params.search['context']; var load_res = this.ds_thread.call('get_pushed_messages', - [[this.session.uid], (limit || 2), (offset || 0), (domain || []), true, [false], (context || null)]).then(function (records) { - if (records.length < self.params.limit) self.display_show_more = false; + [[this.session.uid], (limit || 0), (offset || 0), fetch_domain, true, [false], fetch_context]).then(function (records) { + self.do_update_show_more(records.length >= self.params.limit); self.display_comments(records); - if (! self.display_show_more) { - self.$element.find('button.oe_mail_wall_button_more:last').hide(); - self.$element.find('p.oe_mail_wall_nomore:last').show(); - } }); return load_res; }, @@ -725,7 +737,9 @@ openerp.mail = function(session) { /** * Create a domain to fetch new comments according to - * comment already present in sorted_comments + * comments already present in sorted_comments + * - for each model: + * -- should not be child of already displayed ids * @param {Object} sorted_comments (see sort_comments) * @returns {Array} fetch_domain (OpenERP domain style) */ @@ -741,27 +755,24 @@ openerp.mail = function(session) { return domain; }, - /** - * Action: Shows more discussions - */ + /** Display update: show more button */ + do_update_show_more: function (new_value) { + if (new_value != undefined) this.display_show_more = new_value; + if (this.display_show_more) this.$element.find('div.oe_mail_wall_more:last').show(); + else this.$element.find('div.oe_mail_wall_more:last').hide(); + }, + + /** Action: Shows more discussions */ do_more: function () { var domain = this.get_fetch_domain(this.sorted_comments); - return this.fetch_comments(domain); + return this.fetch_comments(this.params.limit, 0, domain); }, - /** - * Action: Posts a comment - */ + /** Action: Posts a comment */ do_comment: function () { var body_text = this.$element.find('textarea.oe_mail_wall_action_textarea').val(); - return this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, false, 'comment']).then(this.init_comments(this.params.domain, {}, 0, this.params.limit)); - }, - - /** - * Tools: get avatar mini (TODO: should be moved in some tools ?) - */ - thread_get_mini: function(model, field, id) { - return this.session.prefix + '/web/binary/image?session_id=' + this.session.session_id + '&model=' + model + '&field=' + field + '&id=' + (id || ''); + return this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, false, 'comment']).then( + this.init_and_fetch_comments(this.params.limit, 0)); }, }); }; diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index b9de27ca6e9..a8e674c48bb 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -13,7 +13,6 @@
-

You have loaded all discussions.