Thibault Delavallée (OpenERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp into lp:openobject-addons.
Requested reviews: OpenERP Core Team (openerp) For more details, see: https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp/+merge/108744 -- https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp/+merge/108744 Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp.
=== added directory 'mail_extra' === added file 'mail_extra/__init__.py' --- mail_extra/__init__.py 1970-01-01 00:00:00 +0000 +++ mail_extra/__init__.py 2012-06-05 13:26:24 +0000 @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2009-Today OpenERP SA (<http://www.openerp.com>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +import mail_vote +import mail_checklist +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + === added file 'mail_extra/__openerp__.py' --- mail_extra/__openerp__.py 1970-01-01 00:00:00 +0000 +++ mail_extra/__openerp__.py 2012-06-05 13:26:24 +0000 @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010-Today OpenERP S.A. (<http://www.openerp.com>). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################## + +{ + 'name': 'Votes & Checklist Management', + 'version': '1.0', + 'category': 'Hidden/Dependency', + 'complexity': "easy", + 'description': """ + """, + 'author': 'OpenERP SA', + 'website': 'http://www.openerp.com', + 'depends': ['base', 'mail'], + 'data': [ + ], + 'installable': True, + 'auto_install': False, + 'certificate': '', + 'images': [ + ], + 'css': [ + "static/src/css/mail_extra.css", + ], + 'js': [ + "static/src/js/mail_extra.js", + ], + 'qweb': [ + "static/src/xml/mail_extra.xml", + ], +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: === added file 'mail_extra/mail_checklist.py' --- mail_extra/mail_checklist.py 1970-01-01 00:00:00 +0000 +++ mail_extra/mail_checklist.py 2012-06-05 13:26:24 +0000 @@ -0,0 +1,105 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2009-today OpenERP SA (<http://www.openerp.com>) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/> +# +############################################################################## + +from osv import osv, fields +import logging + +class mail_checklist_item(osv.osv): + _name = 'mail.checklist.item' + _description = 'Mail Checklist Item' + + _columns = { + 'msg_id': fields.many2one('mail.message', 'Message'), + 'name': fields.char('Name', size=128, help='Checklist Item Name.'), + '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, check_item_id, check_value, context=None): + if context == None: + context = {} + self.write(cr, uid, check_item_id , {'done': check_value}) + msg_id = self.browse(cr, uid, check_item_id, context=context).msg_id.id + return self.calculate(cr, uid, msg_id, context) + + def create(self, cr, uid, val, context= None): + if context == None: + context = {} + 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, msg_id, context=None): + if context == None: + context = {} + msg_obj = self.pool.get('mail.message') + for msg_ids in msg_obj.browse(cr, uid, [msg_id], context=context): + total_checklist_items = len(msg_ids.checklist_item_ids) + done_checklist_items = 0 + percentage = 0 + if total_checklist_items != 0: + done_checklist_items = len(filter(lambda x: x.done and x or False, msg_ids.checklist_item_ids)) + percentage = (done_checklist_items *100)/total_checklist_items + msg_obj.write(cr, uid, msg_id , {'checklist_advance': percentage}) + return percentage + + def get_checklist(self, cr, uid, msg_ids, context=None): + res = {} + 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_item() + +class mail_message(osv.osv): + _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)) + if total_checklist_items != 0: + try: + perceantage = (done_checklist_items *100)/total_checklist_items + res[msg.id] = perceantage + except Exception, e: + _logger.info('Divide By Zero Exception %s', e) + else: + res[msg.id] = 0 + return res + + _inherit = 'mail.message' + _columns= { + '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'), + } + 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 === added file 'mail_extra/mail_vote.py' --- mail_extra/mail_vote.py 1970-01-01 00:00:00 +0000 +++ mail_extra/mail_vote.py 2012-06-05 13:26:24 +0000 @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2009-today OpenERP SA (<http://www.openerp.com>) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/> +# +############################################################################## + +from osv import osv, fields +from tools.translate import _ + +class mail_vote(osv.osv): + _name = 'mail.vote' + _description = 'Mail Vote' + + _columns = { + 'msg_id': fields.many2one('mail.message', 'Message'), + 'user_id': fields.many2one('res.users', 'User'), + } + +class mail_message(osv.osv): + _inherit = 'mail.message' + _columns= { + 'vote_ids': fields.one2many('mail.vote', 'msg_id', 'Votes'), + } + + def vote_subscribe(self, cr, uid, message_id, context=None): + vote_pool = self.pool.get('mail.vote') + voters_id = vote_pool.search(cr, uid, [('msg_id', '=', message_id), ('user_id', '=', uid)], context=context) + if not voters_id: + return vote_pool.create(cr, uid, {'msg_id': message_id, 'user_id': uid}, context=context) + return True === added directory 'mail_extra/static' === added directory 'mail_extra/static/src' === added directory 'mail_extra/static/src/css' === added file 'mail_extra/static/src/css/mail_extra.css' --- mail_extra/static/src/css/mail_extra.css 1970-01-01 00:00:00 +0000 +++ mail_extra/static/src/css/mail_extra.css 2012-06-05 13:26:24 +0000 @@ -0,0 +1,50 @@ +img.oe_mail_vote_image +{ + width: 20px; + height: 18px; + margin: -5px; + position: relative; +} + +span.oe_mail_vote_span +{ + position: relative; + margin: 2%; +} + +.openerp div.oe_mail_thread_subthread img +{ + width: 20px; + height: 18px; + 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 === added directory 'mail_extra/static/src/img' === added file 'mail_extra/static/src/img/vote.png' Binary files mail_extra/static/src/img/vote.png 1970-01-01 00:00:00 +0000 and mail_extra/static/src/img/vote.png 2012-06-05 13:26:24 +0000 differ === added directory 'mail_extra/static/src/js' === added file 'mail_extra/static/src/js/mail_extra.js' --- mail_extra/static/src/js/mail_extra.js 1970-01-01 00:00:00 +0000 +++ mail_extra/static/src/js/mail_extra.js 2012-06-05 13:26:24 +0000 @@ -0,0 +1,137 @@ +openerp.mail_extra = function(session){ + var QWeb = session.web.qweb; + var _t = session.web._t; + + session.mail.Thread.include({ + start: function(){ + 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(); + }); + } + this.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'); + if (vote_img) + vote_img.click(function(){ + self.subscribe_vote($(this).attr('data-id')); + }); + }, + + init_comments: function(){ + res = this._super(); + var self = this; + return res.then(function(){self.add_vote_event(), self.add_checklist_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'); + return this.mail_message.call('vote_subscribe', [parseInt(message_id)]).then(function(result){ + // for wall only + parent = self.__parentedParent; + 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})) + }, + + display_items: function(){ + var self = this; + this.mail_message = new session.web.DataSet(this, 'mail.message'); + // PAGE LOAD TIME SEARCH ALL Message ids... + this.mail_message.call('search',[[]]).then(function(result){ + self.checkitem_obj.call('get_checklist', [result]).then(function(res){ + for(item in res){ + self.$element.find('img.oe_checklist_image').each(function(){ + if($(this).attr('data-id')==item){ + $(this).parent().find('.oe_mail_msg_body').after(QWeb.render('ChecklistItem', {'record': res[item]})) + 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 check_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); + }); + }); + }); + }, + //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})) + }, + }); +} === added directory 'mail_extra/static/src/xml' === added file 'mail_extra/static/src/xml/mail_extra.xml' --- mail_extra/static/src/xml/mail_extra.xml 1970-01-01 00:00:00 +0000 +++ mail_extra/static/src/xml/mail_extra.xml 2012-06-05 13:26:24 +0000 @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<templates id="template" xml:space="preserve"> + + <t t-extend="ThreadMsg"> + <t t-jquery=".oe_mail_msg_content" t-operation="append"> + <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-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

