Pankita Shah(OpenERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-mail-compose-message-shp
into lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp.
Requested reviews:
Atul Patel(OpenERP) (atp-openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-mail-compose-message-shp/+merge/118877
Hello,
i set image as per comment and add many2many field in mail_extra.
thanks
shp
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-mail-compose-message-shp/+merge/118877
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp.
=== removed file '.bzrignore'
--- .bzrignore 2012-07-21 19:34:59 +0000
+++ .bzrignore 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-.*
=== modified file 'mail/mail_thread.py'
--- mail/mail_thread.py 2012-08-06 06:30:44 +0000
+++ mail/mail_thread.py 2012-08-09 06:28:20 +0000
@@ -65,7 +65,7 @@
def _get_message_ids(self, cr, uid, ids, name, args, context=None):
res = {}
msg_obj = self.pool.get('mail.message')
- img_vote = "<img height='12px' width='16px' src='/mail_extra/static/src/img/vote.gif'/>"
+ img_vote = "<img height='12px' width='16px' src='/mail/static/src/img/vote.gif'/>"
for id in ids:
vote_list = []
message_ids = self.message_search(cr, uid, [id], context=context)
@@ -76,7 +76,7 @@
vote_list.append(msg.vote_ids)
res[id] = {
'message_ids': message_ids,
- 'message_summary': "<span>Msg: %d</span> . <span>Fol: %d</span> . <span> %s %d</span>" % (len(message_ids), len(subscriber_ids),img_vote,len(vote_list)),
+ 'message_summary': "<span>Msg: %d</span> . <span>Fol: %d</span> . <span> %s %d</span>" % (len(message_ids), len(subscriber_ids),img_vote, len(vote_list)),
}
return res
@@ -334,7 +334,6 @@
if partner_ids is None:
partner_ids = []
mail_partner_ids = [(6, 0, partner_ids)]
-
data = {
'subject': subject,
'body_text': body_text or (hasattr(thread, 'description') and thread.description or ''),
=== modified file 'mail/static/src/js/mail.js'
--- mail/static/src/js/mail.js 2012-08-06 06:10:04 +0000
+++ mail/static/src/js/mail.js 2012-08-09 06:28:20 +0000
@@ -1164,7 +1164,7 @@
var records = self.comments_structure.tree_struct[root_id]['for_thread_msgs'];
var model_name = self.comments_structure.msgs[root_id]['model'];
var res_id = self.comments_structure.msgs[root_id]['res_id'];
- var render_res = session.web.qweb.render('mail.wall_thread_container', {});
+ var render_res = session.web.qweb.render('mail.Wall_thread_container', {});
$('<li class="oe_mail_wall_thread">').html(render_res).appendTo(self.$element.find('ul.oe_mail_wall_threads'));
var thread = new mail.Thread(self, {
'res_model': model_name, 'res_id': res_id, 'uid': self.session.uid, 'records': records,
=== modified file 'mail/static/src/xml/mail.xml'
--- mail/static/src/xml/mail.xml 2012-08-06 05:59:42 +0000
+++ mail/static/src/xml/mail.xml 2012-08-09 06:28:20 +0000
@@ -45,7 +45,7 @@
wall_thread_container template for the wall
Each discussion thread is contained inside this template
-->
- <t t-name="mail.wall_thread_container">
+ <t t-name="mail.Wall_thread_container">
</t>
<!--
=== modified file 'mail/wizard/mail_compose_message.py'
--- mail/wizard/mail_compose_message.py 2012-08-06 05:36:51 +0000
+++ mail/wizard/mail_compose_message.py 2012-08-09 06:28:20 +0000
@@ -269,8 +269,7 @@
partner_ids = [partner.id for partner in mail_wiz.dest_partner_ids]
references = None
headers = {}
- body = mail_wiz.body_html if content_subtype == 'html' else mail_wiz.body_text
-
+ body = mail_wiz.body_html if content_subtype == 'html' else mail_wiz.body_text
# get model, active_ids, and check if model is openchatter-enabled
if mass_mail_mode and context.get('active_ids') and context.get('active_model'):
active_ids = context['active_ids']
@@ -324,8 +323,6 @@
# in normal mode, we send the email immediately, as the user expects us to (delay should be sufficiently small)
if type == 'email':
mail_message_obj.send(cr, uid, msg_ids, context=context)
- if type == 'comment':
- return {'type': 'ir.actions.act_window_close', 'msg_ids': msg_ids}
return {'type': 'ir.actions.act_window_close'}
=== modified file 'mail/wizard/mail_compose_message_view.xml'
--- mail/wizard/mail_compose_message_view.xml 2012-07-20 12:56:23 +0000
+++ mail/wizard/mail_compose_message_view.xml 2012-08-09 06:28:20 +0000
@@ -44,7 +44,7 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Compose Email" version="7.0" >
- <group>
+ <group >
<field name="subject" colspan="2" nolabel="1" placeholder="Subject..."
class="oe_mail_compose_message_subject oe_mail_compose_message_invisible"/>
<field name="body_text" colspan="2" nolabel="1" placeholder="What are you working on ?"
@@ -54,7 +54,7 @@
<field name="dest_partner_ids" colspan="2" nolabel="1" widget="many2many_tags"
placeholder="Add contacts to notify..."
class="oe_mail_compose_message_partner_ids oe_mail_compose_message_invisible"/>
- <div>
+ <div class='oe_mail_compose_message_post'>
<button name="send_mail" string="Post" type="object"
class="oe_mail_compose_message_button_send"/>
or <a href="#" class="oe_mail_compose_message_email">Send an Email</a>
=== modified file 'mail_extra/__openerp__.py'
--- mail_extra/__openerp__.py 2012-07-12 05:25:52 +0000
+++ mail_extra/__openerp__.py 2012-08-09 06:28:20 +0000
@@ -42,6 +42,7 @@
],
'data': [
'security/ir.model.access.csv',
+ 'mail_compose_message_view.xml'
],
'css': [
"static/src/css/mail_extra.css",
=== modified file 'mail_extra/mail_checklist.py'
--- mail_extra/mail_checklist.py 2012-08-06 06:30:44 +0000
+++ mail_extra/mail_checklist.py 2012-08-09 06:28:20 +0000
@@ -33,21 +33,19 @@
done : True If Item checked otherwise False.
'''
_columns = {
- 'msg_id': fields.many2one('mail.message', 'Message'),
'name': fields.char('Item Name', size=128, required=True, help='Checklist Item Name.'),
- 'done': fields.boolean('Done', help="When Item is done then check it."),
+ 'done': fields.boolean('Done', help="When Item is done then check it.",readonly="1"),
'user_id': fields.many2one('res.users', 'Related user', readonly=1),
}
- def action_done(self, cr, uid, check_item_ids, check_value, context=None):
+ def action_done(self, cr, uid, ids, message_id, check_value, context=None):
"""
Update checklist Item value(True or False).
Return Checklist Item Details.(name, id, done)
"""
message_pool = self.pool.get("mail.message")
- self.write(cr, uid, check_item_ids , {'done': check_value}, context=context)
- msg_id = self.browse(cr, uid, check_item_ids[0], context=context).msg_id.id
- return message_pool.read_checklist_items(cr, uid, [msg_id], context=context)
+ self.write(cr, uid, ids , {'done': check_value}, context=context)
+ return message_pool.read_checklist_items(cr, uid, [message_id], context=context)
mail_checklist_item()
@@ -58,23 +56,20 @@
Find Checklist Item of particular Message Id.
Return Checklist Item Details.(name, id, done)
"""
- checklist = self.pool.get("mail.checklist.item")
- checklist_ids = checklist.search(cr, uid, [('msg_id','in' ,ids)])
- return checklist.read(cr, uid, checklist_ids, ['id','name','done'])
+ checklist_ids = []
+ checklist_pool = self.pool.get('mail.checklist.item')
+ for msg in self.browse(cr, uid, ids):
+ for checklist in msg.checklist_item_ids:
+ checklist_ids.append(checklist.id)
+ return checklist_pool.read(cr, uid, checklist_ids, ['id','name', 'done'])
_inherit = 'mail.message'
_columns= {
- 'checklist_item_ids': fields.one2many('mail.checklist.item', 'msg_id', 'CheckItems'),
+ 'checklist_item_ids': fields.many2many('mail.checklist.item','mail_message_checklist_rel', 'msg_id', 'checklist_id','Checklist Items'),
+
}
mail_message()
-class mail_compose_message(osv.TransientModel):
- _inherit = 'mail.compose.message'
- def add_checklist_item(self, cr, uid, msg_id, item_names, context=None):
- mail_item = self.pool.get('mail.checklist.item')
- for item in item_names[0]:
- mail_item.create(cr, uid, {'msg_id':msg_id, 'user_id':uid, 'name' : item}, context=context)
- return msg_id
-
+
class mail_thread(osv.Model):
_inherit = 'mail.thread'
@@ -96,6 +91,39 @@
total_items += len(msg.checklist_item_ids)
img_checklist = "<img height='12px' width='16px' src='/mail_extra/static/src/img/checklist.png'/>"
res[key]['message_summary'] += " . <span> %s %d/%d</span>"% (img_checklist,total_done_items,total_items)
+ return res
+
+ def message_append(self, cr, uid, threads, subject, body_text=None, body_html=None,
+ type=type, email_date=None, parent_id=False,
+ content_subtype='plain', state=None,
+ partner_ids=None, email_from=False, email_to=False,
+ email_cc=None, email_bcc=None, reply_to=None,
+ headers=None, message_id=False, references=None,
+ attachments=None, checklist=None, original=None, context=None):
+ res = super(mail_thread, self).message_append(cr, uid, threads, subject, body_text=body_text, body_html=body_html,
+ type=type, email_date=email_date, parent_id=parent_id,
+ content_subtype=content_subtype, state=state,
+ partner_ids=partner_ids, email_from=email_from, email_to=email_to,
+ email_cc=email_cc, email_bcc=email_bcc, reply_to=reply_to,
+ headers=headers, message_id=message_id, references=references,
+ attachments=attachments, original=original, context=context)
+ if context is None:
+ context = {}
+ if checklist is None:
+ checklist = {}
+ mail_message_pool = self.pool.get('mail.message')
+ data ={}
+ if all(isinstance(thread_id, (int, long)) for thread_id in threads):
+ model = context.get('thread_model') or self._name
+ model_pool = self.pool.get(model)
+ threads = model_pool.browse(cr, uid, threads, context=context)
+ for thread in threads:
+ if checklist:
+ checklist_pool = self.pool.get('mail.checklist.item')
+ for chk_id in checklist.get('ids'):
+ checklist_pool.write(cr, uid, chk_id, {'user_id': uid})
+ data.update({'checklist_item_ids': [(6, 0, checklist.get('ids'))]})
+ mail_message_pool.write(cr, uid, res, data)
return res
_columns = {
@@ -107,3 +135,114 @@
}
mail_thread()
+
+
+class mail_compose_message(osv.Model):
+
+ def get_value(self, cr, uid, model, res_id, context=None):
+ """ Returns a defaults-like dict with initial values for the composition
+ wizard when sending an email related to the document record
+ identified by ``model`` and ``res_id``.
+
+ The default implementation returns an empty dictionary, and is meant
+ to be overridden by subclasses.
+
+ :param str model: model name of the document record this mail is
+ related to.
+ :param int res_id: id of the document record this mail is related to.
+ :param dict context: several context values will modify the behavior
+ of the wizard, cfr. the class description.
+ """
+ result = {}
+ result = super(mail_compose_message, self).get_value(cr, uid, model, res_id, context=context)
+ result.update({
+ 'checklist_ids': [],
+ })
+ return result
+
+ def default_get(self, cr, uid, fields, context=None):
+ """ Overridden to provide specific defaults depending on the context
+ parameters.
+
+ Composition mode
+ - comment: default mode; active_model, active_id = model and ID of a
+ document we are commenting,
+ - reply: active_id = ID of a mail.message to which we are replying.
+ From this message we can find the related model and res_id,
+ - mass_mailing mode: active_model, active_id = model and ID of a
+ document we are commenting,
+
+ :param dict context: several context values will modify the behavior
+ of the wizard, cfr. the class description.
+ """
+ if context is None:
+ context = {}
+ compose_mode = context.get('mail.compose.message.mode', 'comment')
+ active_model = context.get('active_model')
+ active_id = context.get('active_id')
+ result = super(mail_compose_message, self).default_get(cr, uid, fields, context=context)
+ # get default values according to the composition mode
+ vals = {}
+ if compose_mode in ['comment', 'mass_mail'] and active_model and active_id:
+ vals = self.get_value(cr, uid, active_model, active_id, context)
+ return result
+
+ def send_mail(self, cr, uid, ids, context=None):
+ msg_list_ids = []
+ checklist_ids = []
+ email_mode = context.get('email_mode')
+ formatting = context.get('formatting')
+ mass_mail_mode = context.get('mail.compose.message.mode') == 'mass_mail'
+ mail_message_obj = self.pool.get('mail.message')
+ for mail_wiz in self.browse(cr, uid, ids, context=context):
+ checklist = {}
+ for items in mail_wiz.checklist_ids:
+ checklist_ids.append(items.id)
+ checklist['ids'] = checklist_ids
+ attachment = {}
+ for attach in mail_wiz.attachment_ids:
+ attachment[attach.datas_fname] = attach.datas and attach.datas.decode('base64')
+ # default values, according to the wizard options
+ subject = mail_wiz.subject if formatting else False
+ content_subtype = 'html' if formatting else 'plain'
+
+ type = 'email' if email_mode else 'comment'
+ state = 'outgoing' if email_mode else False
+ partner_ids = [partner.id for partner in mail_wiz.dest_partner_ids]
+ references = None
+ headers = {}
+ body = mail_wiz.body_html if content_subtype == 'html' else mail_wiz.body_text
+
+ active_model = mail_wiz.model
+ active_ids = [mail_wiz.res_id]
+ active_model_pool = self.pool.get(active_model)
+ mail_thread_enabled = hasattr(active_model_pool, 'message_append')
+ if mail_thread_enabled:
+ msg_ids = active_model_pool.message_append(cr, uid, active_ids, subject, mail_wiz.body_text, mail_wiz.body_html,
+ type=type, content_subtype=content_subtype, state=state, partner_ids=partner_ids,
+ email_from=mail_wiz.email_from, email_to=mail_wiz.email_to, email_cc=mail_wiz.email_cc, email_bcc=mail_wiz.email_bcc,
+ reply_to=mail_wiz.reply_to, references=references, attachments=attachment, checklist=checklist, headers=headers, context=context)
+ else:
+ msg_ids = [mail_message_obj.schedule_with_attach(cr, uid, mail_wiz.email_from, to_email(mail_wiz.email_to), subject, mail_wiz.body_text,
+ type=type, model=mail_wiz.model, email_cc=to_email(mail_wiz.email_cc), email_bcc=to_email(mail_wiz.email_bcc), reply_to=mail_wiz.reply_to,
+ attachments=attachment, checklist=checklist, references=references, res_id=int(mail_wiz.res_id), partner_ids=partner_ids,
+ content_subtype=mail_wiz.content_subtype, headers=headers, context=context)]
+ # in normal mode, we send the email immediately, as the user expects us to (delay should be sufficiently small)
+ msg_list_ids += msg_ids
+ if type == 'comment':
+ return {'type': 'ir.actions.act_window_close', 'msg_ids': msg_list_ids}
+ res = super(mail_compose_message,self).send_mail(cr, uid, ids, context=context)
+ return res
+
+ _inherit = 'mail.compose.message'
+ _columns= {
+ 'checklist_ids': fields.many2many('mail.checklist.item','email_message_send_checklist_rel', 'wizard_id', 'checklist_id','Checklist'),
+ }
+
+mail_compose_message()
+
+class res_users(osv.Model):
+ _name = 'res.users'
+ _inherit = ['res.users', 'mail.thread']
+
+
=== added file 'mail_extra/mail_compose_message_view.xml'
--- mail_extra/mail_compose_message_view.xml 1970-01-01 00:00:00 +0000
+++ mail_extra/mail_compose_message_view.xml 2012-08-09 06:28:20 +0000
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+ <data>
+ <record model="ir.ui.view" id="mail_compose_view_inherit">
+ <field name="name">mail.compose.message.inherit</field>
+ <field name="model">mail.compose.message</field>
+ <field name="type">form</field>
+ <field name="inherit_id" ref="mail.email_compose_message_wizard_form_chatter"/>
+ <field name="arch" type="xml">
+ <xpath expr="//div[@class='oe_mail_compose_message_post']" position="before">
+ <field name="checklist_ids" colspan="4"
+ nolabel="1" widget="many2many_tags" placeholder='Add Checklist Items'/>
+ </xpath>
+ </field>
+ </record>
+ </data>
+</openerp>
=== modified file 'mail_extra/static/src/js/mail_extra.js'
--- mail_extra/static/src/js/mail_extra.js 2012-07-20 11:41:56 +0000
+++ mail_extra/static/src/js/mail_extra.js 2012-08-09 06:28:20 +0000
@@ -1,116 +1,45 @@
openerp.mail_extra = function(session){
var _t = session.web._t;
-
session.mail.ComposeMessage.include({
-
- bind_events: function() {
+ reinit: function() {
var self = this;
- this._super(this)
- this.render_default_checklist_item(self);
- var lastElement = this.$element.find('input[type=text]:last');
- $('a.oe_add_more_item').click(function (event) {
- $(session.web.qweb.render("AddChecklist", {})).insertBefore(this);
- self.$element.find('input[type=text]:last').focus();
- });
- this.$element.find('.oe_mail_compose_message_checklist').click(function () {
- $('.oe_mail_msg_checklist_new').toggle();
- });
+ if (! this.form_view) return;
+ var call_defer = this.ds_compose.call('default_get', [['subject', 'body_text', 'body_html', 'dest_partner_ids', 'checklist_ids'], this.ds_compose.get_context()]).then(
+ function (result) {
+ self.form_view.on_processed_onchange({'value': result}, []);
+ });
+ return call_defer;
},
-
- do_display_checklist: function(element){
- var parent_element = this.$element.find('button.oe_form_button');
- var new_item = $(session.web.qweb.render("AddChecklist", {}));
- $(parent_element).before(new_item);
- },
- render_default_checklist_item: function(element){
- self = this;
- for(i=0; i<3; i++){
- this.do_display_checklist(element);
- }
- var data = this.$element.find('input[type=text]:last');
- $(data).after('</br> <a class= "oe_add_more_item" href="#">Add More Items </a>');
- },
});
+
session.mail.Wall.include({
- get_checklist_items: function(checklist_items){
- check_items = []
- text_items = $(checklist_items).find('input[type=text]');
- _(text_items).each(function(item){
- item_value = $(item).val();
- if (item_value != ""){
- check_items.push(item_value);
- }
- $(item).val('');
- });
- return check_items
- },
- calculate_checklist_progress: function(items){
- if (items.length == 0) return 0;
- total_checklist_items = items.length;
- done_checklist_items = 0;
- checklist_progress = 0;
- _.each(items, function(record){
- if (record.done == true)
- done_checklist_items+=1;
- });
- checklist_progress = Math.round((done_checklist_items *100)/total_checklist_items);
- return checklist_progress;
- },
- do_action: function(action, on_close) {
- res = this._super(action, on_close);
- var mail_thread = new session.mail.Thread(self, {
- 'parent_id': false, 'thread_level': self.params.thread_level, 'show_hide': true, 'is_wall': true}
- );
- var thread_checklist_items = $('.oe_mail_wall_action');
- check_items = this.get_checklist_items(thread_checklist_items);
- mail_checklist_item = new session.web.DataSet(this, 'mail.compose.message');
- var call_done = mail_checklist_item.call('add_checklist_item', [action['msg_ids'][0],[check_items]]).then(function (result) {
- mail_thread.render_checklist_items(result);
- });
- },
- });
+ // Render Wall checklist Items.
+ display_comments: function(records){
+ res = this._super(records);
+ var self = this;
+// var mail_thread = new session.mail.Thread(self, {
+// 'parent_id': false, 'thread_level': self.params.thread_level, 'show_hide': true, 'is_wall': true}
+// );
+// _.each(records, function(record){
+// mail_thread.render_checklist_items(record.id);
+// });
+ if (self.compose_message_widget) {
+ self.compose_message_widget.reinit(); }
+
+ },
+ });
session.mail.Thread.include({
-
+ // Render Thread checklist Items.
display_comments: function(records){
res = this._super(records);
var self = this;
- var main_thread = this.$element.find('.oe_mail_thread_action');
_.each(records, function(record){
self.render_checklist_items(record.id);
});
- },
-
- do_action: function(action, on_close) {
- self = this;
- res = this._super(action, on_close);
- var thread_checklist_items = this.$element.find('.oe_mail_thread_action');
- check_items = this.get_checklist_items(thread_checklist_items);
- mail_checklist_item = new session.web.DataSet(this, 'mail.compose.message');
- var call_done = mail_checklist_item.call('add_checklist_item', [action['msg_ids'][0],[check_items]]).then(function (result) {
- self.render_checklist_items(result);
- });
- },
-
- get_checklist_items: function(checklist_items){
- check_items = []
- /*
- * here we can find the textbox like,
- * text_items = $(checklist_items).find('input[type=text]');
- * but when it will be problamatic to some documetns like lead,oppertunity
- * so here find the text box from its id.
- */
- text_items = $(checklist_items).find('#txt_name');
- _(text_items).each(function(item){
- item_value = $(item).val();
- if (item_value != ""){
- check_items.push(item_value);
- }
- $(item).val('');
- });
- return check_items
- },
-
+ if (self.compose_message_widget) {
+ self.compose_message_widget.reinit();}
+ },
// calculate the progress of item done when strike and unstrike on document comment.
calculate_checklist_progress: function(items){
if (items.length == 0) return 0;
@@ -131,7 +60,7 @@
checked = item.attr("checked");
self = this;
mail_checklist_item = new session.web.DataSet(this, 'mail.checklist.item');
- mail_checklist_item.call('action_done', [[parseInt(check_item_id)], checked]).then(function (result) {
+ mail_checklist_item.call('action_done', [[parseInt(check_item_id)], message_id, checked]).then(function (result) {
checklist_progress = self.calculate_checklist_progress(result);
progresselement = $(self.find_parent_element(".oe_mail_msg_checklist_progress", message_id));
progresselement.find('.oe_mail_msg_checklist_progress_value').html(checklist_progress + "%");
@@ -160,4 +89,4 @@
});
},
});
-}
+}
\ No newline at end of file
=== modified file 'mail_extra/static/src/xml/mail_extra.xml'
--- mail_extra/static/src/xml/mail_extra.xml 2012-07-20 10:40:15 +0000
+++ mail_extra/static/src/xml/mail_extra.xml 2012-08-09 06:28:20 +0000
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
+
<t t-extend="mail.thread.message">
<t t-jquery=".oe_mail_msg_body" t-operation="append">
<div t-att-data-id="record.id" class="oe_mail_msg_checklist">
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp