Nimesh Contractor(Open ERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-checklist_widget-nco
 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-checklist_widget-nco/+merge/107923

Hello sir,
         I have Added the functionality of check-list on messages.
         On click display the dialogue box to add the item.
         On check strike the the text and increase progress bar.
         On unchecked decrease the progress bar.
Thanks,
 NCO.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-checklist_widget-nco/+merge/107923
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp.
=== modified file 'email_template/i18n/ja.po'
--- email_template/i18n/ja.po	2012-05-26 05:07:49 +0000
+++ email_template/i18n/ja.po	2012-05-30 07:27:43 +0000
@@ -8,14 +8,24 @@
 "Project-Id-Version: openobject-addons\n"
 "Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
 "POT-Creation-Date: 2012-02-08 00:36+0000\n"
+<<<<<<< TREE
+"PO-Revision-Date: 2012-05-10 18:28+0000\n"
+"Last-Translator: Raphael Collet (OpenERP) <Unknown>\n"
+=======
 "PO-Revision-Date: 2012-05-25 04:53+0000\n"
 "Last-Translator: Akira Hiyama <Unknown>\n"
+>>>>>>> MERGE-SOURCE
 "Language-Team: Japanese <[email protected]>\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
+<<<<<<< TREE
+"X-Launchpad-Export-Date: 2012-05-11 05:11+0000\n"
+"X-Generator: Launchpad (build 15225)\n"
+=======
 "X-Launchpad-Export-Date: 2012-05-26 05:07+0000\n"
 "X-Generator: Launchpad (build 15288)\n"
+>>>>>>> MERGE-SOURCE
 
 #. module: email_template
 #: field:email.template,subtype:0
@@ -408,7 +418,11 @@
 #: field:email.template,body_html:0
 #: field:email_template.preview,body_html:0
 msgid "Rich-text Contents"
+<<<<<<< TREE
+msgstr "リッチテキストの内容"
+=======
 msgstr "リッチテキストのコンテンツ"
+>>>>>>> MERGE-SOURCE
 
 #. module: email_template
 #: field:email.template,copyvalue:0

=== modified file 'mail_extra/__init__.py'
--- mail_extra/__init__.py	2012-05-28 09:48:42 +0000
+++ mail_extra/__init__.py	2012-05-30 07:27:43 +0000
@@ -20,6 +20,6 @@
 ##############################################################################
 
 import mail_vote
-
+import mail_checklist
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 

=== modified file 'mail_extra/mail_checklist.py'
--- mail_extra/mail_checklist.py	2012-05-17 05:43:04 +0000
+++ mail_extra/mail_checklist.py	2012-05-30 07:27:43 +0000
@@ -20,8 +20,9 @@
 ##############################################################################
 
 from osv import osv, fields
+import logging
 
-class mail_checklist_items(osv.osv):
+class mail_checklist_item(osv.osv):
     _name = 'mail.checklist.item'
     _description = 'Mail Checklist Item'
     
@@ -31,46 +32,69 @@
             'done': fields.boolean('Done', help="When Item is done then check it."),
             'user_id': fields.many2one('res.users', 'Related user', readonly=1),
         }
-    def action_done(self, cr, uid, ids, context=None):
-        return self.write(cr, uid, ids , {'done': True})
-        
-    
-    def get_checklist(self, cr, uid, ids, context=None):
+    def action_done(self, cr, uid, id, chek_value, context=None):
+        self.write(cr, uid, id , {'done': chek_value})
+        msg_id = self.browse(cr, uid, id, context=context).msg_id.id
+        return self.calculate(cr, uid, msg_id, context)
+    
+    def create(self, cr, uid, val, context= None):
+        item_id = super(mail_checklist_item, self).create(cr, uid, val, context=context)
+        msg_id = self.browse(cr, uid, item_id, context=context).msg_id.id
+        return self.calculate(cr, uid, msg_id, context)
+    
+    def calculate(self, cr, uid, id, context=None):
+        msg_obj = self.pool.get('mail.message')
+        msg_ids = msg_obj.read(cr, uid, [id],['checklist_item_ids','checklist_advance'], context=context)
+        total_checklist_items = len(msg_ids[0]['checklist_item_ids'])
+        done_checklist_items = 0
+        percentage = 0
+        if total_checklist_items != 0:
+            for msg in self.browse(cr, uid, msg_ids[0]['checklist_item_ids'], context=context):
+                if msg.done:
+                    done_checklist_items += 1
+            percentage = (done_checklist_items *100)/total_checklist_items
+        msg_obj.write(cr, uid, id , {'checklist_advance': percentage})
+        return percentage
+    
+    def get_checklist(self, cr, uid, msg_ids, context=None):
         res = {}
