[IMP] Reduced code, deleted redundant code, deleted the edit template and used it in the existing by using 'mode' and improved code using the existing code and removed unwanted code.
bzr revid: psa@tinyerp.com-20130321124036-0s4pv3oivzesmjh5
This commit is contained in:
@@ -126,6 +126,8 @@ class mail_thread(osv.AbstractModel):
|
||||
for id in ids:
|
||||
res[id]['message_subtype_data'] = subtype_dict.copy()
|
||||
|
||||
if context and 'partner_id' in context:
|
||||
user_pid = context.get('partner_id')
|
||||
# find the document followers, update the data
|
||||
fol_obj = self.pool.get('mail.followers')
|
||||
fol_ids = fol_obj.search(cr, uid, [
|
||||
@@ -138,6 +140,7 @@ class mail_thread(osv.AbstractModel):
|
||||
for subtype in fol.subtype_ids:
|
||||
thread_subtype_dict[subtype.name]['followed'] = True
|
||||
res[fol.res_id]['message_subtype_data'] = thread_subtype_dict
|
||||
|
||||
return res
|
||||
|
||||
def _search_message_unread(self, cr, uid, obj=None, name=None, domain=None, context=None):
|
||||
@@ -289,34 +292,8 @@ class mail_thread(osv.AbstractModel):
|
||||
default['message_follower_ids'] = []
|
||||
return super(mail_thread, self).copy(cr, uid, id, default=default, context=context)
|
||||
|
||||
#------------------------------------------------------
|
||||
# Edit and apply followers subtypes.
|
||||
#------------------------------------------------------
|
||||
def edit_followers_subtype(self, cr, uid, ids, partner_id, context=None):
|
||||
res = dict((id, dict(message_subtype_data='')) for id in ids)
|
||||
|
||||
subtype_obj = self.pool.get('mail.message.subtype')
|
||||
subtype_ids = subtype_obj.search(cr, uid, ['|', ('res_model', '=', self._name), ('res_model', '=', False)], context=context)
|
||||
subtype_dict = dict((subtype.name, dict(default=subtype.default, followed=False, id=subtype.id)) for subtype in subtype_obj.browse(cr, uid, subtype_ids, context=context))
|
||||
for id in ids:
|
||||
res[id]['message_subtype_data'] = subtype_dict.copy()
|
||||
|
||||
fol_obj = self.pool.get('mail.followers')
|
||||
fol_ids = fol_obj.search(cr, uid, [
|
||||
('partner_id', '=', partner_id),
|
||||
('res_id', 'in', ids),
|
||||
('res_model', '=', self._name),
|
||||
], context=context)
|
||||
for fol in fol_obj.browse(cr, uid, fol_ids, context=context):
|
||||
thread_subtype_dict = res[fol.res_id]['message_subtype_data']
|
||||
for subtype in fol.subtype_ids:
|
||||
thread_subtype_dict[subtype.name]['followed'] = True
|
||||
res[fol.res_id]['message_subtype_data'] = thread_subtype_dict
|
||||
return res
|
||||
|
||||
def apply_edited_subtypes(self, cr, uid, ids, partner_id, check_list, context=None):
|
||||
""" Apply the edited subtypes
|
||||
of the user."""
|
||||
""" Apply the edited subtypes of the user."""
|
||||
fol_obj = self.pool.get('mail.followers')
|
||||
fol_ids = fol_obj.search(cr, uid, [
|
||||
('partner_id', '=', partner_id),
|
||||
|
||||
@@ -81,37 +81,27 @@ openerp_mail_followers = function(session, mail) {
|
||||
|
||||
on_edit_subtype: function(event) {
|
||||
var self = this;
|
||||
var records = [];
|
||||
var partner_id = $(event.target).data('id');
|
||||
var partner_name = $(event.target).siblings('a').text();
|
||||
var id = this.view.datarecord.id;
|
||||
var res_model = this.view.dataset.model;
|
||||
var $dialog = new session.web.dialog($('<div class = "oe_edit_actions">'), {
|
||||
var context = new session.web.CompoundContext(this.build_context(), {'partner_id': partner_id});
|
||||
self.$dialog = new session.web.dialog($('<div class = "oe_edit_actions">'), {
|
||||
modal: true,
|
||||
title: _t('Edit Subtypes of ') + '"' + partner_name + '"',
|
||||
width: 'auto',
|
||||
height: 'auto',
|
||||
title: _t('Edit Subscriptions of ') + $(event.target).siblings('a').text(),
|
||||
buttons: [
|
||||
{ text: _t("Apply"), click: function() {
|
||||
self.on_apply_subtype(id, partner_id);
|
||||
self.on_apply_subtype(partner_id);
|
||||
$(this).remove();
|
||||
}},
|
||||
{ text: _t("Cancel"), click: function() { $(this).remove(); }}
|
||||
],
|
||||
});
|
||||
this.ds_model.call('edit_followers_subtype', [[id], partner_id, new session.web.CompoundContext(this.build_context(), {})])
|
||||
.then(function (data) {
|
||||
if (data[id]) {
|
||||
records = data[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.edit.subtype", {'record': record})).appendTo($dialog);
|
||||
});
|
||||
});
|
||||
return self.fetch_subtypes(context);
|
||||
},
|
||||
|
||||
on_apply_subtype: function(id, partner_id) {
|
||||
on_apply_subtype: function(partner_id) {
|
||||
var check_list = new Array();
|
||||
var id = this.view.datarecord.id;
|
||||
_($('.oe_edit_actions input[type="checkbox"]')).each(function (record) {
|
||||
if ($(record).is(':checked')) {
|
||||
check_list.push(parseInt($(record).data('id')));
|
||||
@@ -256,25 +246,34 @@ openerp_mail_followers = function(session, mail) {
|
||||
},
|
||||
|
||||
/** Fetch subtypes, only if current user is follower */
|
||||
fetch_subtypes: function () {
|
||||
fetch_subtypes: function (context) {
|
||||
var self = this;
|
||||
var subtype_list_ul = this.$('.oe_subtype_list').empty();
|
||||
if (! this.message_is_follower) return;
|
||||
var mode = "";
|
||||
if (context && context.eval('partner_id')) {
|
||||
mode = "edit_follower";
|
||||
} else {
|
||||
var subtype_list_ul = this.$('.oe_subtype_list').empty();
|
||||
if (! this.message_is_follower) return;
|
||||
}
|
||||
var id = this.view.datarecord.id;
|
||||
this.ds_model.call('message_get_subscription_data', [[id], new session.web.CompoundContext(this.build_context(), {})])
|
||||
.then(function (data) {self.display_subtypes(data, id);});
|
||||
this.ds_model.call('message_get_subscription_data', [[id],context])
|
||||
.then(function (data) {self.display_subtypes(data, id, mode);});
|
||||
},
|
||||
|
||||
/** Display subtypes: {'name': default, followed} */
|
||||
display_subtypes:function (data, id) {
|
||||
display_subtypes:function (data, id, mode) {
|
||||
var self = this;
|
||||
var $list = this.$('.oe_subtype_list');
|
||||
$list.empty().hide();
|
||||
if (mode.length == 0){ $list.empty().hide();}
|
||||
var records = data[this.view.datarecord.id || this.view.dataset.ids[0]].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.$('.oe_subtype_list') );
|
||||
if (mode.length == 0) {
|
||||
$(session.web.qweb.render('mail.followers.subtype', {'record': record,'mode': mode})).appendTo( self.$('.oe_subtype_list') );
|
||||
} else {
|
||||
$(session.web.qweb.render('mail.followers.subtype', {'record': record,'mode': mode})).appendTo(self.$dialog);
|
||||
}
|
||||
});
|
||||
if (_.size(records) > 1) {
|
||||
$list.show();
|
||||
|
||||
@@ -42,21 +42,8 @@
|
||||
<t t-name="mail.followers.subtype">
|
||||
<table class='oe_subtype'>
|
||||
<tr>
|
||||
<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>
|
||||
<td><label t-att-for="'input_mail_followers_subtype_'+record.id"><t t-raw="record.name"/></label></td>
|
||||
</tr>
|
||||
</table>
|
||||
</t>
|
||||
|
||||
<!--
|
||||
followers.edit.subtype template
|
||||
Template used to edit the display message subtypes of a follower subscription
|
||||
-->
|
||||
<t t-name="mail.followers.edit.subtype">
|
||||
<table class='oe_subtype'>
|
||||
<tr>
|
||||
<td width="10%"><input type="checkbox" t-att-checked="record.followed" t-att-id="'input_mail_followers_edit_subtype_'+record.id" t-att-data-id="record.id" t-att-name="record.name" class="oe_msg_subtype_edit_check"/></td>
|
||||
<td><label t-att-for="'input_mail_followers_edit_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_'+mode+record.id" t-att-data-id="record.id" t-att-name="record.name" class="oe_msg_subtype_check"/></td>
|
||||
<td><label t-att-for="'input_mail_followers_subtype_'+mode+record.id"><t t-raw="record.name"/></label></td>
|
||||
</tr>
|
||||
</table>
|
||||
</t>
|
||||
|
||||
Reference in New Issue
Block a user