[IMP] Improved ThradView widget: follow/unfollow mechanism, draft of comment post mechanism
bzr revid: tde@openerp.com-20120206151009-qvfutg9n6ytffxei
This commit is contained in:
parent
9a8782ba05
commit
2a73f8bdd1
|
@ -66,7 +66,8 @@ class mail_thread(osv.osv):
|
|||
'message_ids': fields.one2many('mail.message', 'res_id', 'Messages', readonly=True),
|
||||
'message_ids_social': fields.function(_get_message_ids, method=True,
|
||||
type='one2many', obj='mail.message', string='Temp messages',
|
||||
widget='mail.ThreadView'),
|
||||
),
|
||||
#widget='mail.ThreadView'),
|
||||
}
|
||||
|
||||
#------------------------------------------------------
|
||||
|
@ -523,7 +524,17 @@ class mail_thread(osv.osv):
|
|||
sub_ids = subscription_obj.search(cr, uid, ['&', ('res_model', '=', self._name), ('res_id', '=', id)], context=context)
|
||||
subs = subscription_obj.browse(cr, uid, sub_ids, context=context)
|
||||
return subs
|
||||
|
||||
|
||||
def message_is_subscriber(self, cr, uid, ids, context=None):
|
||||
print uid
|
||||
print ids
|
||||
subs = self.message_get_subscribers(cr, uid, ids, context=context)
|
||||
for sub in subs:
|
||||
print sub
|
||||
print sub.user_id
|
||||
if sub.user_id == uid: return True
|
||||
return False
|
||||
|
||||
def message_subscribe(self, cr, uid, ids, context=None):
|
||||
subscription_obj = self.pool.get('mail.subscription')
|
||||
subscriber_id = uid # TODO
|
||||
|
|
|
@ -8,31 +8,64 @@ openerp.mail = function(session) {
|
|||
/* ThreadView Widget: thread of comments */
|
||||
mail.ThreadView = session.web.form.Field.extend({
|
||||
// QWeb template to use when rendering the object
|
||||
template: 'MailTest',
|
||||
template: 'ThreadView',
|
||||
|
||||
init: function() {
|
||||
console.log('Entering init');
|
||||
// this.timeout;
|
||||
this.follow_state = 0;
|
||||
this._super.apply(this, arguments);
|
||||
this.ds = new session.web.DataSet(this, this.view.model);
|
||||
this.ds_sub = new session.web.DataSet(this, 'mail.subscription');
|
||||
console.log('Leaving init');
|
||||
},
|
||||
|
||||
start: function() {
|
||||
console.log('Entering start');
|
||||
var self = this;
|
||||
this._super.apply(this, arguments);
|
||||
/* bind follow and unfollow buttons */
|
||||
self.$element.find('button.oe_mail_action_follow').bind('click', function () { self.do_follow(); });
|
||||
self.$element.find('button.oe_mail_action_follow').hide();
|
||||
self.$element.find('button.oe_mail_action_unfollow').bind('click', function () { self.do_unfollow(); });
|
||||
self.$element.find('button.oe_mail_action_unfollow').hide();
|
||||
/* find wich (un)follow buttons to show */
|
||||
var call_res = this.ds.call('message_is_subscriber', [[this.session.uid]]).then(function (records) {
|
||||
console.log('Pouet');
|
||||
console.log(records);
|
||||
console.log('Pouet2');
|
||||
if (records == true) { self.follow_state = 1; console.log('brout!'); self.$element.find('button.oe_mail_action_unfollow').show(); }
|
||||
else { self.follow_state = 0; console.log('proutch!'); self.$element.find('button.oe_mail_action_follow').show(); }
|
||||
});
|
||||
console.log(call_res);
|
||||
console.log('Leaving start');
|
||||
},
|
||||
|
||||
render: function() {
|
||||
console.log('Entering render');
|
||||
// this._super.apply(this, arguments);
|
||||
var template = this.template;
|
||||
var render_res = session.web.qweb.render(template, {
|
||||
'tmp': 'comment',
|
||||
});
|
||||
console.log('Leaving render');
|
||||
return render_res;
|
||||
},
|
||||
|
||||
stop: function () {
|
||||
// clearTimeout(this.timeout);
|
||||
console.log('Entering stop');
|
||||
this._super();
|
||||
console.log('Leaving stop');
|
||||
},
|
||||
|
||||
set_value: function() {
|
||||
console.log('Entering set_value');
|
||||
this._super.apply(this, arguments);
|
||||
if (! this.view.datarecord.id) { return; }
|
||||
return this.fetch_messages();
|
||||
var fetch_res = this.fetch_messages();
|
||||
console.log('Leaving set_value');
|
||||
return fetch_res
|
||||
},
|
||||
|
||||
fetch_messages: function () {
|
||||
|
@ -57,12 +90,16 @@ openerp.mail = function(session) {
|
|||
do_follow: function () {
|
||||
console.log('Follow');
|
||||
console.log(this);
|
||||
this.ds_sub.create({'res_model': this.view.model, 'user_id': this.session.uid, 'res_id': this.view.datarecord.id}).then(
|
||||
this.$element.find('button.oe_mail_action_unfollow').show();
|
||||
this.$element.find('button.oe_mail_action_follow').hide();
|
||||
return this.ds_sub.create({'res_model': this.view.model, 'user_id': this.session.uid, 'res_id': this.view.datarecord.id}).then(
|
||||
console.log('Subscription done'));
|
||||
},
|
||||
|
||||
do_unfollow: function () {
|
||||
console.log('Unfollow');
|
||||
this.$element.find('button.oe_mail_action_follow').show();
|
||||
this.$element.find('button.oe_mail_action_unfollow').hide();
|
||||
return this.ds.call('message_unsubscribe', [[this.view.datarecord.id]]).then(
|
||||
console.log('Unfollowing'));
|
||||
}
|
||||
|
|
|
@ -1,25 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<template>
|
||||
|
||||
<div t-name="MailTest">
|
||||
<button type="button" class="oe_mail_action_follow">
|
||||
Follow
|
||||
<!-- <img src="/edi/static/src/img/pdf.png"/> -->
|
||||
</button>
|
||||
<button type="button" class="oe_mail_action_unfollow">
|
||||
Unfollow
|
||||
<!-- <img src="/edi/static/src/img/pdf.png"/> -->
|
||||
</button>
|
||||
<p>Bladivoctock !</p>
|
||||
<t t-if="type=='comment'">Blougiboulga !!</t>
|
||||
<p>Ouagadougou</p>
|
||||
<div t-name="ThreadView">
|
||||
<div class="oe_mail_actions">
|
||||
<button type="button" class="oe_mail_action_follow">Follow</button>
|
||||
<button type="button" class="oe_mail_action_unfollow">Unfollow</button>
|
||||
</div>
|
||||
<div class="oe_mail_comment">
|
||||
<textarea rows="2" cols="15">Type your comment</textarea>
|
||||
<button type="button" class="oe_mail_action_comment">Post comment</button>
|
||||
</div>
|
||||
<div>
|
||||
<p>
|
||||
<t t-if="tmp=='comment'">Variable tmp valant comment</t>
|
||||
<t t-if="tmp=='note'">Variable tmp valant note</t>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- <t t-extend="ViewManagerAction">
|
||||
<t t-jquery=".oe-shortcut-toggle" t-operation="after">
|
||||
<a class="oe-share_link" href="#share_link" title="Follow">Follow</a>
|
||||
<a class="oe-share" href="#share" title="Unfollow">Unfollow</a>
|
||||
</t>
|
||||
</t>-->
|
||||
|
||||
</template>
|
Loading…
Reference in New Issue