-        for id in ids:
-            lst = []
-            message_id = self.search(cr,uid, [('msg_id', '=', id)], context=context)
-            for name in self.browse(cr, uid, message_id, context=context):
-                lst.append(name.name)
-                res[id]=lst
+        for msg_id in msg_ids:
+            check_items = []
+            item_id = self.search(cr,uid, [('msg_id', '=', msg_id)], context=context)
+            for item in self.browse(cr, uid, item_id, context=context):
+                item_data = {}
+                item_data['id'] = item.id
+                item_data['name'] = item.name
+                item_data['done'] = item.done
+                check_items.append(item_data)
+            res[msg_id]=check_items
         return res
-
-mail_checklist_items()
+mail_checklist_item()
 
 class mail_message(osv.osv):
-    
-    def add_checklist_item(self, cr, uid, msg_id, item_name, context=None):
-        self.pool.get('mail.checklist.item').create(cr, uid, {'msg_id':msg_id, 'user_id':uid, 'name' : item_name}, context)
-        return True
-
-    def cal_check_items(self, cr, uid, ids, field, args, context=None):
+    _logger = logging.getLogger(__name__)
+    def cal_checked_items(self, cr, uid, ids, field, args, context=None):
         res = {}
         for msg in self.browse(cr, uid, ids, context=context):
             total_checklist_items = len(msg.checklist_item_ids)
             done_checklist_items = len(filter(lambda x: x.done and x or False, msg.checklist_item_ids))
-            perchantage = (done_checklist_items *100)/total_checklist_items
-            res[msg.id] = perchantage
-#        chek_items_obj = self.pool.get('mail.checklist.items')
-#        tot_items = chek_items_obj.search(cr, uid, ['|', ('done', '=', True), ('done', '=', False)], context=context)
-#        tot_items = len(tot_items)
-#        tot_check_items = chek_items_obj.search(cr, uid, ['&', ('user_id', '=', uid), ('done', '=', True)], context=context)
-#        tot_check_items = len(tot_check_items)
+            if total_checklist_items != 0:
+                try:
+                    perceantage = (done_checklist_items *100)/total_checklist_items
+                    res[msg.id] = perceantage
+                except Exception, e:
+                    _logger.info('Devide By Zero Exception %s', e)
+            else:
+                res[msg.id] = 0
         return res
     
     _inherit = 'mail.message'
     _columns= {
-           'checklist_item_ids': fields.one2many('mail.checklist.items', 'msg_id', 'Votes'),
-           'checklist_advance': fields.function(cal_check_items, string='Checked Items', type='float', store=True, help="Calculate the checked Items."),
+           'checklist_item_ids': fields.one2many('mail.checklist.item', 'msg_id', 'CheckItems'),
+           'checklist_advance': fields.function(cal_checked_items, string='Total Checked Items', store=True, type='integer'),
        }
-   
-mail_message()
+    def add_checklist_item(self, cr, uid, msg_id, item_name, context=None):
+        mail_item = self.pool.get('mail.checklist.item')
+        return mail_item.create(cr, uid, {'msg_id':msg_id, 'user_id':uid, 'name' : item_name}, context=context)
+    
+mail_message()
\ No newline at end of file

=== modified file 'mail_extra/static/src/css/mail_extra.css'
--- mail_extra/static/src/css/mail_extra.css	2012-05-28 09:31:16 +0000
+++ mail_extra/static/src/css/mail_extra.css	2012-05-30 07:27:43 +0000
@@ -19,3 +19,32 @@
     margin: -5px;
     position: relative;
 }
