summaryrefslogtreecommitdiff
path: root/addons/website_mail/static/src
diff options
context:
space:
mode:
authorDamien Bouvy <dbo@odoo.com>2015-08-06 11:59:28 +0200
committerAntony Lesuisse <al@openerp.com>2015-08-07 01:47:06 +0200
commitad081b0da128adc5a1454eabf17c5d438eee42fa (patch)
tree854df99336b8b554d0387da0a1f6640da6a1b617 /addons/website_mail/static/src
parent5f48cb992e75a31ae8d60d7a574b178f5fa01192 (diff)
[IMP] website_mail: generic chatter implementation
A new generic chatter template is available in website_mail This template allows access rights escalation when some kind of token or uuid is available on the model or if you use the object_shasign function in the main controller of website_maill to generate a cryptographic signature to allow commenting on any object. To use this chatter, you need to make a t-call to website_maill.thread in your template after having set the following variables: - chatter_object: the browserecord of the mail_thread object (mandatory) - token: if you use a token system (optional) - token_field: name of the field that stores the token on your object (optional) - sha_in: if you use a shasign to allow public comment (optional) - nosubscribe: set False if you want the partner to be set as follower of the object (optional) - message_type, subtype: see message_post in mail_thread.py
Diffstat (limited to 'addons/website_mail/static/src')
-rw-r--r--addons/website_mail/static/src/js/message_post.js49
-rw-r--r--addons/website_mail/static/src/xml/chatter_message.xml15
2 files changed, 64 insertions, 0 deletions
diff --git a/addons/website_mail/static/src/js/message_post.js b/addons/website_mail/static/src/js/message_post.js
new file mode 100644
index 00000000000..177101bcce1
--- /dev/null
+++ b/addons/website_mail/static/src/js/message_post.js
@@ -0,0 +1,49 @@
+odoo.define('website_mail_post', function(require) {
+ 'use strict';
+ require('website.website');
+ var qweb = require('qweb');
+ var ajax = require('web.ajax');
+ ajax.loadXML('/website_mail/static/src/xml/chatter_message.xml', qweb);
+
+ if(!$('.o_website_chatter_json').length) {
+ return $.Deferred().reject("DOM doesn't contain '.o_website_chatter_json'");
+ }
+
+ $('.o_website_chatter_json').on('click', function(ev) {
+ ev.preventDefault();
+ var $button = $(this);
+ var $form = $(this).parents().find('.o_website_chatter_form');
+ var action = $form.attr('action');
+ var data = getFormData($form);
+ data.message = data.message.replace(/\n/g,"<br/>");
+ if (data.message) {
+ $button.attr('disabled', true);
+ var button_bk = $button.html();
+ $button.prepend('<i class="fa fa-refresh fa-spin"></i> ');
+ ajax.jsonRpc(action, 'call', data).then(function (result) {
+ if (result) {
+ $('.o_website_chatter_error').fadeOut();
+ var msg = qweb.render('website_mail.thread_message', result);
+ var elem = $(msg).hide().prependTo($('.o_website_comments'));
+ elem.slideToggle();
+ $form.find('textarea').val('');
+ } else {
+ $('o_website_chatter_error').fadeIn();
+ }
+ $button.html(button_bk);
+ $button.attr('disabled', false);
+ });
+ }
+
+ function getFormData($form){
+ var unindexed_array = $form.serializeArray();
+ var indexed_array = {};
+
+ $.map(unindexed_array, function(n, i){
+ indexed_array[n.name] = n.value;
+ });
+
+ return indexed_array;
+ }
+ });
+});
diff --git a/addons/website_mail/static/src/xml/chatter_message.xml b/addons/website_mail/static/src/xml/chatter_message.xml
new file mode 100644
index 00000000000..dec459c0f18
--- /dev/null
+++ b/addons/website_mail/static/src/xml/chatter_message.xml
@@ -0,0 +1,15 @@
+<templates id="template" xml:space="preserve">
+ <t t-name="website_mail.thread_message">
+ <li class="media">
+ <div class="media-body">
+ <img class="media-object pull-left" t-att-src="image_url" style="width: 50px; margin-right: 10px;"/>
+ <div class="media-body">
+ <h5 class="media-heading">
+ <span t-esc="author"/> <small>just now</small>
+ </h5>
+ <div t-raw="body"/>
+ </div>
+ </div>
+ </li>
+ </t>
+</templates> \ No newline at end of file