[IMP] project: displayed image on task not computed anymore

We don't want the dispayed image to be set to the last attached image but we want to be able to choose it.
This commit is contained in:
Martin Geubelle
2015-09-07 14:19:12 +02:00
parent 2f4ea81208
commit c5a36b522f
7 changed files with 82 additions and 10 deletions
+1
View File
@@ -47,6 +47,7 @@ Dashboard / Reports for Project Management will include:
'project_dashboard.xml',
'web_planner_data.xml',
],
'qweb': ['static/src/xml/project.xml'],
'demo': ['project_demo.xml'],
'test': [
],
+2 -7
View File
@@ -411,12 +411,6 @@ class task(osv.osv):
default['name'] = _("%s (copy)") % current.name
return super(task, self).copy_data(cr, uid, id, default, context)
def _compute_displayed_image(self, cr, uid, ids, prop, arg, context=None):
res = {}
for line in self.browse(cr, uid, ids, context=context):
res[line.id] = line.attachment_ids and line.attachment_ids.filtered(lambda x: x.mimetype.startswith('image'))[0] or None
return res
_columns = {
'active': fields.boolean('Active'),
'name': fields.char('Task Title', track_visibility='onchange', size=128, required=True, select=True),
@@ -454,7 +448,8 @@ class task(osv.osv):
'color': fields.integer('Color Index'),
'user_email': fields.related('user_id', 'email', type='char', string='User Email', readonly=True),
'attachment_ids': fields.one2many('ir.attachment', 'res_id', domain=lambda self: [('res_model', '=', self._name)], auto_join=True, string='Attachments'),
'displayed_image_id': fields.function(_compute_displayed_image, relation='ir.attachment', type="many2one", string='Attachment'),
# In the domain of displayed_image_id, we couln't use attachment_ids because a one2many is represented as a list of commands so we used res_model & res_id
'displayed_image_id': fields.many2one('ir.attachment', domain="[('res_model', '=', 'project.task'), ('res_id', '=', id), ('mimetype', 'ilike', 'image')]", string='Displayed Image'),
}
_defaults = {
'stage_id': _get_default_stage_id,
+8
View File
@@ -249,6 +249,10 @@
<field name="attachment_ids" eval="[(6, 0, [ref('msg_task_data_8_attach')])]"/>
</record>
<record id="project_task_data_8" model="project.task">
<field name="displayed_image_id" ref="msg_task_data_8_attach"/>
</record>
<record id="project_task_data_7" model="project.task">
<field name="user_id" ref="base.user_root"/>
<field name="priority">0</field>
@@ -303,6 +307,10 @@
<field name="attachment_ids" eval="[(6, 0, [ref('msg_task_data_14_attach')])]"/>
</record>
<record id="project_task_data_14" model="project.task">
<field name="displayed_image_id" ref="msg_task_data_14_attach"/>
</record>
</data>
</openerp>
+3
View File
@@ -290,6 +290,7 @@
<field name="sequence" groups="base.group_no_one"/>
<field name="partner_id"/>
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
<field name="displayed_image_id" groups="base.group_no_one"/>
</group>
<group col="2">
<field name="date_assign" groups="base.group_no_one"/>
@@ -324,6 +325,7 @@
<field name="date_deadline"/>
<field name="message_needaction_counter"/>
<field name="tag_ids"/>
<field name="attachment_ids"/>
<field name="displayed_image_id"/>
<field name="active"/>
<templates>
@@ -335,6 +337,7 @@
<span class="fa fa-bars fa-lg"/>
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<t t-if="widget.editable"><li><a type="set_cover">Set Cover Image</a></li></t>
<t t-if="widget.editable"><li><a type="edit">Edit Task</a></li></t>
<t t-if="widget.deletable"><li><a type="delete">Delete</a></li></t>
<li><ul class="oe_kanban_colorpicker" data-field="color"/></li>
+37 -2
View File
@@ -1,10 +1,15 @@
odoo.define('project.update_kanban', function (require) {
var KanbanRecord = require('web_kanban.Record');
var KanbanView = require('web_kanban.KanbanView');
var core = require('web.core');
var data = require('web.data');
var Model = require('web.Model');
var session = require('web.session');
var KanbanView = require('web_kanban.KanbanView');
var KanbanRecord = require('web_kanban.Record');
var QWeb = core.qweb;
KanbanRecord.include({
on_card_clicked: function() {
@@ -14,5 +19,35 @@ KanbanRecord.include({
this._super.apply(this, arguments);
}
},
on_kanban_action_clicked: function(ev) {
var self = this;
if (this.model === 'project.task' && $(ev.currentTarget).data('type') === 'set_cover') {
ev.preventDefault();
new Model('ir.attachment').query(['id', 'name'])
.filter([['res_model', '=', 'project.task'], ['res_id', '=', this.id], ['mimetype', 'ilike', 'image']])
.all().then(function (attachment_ids) {
var $cover_modal = $(QWeb.render("project.SetCoverModal", {
widget: self,
attachment_ids: attachment_ids,
}));
$cover_modal.appendTo($('body'));
$cover_modal.modal('toggle');
$cover_modal.on('click', 'img', function(ev){
self.update_record({
data : {
displayed_image_id: $(ev.currentTarget).data('id'),
}
});
$cover_modal.modal('toggle');
$cover_modal.remove();
});
});
} else {
this._super.apply(this, arguments, ev);
}
},
});
});
+30
View File
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<div t-name="project.SetCoverModal" class="modal" tabindex="-1" data-backdrop="static" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&amp;times;</button>
<h4 class="modal-title">Set a Cover Image</h4>
</div>
<div class="modal-body">
<div class="container-fluid">
<div t-if="attachment_ids.length > 0" class="row">
<t t-foreach="attachment_ids" t-as="attachment">
<div class="col-sm-3 o_image" style="height: 100%">
<img style="cursor: pointer; width: 100%" t-att-src="'/web/image/' + attachment['id'] + '?unique=1'" t-att-data-id="attachment['id']"/>
</div>
</t>
</div>
<div t-if="attachment_ids.length == 0">
There is no available image to be set as cover. Send a message on the task with an attached image.
</div>
</div>
</div>
<div class="modal-footer"><button type="button" class="btn btn-primary" data-dismiss="modal">Close</button></div>
</div>
</div>
</div>
</templates>
@@ -751,7 +751,7 @@ function transform_qweb_template (node, fvg, many2manys) {
case 'button':
case 'a':
var type = node.attrs.type || '';
if (_.indexOf('action,object,edit,open,delete,url'.split(','), type) !== -1) {
if (_.indexOf('action,object,edit,open,delete,url,set_cover'.split(','), type) !== -1) {
_.each(node.attrs, function(v, k) {
if (_.indexOf('icon,type,name,args,string,context,states,kanban_states'.split(','), k) != -1) {
node.attrs['data-' + k] = v;