+
+.openerp .oe_checklist_image{
+	padding : 9px;
+	width: 18px;
+    height: 18px;
+    margin-bottom: -15px;
+	cursor:pointer;
+}
+.openerp div.oe_mail_thread_subthread img.oe_checklist_image
+{
+    padding : 9px;
+    width: 18px;
+    height: 18px;
+    margin-bottom: -15px;
+    cursor:pointer;
+}
+
+.openerp .oe_strike_checkbox {
+   color:blue;
+   text-decoration:line-through;
+}
+
+.openerp .oe_progressbar {
+
+	background-color:white;
+	width:220px;
+	height:4px;
+	
+}
\ No newline at end of file

=== modified file 'mail_extra/static/src/js/mail_extra.js'
--- mail_extra/static/src/js/mail_extra.js	2012-05-28 09:31:16 +0000
+++ mail_extra/static/src/js/mail_extra.js	2012-05-30 07:27:43 +0000
@@ -1,15 +1,75 @@
 openerp.mail_extra = function(session){
     var QWeb = session.web.qweb;
+    var _t = session.web._t;
+    session.ItemView = session.mail.Thread.extend({
+        template: 'ChecklistItem',
+        init: function(){
+        	this._super(this,arguments);
+        },
+        
+        display_items: function(self){
+        	self_self = this;
+	        this.mail_message = new session.web.DataSet(this, 'mail.message');
+	        this.mail_message.call('search',[[]]).then(function(result){
+	        	self.checkitem_obj.call('get_checklist', [result]).then(function(res){
+		            for(i in res){
+		        		self.$element.find('img.oe_checklist_image').each(function(){
+		        			if($(this).attr('data-id')==i){
+		            			$(this).parent().find('.oe_mail_msg_body').after(QWeb.render('ChecklistItem', {'record': res[i]}))
+		            			self_self.strike_items(this);
+	         		   		 }
+	        			});
+	            	 }
+	         	});
+	        });
+        },
+        
+		// Strike and unstrike the checklist item.
+        strike_items: function(value){
+        	var self = this;
+        	mail_checklist_item = new session.web.DataSet(this, 'mail.checklist.item');
+        	mail_message = new session.web.DataSet(this, 'mail.message');
+        	$(value).parent().find('input').each(function(j){
+		    	$(this).click(function(cheboxValue){
+		    		var check_item_id = $(this).attr('data-id');
+		    		var chek_value;
+		    		(this.checked == true)?
+		    			$(this).parent().addClass('oe_strike_checkbox'):
+							$(this).parent().removeClass('oe_strike_checkbox');
+					mail_checklist_item.call('action_done', [parseInt(check_item_id), this.checked]).then(function (percentage) {
+						$(value).parent().find('.oe_mail_msg_body span').html(percentage +  "%");
+						$(value).parent().find('.oe_progressbar').attr("value", percentage);
+					});
+		    	});
+		    });
+        },
+	});
     
     session.mail.Thread.include({
         start: function(){
-            // for wall only
             var self = this;
+            this.checkitem_obj = new session.web.DataSet(this, "mail.checklist.item");
             super_instance = this._super();
             if(!super_instance){
                 self.add_vote_event();
-            }
-        },
+                self.add_checklist_event();
+            }
+            else{
+            	super_instance.done(function(){
+                    self.add_checklist_event();
+                });
+            }
+            var check_load = new session.ItemView();
+            check_load.display_items(self);
+        },
+        add_checklist_event: function(){
+        	var self = this;
+            this.$element.find('img.oe_checklist_image').click(function(){
+           		var render_to = $(this).siblings().find(".oe_mail_thread_msg");
+             	self.do_display_checklist($(this).attr('data-id'),render_to);
+             });
+        },
+        
         add_vote_event: function(){
             var self = this;
             vote_img = this.$element.find('img.oe_mail_vote_image');
@@ -18,16 +78,19 @@
                     self.subscribe_vote($(this).attr('data-id'));
                 });
         },
+        
         init_comments: function(){
             res = this._super();
             var self = this;
             return res.then(function(){self.add_vote_event();});
         },
+        
         add_events: function() {
             res = this._super();
             this.add_vote_event();
             return res;
         },
