diff options
| author | Atul Patel (OpenERP) <atp@tinyerp.com> | 2012-08-16 10:50:21 +0530 |
|---|---|---|
| committer | Atul Patel (OpenERP) <atp@tinyerp.com> | 2012-08-16 10:50:21 +0530 |
| commit | 22a810507cc6b4e48a067b6baaf9869d72e5a38e (patch) | |
| tree | 1808e0671b83dec971ae431b6ab1f09cfbfb44e8 /addons/mail/static/src | |
| parent | 1d2168a02ebeeb7441c9171bd9dcda8226d29cdc (diff) | |
| parent | f4f7de136921528f4b465629ff756b367ee0bba7 (diff) | |
[MERGE]: Merged with lp:openobject-addons
bzr revid: atp@tinyerp.com-20120816052021-igdj7knaimwg9x7z
Diffstat (limited to 'addons/mail/static/src')
| -rw-r--r-- | addons/mail/static/src/css/mail.css | 6 | ||||
| -rw-r--r-- | addons/mail/static/src/js/mail.js | 77 | ||||
| -rw-r--r-- | addons/mail/static/src/js/mail_followers.js | 122 | ||||
| -rw-r--r-- | addons/mail/static/src/xml/mail.xml | 25 | ||||
| -rw-r--r-- | addons/mail/static/src/xml/mail_followers.xml | 31 |
5 files changed, 169 insertions, 92 deletions
diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index ae934eeb4ff..baab34bca82 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -89,10 +89,14 @@ /* RecordThread /* ------------------------------------------------------------ */ -.openerp div.oe_mail_recthread { +.openerp .oe_form div.oe_chatter { overflow: auto; } +.openerp div.oe_mail_recthread { + /*overflow: auto;*/ +} + .openerp div.oe_mail_recthread_main { float: left; width: 560px; diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 2923f723952..d9ebf138ff2 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -4,6 +4,8 @@ openerp.mail = function(session) { var mail = session.mail = {}; + openerp_mail_followers(session, mail); // import mail_followers.js + /** * ------------------------------------------------------------ * FormView @@ -887,32 +889,17 @@ openerp.mail = function(session) { this._super.apply(this, arguments); this.params = this.get_definition_options(); this.params.thread_level = this.params.thread_level || 0; - this.params.see_subscribers = true; - this.params.see_subscribers_options = this.params.see_subscribers_options || false; this.thread = null; this.ds = new session.web.DataSet(this, this.view.model); this.ds_users = new session.web.DataSet(this, 'res.users'); }, start: function() { - var self = this; - // NB: all the widget should be modified to check the actual_mode property on view, not use // any other method to know if the view is in create mode anymore this.view.on("change:actual_mode", this, this._check_visibility); this._check_visibility(); - mail.ChatterUtils.bind_events(this); - this.$element.find('button.oe_mail_button_followers').click(function () { self.do_toggle_followers(); }); - if (! this.params.see_subscribers_options) { - this.$element.find('button.oe_mail_button_followers').hide(); } - this.$element.find('button.oe_mail_button_follow').click(function () { self.do_follow(); }) - .mouseover(function () { $(this).html('Follow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); }) - .mouseleave(function () { $(this).html('Not following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); }); - this.$element.find('button.oe_mail_button_unfollow').click(function () { self.do_unfollow(); }) - .mouseover(function () { $(this).html('Unfollow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); }) - .mouseleave(function () { $(this).html('Following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); }); - this.reinit(); }, _check_visibility: function() { @@ -923,72 +910,20 @@ openerp.mail = function(session) { this._super.apply(this, arguments); }, - reinit: function() { - this.params.see_subscribers = true; - this.params.see_subscribers_options = this.params.see_subscribers_options || false; - this.$element.find('button.oe_mail_button_followers').html('Hide followers') - this.$element.find('button.oe_mail_button_follow').hide(); - this.$element.find('button.oe_mail_button_unfollow').hide(); - }, - set_value: function() { this._super.apply(this, arguments); - var self = this; - this.reinit(); if (! this.view.datarecord.id || session.web.BufferedDataSet.virtual_id_regex.test(this.view.datarecord.id)) { this.$element.find('.oe_mail_thread').hide(); return; } - // fetch followers - var fetch_sub_done = this.fetch_subscribers(); // create and render Thread widget this.$element.find('div.oe_mail_recthread_main').empty(); if (this.thread) this.thread.destroy(); this.thread = new mail.Thread(this, {'res_model': this.view.model, 'res_id': this.view.datarecord.id, 'uid': this.session.uid, 'thread_level': this.params.thread_level, 'show_post_comment': true, 'limit': 15}); var thread_done = this.thread.appendTo(this.$element.find('div.oe_mail_recthread_main')); - return fetch_sub_done && thread_done; - }, - - fetch_subscribers: function () { - return this.ds.call('message_read_subscribers', [[this.view.datarecord.id]]).then(this.proxy('display_subscribers')); - }, - - display_subscribers: function (records) { - var self = this; - this.is_subscriber = false; - var user_list = this.$element.find('ul.oe_mail_followers_display').empty(); - this.$element.find('div.oe_mail_recthread_followers h4').html('Followers (' + records.length + ')'); - _(records).each(function (record) { - if (record.id == self.session.uid) { self.is_subscriber = true; } - record.avatar_url = mail.ChatterUtils.get_image(self.session.prefix, self.session.session_id, 'res.users', 'image_small', record.id); - $(session.web.qweb.render('mail.record_thread.subscriber', {'record': record})).appendTo(user_list); - }); - if (self.is_subscriber) { - self.$element.find('button.oe_mail_button_follow').hide(); - self.$element.find('button.oe_mail_button_unfollow').show(); } - else { - self.$element.find('button.oe_mail_button_follow').show(); - self.$element.find('button.oe_mail_button_unfollow').hide(); } - }, - - do_follow: function () { - return this.ds.call('message_subscribe', [[this.view.datarecord.id]]).pipe(this.proxy('fetch_subscribers')); - }, - - do_unfollow: function () { - var self = this; - return this.ds.call('message_unsubscribe', [[this.view.datarecord.id]]).then(function (record) { - if (record == false) self.do_notify("Impossible to unsubscribe", "You are automatically subscribed to this record. You cannot unsubscribe."); - }).pipe(this.proxy('fetch_subscribers')); - }, - - do_toggle_followers: function () { - this.params.see_subscribers = ! this.params.see_subscribers; - if (this.params.see_subscribers) { this.$element.find('button.oe_mail_button_followers').html('Hide followers'); } - else { this.$element.find('button.oe_mail_button_followers').html('Show followers'); } - this.$element.find('div.oe_mail_recthread_followers').toggle(); + return thread_done; }, }); @@ -1021,6 +956,8 @@ openerp.mail = function(session) { this.params.limit = params.limit || 25; this.params.domain = params.domain || []; this.params.context = params.context || {}; + this.params.res_model = params.res_model || false; + this.params.res_id = params.res_id || false; this.params.search_view_id = params.search_view_id || false; this.params.thread_level = params.thread_level || 1; this.comments_structure = {'root_ids': [], 'new_root_ids': [], 'msgs': {}, 'tree_struct': {}, 'model_to_root_ids': {}}; @@ -1068,8 +1005,8 @@ openerp.mail = function(session) { this.compose_message_widget.destroy(); } this.compose_message_widget = new mail.ComposeMessage(this, { - 'extended_mode': false, 'uid': this.session.uid, 'res_model': 'res.users', - 'res_id': this.session.uid, 'mode': mode || 'comment', 'msg_id': msg_id }); + 'extended_mode': false, 'uid': this.session.uid, 'res_model': this.params.res_model, + 'res_id': this.params.res_id, 'mode': mode || 'comment', 'msg_id': msg_id }); var composition_node = this.$element.find('div.oe_mail_wall_action'); composition_node.empty(); var compose_done = this.compose_message_widget.appendTo(composition_node); diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js new file mode 100644 index 00000000000..0e920f73041 --- /dev/null +++ b/addons/mail/static/src/js/mail_followers.js @@ -0,0 +1,122 @@ +openerp_mail_followers = function(session, mail) { + var _t = session.web._t, + _lt = session.web._lt; + + var mail_followers = session.mail_followers = {}; + + /** + * ------------------------------------------------------------ + * mail_followers Widget + * ------------------------------------------------------------ + * + * This widget handles the display of a list of records as a vetical + * list, with an image on the left. The widget itself is a floatting + * right-sided box. + * This widget is mainly used to display the followers of records + * in OpenChatter. + */ + + /* Add the widget to registry */ + session.web.form.widgets.add('mail_followers', 'openerp.mail_followers.Followers'); + + mail_followers.Followers = session.web.form.AbstractField.extend({ + template: 'mail.followers', + + init: function() { + this._super.apply(this, arguments); + this.params = {}; + this.params.image = this.node.attrs.image || 'image_small'; + this.params.title = this.node.attrs.title || 'Followers'; + this.params.display_followers = true; + this.params.display_control = this.node.attrs.display_control || false; + this.params.display_actions = this.node.attrs.display_actions || false; + this.ds_model = new session.web.DataSetSearch(this, this.view.model); + this.ds_follow = new session.web.DataSetSearch(this, this.field.relation); + }, + + start: function() { + var self = this; + // NB: all the widget should be modified to check the actual_mode property on view, not use + // any other method to know if the view is in create mode anymore + this.view.on("change:actual_mode", this, this._check_visibility); + this._check_visibility(); + this.$element.find('button.oe_mail_button_followers').click(function () { self.do_toggle_followers(); }); + if (! this.params.display_control) { + this.$element.find('button.oe_mail_button_followers').hide(); } + this.$element.find('button.oe_mail_button_follow').click(function () { self.do_follow(); }) + .mouseover(function () { $(this).html('Follow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); }) + .mouseleave(function () { $(this).html('Not following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); }); + this.$element.find('button.oe_mail_button_unfollow').click(function () { self.do_unfollow(); }) + .mouseover(function () { $(this).html('Unfollow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); }) + .mouseleave(function () { $(this).html('Following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); }); + this.reinit(); + }, + + _check_visibility: function() { + this.$element.toggle(this.view.get("actual_mode") !== "create"); + }, + + destroy: function () { + this._super.apply(this, arguments); + }, + + reinit: function() { + this.params.display_followers = true; + this.params.display_control = this.node.attrs.display_control || false; + this.params.display_actions = this.node.attrs.display_actions || false; + this.$element.find('button.oe_mail_button_followers').html('Hide followers') + this.$element.find('button.oe_mail_button_follow').hide(); + this.$element.find('button.oe_mail_button_unfollow').hide(); + }, + + set_value: function(value_) { + this.reinit(); + if (! this.view.datarecord.id || + session.web.BufferedDataSet.virtual_id_regex.test(this.view.datarecord.id)) { + this.$element.find('div.oe_mail_recthread_aside').hide(); + return; + } + return this.fetch_subscribers(value_); + }, + + fetch_subscribers: function (value_) { + return this.ds_follow.call('read', [value_ || this.get_value(), ['name', this.params.image]]).then(this.proxy('display_subscribers')); + }, + + /** + * Display the followers. + * TODO: replace the is_subscriber check by fields read */ + display_subscribers: function (records) { + var self = this; + this.is_subscriber = false; + var user_list = this.$element.find('ul.oe_mail_followers_display').empty(); + this.$element.find('div.oe_mail_recthread_followers h4').html(this.params.title + ' (' + records.length + ')'); + _(records).each(function (record) { + if (record.id == self.session.uid) { self.is_subscriber = true; } + record.avatar_url = mail.ChatterUtils.get_image(self.session.prefix, self.session.session_id, 'res.users', 'image_small', record.id); + $(session.web.qweb.render('mail.followers.partner', {'record': record})).appendTo(user_list); + }); + if (this.is_subscriber) { + this.$element.find('button.oe_mail_button_follow').hide(); + this.$element.find('button.oe_mail_button_unfollow').show(); } + else { + this.$element.find('button.oe_mail_button_follow').show(); + this.$element.find('button.oe_mail_button_unfollow').hide(); } + }, + + do_follow: function () { + return this.ds_model.call('message_subscribe', [[this.view.datarecord.id]]).pipe(this.proxy('set_value')); + }, + + do_unfollow: function () { + return this.ds_model.call('message_unsubscribe', [[this.view.datarecord.id]]).pipe(this.proxy('set_value')); + }, + + do_toggle_followers: function () { + this.params.see_subscribers = ! this.params.see_subscribers; + if (this.params.see_subscribers) { this.$element.find('button.oe_mail_button_followers').html('Hide followers'); } + else { this.$element.find('button.oe_mail_button_followers').html('Show followers'); } + this.$element.find('div.oe_mail_recthread_followers').toggle(); + }, + }); +}; diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index bf29ada9f63..00c7cd1d3c6 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -16,7 +16,10 @@ <tr class="oe_header_row oe_header_row_top"> <td colspan="2"> <h2 class="oe_view_title"> - <span class="oe_view_title_text">All Feeds</span> + <span class="oe_view_title_text"> + <t t-if="! widget.params.res_model">News Feeds</t> + <t t-if="widget.params.res_model" t-esc="widget.params.res_model"/> + </span> </h2> </td> <td><div class="oe_view_manager_view_search" t-opentag="true"/></td> @@ -58,29 +61,9 @@ <div class="oe_mail_recthread_main"> <!-- contains the document thread --> </div> - <div class="oe_mail_recthread_aside"> - <div class="oe_mail_recthread_actions"> - <button type="button" class="oe_mail_button_follow oe_mail_button_mouseout">Not following</button> - <button type="button" class="oe_mail_button_unfollow oe_mail_button_mouseout">Following</button> - <button type="button" class="oe_mail_button_followers">Show followers</button> - </div> - <div class="oe_mail_recthread_followers"> - <h4>Followers</h4> - <ul class="oe_mail_followers_display"></ul> - </div> - </div> </div> <!-- - record_thread.subscriber template - Template used to display a subscriber. - --> - <li t-name="mail.record_thread.subscriber"> - <img class="oe_mail_thumbnail oe_mail_frame" t-attf-src="{record.avatar_url}"/> - <a t-attf-href="#model=res.users&id=#{record.id}"><t t-raw="record.name"/></a> - </li> - - <!-- mail.compose_message template This template holds the composition form to write a note or send an e-mail. It contains by default a textarea, that will be replaced diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml new file mode 100644 index 00000000000..53c899b9569 --- /dev/null +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<template> + + <!-- + followers main template + Template used to display the followers and the actions in a record. + --> + <div t-name="mail.followers" class="oe_mail_recthread_aside"> + <div class="oe_mail_recthread_actions"> + <button type="button" class="oe_mail_button_follow oe_mail_button_mouseout">Not following</button> + <button type="button" class="oe_mail_button_unfollow oe_mail_button_mouseout">Following</button> + <button type="button" class="oe_mail_button_followers">Show followers</button> + </div> + <div class="oe_mail_recthread_followers"> + <t t-if="widget.params.title"> + <h4><t t-raw="widget.params.title"/></h4> + </t> + <ul class="oe_mail_followers_display"></ul> + </div> + </div> + + <!-- + followers.partner template + Template used to display a partner following the record + --> + <li t-name="mail.followers.partner"> + <img class="oe_mail_thumbnail oe_mail_frame" t-attf-src="{record.avatar_url}"/> + <a t-attf-href="#model=res.users&id=#{record.id}"><t t-raw="record.name"/></a> + </li> + +</template> |
