diff options
Diffstat (limited to 'addons/mail/static/src')
| -rw-r--r-- | addons/mail/static/src/css/mail.css | 163 | ||||
| -rw-r--r-- | addons/mail/static/src/js/mail.js | 1016 | ||||
| -rw-r--r-- | addons/mail/static/src/js/mail_followers.js | 167 | ||||
| -rw-r--r-- | addons/mail/static/src/xml/mail.xml | 143 | ||||
| -rw-r--r-- | addons/mail/static/src/xml/mail_followers.xml | 34 |
5 files changed, 1080 insertions, 443 deletions
diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index 717d0439486..364ac7e3165 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -14,7 +14,6 @@ margin: 0; } - /* ------------------------------------------------------------ */ /* Wall /* ------------------------------------------------------------ */ @@ -37,6 +36,21 @@ list-style-type: none; } +/* ------------------------------------------------------------ */ +/* Followers +/* ------------------------------------------------------------ */ + +.openerp div.oe_mail_recthread_aside h4 { + display: inline-block; +} +.openerp div.oe_mail_recthread_aside button { + position: relative; +} +.openerp div.oe_mail_recthread_aside label, +.openerp div.oe_mail_recthread_aside input { + cursor:pointer; +} + /* Specific display of threads in the wall */ /* ------------------------------------------------------------ */ @@ -50,22 +64,12 @@ border-top: 0; } -.openerp div.oe_mail_thread_subthread img { +.openerp div.oe_thread_placeholder img { width: 28px; height: 28px; } -.openerp div.oe_mail_msg_content { - position: relative; - width: 486px; -} - -.openerp div.oe_mail_msg_content > li { - float: left; - margin-right: 3px; -} - -.openerp div.oe_mail_thread_subthread div.oe_mail_msg_content { +.openerp div.oe_thread_placeholder div.oe_mail_msg_content { width: 440px; } @@ -78,7 +82,7 @@ overflow: auto; } -.openerp div.oe_mail_recthread_main { +.openerp .oe_mail_record_wall > .oe_mail_wall_threads { float: left; width: 560px; } @@ -96,7 +100,7 @@ width: 120px; } -.openerp button.oe_mail_button_mouseout { +.openerp .oe_mail_recthread_aside .oe_follower.oe_follow { color: white; background-color: #8a89ba; background-image: -webkit-gradient(linear, left top, left bottom, from(#8a89ba), to(#807fb4)); @@ -106,9 +110,7 @@ background-image: -o-linear-gradient(top, #8a89ba, #807fb4); background-image: linear-gradient(to bottom, #8a89ba, #807fb4); } - -.openerp button.oe_mail_button_mouseover { - display: none; +.openerp .oe_mail_recthread_aside .oe_follower.oe_following { color: white; background-color: #dc5f59; background-image: -webkit-gradient(linear, left top, left bottom, from(#dc5f59), to(#b33630)); @@ -119,12 +121,41 @@ background-image: linear-gradient(to bottom, #dc5f59, #b33630); } + +.openerp .oe_mail_recthread_aside .oe_follower span { + display:none; +} +.openerp .oe_mail_recthread_aside .oe_following span.oe_following, +.openerp .oe_mail_recthread_aside .oe_notfollow span.oe_follow { + display:block; +} + .openerp div.oe_mail_recthread_followers { margin-bottom: 8px; } /* ------------------------------------------------------------ */ +/* subtypes +/* ------------------------------------------------------------ */ + +.openerp .oe_mouse_subtypes { + display:inline-block; + position: relative; + z-index: 5; +} +.openerp .oe_mouse_subtypes .oe_recthread_subtypes { + position: absolute; + z-index: 2; +} +.openerp .oe_mouse_subtypes.oe_mouseout .oe_recthread_subtypes { + display: none; +} +.openerp .oe_mouse_subtypes.oe_mouseover .oe_recthread_subtypes { + display: block; +} + +/* ------------------------------------------------------------ */ /* Thread /* ------------------------------------------------------------ */ @@ -132,6 +163,8 @@ display: none; white-space: normal; padding: 8px; + z-index:5; + background: #fff; } .openerp div.oe_mail_thread_action:after { @@ -160,15 +193,20 @@ -box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 8px rgba(82, 168, 236, 0.6); } +.openerp .oe_mail_vote_count, +.openerp .oe_mail_msg_vote{ + vertical-align: bottom; +} + .openerp div.oe_mail_thread_display { white-space: normal; } -.openerp div.oe_mail_thread_subthread { +.openerp div.oe_thread_placeholder { margin-left: 66px; } -.openerp div.oe_mail_thread_subthread li.oe_mail_thread_msg:last-child { +.openerp div.oe_thread_placeholder li.oe_mail_thread_msg:last-child { margin-bottom: 8px; } @@ -183,6 +221,15 @@ clear: both; } +.openerp li.oe_mail_thread_msg.oe_mail_read, +.openerp li.oe_mail_thread_msg.oe_mail_read div { + background-color: #F0F0F0; +} +.openerp li.oe_mail_thread_msg.oe_mail_read li.oe_mail_thread_msg.oe_mail_unread, +.openerp li.oe_mail_thread_msg.oe_mail_read li.oe_mail_thread_msg.oe_mail_unread div { + background-color: #F6F6F6; +} + .openerp li.oe_mail_thread_msg > div:after { content: ""; display: block; @@ -194,18 +241,15 @@ margin: 0 0 4px 0; } -.openerp .oe_mail_msg_notification, -.openerp .oe_mail_msg_comment, +.openerp .oe_mail_msg_notification, +.openerp .oe_mail_msg_expandable, +.openerp .oe_mail_msg_comment, .openerp .oe_mail_msg_email { padding: 8px; background: white; border-top: 1px solid #ebebeb; } -.openerp div.oe_mail_thread_subthread .oe_mail_msg_comment { - background: #eee; -} - .openerp .oe_mail_msg_notification:after, .openerp .oe_mail_msg_comment:after, .openerp .oe_mail_msg_email:after { @@ -214,8 +258,15 @@ clear: both; } -.openerp .oe_mail_msg_content { +.openerp div.oe_mail_msg_content { + float: right; + position: relative; + width: 486px; +} + +.openerp div.oe_mail_msg_content > li { float: left; + margin-right: 3px; } .openerp .oe_mail_msg_content:after { @@ -224,7 +275,7 @@ clear: both; } -.openerp .oe_mail_msg_content a { +.openerp .oe_chatter a { cursor: pointer; } @@ -258,31 +309,6 @@ display: none; } -/*--------------------------------------------------------------*/ -/* mail.vote -/*--------------------------------------------------------------*/ - -.openerp .oe_mail_msg_content button.oe_mail_msg_vote { - height:21px; - width: 30px; - padding: 1px; - background: #8A89BA; - margin-top: -4px; -} - -.openerp .oe_mail_msg_content button.oe_mail_msg_vote_true { - background:#DC5F59; -} - -.openerp .oe_mail_msg_content button.oe_mail_msg_vote span { - color: white; -} - -.openerp .oe_mail_msg_content span.oe_mail_vote_count{ - color: #807FB4; -} - - /* ------------------------------------------------------------ */ /* mail.compose.message form view & OpenERP hacks /* ------------------------------------------------------------ */ @@ -387,15 +413,38 @@ } /* Dropdown menu */ -.openerp .oe_mail_msg_content .oe_dropdown_toggle { +/*.openerp .oe_mail_msg_content .oe_dropdown_toggle { position: absolute; top: 0px; right: 3px; +}*/ + +.openerp .oe_mail .oe_semantic_html_override { + position: relative; } -.openerp .oe_mail_msg_content .oe_dropdown_arrow:after { - border-top: 4px solid transparent; + +.openerp .oe_mail ul.oe_header { + position: absolute; + right: 3px; + top: -6px; + display: none; + z-index: 10; + height: 18px; +} + +.openerp .oe_mail ul.oe_header a { + text-decoration: none; +} + +.openerp .oe_mail .oe_semantic_html_override:hover > ul.oe_header { + display: block; } -.openerp .oe_mail_msg_content:hover .oe_dropdown_arrow:after { + +.openerp .oe_mail ul.oe_header>li { + display: inline-block; +} + +.openerp .oe_mail_msg_content .oe_dropdown_arrow:after { border-top: 4px solid #404040; } diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 57c777441e7..e0c9ac9b7fc 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -22,8 +22,9 @@ openerp.mail = function(session) { action.context && action.context.redirect == true && this.fields && this.fields.message_ids && this.fields.message_ids.view.get("actual_mode") != 'create') { var thread = this.fields.message_ids.thread; - thread.refresh_composition_form(action.context); - return true; + + thread.refresh(action.context); + return false; } else { return this._super(action, on_close); @@ -56,11 +57,6 @@ openerp.mail = function(session) { return session.origin + '/web/binary/saveas?session_id=' + session.session_id + '&model=ir.attachment&field=datas&filename_field=datas_fname&id=' + attachment['id']; }, - /** Check if the current user is the message author */ - is_author: function (widget, message_user_id) { - return (widget.session && widget.session.uid != 0 && widget.session.uid == message_user_id); - }, - /** Replaces some expressions * - :name - shortcut to an image */ @@ -115,8 +111,8 @@ openerp.mail = function(session) { this._super.apply(this, arguments); // customize display: add avatar, clean previous content var user_avatar = mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid); - this.$el.find('img.oe_mail_icon').attr('src', user_avatar); - this.$el.find('div.oe_mail_msg_content').empty(); + this.$('img.oe_mail_icon').attr('src', user_avatar); + this.$('div.oe_mail_msg_content').empty(); // create a context for the dataset and default_get of the wizard var context = _.extend({}, this.options.context); this.ds_compose = new session.web.DataSetSearch(this, 'mail.compose.message', context); @@ -144,21 +140,21 @@ openerp.mail = function(session) { disable_autofocus: true, }); // add the form, bind events, activate the form - var msg_node = this.$el.find('div.oe_mail_msg_content'); + var msg_node = this.$('div.oe_mail_msg_content'); return $.when(this.form_view.appendTo(msg_node)).pipe(this.proxy('postprocess_create_form_view')); }, postprocess_create_form_view: function () { // handle attachment button this.fileupload_id = _.uniqueId('oe_fileupload'); - var button_attach = this.$el.find('button.oe_mail_compose_message_attachment'); + var button_attach = this.$('button.oe_mail_compose_message_attachment'); var rendered = session.web.qweb.render('mail.compose_message.add_attachment', {'widget': this}); $(rendered).insertBefore(button_attach); // move the button inside div.oe_hidden_input_file - var input_node = this.$el.find('input[name=ufile]'); + var input_node = this.$('input[name=ufile]'); button_attach.detach().insertAfter(input_node); // set the function called when attachments are added - this.$el.find('input.oe_form_binary_file').change(this.on_attachment_change); + this.$('input.oe_form_binary_file').change(this.on_attachment_change); this.bind_events(); this.form_view.do_show(); }, @@ -166,7 +162,7 @@ openerp.mail = function(session) { on_attachment_change: function (event) { var $target = $(event.target); if ($target.val() !== '') { - this.$el.find('form.oe_form_binary_form').submit(); + this.$('form.oe_form_binary_form').submit(); session.web.blockUI(); } }, @@ -183,11 +179,11 @@ openerp.mail = function(session) { }, display_attachments: function () { - var attach_node = this.$el.find('div.oe_mail_compose_message_attachments'); + var attach_node = this.$('div.oe_mail_compose_message_attachments'); var rendered = session.web.qweb.render('mail.thread.message.attachments', {'record': this}); attach_node.empty(); $(rendered).appendTo(attach_node); - this.$el.find('.oe_mail_msg_attachments').show(); + this.$('.oe_mail_msg_attachments').show(); var composer_attachment_ids = _.pluck(this.attachment_ids, 'id'); var onchange_like = {'value': {'attachment_ids': composer_attachment_ids}} this.form_view.on_processed_onchange(onchange_like, []); @@ -233,22 +229,89 @@ openerp.mail = function(session) { this.$el.on('click', '.oe_mail_attachment_delete', self.on_attachment_delete); }, }), + /** * ------------------------------------------------------------ - * Thread Widget + * Thread Message Expandable Widget * ------------------------------------------------------------ * - * This widget handles the display of a thread of messages. The + * This widget handles the display the expandable message in a thread. The * [thread_level] parameter sets the thread level number: - * - root message + * - thread + * - - visible message + * - - expandable + * - - visible message + * - - visible message + * - - expandable + */ + mail.ThreadExpandable = session.web.Widget.extend({ + template: 'mail.thread.expandable', + + init: function(parent, options) { + this._super(parent); + this.domain = options.domain || []; + this.context = _.extend({ + default_model: 'mail.thread', + default_res_id: 0, + default_parent_id: false }, options.context || {}); + + this.id = -1; + this.parent_id= options.parameters.parent_id || false; + this.nb_messages = options.parameters.nb_messages || 0; + this.type = options.parameters.type || false; + + // record options and data + this.parent_thread= parent.messages!= undefined ? parent : options.options.thread._parents[0] ; + + }, + + + start: function() { + this._super.apply(this, arguments); + this.bind_events(); + }, + + /** + * Bind events in the widget. Each event is slightly described + * in the function. */ + bind_events: function() { + var self = this; + // event: click on 'Vote' button + this.$el.on('click', 'a.oe_mail_fetch_more', self.on_expandable); + }, + + /*The selected thread and all childs (messages/thread) became read + * @param {object} mouse envent + */ + on_expandable: function (event) { + event.stopPropagation(); + this.parent_thread.message_fletch(false, this.domain, this.context); + this.destroy(); + return false; + }, + }); + + /** + * ------------------------------------------------------------ + * Thread Message Widget + * ------------------------------------------------------------ + * This widget handles the display of a messages in a thread. + * Displays a record and performs some formatting on the record : + * - record.date: formatting according to the user timezone + * - record.timerelative: relative time givein by timeago lib + * - record.avatar: image url + * - record.attachment_ids[].url: url of each attachmentThe + * [thread_level] parameter sets the thread level number: + * - root thread * - - sub message (parent_id = root message) - * - - - sub sub message (parent id = sub message) + * - - - sub thread + * - - - - sub sub message (parent id = sub thread) * - - sub message (parent_id = root message) + * - - - sub thread */ - - mail.Thread = session.web.Widget.extend({ - template: 'mail.thread', + mail.ThreadMessage = session.web.Widget.extend({ + template: 'mail.thread.message', /** * @param {Object} parent parent @@ -257,66 +320,99 @@ openerp.mail = function(session) { contain at least default_model, default_res_id. Please refer to the ComposeMessage widget for more information about it. * @param {Object} [options] - * @param {Number} [options.message_ids=null] ids for message_fetch - * @param {Number} [options.message_data=null] already formatted message - data, for subthreads getting data from their parent - * @param {Number} [options.thread_level=0] number of thread levels - * @param {Boolean} [options.use_composer] use the advanced composer, or - the default basic textarea if not set - * @param {Number} [options.truncate_limit=250] number of character to - * display before having a "show more" link; note that the text - * will not be truncated if it does not have 110% of the parameter + * @param {Object} [thread] read obout mail.Thread object + * @param {Object} [message] + * @param {Number} [message_ids=null] ids for message_fletch + * @param {Number} [message_data=null] already formatted message data, + * for subthreads getting data from their parent + * @param {Number} [truncate_limit=250] number of character to + * display before having a "show more" link; note that the text + * will not be truncated if it does not have 110% of the parameter + * @param {Boolean} [show_record_name] + * @param {Boolean} [show_reply] + * @param {Boolean} [show_reply_by_email] + * @param {Boolean} [show_dd_delete] + * @param {Boolean} [show_dd_hide] */ - init: function(parent, domain, context, options) { + init: function(parent, options) { this._super(parent); - this.domain = domain || []; + this.domain = options.domain || []; this.context = _.extend({ default_model: 'mail.thread', default_res_id: 0, - default_parent_id: false }, context || {}); + default_parent_id: false }, options.context || {}); + // options - this.options = { - message_ids: options.message_ids || null, - message_data: options.message_data || null, - thread_level: options.thread_level || 0, - use_composer: options.use_composer || false, - show_header_compose: options.show_header_compose != undefined ? options.show_header_compose: true, - show_record_name: options.show_record_name != undefined ? options.show_record_name: true, - show_reply: options.show_reply || false, - show_reply_by_email: options.show_reply_by_email || false, - show_dd_reply_by_email:options.show_dd_reply_by_email != undefined ? options.show_dd_reply_by_email: true, - show_dd_delete: options.show_dd_delete || false, - show_dd_hide: options.show_dd_hide || false, - show_more: options.show_more || false, - truncate_limit: options.truncate_limit || 250, + this.options={ + 'thread' : options.options.thread, + 'message' : { + 'message_ids': options.options.message.message_ids || null, + 'message_data': options.options.message.message_data || null, + 'show_record_name': options.options.message.show_record_name != undefined ? options.options.message.show_record_name: true, + 'show_reply': options.options.message.show_reply || false, + 'show_reply_by_email': options.options.message.show_reply_by_email || false, + 'show_dd_delete': options.options.message.show_dd_delete || false, + 'show_dd_hide': options.options.message.show_dd_hide || false, + 'truncate_limit': options.options.message.truncate_limit || 250, + } + }; + // record options and data + this.parent_thread= parent.messages!= undefined ? parent : options.options.thread._parents[0] ; + + var param = options.parameters; + // record parameters + this.id = param.id || -1; + this.model = param.model || false; + this.parent_id= param.parent_id || false; + this.res_id = param.res_id || false; + this.type = param.type || false; + this.is_author = param.is_author || false; + this.subject = param.subject || false; + this.name = param.name || false; + this.record_name = param.record_name || false; + this.body = param.body || false; + this.vote_user_ids =param.vote_user_ids || []; + this.has_voted = param.has_voted || false; + + this.vote_user_ids = param.vote_user_ids || []; + + this.unread = param.unread || false; + this._date = param.date; + this.author_id = param.author_id || []; + this.attachment_ids = param.attachment_ids || []; + + this.thread = false; + + if( param.id > 0 ) { + this.formating_data(); } - // datasets and internal vars - this.records = {}; - this.ds_thread = new session.web.DataSetSearch(this, this.context.default_model); + this.ds_notification = new session.web.DataSetSearch(this, 'mail.notification'); this.ds_message = new session.web.DataSetSearch(this, 'mail.message'); }, + + formating_data: function(){ + + //formating and add some fields for render + this.date = session.web.format_value(this._date, {type:"datetime"}); + this.timerelative = $.timeago(this.date); + if (this.type == 'email') { + this.avatar = ('/mail/static/src/img/email_icon.png'); + } else { + this.avatar = mail.ChatterUtils.get_image(this.session, 'res.partner', 'image_small', this.author_id[0]); + } + for (var l in this.attachment_ids) { + var attach = this.attachment_ids[l]; + attach['url'] = mail.ChatterUtils.get_attachment_url(this.session, attach); + } + }, start: function() { - // TDE TODO: check for deferred, not sure it is correct this._super.apply(this, arguments); + this.expender(); + this.$el.hide().fadeIn(750); this.bind_events(); - // fetch and display message, using message_ids if set - var display_done = $.when(this.message_fetch(true, [], {})).then(this.proxy('do_customize_display')); - // add message composition form view - if (this.options.show_header_compose && this.options.use_composer) { - var compose_done = this.instantiate_composition_form(); - } - return display_done && compose_done; - }, - - /** Customize the display - * - show_header_compose: show the composition form in the header */ - do_customize_display: function() { - this.display_user_avatar(); - if (this.options.show_header_compose) { - this.$el.find('div.oe_mail_thread_action').eq(0).show(); - } + this.create_thread(); }, /** @@ -324,281 +420,569 @@ openerp.mail = function(session) { * in the function. */ bind_events: function() { var self = this; - // event: click on 'More' at bottom of thread - this.$el.on('click', 'button.oe_mail_button_more', this.do_message_fetch_more); - // event: writing in basic textarea of composition form (quick reply) - this.$el.find('textarea.oe_mail_compose_textarea').keyup(function (event) { - var charCode = (event.which) ? event.which : window.event.keyCode; - if (event.shiftKey && charCode == 13) { this.value = this.value+"\n"; } - else if (charCode == 13) { return self.message_post(); } - }); - // event: click on 'Reply' in msg - this.$el.on('click', 'a.oe_mail_msg_reply', function (event) { - var act_dom = $(this).parents('li.oe_mail_thread_msg').eq(0).find('div.oe_mail_thread_action:first'); - act_dom.toggle(); - }); // event: click on 'Attachment(s)' in msg this.$el.on('click', 'a.oe_mail_msg_view_attachments', function (event) { var act_dom = $(this).parent().parent().parent().find('.oe_mail_msg_attachments'); act_dom.toggle(); }); + // event: click on icone 'Read' in header + this.$el.on('click', 'a.oe_read', this.on_message_read_unread); + // event: click on icone 'UnRead' in header + this.$el.on('click', 'a.oe_unread', this.on_message_read_unread); // event: click on 'Delete' in msg side menu this.$el.on('click', 'a.oe_mail_msg_delete', this.on_message_delete); - // event: click on 'Hide' in msg side menu - this.$el.on('click', 'a.oe_mail_msg_hide', this.on_message_read); + + // event: click on 'Reply' in msg + this.$el.on('click', 'a.oe_reply', this.on_message_reply); // event: click on 'Reply by email' in msg side menu - this.$el.on('click', 'a.oe_mail_msg_reply_by_email', function (event) { - if (! self.compose_message_widget) return true; - var msg_id = event.srcElement.dataset.msg_id; - if (! msg_id) return false; - self.compose_message_widget.refresh({ - 'default_composition_mode': 'reply', - 'default_parent_id': parseInt(msg_id), - 'default_content_subtype': 'html'} ); - }); + this.$el.on('click', 'a.oe_reply_by_email', this.on_message_reply_by_mail); // event: click on 'Vote' button this.$el.on('click', 'button.oe_mail_msg_vote', this.on_vote); }, + on_message_reply:function(event){ + event.stopPropagation(); + this.thread.on_compose_message($(event.srcElement).hasClass("oe_full_reply"), false); + return false; + }, + + on_message_reply_by_mail:function(event){ + event.stopPropagation(); + this.thread.on_compose_message(true, true); + return false; + }, + + expender: function(){ + this.$('div.oe_mail_msg_body:first').expander({ + slicePoint: this.options.truncate_limit, + expandText: 'read more', + userCollapseText: '[^]', + detailClass: 'oe_mail_msg_tail', + moreClass: 'oe_mail_expand', + lessClass: 'oe_mail_reduce', + }); + }, + + create_thread: function(){ + var self=this; + if(this.thread){ + return false; + } + /*create thread*/ + self.thread = new mail.Thread(self, { + 'domain': self.domain, + 'context':{ + 'default_model': self.model, + 'default_res_id': self.res_id, + 'default_parent_id': self.id + }, + 'options': { + 'thread' : self.options.thread, + 'message' : self.options.message + }, + 'parameters':{ + 'model': self.model, + 'id': self.id, + 'parent_id': self.id + } + } + ); + /*insert thread in parent message*/ + self.thread.appendTo(self.$el.find('div.oe_thread_placeholder')); + }, + + animated_destroy: function(options) { + var self=this; + //graphic effects + if(options && options.fadeTime) { + self.$el.fadeOut(options.fadeTime, function(){ + self.destroy(); + }); + } else { + self.destroy(); + } + for(var i in this.thread.messages){ + this.thread.messages[i].animated_destroy({fadeTime:0}); + } + }, + on_message_delete: function (event) { + event.stopPropagation(); if (! confirm(_t("Do you really want to delete this message?"))) { return false; } - var msg_id = event.srcElement.dataset.id; - if (! msg_id) return false; - $(event.srcElement).parents('li.oe_mail_thread_msg').eq(0).remove(); - return this.ds_message.unlink([parseInt(msg_id)]); + + this.animated_destroy({fadeTime:250}); + // delete this message and his childs + var ids = [this.id].concat( this.get_child_ids() ); + this.ds_message.unlink(ids); + this.animated_destroy(); + return false; }, - on_message_read: function (event) { - //TDE: TODO - var msg_id = event.srcElement.dataset.id; - if (! msg_id) return false; - $(event.srcElement).parents('li.oe_mail_thread_msg').eq(0).remove(); - return this.ds_notification.call('set_message_read', [parseInt(msg_id)]); + /*The selected thread and all childs (messages/thread) became read + * @param {object} mouse envent + */ + on_message_read_unread: function (event) { + event.stopPropagation(); + this.animated_destroy({fadeTime:250}); + // if this message is read, all childs message display is read + var ids = [this.id].concat( this.get_child_ids() ); + this.ds_notification.call('set_message_read', [ids,$(event.srcElement).hasClass("oe_read")]); + return false; }, + /** browse message + * @param {object}{int} option.id + * @param {object}{string} option.model + * @param {object}{boolean} option._go_thread_wall + * private for check the top thread + * @return thread object + */ + browse_message: function(options){ + // goto the wall thread for launch browse + if(!options._go_thread_wall) { + options._go_thread_wall = true; + for(var i in this.options.thread._parents[0].messages){ + var res=this.options.thread._parents[0].messages[i].browse_message(options); + if(res) return res; + } + } + + if(this.id==options.id) + return this; + + for(var i in this.thread.messages){ + if(this.thread.messages[i].thread){ + var res=this.thread.messages[i].browse_message(options); + if(res) return res; + } + } + + return false; + }, + + /* get all child message/thread id linked + */ + get_child_ids: function(){ + var res=[] + if(arguments[0]) res.push(this.id); + if(this.thread){ + res = res.concat( this.thread.get_child_ids(true) ); + } + return res; + }, + + on_vote: function (event) { event.stopPropagation(); + var self=this; + return this.ds_message.call('vote_toggle', [[self.id]]).pipe(function(vote){ + + self.has_voted=vote; + if (!self.has_voted) { + var votes=[]; + for(var i in self.vote_user_ids){ + if(self.vote_user_ids[i][0]!=self.session.uid) + vote.push(self.vote_user_ids[i]); + } + self.vote_user_ids=votes; + } + else { + self.vote_user_ids.push([self.session.uid, 'You']); + } + self.display_vote(); + }); + return false; + }, + + // Render vote Display template. + display_vote: function () { var self = this; - var message_id = $(event.srcElement).parent().data().msg_id; - var vote_node = $(event.srcElement).parents('li').eq(0); - if (! message_id) { return false; } - return this.ds_message.call('vote_toggle', [[parseInt(message_id)]]).pipe( - self.toggle_vote(message_id, vote_node)); + var vote_element = session.web.qweb.render('mail.thread.message.vote', {'widget': self}); + self.$(".placeholder-mail-vote").empty(); + self.$(".placeholder-mail-vote").html(vote_element); }, + }); + + /** + * ------------------------------------------------------------ + * Thread Widget + * ------------------------------------------------------------ + * + * This widget handles the display of a thread of messages. The + * [thread_level] parameter sets the thread level number: + * - root message + * - - sub message (parent_id = root message) + * - - - sub sub message (parent id = sub message) + * - - sub message (parent_id = root message) + */ + mail.Thread = session.web.Widget.extend({ + template: 'mail.thread', /** - * Override-hack of do_action: automatically reload the chatter. - * Normally it should be called only when clicking on 'Post/Send' - * in the composition form. */ + * @param {Object} parent parent + * @param {Array} [domain] + * @param {Object} [context] context of the thread. It should + contain at least default_model, default_res_id. Please refer to + the ComposeMessage widget for more information about it. + * @param {Object} [options] + * @param {Object} [message] read about mail.ThreadMessage object + * @param {Object} [thread] + * @param {Number} [thread_level=0] number of thread levels + * @param {Boolean} [use_composer] use the advanced composer, or + * the default basic textarea if not set + * @param {Number} [expandable_number=5] number message show + * for each click on "show more message" + * @param {Number} [expandable_default_number=5] number message show + * on begin before the first click on "show more message" + * @param {Boolean} [display_on_flat] display all thread + * on the wall thread level (no hierarchy) + * @param {Array} [parents] liked with the parents thread + * use with browse, fletch... [O]= top parent + */ + init: function(parent, options) { + this._super(parent); + this.domain = options.domain || []; + this.context = _.extend({ + default_model: 'mail.thread', + default_res_id: 0, + default_parent_id: false }, options.context || {}); + + // options + this.options={ + 'thread' : { + 'thread_level': options.options.thread.thread_level || 0, + 'show_header_compose': (options.options.thread.show_header_compose != undefined ? options.options.thread.show_header_compose: false), + 'use_composer': options.options.thread.use_composer || false, + 'expandable_number': options.options.thread.expandable_number || 5, + 'expandable_default_number': options.options.thread.expandable_default_number || 5, + '_expandable_max': options.options.thread.expandable_default_number || 5, + 'display_on_flat': options.options.thread.display_on_flat || false, + '_parents': (options.options.thread._parents != undefined ? options.options.thread._parents : []).concat( [this] ) + }, + 'message' : options.options.message + }; + + // record options and data + this.parent_linked_message= parent.thread!= undefined ? parent : false ; + + var param = options.parameters + // datasets and internal vars + this.id= param.id || false; + this.model= param.model || false; + this.parent_id= param.parent_id || false; + + this.messages = []; + + this.ds_thread = new session.web.DataSetSearch(this, this.context.default_model); + this.ds_message = new session.web.DataSetSearch(this, 'mail.message'); + }, + + start: function() { + // TDE TODO: check for deferred, not sure it is correct + this._super.apply(this, arguments); + + this.list_ul=this.$('ul.oe_mail_thread_display:first'); + this.more_msg=this.$(">.oe_mail_msg_more_message:first"); + + this.display_user_avatar(); + var display_done = compose_done = false; + + // add message composition form view + compose_done = this.instantiate_composition_form(); + + this.bind_events(); + + if(this.options.thread._parents[0]==this){ + this.on_first_thread(); + } + + return display_done && compose_done; + }, + + /** + * Override-hack of do_action: automatically load message on the chatter. + * Normally it should be called only when clicking on 'Post/Send' + * in the composition form. */ do_action: function(action, on_close) { - //TDE: TODO: instead of reloading, push the message ? - this.message_clean(); - this.message_fetch(); - if (this.compose_message_widget) { - this.compose_message_widget.refresh({ - 'default_composition_mode': 'comment', - 'default_parent_id': this.context.default_parent_id, - 'default_content_subtype': 'plain'} ); + this.instantiate_composition_form(); + this.message_fletch(false, false, false, [action.id]); + return this._super(action, on_close); + }, + + /* this method is runing for first parent thread + */ + on_first_thread: function(){ + // fetch and display message, using message_ids if set + display_done = this.message_fletch(true); + //show the first write message + this.$(">.oe_mail_thread_action").show(); + }, + + /** + * Bind events in the widget. Each event is slightly described + * in the function. */ + bind_events: function() { + var self = this; + // event: writing in basic textarea of composition form (quick reply) + // event: onblur for hide 'Reply' + this.$('.oe_mail_compose_textarea:first textarea') + .keyup(function (event) { + var charCode = (event.which) ? event.which : window.event.keyCode; + if (event.shiftKey && charCode == 13) { this.value = this.value+"\n"; } + else if (charCode == 13) { return self.message_post(); } + }) + .blur(function (event) { + $(this).parents('.oe_mail_thread_action:first').hide(); + }); + }, + + /* get all child message/thread id linked + */ + get_child_ids: function(){ + var res=[]; + for(var i in this.messages){ + if(this.messages[i].thread){ + res = res.concat( this.messages[i].get_child_ids(true) ); + } + } + return res; + }, + + /** browse thread + * @param {object}{int} option.id + * @param {object}{string} option.model + * @param {object}{boolean} option._go_thread_wall + * private for check the top thread + * @param {object}{boolean} option.default_return_top_thread + * return the top thread (wall) if no thread found + * @return thread object + */ + browse_thread: function(options){ + // goto the wall thread for launch browse + if(!options._go_thread_wall) { + options._go_thread_wall = true; + return this.options.thread._parents[0].browse_thread(options); + } + + if(this.id==options.id){ + return this; } - // return this._super(action, on_close); + + if(options.id) + for(var i in this.messages){ + if(this.messages[i].thread){ + var res=this.messages[i].thread.browse_thread({'id':options.id, '_go_thread_wall':true}); + if(res) return res; + } + } + + //if option default_return_top_thread, return the top if no found thread + if(options.default_return_top_thread){ + return this; + } + + return false; + }, + + /** browse message + * @param {object}{int} option.id + * @param {object}{string} option.model + * @param {object}{boolean} option._go_thread_wall + * private for check the top thread + * @return thread object + */ + browse_message: function(options){ + if(this.options.thread._parents[0].messages[0]) + return this.options.thread._parents[0].messages[0].browse_message(options); }, /** Instantiate the composition form, with every parameters in context - or in the widget context. */ + * or in the widget context. + * @param {object} + * @param {boolean} show_header_compose, force to instantiate form + */ instantiate_composition_form: function(context) { + // add message composition form view + if ((!context || !context.show_header_compose) && + (!this.options.thread.show_header_compose || !this.options.thread.use_composer || + (this.options.thread.show_header_compose <= this.options.thread._parents.length && this.options.thread._parents[0]!=this))) { + this.$("textarea:first").val(""); + return false; + } if (this.compose_message_widget) { - this.compose_message_widget.destroy(); + this.compose_message_widget.refresh(); + } else { + var context = _.extend(context || {}, this.context); + this.compose_message_widget = new mail.ComposeMessage(this, {'context': context}); + var composition_node = this.$('div.oe_mail_thread_action'); + composition_node.empty(); + return this.compose_message_widget.appendTo(composition_node); } - this.compose_message_widget = new mail.ComposeMessage(this, { - 'context': _.extend(context || {}, this.context), - }); - var composition_node = this.$el.find('div.oe_mail_thread_action'); - composition_node.empty(); - var compose_done = this.compose_message_widget.appendTo(composition_node); - return compose_done; }, - refresh_composition_form: function (context) { - if (! this.compose_message_widget) return; - return this.compose_message_widget.refresh(context); + /* this function is launch when a user click on "Reply" button + */ + on_compose_message: function(full_reply, by_mail){ + if(full_reply){ + this.instantiate_composition_form({'show_header_compose':true}); + } + if(by_mail){ + if (!this.compose_message_widget) return true; + this.compose_message_widget.refresh({ + 'default_composition_mode': 'reply', + 'default_parent_id': this.id, + 'default_content_subtype': 'html'} ); + } + this.$('div.oe_mail_thread_action:first').toggle(); + return false; + }, + + refresh: function (action_context) { + var self=this; + _(this.messages).each(function(){ self.destroy(); }); + self.message_fletch(); }, - /** Clean the thread */ - message_clean: function() { - this.$el.find('div.oe_mail_thread_display').empty(); + /*post a message and fletch the message*/ + message_post: function (body) { + var self = this; + if (! body) { + var comment_node = this.$('textarea'); + var body = comment_node.val(); + comment_node.val(''); + } + if(body.match(/\S+/)) { + this.ds_thread.call('message_post_api', [ + [this.context.default_res_id], body, false, 'comment', false, this.context.default_parent_id, undefined]) + .then(this.proxy('switch_new_message')); + } + else { + return false; + } }, /** Fetch messages * @param {Bool} initial_mode: initial mode: try to use message_data or * message_ids, if nothing available perform a message_read; otherwise * directly perform a message_read - * @param {Array} additional_domain: added to this.domain - * @param {Object} additional_context: added to this.context + * @param {Array} replace_domain: added to this.domain + * @param {Object} replace_context: added to this.context */ - message_fetch: function (initial_mode, additional_domain, additional_context) { + message_fletch: function (initial_mode, replace_domain, replace_context, ids) { var self = this; - // domain and context: options + additional - fetch_domain = _.flatten([this.domain, additional_domain || []], true) - fetch_context = _.extend(this.context, additional_context || {}) + // initial mode: try to use message_data or message_ids - if (initial_mode && this.options.message_data) { - return this.message_display(this.options.message_data); + if (initial_mode && this.options.thread.message_data) { + return this.create_message_object(this.options.message_data); } - message_ids = initial_mode && this.options.message_ids != null && this.options.message_ids || false; - return this.ds_message.call('message_read', [message_ids, fetch_domain, this.options.thread_level, undefined, fetch_context] - ).then(this.proxy('message_display')); + // domain and context: options + additional + fetch_domain = replace_domain ? replace_domain : this.domain; + fetch_context = replace_context ? replace_context : this.context; + fetch_context.message_loaded= [this.id||0].concat( self.options.thread._parents[0].get_child_ids() ); + + return this.ds_message.call('message_read', [ids, fetch_domain, (this.options.thread.thread_level+1), fetch_context, this.context.default_parent_id || undefined] + ).then(this.proxy('switch_new_message')); }, - /* Display a list of records - * A specific case is done for 'expandable' messages that are messages - displayed under a 'show more' button form + /* create record object and linked him */ - message_display: function (records) { + create_message_object: function (message) { var self = this; - var _expendable = false; - _(records).each(function (record) { - if (record.type == 'expandable') { - _expendable = true; - self.update_fetch_more(true); - self.fetch_more_domain = record.domain; - self.fetch_more_context = record.context; - } - else { - self.display_record(record); - self.thread = new mail.Thread(self, self.domain, - { 'default_model': record.model, - 'default_res_id': record.res_id, - 'default_parent_id': record.id }, - { 'message_data': record.child_ids, - 'thread_level': self.options.thread_level - 1, - 'show_header_compose': false, - 'show_reply': self.options.show_reply && self.options.thread_level > 1, - 'show_reply_by_email': self.options.show_reply_by_email, - 'show_dd_hide': self.options.show_dd_hide, - 'show_dd_delete': self.options.show_dd_delete }); - self.$el.find('li.oe_mail_thread_msg:last').append('<div class="oe_mail_thread_subthread"/>'); - self.thread.appendTo(self.$el.find('div.oe_mail_thread_subthread:last')); + + // check if the message is already create + for(var i in this.messages){ + if(this.messages[i].id==message.id){ + this.messages[i].destroy(); + this.messages[i]=self.insert_message(message); + return true; } - }); - if (! _expendable) { - this.update_fetch_more(false); - } - }, - - /** Displays a record and performs some formatting on the record : - * - record.date: formatting according to the user timezone - * - record.timerelative: relative time givein by timeago lib - * - record.avatar: image url - * - record.attachment_ids[].url: url of each attachment - * - record.is_author: is the current user the author of the record */ - display_record: function (record) { - // formatting and additional fields - record.date = session.web.format_value(record.date, {type:"datetime"}); - record.timerelative = $.timeago(record.date); - if (record.type == 'email') { - record.avatar = ('/mail/static/src/img/email_icon.png'); - } else { - record.avatar = mail.ChatterUtils.get_image(this.session, 'res.partner', 'image_small', record.author_id[0]); } - for (var l in record.attachment_ids) { - var attach = record.attachment_ids[l]; - attach['url'] = mail.ChatterUtils.get_attachment_url(this.session, attach); - } - record.is_author = mail.ChatterUtils.is_author(this, record.author_user_id[0]); - // add to internal storage - this.records[record.id] = record; - // render, add the expand feature - var rendered = session.web.qweb.render('mail.thread.message', {'record': record, 'thread': this, 'options': this.options}); - $(rendered).appendTo(this.$el.children('div.oe_mail_thread_display:first')); - this.$el.find('div.oe_mail_msg_body').expander({ - slicePoint: this.options.truncate_limit, - expandText: 'read more', - userCollapseText: '[^]', - detailClass: 'oe_mail_msg_tail', - moreClass: 'oe_mail_expand', - lessClass: 'oe_mail_reduce', - }); + + self.messages.push( self.insert_message(message) ); + }, - // Render vote Display template. - toggle_vote: function (message_id, vote_node) { - var self = this; - var record = this.records[message_id]; - if (record.has_voted) { - var idx = _.map(record.vote_user_ids, function (x) { return x[0]; }).indexOf(message_id); - record.vote_user_ids.splice(idx, 1); + /** Displays a message or an expandable message */ + insert_message: function (message) { + var self=this; + + if(message.type=='expandable'){ + var message = new mail.ThreadExpandable(self, { + 'domain': message.domain, + 'context': { + 'default_model': message.model, + 'default_res_id': message.res_id, + 'default_parent_id': message.id }, + 'parameters': message + }); + } else { + var message = new mail.ThreadMessage(self, { + 'domain': message.domain, + 'context': { + 'default_model': message.model, + 'default_res_id': message.res_id, + 'default_parent_id': message.id }, + 'options':{ + 'thread': self.options.thread, + 'message': self.options.message + }, + 'parameters': message + }); } - else { - record.vote_user_ids.push([this.session.uid, 'You']); + + var thread = self.options.thread.display_on_flat ? self.options.thread._parents[0] : this; + + // check older and newer message for insert + var parent_newer = false; + var parent_older = false; + for(var i in thread.messages){ + if(thread.messages[i].id > message.id){ + if(!parent_newer || parent_newer.id>thread.messages[i].id) + parent_newer = thread.messages[i]; + } else if(thread.messages[i].id>0 && thread.messages[i].id < message.id) { + if(!parent_older || parent_older.id<thread.messages[i].id) + parent_older = thread.messages[i]; + } } - record.has_voted = ! record.has_voted; - var vote_element = session.web.qweb.render('mail.thread.message.vote', {'record': record}); - vote_node.empty(); - vote_node.html(vote_element); + + if(parent_newer) + message.insertAfter(parent_newer.$el); + else if(parent_older) + message.insertBefore(parent_older.$el); + else + message.prependTo(thread.list_ul); + + return message }, - /** Display 'show more' button */ - update_fetch_more: function (new_value) { - if (new_value) { - this.$el.find('div.oe_mail_thread_more:last').show(); + /* Hide messages if they are more message that _expandable_max + * display "show more messages" + */ + display_expandable: function(){ + if(this.messages.length>this.options._expandable_max){ + this.list_ul.find('>li:gt('+(this.options._expandable_max-1)+')').hide(); + this.more_msg.show(); } else { - this.$el.find('div.oe_mail_thread_more:last').hide(); + this.list_ul.find('>li').show(); + this.more_msg.hide(); } }, display_user_avatar: function () { var avatar = mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid); - return this.$el.find('img.oe_mail_icon').attr('src', avatar); + return this.$('img.oe_mail_icon').attr('src', avatar); }, - message_post: function (body) { - var self = this; - if (! body) { - var comment_node = this.$el.find('textarea'); - var body = comment_node.val(); - comment_node.val(''); - } - return this.ds_thread.call('message_post', [ - [this.context.default_res_id], body, false, 'comment', this.context.default_parent_id, undefined] - ).then(self.message_fetch()); - }, - - /** Action: 'shows more' to fetch new messages */ - do_message_fetch_more: function () { - return this.message_fetch(false, this.fetch_more_domain, this.fetch_more_context); - }, - - // TDE: keep currently because need something similar - // /** - // * Create a domain to fetch new comments according to - // * comment already present in comments_structure - // * @param {Object} comments_structure (see chatter utils) - // * @returns {Array} fetch_domain (OpenERP domain style) - // */ - // get_fetch_domain: function (comments_structure) { - // var domain = []; - // var ids = comments_structure.root_ids.slice(); - // var ids2 = []; - // // must be child of current parent - // if (this.options.parent_id) { domain.push(['id', 'child_of', this.options.parent_id]); } - // _(comments_structure.root_ids).each(function (id) { // each record - // ids.push(id); - // ids2.push(id); - // }); - // if (this.options.parent_id != false) { - // ids2.push(this.options.parent_id); - // } - // // must not be children of already fetched messages - // if (ids.length > 0) { - // domain.push('&'); - // domain.push('!'); - // domain.push(['id', 'child_of', ids]); - // } - // if (ids2.length > 0) { - // domain.push(['id', 'not in', ids2]); - // } - // return domain; - // }, + /* Send the records to his parent thread */ + switch_new_message: function(records) { + var self=this; + _(records).each(function(record){ + self.browse_thread({ + 'id': record.parent_id, + 'default_return_top_thread':true + }).create_message_object( record ); + }); + }, }); @@ -637,7 +1021,7 @@ openerp.mail = function(session) { var self = this; this._super.apply(this, arguments); if (! this.view.datarecord.id || session.web.BufferedDataSet.virtual_id_regex.test(this.view.datarecord.id)) { - this.$el.find('oe_mail_thread').hide(); + this.$('oe_mail_thread').hide(); return; } // update context @@ -647,13 +1031,33 @@ openerp.mail = function(session) { // update domain var domain = this.options.domain.concat([['model', '=', this.view.model], ['res_id', '=', this.view.datarecord.id]]); // create and render Thread widget - this.$el.find('div.oe_mail_recthread_main').empty(); - var thread = new mail.Thread(self, domain, this.options.context, - { 'thread_level': this.options.thread_level, - 'use_composer': true, - 'show_dd_delete': true, - 'show_reply_by_email': true }); - return thread.appendTo(this.$el.find('div.oe_mail_recthread_main')); + var show_header_compose = this.view.is_action_enabled('edit') || + (this.getParent().fields.message_is_follower && this.getParent().fields.message_is_follower.get_value()); + + this.thread = new mail.Thread(self, { + 'domain': domain, + 'context': this.options.context, + 'options':{ + 'thread':{ + 'thread_level': this.options.thread_level, + 'show_header_compose': show_header_compose, + 'use_composer': show_header_compose, + 'display_on_flat':true + }, + 'message':{ + 'show_dd_delete': true, + 'show_reply_by_email': show_header_compose, + } + }, + 'parameters': {}, + } + ); + + this.$('ul.oe_mail_wall_threads').empty(); + var render_res = session.web.qweb.render('mail.wall_thread_container', {}); + $(render_res).appendTo(this.$('ul.oe_mail_wall_threads')); + + return this.thread.appendTo( this.$('li.oe_mail_wall_thread:last') ); }, }); @@ -705,7 +1109,7 @@ openerp.mail = function(session) { load_searchview: function (defaults, hidden) { var self = this; this.searchview = new session.web.SearchView(this, this.ds_msg, false, defaults || {}, hidden || false); - return this.searchview.appendTo(this.$el.find('.oe_view_manager_view_search')).then(function () { + return this.searchview.appendTo(this.$('.oe_view_manager_view_search')).then(function () { self.searchview.on_search.add(self.do_searchview_search); }); }, @@ -726,25 +1130,41 @@ openerp.mail = function(session) { }, function (results) { self.search_results['context'] = results.context; self.search_results['domain'] = results.domain; - self.search_results['groupby'] = results.group_by; + self.thread.destroy(); return self.message_render(); }); }, /** Clean and display the threads */ - message_render: function () { - this.$el.find('ul.oe_mail_wall_threads').empty(); + message_render: function (search) { var domain = this.options.domain.concat(this.search_results['domain']); - var render_res = session.web.qweb.render('mail.wall_thread_container', {}); - $(render_res).appendTo(this.$el.find('ul.oe_mail_wall_threads')); - var thread = new mail.Thread(this, domain, this.options.context, - { 'thread_level': this.options.thread_level, - 'use_composer': true, - 'show_reply': this.options.thread_level > 0, - 'show_dd_hide': true, + + var domain = _.extend(this.options.domain, search&&search.domain? search.domain : {}); + var context = _.extend(this.options.context, search&&search.context ? search.context : {}); + + this.thread = new mail.Thread(this, { + 'domain' : domain, + 'context' : context, + 'options': { + 'thread' :{ + 'thread_level': this.options.thread_level, + 'use_composer': true, + 'show_header_compose': 1, + }, + 'message': { + 'show_reply': this.options.thread_level > 0, + 'show_dd_hide': true, + }, + }, + 'parameters': {}, } ); - return thread.appendTo(this.$el.find('li.oe_mail_wall_thread:last')); + + this.$('ul.oe_mail_wall_threads').empty(); + var render_res = session.web.qweb.render('mail.wall_thread_container', {}); + $(render_res).appendTo(this.$('ul.oe_mail_wall_threads')); + + return this.thread.appendTo( this.$('li.oe_mail_wall_thread:last') ); }, }); }; diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index cf33bd64640..953b8cd9fc8 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -26,8 +26,12 @@ openerp_mail_followers = function(session, mail) { this._super.apply(this, arguments); this.options.image = this.node.attrs.image || 'image_small'; this.options.title = this.node.attrs.title || 'Followers'; + this.options.context = this.node.attrs.context; + this.options.comment = this.node.attrs.help || false; this.ds_model = new session.web.DataSetSearch(this, this.view.model); + this.sub_model = new session.web.DataSetSearch(this,'mail.message.subtype'); this.ds_follow = new session.web.DataSetSearch(this, this.field.relation); + this.follower_model = new session.web.DataSetSearch(this,'mail.followers'); }, start: function() { @@ -43,17 +47,39 @@ openerp_mail_followers = function(session, mail) { }, reinit: function() { - this.$el.find('button.oe_mail_button_follow').hide(); - this.$el.find('button.oe_mail_button_unfollow').hide(); + this.message_is_follower == undefined; + this.display_buttons(); }, bind_events: function() { var self = this; - this.$('button.oe_mail_button_unfollow').on('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.$el.on('click', 'button.oe_mail_button_follow', function () { self.do_follow(); }); - this.$el.on('click', 'button.oe_mail_button_invite', function(event) { + this.$('div.oe_mouse_subtypes') + .on('mouseover', function () { + $(this).removeClass('oe_mouseout').addClass('oe_mouseover'); + self.display_subtypes(); + }) + .on('mouseleave', function () { + $(this).removeClass('oe_mouseover').addClass('oe_mouseout'); + self.display_subtypes(); + }); + + this.$('button.oe_follower') + .on('click', function () { + if($(this).hasClass('oe_notfollow')) + self.do_follow(); + else + self.do_unfollow(); + }) + .on('mouseover', function () { + $(this).removeClass('oe_mouseout').addClass('oe_mouseover'); + }) + .on('mouseleave', function () { + $(this).removeClass('oe_mouseover').addClass('oe_mouseout'); + }); + + this.$el.on('click', 'ul.oe_subtypes input', function () { self.do_update_subscription(); }) + + this.$el.on('click', 'button.oe_invite', function(event) { action = { type: 'ir.actions.act_window', res_model: 'mail.wizard.invite', @@ -73,50 +99,137 @@ openerp_mail_followers = function(session, mail) { read_value: function() { var self = this; return this.ds_model.read_ids([this.view.datarecord.id], ['message_follower_ids']).pipe(function (results) { - return results[0].message_follower_ids; - }).pipe(this.proxy('set_value')); + self.set_value(results[0].message_follower_ids); + }); }, set_value: function(value_) { this.reinit(); - if (! this.view.datarecord.id || - session.web.BufferedDataSet.virtual_id_regex.test(this.view.datarecord.id)) { - this.$el.find('div.oe_mail_recthread_aside').hide(); - return; - } return this.fetch_followers(value_ || this.get_value()); }, + set_is_follower: function(value_) { + for(var i in value_){ + if(value_[i]['user_ids'][0]==this.session.uid) + this.message_is_follower=true; + this.display_buttons(); + return true; + } + this.message_is_follower=false; + this.display_buttons(); + return false; + }, + fetch_followers: function (value_) { - return this.ds_follow.call('read', [value_, ['name', 'user_ids']]).pipe(this.proxy('display_followers')); + this.value = value_ || {}; + this.message_is_follower = (this.getParent().fields.message_is_follower && this.getParent().fields.message_is_follower.get_value()); + if(value_) + return this.ds_follow.call('read', [this.value, ['name', 'user_ids']]).pipe(this.proxy('display_followers'), this.proxy('display_generic')); + }, + + /* Display generic info about follower, for people not having access to res_partner */ + display_generic: function (error, event) { + event.preventDefault(); + var node_user_list = this.$('ul.oe_mail_followers_display').empty(); + // format content: Followers (You and 0 other) // Followers (3) + var content = this.options.title; + if (this.message_is_follower) { + content += ' (You and ' + (this.value.length-1) + ' other)'; + } + else { + content += ' (' + this.value.length + ')' + } + this.$('div.oe_mail_recthread_followers h4').html(content); + this.display_buttons(); + return $.when(); }, /** Display the followers, evaluate is_follower directly */ display_followers: function (records) { var self = this; - this.message_is_follower = _.indexOf(_.flatten(_.pluck(records, 'user_ids')), this.session.uid) != -1; - var node_user_list = this.$el.find('ul.oe_mail_followers_display').empty(); - this.$el.find('div.oe_mail_recthread_followers h4').html(this.options.title + ' (' + records.length + ')'); - _(records).each(function (record) { + var node_user_list = this.$('ul.oe_mail_followers_display').empty(); + this.$('div.oe_mail_recthread_followers h4').html(this.options.title + (records.length>=5 ? ' (' + records.length + ')' : '') ); + console.log(records); + for(var i=0; i<records.length&&i<5; i++) { + var record=records[i]; record.avatar_url = mail.ChatterUtils.get_image(self.session, 'res.partner', 'image_small', record.id); $(session.web.qweb.render('mail.followers.partner', {'record': record})).appendTo(node_user_list); - }); + } + self.set_is_follower(records); + }, + + display_buttons: function () { if (this.message_is_follower) { - this.$el.find('button.oe_mail_button_follow').hide(); - this.$el.find('button.oe_mail_button_unfollow').show(); } + this.$('button.oe_follower').removeClass('oe_notfollow').addClass('oe_following'); + } else { - this.$el.find('button.oe_mail_button_follow').show(); - this.$el.find('button.oe_mail_button_unfollow').hide(); } + this.$('button.oe_follower').removeClass('oe_following').addClass('oe_notfollow'); + } + + if (this.view.is_action_enabled('edit')) + this.$('span.oe_mail_invite_wrapper').hide(); + else + this.$('span.oe_mail_invite_wrapper').show(); }, + set_subtypes:function(data){ + var self = this; + var records = data[this.view.datarecord.id].message_subtype_data; + _(records).each(function (record, record_name) { + record.name = record_name; + record.followed = record.followed || undefined; + $(session.web.qweb.render('mail.followers.subtype', {'record': record})).appendTo( self.$('ul.oe_subtypes') ); + }); + }, + + /** Display subtypes: {'name': default, followed} */ + display_subtypes: function (visible) { + var self = this; + var recthread_subtypes = self.$('.oe_recthread_subtypes'); + subtype_list_ul = self.$('ul.oe_subtypes'); + + if(subtype_list_ul.is(":empty")) { + var context = new session.web.CompoundContext(this.build_context(), {}); + this.ds_model.call('get_message_subtypes',[[self.view.datarecord.id], context]).pipe(this.proxy('set_subtypes')); + } + }, + do_follow: function () { + var self =this; + _(this.$('.oe_msg_subtype_check')).each(function(record){ + $(record).attr('checked','checked'); + }); var context = new session.web.CompoundContext(this.build_context(), {}); - return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], undefined, context]).pipe(this.proxy('read_value')); + return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], undefined, undefined, context]).pipe(function(value_){ + self.read_value(value_); + if(!self.$('.oe_recthread_subtypes').is(":visible")) + self.display_subtypes(true); + }); }, - + do_unfollow: function () { + _(this.$('.oe_msg_subtype_check')).each(function(record){ + $(record).attr('checked',false); + }); var context = new session.web.CompoundContext(this.build_context(), {}); return this.ds_model.call('message_unsubscribe_users', [[this.view.datarecord.id], undefined, context]).pipe(this.proxy('read_value')); }, + + do_update_subscription: function () { + var context = new session.web.CompoundContext(this.build_context(), {}); + var self = this; + + var checklist = new Array(); + _(this.$('.oe_msg_subtype_check')).each(function(record){ + if($(record).is(':checked')) { + checklist.push(parseInt($(record).data('id')))} + }); + + if(!checklist.length) + return this.do_unfollow(); + else + return this.ds_model.call('message_subscribe_users',[[self.view.datarecord.id], undefined, checklist, context]).pipe(this.proxy('read_value')); + }, + }); -}; +};
\ No newline at end of file diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index e3586e723e4..07c9b406cdc 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -47,11 +47,11 @@ Template used to display the communication history in documents form view. --> - <div t-name="mail.record_thread"> + <div t-name="mail.record_thread" class="oe_mail_record_wall"> <!-- <h4>History and Comments</h4> --> - <div class="oe_mail_recthread_main"> + <ul class="oe_mail_wall_threads"> <!-- contains the document thread --> - </div> + </ul> </div> <!-- @@ -62,12 +62,12 @@ for main thread composition form in document form view. --> <t t-name="mail.compose_message"> - <div> + <div class="oe_mail_compose_textarea"> <img class="oe_mail_icon oe_mail_frame oe_left" alt="User img"/> <div class="oe_mail_msg_content"> <!-- contains the composition form --> <!-- default content: old basic textarea --> - <textarea class="oe_mail_compose_textarea" placeholder="Add your comment here..." onfocus="this.value = '';"/> + <textarea placeholder="Add your comment here..."/> </div> <div class="oe_clear"/> </div> @@ -93,72 +93,90 @@ container, holding the composition form. Then come the various messages. Then comes the 'more' button. --> - <ul t-name="mail.thread" class="oe_mail oe_mail_thread oe_semantic_html_override"> + <div t-name="mail.thread" class="oe_mail oe_mail_thread oe_semantic_html_override"> <div class="oe_mail_thread_action"> <!-- contains the composition box (form + image) --> <t t-call="mail.compose_message"/> </div> - <div class="oe_mail_thread_display"> + <ul class="oe_mail_thread_display"> <!-- contains the threads --> - </div> - <div class="oe_mail_thread_more"> - <button class="oe_mail_button_more" type="button">Load more messages</button> - </div> - </ul> + </ul> + </div> <!-- default layout --> - <li t-name="mail.thread.message" class="oe_mail oe_mail_thread_msg"> - <div t-attf-class="oe_mail_msg_#{record.type} oe_semantic_html_override"> - <img class="oe_mail_icon oe_mail_frame oe_left" t-att-src="record.avatar"/> + <li t-name="mail.thread.message" t-attf-class="oe_mail oe_mail_thread_msg #{widget.unread?'oe_mail_unread':'oe_mail_read'}" t-attf-data-msg_id="{widget.id}"> + <div t-attf-class="oe_mail_msg_#{widget.type} oe_semantic_html_override"> + <!-- message actions (read/unread, reply, delete...) --> + <ul class="oe_header"> + <li class="placeholder-mail-vote"><t t-call="mail.thread.message.vote"/></li> + <li t-if="!widget.options.thread.display_on_flat and widget.unread" title="Read"><a class="oe_read oe_e">W</a></li> + <li t-if="!widget.options.thread.display_on_flat and !widget.unread" title="Set back to unread"><a class="oe_unread oe_e">h</a></li> + <li t-if="!widget.options.message.show_reply_by_email" title="Reply"><a class="oe_reply oe_e">)</a></li> + <li t-if="widget.options.message.show_reply_by_email"><a class="oe_reply_by_email oe_e" title="Reply by mail">)</a></li> + <t t-if="(widget.options.message.show_reply || widget.options.message.show_reply_by_email || (widget.is_author and widget.options.message.show_dd_delete) || widget.type == 'email')"> + <li> + <span class="oe_dropdown_toggle"> + <a class="oe_e" title="More options">í</a> + <ul class="oe_dropdown_menu"> + <li t-if="widget.is_author and widget.options.message.show_dd_delete"><a class="oe_mail_msg_delete">Delete</a></li> + <!-- Uncomment when adding subtype hiding + <li t-if="display['show_hide']"> + <a href="#" class="oe_mail_msg_hide_type" t-attf-data-subtype='{widget.subtype}'>Hide '<t t-esc="widget.subtype"/>' for this document</a> + </li> --> + <li t-if="widget.options.message.show_reply" title="Reply"><a class="oe_reply oe_full_reply">Full reply</a></li> + <li t-if="widget.options.message.show_reply_by_email"><a class="oe_reply_by_email oe_full_reply" title="Reply by mail">Full reply</a></li> + <li t-if="widget.type == 'email'"><a class="oe_mail_msg_details" t-attf-href="#model=mail.message&id=#{widget.id}" >Details</a></li> + </ul> + </span> + </li> + </t> + </ul> + + <a t-attf-href="#model=res.partner&id=#{widget.author_id[0]}" t-att-title="widget.author_id[1]"> + <img class="oe_mail_icon oe_mail_frame oe_left" t-att-src="widget.avatar"/> + </a> + <div class="oe_mail_msg_content"> - <!-- dropdown menu with message options and actions --> - <span class="oe_dropdown_toggle oe_dropdown_arrow"> - <ul class="oe_dropdown_menu"> - <li t-if="record.is_author and options.show_dd_delete"><a class="oe_mail_msg_delete" t-attf-data-id='{record.id}'>Delete</a></li> - <li t-if="options.show_dd_hide"><a class="oe_mail_msg_hide" t-attf-data-id='{record.id}'>Remove notification</a></li> -<!-- Uncomment when adding subtype hiding - <li t-if="display['show_hide']"> - <a href="#" class="oe_mail_msg_hide_type" t-attf-data-subtype='{record.subtype}'>Hide '<t t-esc="record.subtype"/>' for this document</a> - </li> --> - <li t-if="options.show_dd_reply_by_email"><a class="oe_mail_msg_reply_by_email" t-attf-data-msg_id="{record.id}">Quote and reply</a></li> - <li t-if="record.type == 'email'"><a class="oe_mail_msg_details" t-attf-href="#model=mail.message&id=#{record.id}" >Details</a></li> - </ul> - </span> <!-- message itself --> <div class="oe_mail_msg"> - <h1 t-if="record.subject" class="oe_mail_msg_title"> - <t t-raw="record.subject"/> + <h1 t-if="widget.subject" class="oe_mail_msg_title"> + <t t-raw="widget.subject"/> </h1> - <div class="oe_mail_msg_body"> - <t t-if="options.show_record_name and record.record_name and (!record.subject) and (options.thread_level > 0)"> - <a t-attf-href="#model=#{record.model}&id=#{record.res_id}"><t t-raw="record.record_name"/></a> - </t> - <t t-raw="record.body"/> - </div> - <div class="oe_clear"/> <ul class="oe_mail_msg_footer"> - <li t-if="options.show_record_name and record.record_name and record.subject and options.thread_level > 0"> - <a t-attf-href="#model=#{record.model}&id=#{record.res_id}"><t t-raw="record.record_name"/></a> - </li> - <li><a t-attf-href="#model=res.partner&id=#{record.author_id[0]}"><t t-raw="record.author_id[1]"/></a></li> - <li><span t-att-title="record.date"><t t-raw="record.timerelative"/></span></li> - <t t-call="mail.thread.message.vote"/> - <li t-if="options.show_reply"><a class="oe_mail_msg_reply">Reply</a></li> - <li t-if="options.show_reply_by_email"><a class="oe_mail_msg_reply_by_email" t-attf-data-msg_id="{record.id}">Reply</a></li> - <li t-if="record.attachment_ids.length > 0"> + <li t-if="widget.author_id"><a t-attf-href="#model=res.partner&id=#{widget.author_id[0]}"><t t-raw="widget.author_id[1]"/></a></li> + <li><span t-att-title="widget.date"><t t-raw="widget.timerelative"/></span></li> + + <li t-if="widget.attachment_ids.length > 0"> <a class="oe_mail_msg_view_attachments"> - <t t-if="record.attachment_ids.length == 1">1 Attachment</t> - <t t-if="record.attachment_ids.length > 1"><t t-raw="record.attachment_ids.length"/> Attachments</t> + <t t-if="widget.attachment_ids.length == 1">1 Attachment</t> + <t t-if="widget.attachment_ids.length > 1"><t t-raw="widget.attachment_ids.length"/> Attachments</t> </a> </li> </ul> - <t t-if="record.attachment_ids.length > 0"> + <div class="oe_clear"/> + <div class="oe_mail_msg_body"> + <t t-if="widget.options.message.show_record_name and widget.record_name and (!widget.subject) and widget.options.thread._parents.length<=widget.options.thread.thread_level and widget.model!='res.partner'"> + <a class="oe_mail_action_model" t-attf-href="#model=#{widget.model}&id=#{widget.res_id}"><t t-raw="widget.record_name"/></a> + </t> + <t t-raw="widget.body"/> + </div> + <t t-if="widget.attachment_ids.length > 0"> <div class="oe_clear"></div> <t t-call="mail.thread.message.attachments"/> </t> </div> </div> </div> + <div class="oe_thread_placeholder"></div> + </li> + + <!-- expandable message layout --> + <li t-name="mail.thread.expandable" t-attf-class="oe_mail oe_mail_thread_msg oe_mail_unread" t-attf-data-thread_id="{widget.id}"> + <div t-attf-class="oe_mail_msg_#{widget.type} oe_semantic_html_override"> + <div class="oe_mail_msg_content oe_mail_msg_more_message"> + <a class="oe_mail_fetch_more">Load more messages <span t-if="widget.nb_messages>0">(<t t-raw="widget.nb_messages"/> messages not display)</span>...</a> + </div> + </div> </li> <!-- @@ -181,14 +199,25 @@ <!-- mail.thread.message.vote Template used to display Like/Unlike in a mail.message --> - <li t-name="mail.thread.message.vote"> - <t t-if='record.vote_user_ids.length > 0'> - <span class="oe_left oe_mail_vote_count"><t t-esc="record.vote_user_ids.length"/> votes</span> - </t> - <button t-attf-class="oe_mail_msg_vote oe_mail_msg_vote_#{record.has_voted}" t-attf-data-msg_id="{record.id}"> - <t t-if="! record.has_voted"><span>+1</span></t> - <t t-if="record.has_voted"><span>-1</span></t> + <span t-name="mail.thread.message.vote"> + <span class="oe_left oe_mail_vote_count"> + <t t-if='widget.has_voted'> + You + </t> + <t t-if='(widget.vote_user_ids.length-(widget.has_voted?1:0)) > 0'> + <t t-if='widget.has_voted'> and </t> + <t t-esc="widget.vote_user_ids.length"/> people + </t> + <t t-if='widget.vote_user_ids.length > 0'> + agree + </t> + </span> + <button t-attf-class="oe_mail_msg_vote oe_tag"> + <span> + <t t-if="!widget.has_voted">Agree</t> + <t t-if="widget.has_voted">Unagree</t> + </span> </button> - </li> + </span> </template> diff --git a/addons/mail/static/src/xml/mail_followers.xml b/addons/mail/static/src/xml/mail_followers.xml index 32ce34d48d1..a6df1f0fe8c 100644 --- a/addons/mail/static/src/xml/mail_followers.xml +++ b/addons/mail/static/src/xml/mail_followers.xml @@ -3,15 +3,28 @@ <!-- followers main template - Template used to display the followers and the actions in a record. + Template used to display the followers, the actions and the subtypes in a record. --> <div t-name="mail.followers" class="oe_mail_recthread_aside oe_semantic_html_override"> <div class="oe_mail_recthread_actions"> - <button type="button" class="oe_mail_button_invite">Invite</button> - <button type="button" class="oe_mail_button_follow">Follow</button> - <button type="button" class="oe_mail_button_unfollow oe_mail_button_mouseout">Following</button> + <div class="oe_mouse_subtypes"> + <button type="button" class="oe_follower oe_notfollow"> + <span class="oe_follow">Follow</span> + <span class="oe_unfollow">Unfollow</span> + <span class="oe_following">Following</span> + </button> + <div class="oe_recthread_subtypes"> + <ul class="oe_subtypes"></ul> + </div> + </div> + </div> + <div class="oe_grey"> + <t t-if="widget.options.comment"> + <h5><t t-raw="widget.options.comment"/></h5> + </t> </div> <div class="oe_mail_recthread_followers"> + <button type="button" class="oe_invite"><span>Invite</span></button> <t t-if="widget.options.title"> <h4><t t-raw="widget.options.title"/></h4> </t> @@ -26,6 +39,19 @@ <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.partner&id=#{record.id}"><t t-raw="record.name"/></a> + </li>\ + + <!-- + followers.subtype template + Template used to display message subtypes of a follower subscription + --> + <li t-name="mail.followers.subtype"> + <table width="50%"> + <tr> + <td><label t-att-for="'input_mail_followers_subtype_'+record.id"><t t-raw="record.name"/></label></td> + <td width="10%"><input type="checkbox" t-att-checked="record.followed" t-att-id="'input_mail_followers_subtype_'+record.id" t-att-data-id="record.id" t-att-name="record.name" class="oe_msg_subtype_check"/></td> + </tr> + </table> </li> </template> |