+        
         subscribe_vote: function(message_id){
             var self = this;
             this.mail_message = new session.web.DataSet(this, 'mail.message');
@@ -37,5 +100,39 @@
                     if (parent.template == "Wall") parent.init_and_fetch_comments();
                     else self.init_comments();});
         },
+        
+        do_display_checklist: function (cur_msg_id,render_to) {
+        	var self=this;
+        	var add_checklist = new session.web.Dialog(this,{
+        		
+	            title: _t("Add Checklist"),
+	            width: 250,
+	            buttons: [
+			                {text: "Add", click: function() {
+			                	var value = add_checklist.$element.find("input").val();
+			            		this.mail_message = new session.web.DataSet(this, 'mail.message');
+			                	if(!_.isEmpty(value)){
+							        this.mail_message.call('add_checklist_item', [cur_msg_id,value]).done(function(result){
+								        add_checklist.close()
+								        self.render_checklist(value,render_to);
+								        // Wall load
+								        parent = self.__parentedParent;
+	            						if (parent.template == "Wall") parent.init_and_fetch_comments();
+    	        						else self.init_comments();
+							        });
+							    }
+			                	else add_checklist.close();
+			                }},
+			            ]
+        	}).open();
+            add_checklist.$element.append(session.web.qweb.render("AddChecklist"));
+        },
+        
+        //render checklist
+        render_checklist: function(value, render_to){
+                var add_check_item=[];
+                add_check_item.push(value)
+                render_to.append(session.web.qweb.render('ChecklistItem', {'record': add_check_item}))
+        },
     });
 }

=== modified file 'mail_extra/static/src/xml/mail_extra.xml'
--- mail_extra/static/src/xml/mail_extra.xml	2012-05-25 10:57:28 +0000
+++ mail_extra/static/src/xml/mail_extra.xml	2012-05-30 07:27:43 +0000
@@ -4,18 +4,46 @@
     
     <t t-extend="ThreadMsg">
         <t t-jquery=".oe_mail_msg_content" t-operation="append">
-            <t t-if="record.type == 'comment'"><t t-call="VoteDisplay"/></t>
+            <t t-if="record.type == 'comment'">
+            	<t t-call="VoteDisplay"/>
+            	<img class="oe_checklist_image" t-attf-data-id='{record.id}' src="/web/static/src/img/icons/gtk-index.png"></img>
+            </t>
         </t>
     </t>
     
     <t t-name="VoteDisplay">
-
         <img src="/mail_extra/static/src/img/vote.png" t-attf-data-id='{record.id}' class="oe_mail_vote_image"></img>
-                
         <t t-if='(record.vote_ids.length)'>
             <span class="oe_mail_vote_span"><t t-esc="record.vote_ids.length"/></span>
         </t>
-        
-    </t>
-
+    </t>
+    
+	<t t-extend="NoteDisplay">
+        <t t-jquery=".oe_mail_msg_body" t-operation="append">
+        	<t t-if="record.checklist_item_ids.length !== 0">
+        		<br/><progress t-att-value='record.checklist_advance' class="oe_progressbar" max="100"/> 
+        		<span><t t-esc = "record.checklist_advance"/>%</span>
+        	</t>
+        </t>
+    </t>
+    
+    <div t-name = "AddChecklist">
+		<label>Item Name</label>
+		<input type="text" size = "10"></input>
+    </div>
+    
+    <t t-name="ChecklistItem">
+		<li class = "oe_mail oe_mail_thread_msg" t-if="record.length != 0">
+			<t t-foreach="record" t-as="checklist_item">
+				<!-- 	If chebox value is True then	 -->
+				<span t-if="checklist_item.done == true" class = "oe_strike_checkbox">
+					<input t-att-data-id='checklist_item.id' type="checkbox" checked="checked" t-att-value="checklist_item.done" /><t t-esc="checklist_item.name" /><br/>
+				</span>
+				<!-- 	If chebox value is False then	 -->
+				<span t-if="checklist_item.done == false">
+					<input t-att-data-id='checklist_item.id' type="checkbox" t-att-value="checklist_item.done"/><t t-esc="checklist_item.name" /><br/>
+				</span>
+			</t>
+	    </li>
+    </t>
 </templates>

_______________________________________________
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

Reply via email to