[IMP] Improved ThreadView widget display; cleaned ThreadView widget js code; added basic access rules; added message_mark_done method to clean a mail.thread of its need_action_user_id; added auto-push of notifications if user requested to perform an action is not following the object; added first draft of messaging mechanism in hr_holidays
bzr revid: tde@openerp.com-20120208152521-68i4nekjj8mnuyc8
This commit is contained in:
@@ -93,6 +93,7 @@ class hr_holidays(osv.osv):
|
||||
_name = "hr.holidays"
|
||||
_description = "Leave"
|
||||
_order = "type desc, date_from asc"
|
||||
_inherit = ['mail.thread']
|
||||
|
||||
def _employee_get(self, cr, uid, context=None):
|
||||
ids = self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context)
|
||||
@@ -250,8 +251,16 @@ class hr_holidays(osv.osv):
|
||||
obj_emp = self.pool.get('hr.employee')
|
||||
ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)])
|
||||
manager = ids2 and ids2[0] or False
|
||||
self.holidays_validate_notificate(cr, uid, ids, context=context)
|
||||
return self.write(cr, uid, ids, {'state':'validate1', 'manager_id': manager})
|
||||
|
||||
def holidays_validate_notificate(self, cr, uid, ids, context=None):
|
||||
for obj in self.browse(cr, uid, ids):
|
||||
self.message_mark_done(cr, uid, [obj.id], context=context)
|
||||
self.message_append_note(cr, uid, [obj.id], 'System notification', _("The %s request '%s' has been validated.") % ('leave' if obj.type == 'remove' else 'allocation', obj.name,), type='notification', context=context)
|
||||
if obj.holiday_status_id.double_validation:
|
||||
self.message_append_note(cr, uid, [obj.id], 'System notification', _("The %s request '%s' is waiting for second validation.") % ('leave' if obj.type == 'remove' else 'allocation', obj.name,), type='notification', context=context)
|
||||
|
||||
def holidays_validate2(self, cr, uid, ids, context=None):
|
||||
self.check_holidays(cr, uid, ids, context=context)
|
||||
obj_emp = self.pool.get('hr.employee')
|
||||
@@ -301,13 +310,23 @@ class hr_holidays(osv.osv):
|
||||
wf_service.trg_validate(uid, 'hr.holidays', leave_id, 'validate', cr)
|
||||
wf_service.trg_validate(uid, 'hr.holidays', leave_id, 'second_validate', cr)
|
||||
if holiday_ids:
|
||||
self.holidays_valid2_notificate(self, cr, uid, [holiday_ids], context=context)
|
||||
self.write(cr, uid, holiday_ids, {'manager_id2': manager})
|
||||
return True
|
||||
|
||||
def holidays_valid2_notificate(self, cr, uid, ids, context=None):
|
||||
for obj in self.browse(cr, uid, ids):
|
||||
self.message_append_note(cr, uid, [obj.id], 'System notification', _("The %s request '%s' has been double validated.") % ('leave' if obj.type == 'remove' else 'allocation', obj.name,), type='notification', context=context)
|
||||
|
||||
def holidays_confirm(self, cr, uid, ids, context=None):
|
||||
self.check_holidays(cr, uid, ids, context=context)
|
||||
self.holidays_confirm_notificate(cr, uid, ids, context=context)
|
||||
return self.write(cr, uid, ids, {'state':'confirm'})
|
||||
|
||||
|
||||
def holidays_confirm_notificate(self, cr, uid, ids, context=None):
|
||||
for obj in self.browse(cr, uid, ids):
|
||||
self.message_append_note(cr, uid, [obj.id], 'System notification', _("The %s request '%s' has been confirmed and is waiting for validation.") % ('leave' if obj.type == 'remove' else 'allocation', obj.name,), type='notification', need_action_user_id=obj.employee_id.parent_id.user_id.id)
|
||||
|
||||
def holidays_refuse(self, cr, uid, ids, approval, context=None):
|
||||
obj_emp = self.pool.get('hr.employee')
|
||||
ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)])
|
||||
|
||||
@@ -95,6 +95,7 @@
|
||||
<button string="Approved" name="second_validate" states="validate1" type="workflow" icon="gtk-apply" groups="base.group_hr_user"/>
|
||||
<button string="Set to Draft" name="set_to_draft" states="refuse,validate" type="object" icon="gtk-convert" groups="base.group_hr_user"/>
|
||||
</group>
|
||||
<field name="message_ids_social" colspan="4" widget="ThreadView" nolabel="1"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
|
||||
@@ -49,12 +49,6 @@ class mail_group(osv.osv):
|
||||
|
||||
return True
|
||||
|
||||
def action_test(self, cr, uid, ids, context={}):
|
||||
for o in self.browse(cr, uid, ids):
|
||||
message = _('You are doing things with the group %s, wooooh !') % (o.name,)
|
||||
self.log(cr, uid, o.id, message)
|
||||
return True
|
||||
|
||||
def action_null(self, cr, uid, ids, context={}):
|
||||
return True
|
||||
|
||||
|
||||
@@ -49,9 +49,7 @@
|
||||
<label string="This group is visible by non members" colspan="2"/>
|
||||
</group>
|
||||
<separator string="Test actions" colspan="4"/>
|
||||
<button name="action_test" string="Test" type="object" icon="gtk-go-forward" colspan="2"/>
|
||||
<button name="action_null" string="Test2" type="object" icon="gtk-go-forward" colspan="2"/>
|
||||
<separator string="OpenChatter" colspan="4"/>
|
||||
<field name="message_ids_social" colspan="4" widget="ThreadView" nolabel="1"/>
|
||||
</form>
|
||||
</field>
|
||||
@@ -84,15 +82,5 @@
|
||||
<!-- left-side Tmp: temporary Groups link to see groups !-->
|
||||
<menuitem id="mg_groups_tmp" name="Groups" parent="mg_tmp" action="action_view_groups"/>
|
||||
|
||||
<act_window
|
||||
context="{}"
|
||||
domain="[('res_model', '=', active_model), ('res_id', '=', active_id)]"
|
||||
id="act_group_see_followers"
|
||||
name="See followers"
|
||||
res_model="mail.subscription"
|
||||
src_model="mail.group"
|
||||
view_mode="kanban,tree,form"
|
||||
view_type="form"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -197,17 +197,23 @@ class mail_message(osv.osv):
|
||||
#------------------------------------------------------
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
# OpenSocial: notifications do not come from any user but from system
|
||||
if vals['type'] == 'notification': vals['user_id'] = False
|
||||
need_action_pushed = False
|
||||
msg_id = super(mail_message, self).create(cr, uid, vals, context)
|
||||
# push the message to suscribed users
|
||||
subscription_obj = self.pool.get('mail.subscription')
|
||||
notification_obj = self.pool.get('mail.notification')
|
||||
sub_ids = subscription_obj.search(cr, uid, ['&', '&',
|
||||
sub_ids = subscription_obj.search(cr, uid, ['&',
|
||||
('res_model', '=', vals['model']),
|
||||
('user_id', '=', uid),
|
||||
('res_id', '=', vals['res_id'])], context=context)
|
||||
subs = subscription_obj.browse(cr, uid, sub_ids, context=context)
|
||||
for sub in subs:
|
||||
notification_obj.create(cr, uid, {'user_id': sub.user_id, 'message_id': msg_id}, context=context)
|
||||
if vals['need_action_user_id'] == sub.user_id: need_action_pushed = True
|
||||
# push to need_action_user_id if user does not follow the object
|
||||
if vals['need_action_user_id'] != False and not need_action_pushed:
|
||||
notification_obj.create(cr, uid, {'user_id': vals['need_action_user_id'], 'message_id': msg_id}, context=context)
|
||||
return msg_id
|
||||
|
||||
def get_pushed_messages(self, cr, uid, context=None):
|
||||
|
||||
@@ -506,10 +506,8 @@ class mail_thread(osv.osv):
|
||||
# Note specific
|
||||
#------------------------------------------------------
|
||||
|
||||
def message_append_note(self, cr, uid, ids, subject, body, type='notification', need_action=False,
|
||||
need_action_user_id=False, context=None):
|
||||
return self.message_append(cr, uid, ids, subject, body_text=body, type=type, need_action=need_action,
|
||||
need_action_user_id=need_action_user_id, context=context)
|
||||
def message_append_note(self, cr, uid, ids, subject, body, type='notification', need_action_user_id=False, context=None):
|
||||
return self.message_append(cr, uid, ids, subject, body_text=body, type=type, need_action_user_id=need_action_user_id, context=context)
|
||||
|
||||
# old log overrided method: now calls message_append_note
|
||||
def log(self, cr, uid, id, message, secondary=False, context=None):
|
||||
@@ -523,8 +521,17 @@ class mail_thread(osv.osv):
|
||||
if context and context.get('disable_log'):
|
||||
#return True # old behavior
|
||||
print 'Log diabled, but we do not care currently about that. We want you to have our logs !'
|
||||
return self.message_append_note(cr, uid, [id], 'System notification', message, context=context)
|
||||
#return self.message_append_note(cr, uid, [id], 'System notification', message, context=context)
|
||||
|
||||
def message_mark_done(self, cr, uid, ids, context=None):
|
||||
""" OpenSocial add: mark a need_action message sa done
|
||||
Find by: res_id (thread id), model (self._name), need_action_user_id != false
|
||||
"""
|
||||
msg_obj = self.pool.get('mail.message')
|
||||
for id in ids:
|
||||
msg_ids = msg_obj.search(cr, uid, ['&', ('res_id', '=', id), ('model', '=', self._name)], context=context)
|
||||
msg_obj.write(cr, uid, msg_ids, {'need_action_user_id': False}, context=context)
|
||||
|
||||
#------------------------------------------------------
|
||||
# Subscription mechanism
|
||||
#------------------------------------------------------
|
||||
|
||||
@@ -50,5 +50,15 @@
|
||||
<field name="act_window_id" ref="action_view_mailgate_thread"/>
|
||||
</record>
|
||||
|
||||
<act_window
|
||||
context="{}"
|
||||
domain="[('res_model', '=', active_model), ('res_id', '=', active_id)]"
|
||||
id="act_thread_see_followers"
|
||||
name="See followers"
|
||||
res_model="mail.subscription"
|
||||
src_model="mail.thread"
|
||||
view_mode="tree,form"
|
||||
view_type="form"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_mail_message,mail.message,model_mail_message,,1,0,1,0
|
||||
access_mail_thread,mail.thread,model_mail_thread,,1,0,1,0
|
||||
access_mail_subscription,mail.subscription,model_mail_subscription,,1,0,1,0
|
||||
access_mail_notification,mail.notification,model_mail_notification,,1,0,1,0
|
||||
|
||||
|
@@ -1,13 +1,25 @@
|
||||
/** ThreadView widget **/
|
||||
|
||||
.oe_mail_comment {
|
||||
.oe_mail_main {
|
||||
}
|
||||
|
||||
.oe_mail_actions {
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.oe_mail_post_comment {
|
||||
width: 65%;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.oe_mail_comments {
|
||||
width: 65%;
|
||||
border: 4px solid #770033;
|
||||
}
|
||||
|
||||
.oe_mail_msg {
|
||||
width: 80%;
|
||||
border: 4px solid #998877;
|
||||
width: 65%;
|
||||
/* border: 1px solid #998877; */
|
||||
padding: 10px 0px 10px 0px;
|
||||
}
|
||||
|
||||
.oe_mail_msg:after {
|
||||
@@ -18,27 +30,32 @@
|
||||
|
||||
.oe_mail_msg_image {
|
||||
float: left;
|
||||
width: 10%;
|
||||
width: 9%;
|
||||
}
|
||||
|
||||
.oe_mail_msg_content {
|
||||
float: right;
|
||||
width: 80%;
|
||||
border: 4px solid #557722;
|
||||
width: 89%;
|
||||
margin-left: 10%;
|
||||
/* border: 1px solid #557722; */
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.oe_mail_msg_p {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.oe_mail_msg_body {
|
||||
}
|
||||
|
||||
.oe_mail_msg_author {
|
||||
color: #4E43E7;
|
||||
}
|
||||
|
||||
.oe_mail_msg_need_action {
|
||||
color: #C03000;
|
||||
}
|
||||
|
||||
.oe_mail_msg_date {
|
||||
}
|
||||
|
||||
.oe_mail_msg_p {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
width: 25%;
|
||||
word-wrap: break-word;
|
||||
color: #4E43E7;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ openerp.mail = function(session) {
|
||||
|
||||
session.web.form.widgets.add(
|
||||
'ThreadView', 'openerp.mail.ThreadView');
|
||||
session.web.page.readonly.add(
|
||||
'ThreadView', 'openerp.mail.ThreadView');
|
||||
|
||||
/* ThreadView Widget: thread of comments */
|
||||
mail.ThreadView = session.web.form.Field.extend({
|
||||
@@ -11,17 +13,16 @@ openerp.mail = function(session) {
|
||||
template: 'ThreadView',
|
||||
|
||||
init: function() {
|
||||
this.timeout;
|
||||
// this.timeout;
|
||||
this.follow_state = 0;
|
||||
this._super.apply(this, arguments);
|
||||
/* DataSets */
|
||||
this.ds = new session.web.DataSet(this, this.view.model);
|
||||
this.ds_sub = new session.web.DataSet(this, 'mail.subscription');
|
||||
this.ds_msg = new session.web.DataSet(this, 'mail.message');
|
||||
// this.ds_msg = new session.web.DataSet(this, 'mail.message');
|
||||
},
|
||||
|
||||
start: function() {
|
||||
console.log('Entering start');
|
||||
var self = this;
|
||||
this._super.apply(this, arguments);
|
||||
/* bind follow and unfollow buttons */
|
||||
@@ -32,27 +33,20 @@ openerp.mail = function(session) {
|
||||
self.$element.find('button.oe_mail_action_comment').bind('click', function () { self.do_comment(); });
|
||||
/* find wich (un)follow buttons to show */
|
||||
var call_res = this.ds.call('message_is_subscriber', [[this.session.uid]]).then(function (records) {
|
||||
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(); }
|
||||
if (records == true) { self.follow_state = 1; self.$element.find('button.oe_mail_action_unfollow').show(); }
|
||||
else { self.follow_state = 0; self.$element.find('button.oe_mail_action_follow').show(); }
|
||||
});
|
||||
console.log(call_res);
|
||||
console.log('Leaving start');
|
||||
},
|
||||
|
||||
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; }
|
||||
var fetch_res = this.fetch_messages();
|
||||
console.log('Leaving set_value');
|
||||
return fetch_res
|
||||
return this.fetch_messages();
|
||||
},
|
||||
|
||||
fetch_messages: function () {
|
||||
@@ -61,40 +55,34 @@ openerp.mail = function(session) {
|
||||
},
|
||||
|
||||
display_records: function (records) {
|
||||
console.log(records);
|
||||
// this.$element.empty();
|
||||
this.$element.find('div.oe_mail_comments').empty();
|
||||
var self = this;
|
||||
_(records).each(function (record) {
|
||||
var template = 'ThreadMsgView';
|
||||
var render_res = session.web.qweb.render(template, {
|
||||
'record': record,
|
||||
});
|
||||
$('<div>').html(render_res).appendTo(self.$element);
|
||||
$('<div class="oe_mail_msg">').html(render_res).appendTo(self.$element.find('div.oe_mail_comments'));
|
||||
});
|
||||
// this.timeout = setTimeout(this.proxy('fetch_messages'), 5000);
|
||||
},
|
||||
|
||||
do_follow: function () {
|
||||
console.log('Follow');
|
||||
console.log(this);
|
||||
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'));
|
||||
return this.ds_sub.create({'res_model': this.view.model, 'user_id': this.session.uid, 'res_id': this.view.datarecord.id}).then();
|
||||
},
|
||||
|
||||
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'));
|
||||
return this.ds.call('message_unsubscribe', [[this.view.datarecord.id]]).then();
|
||||
},
|
||||
|
||||
do_comment: function () {
|
||||
console.log('Comment');
|
||||
var body_text = this.$element.find('textarea').val();
|
||||
return this.ds_msg.call('create', [{'model': this.view.model, 'user_id': this.session.uid, 'res_id': this.view.datarecord.id, 'body_text': body_text, 'subject': 'Reply comment'}]).then(console.log('Comment posted'));
|
||||
return this.ds.call('message_append_note', [[this.view.datarecord.id], 'Reply comment', body_text, type='comment']).then(
|
||||
this.proxy('fetch_messages'));
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,33 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<template>
|
||||
|
||||
<div t-name="ThreadView">
|
||||
<div t-name="ThreadView" class="oe_mail_main">
|
||||
<div class="separator horizontal">OpenSocial</div>
|
||||
<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">
|
||||
<div class="oe_mail_post_comment">
|
||||
<textarea rows="3" cols="15">Type your comment</textarea><br />
|
||||
<button type="button" class="oe_mail_action_comment">Post comment</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div t-name="ThreadMsgView">
|
||||
<div class="oe_mail_msg">
|
||||
<!-- <p style="border: 3px solid #332299;"> -->
|
||||
zmeofizepofinzepfoiznepfoizpfozeinfpzoeinfpoznf zfe zef zef ze fz efz efz ef zef ze fz efznf zfe zef zef ze fz efz efz ef zef ze fz efznf zfe zef zef ze fz efz efz ef zef ze fz ef
|
||||
<!-- </p> -->
|
||||
<div class="oe_mail_msg_image">Image</div>
|
||||
<div class="oe_mail_msg_content">
|
||||
<p class="oe_mail_msg_p">
|
||||
zmeofizepofinzepfoiznepfoizpfozeinfpzoeinfpoznf zfe zef zef ze fz efz efz ef zef ze fz efznf zfe zef zef ze fz efz efz ef zef ze fz efznf zfe zef zef ze fz efz efz ef zef ze fz ef
|
||||
<!-- <t t-raw="record.body_text"/> -->
|
||||
<!-- <span class="oe_mail_msg_body"><t t-raw="record.body_text"/></span><br /> -->
|
||||
<!-- <span class="oe_mail_msg_author"><t t-raw="record.user_id[1]"/></span><br /> -->
|
||||
<!-- <span class="oe_mail_msg_date"><t t-raw="record.date"/></span> -->
|
||||
</p>
|
||||
</div>
|
||||
<div class="oe_mail_comments">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<t t-name="ThreadMsgView">
|
||||
<div class="oe_mail_msg_image">Image</div>
|
||||
<div class="oe_mail_msg_content">
|
||||
<p class="oe_mail_msg_p">
|
||||
<t t-if="record.type == 'notification'">
|
||||
<span class="oe_mail_msg_author">OpenERP System Notification</span>
|
||||
</t>
|
||||
<t t-if="record.type == 'comment'">
|
||||
<span class="oe_mail_msg_author"><t t-raw="record.user_id[1]"/></span>
|
||||
</t>
|
||||
<t t-if="record.type == 'email'">
|
||||
<span class="oe_mail_msg_author"><t t-raw="record.user_id[1]"/></span>
|
||||
</t>
|
||||
<t t-if="record.need_action_user_id != false">- <span class="oe_mail_msg_need_action">Need action</span></t>
|
||||
<br />
|
||||
<span class="oe_mail_msg_body"><t t-raw="record.body_text"/></span><br />
|
||||
<span class="oe_mail_msg_date"><t t-raw="record.date"/></span>
|
||||
</p>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
</template>
|
||||
Reference in New Issue
Block a user