[IMP] project: small code cleanup for project kanban view

bzr revid: rco@openerp.com-20120509065522-16ouzxqiwqgjdcyd
This commit is contained in:
Raphael Collet 2012-05-09 08:55:22 +02:00
parent e9d359a7ed
commit 7dab19c32b
3 changed files with 21 additions and 24 deletions

View File

@ -154,14 +154,14 @@ class project(osv.osv):
if proj.tasks:
raise osv.except_osv(_('Operation Not Permitted !'), _('You cannot delete a project containing tasks. I suggest you to desactivate it.'))
return super(project, self).unlink(cr, uid, ids, *args, **kwargs)
def _task_count(self, cr, uid, ids, field_name, arg, context=None):
res = dict.fromkeys(ids, 0)
task_ids = self.pool.get('project.task').search(cr, uid, [('project_id', 'in', ids)])
for task in self.pool.get('project.task').browse(cr, uid, task_ids, context):
res[task.project_id.id] += 1
return res
_columns = {
'complete_name': fields.function(_complete_name, string="Project Name", type='char', size=250),
'active': fields.boolean('Active', help="If the active field is set to False, it will allow you to hide the project without removing it."),
@ -198,14 +198,14 @@ class project(osv.osv):
'warn_header': fields.text('Mail Header', help="Header added at the beginning of the email for the warning message sent to the customer when a task is closed.", states={'close':[('readonly',True)], 'cancelled':[('readonly',True)]}),
'warn_footer': fields.text('Mail Footer', help="Footer added at the beginning of the email for the warning message sent to the customer when a task is closed.", states={'close':[('readonly',True)], 'cancelled':[('readonly',True)]}),
'type_ids': fields.many2many('project.task.type', 'project_task_type_rel', 'project_id', 'type_id', 'Tasks Stages', states={'close':[('readonly',True)], 'cancelled':[('readonly',True)]}),
'use_tasks': fields.boolean('Task',help = "If you check this field tasks appears in kanban view"),
'task_count': fields.function(_task_count , type='integer',string="Open Tasks"),
'use_tasks': fields.boolean('Use Tasks', help="Check this field if this project is aimed at managing tasks"),
'task_count': fields.function(_task_count, type='integer', string="Open Tasks"),
'color': fields.integer('Color Index'),
'company_uom_id': fields.related('company_id', 'project_time_mode_id', type='many2one', relation='product.uom'),
}
def dummy(self, cr, uid,ids, context):
return False
def dummy(self, cr, uid, ids, context):
return True
def _get_type_common(self, cr, uid, context):
ids = self.pool.get('project.task.type').search(cr, uid, [('project_default','=',1)], context=context)
@ -217,7 +217,7 @@ class project(osv.osv):
'priority': 1,
'sequence': 10,
'type_ids': _get_type_common,
'use_tasks' : True,
'use_tasks': True,
}
# TODO: Why not using a SQL contraints ?

View File

@ -207,12 +207,12 @@
</ul>
<h4><t t-esc="record.name.value.substr(0,33)"/><t t-if="record.name.value.length > 33">...</t></h4>
<div id="list">
<t t-if="record.use_tasks.raw_value">
<a id="1" name="%(act_project_project_2_project_task_all)d" class="oe_project_buttons" type="action"><t t-if="record.task_count.value &lt;= 1"> Task</t><t t-if="record.task_count.value &gt; 1"> Tasks</t>(<t t-esc="record.task_count.value"/>)</a>
</t>
<a t-if="record.use_tasks.raw_value" class="oe_project_buttons"
id="1" name="%(act_project_project_2_project_task_all)d" type="action">
Tasks(<field name="task_count"/>)</a>
</div>
<br/>
<button class="click_button" type="action">
<button class="click_button" name="dummy" type="object">
<table class="project_fields">
<tr id="deadline" t-if="record.date.raw_value">
<th align="left">Deadline</th>

View File

@ -1,7 +1,7 @@
openerp.project = function(openerp) {
openerp.web_kanban.ProjectKanban = openerp.web_kanban.KanbanRecord.include({
bind_events: function() {
self = this;
var self = this;
self._super();
if(this.view.dataset.model == 'project.project') {
@ -17,7 +17,7 @@ openerp.project = function(openerp) {
});
// set sequence like Tasks,Issues,Timesheets and Phases
my_list = $("#list a")
var my_list = $("#list a")
my_list.sort(function (a, b) {
var aValue = parseInt(a.id);
var bValue = parseInt(b.id);
@ -25,27 +25,24 @@ openerp.project = function(openerp) {
});
$('#list').replaceWith(my_list);
//it opens action in sequence which ever is first.
click_button = $(this.$element).find('.click_button')
if (my_list.length!=0){
click_button.attr('data-name',my_list[0].getAttribute('data-name'));
// when vignette is clicked, it opens the first action in sequence
if (my_list.length != 0) {
var click_button = $(this.$element).find('.click_button')
click_button.attr('data-name', my_list[0].getAttribute('data-name'));
click_button.attr('data-type', "action");
}
else{
click_button.attr('data-name','dummy');
}
if(isNaN(parseInt(click_button.attr('data-name'))))click_button.attr('data-type',"object");
/* set background color.
we can do other way to implement new widget.
because we need to rpc call for that.
*/
this.$element.find('.bgcolor').click(function(){
color = parseInt($(this).find('span').attr('class').split(' ')[0].substring(16))
color_class = $(this).find('span').attr('class').split(' ')[0]
var color = parseInt($(this).find('span').attr('class').split(' ')[0].substring(16))
var color_class = $(this).find('span').attr('class').split(' ')[0]
$(this).closest('#oe_project_kanban_vignette').removeClass().addClass(color_class + ' oe_project_kanban_vignette');
self.view.dataset.write(parseInt(this.id), {color:color});
});
};
}
}
});
}