[REF] project: refactor project_kanban.js
Replaces multiple .includes in favor of .extend for cleaner code. Closes: odoo/odoo#74822 Task ID: 2618321
This commit is contained in:
@@ -1,32 +1,63 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import KanbanController from 'web.KanbanController';
|
||||
import KanbanRenderer from 'web.KanbanRenderer';
|
||||
import KanbanView from 'web.KanbanView';
|
||||
import KanbanColumn from 'web.KanbanColumn';
|
||||
import viewRegistry from 'web.view_registry';
|
||||
import KanbanRecord from 'web.KanbanRecord';
|
||||
import { ProjectControlPanel } from '@project/js/project_control_panel';
|
||||
|
||||
KanbanRecord.include({
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
// PROJECTS
|
||||
|
||||
const ProjectProjectKanbanRecord = KanbanRecord.extend({
|
||||
/**
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
// YTI TODO: Should be transformed into a extend and specific to project
|
||||
_openRecord: function () {
|
||||
if (this.selectionMode !== true && this.modelName === 'project.project' &&
|
||||
this.$(".o_project_kanban_boxes a").length) {
|
||||
this.$('.o_project_kanban_boxes a').first().click();
|
||||
const kanbanBoxesElement = this.el.querySelectorAll('.o_project_kanban_boxes a');
|
||||
if (this.selectionMode !== true && kanbanBoxesElement.length) {
|
||||
kanbanBoxesElement[0].click();
|
||||
} else {
|
||||
this._super.apply(this, arguments);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const ProjectProjectKanbanRenderer = KanbanRenderer.extend({
|
||||
config: _.extend({}, KanbanRenderer.prototype.config, {
|
||||
KanbanRecord: ProjectProjectKanbanRecord,
|
||||
}),
|
||||
});
|
||||
|
||||
const ProjectProjectKanbanView = KanbanView.extend({
|
||||
config: Object.assign({}, KanbanView.prototype.config, {
|
||||
Renderer: ProjectProjectKanbanRenderer,
|
||||
})
|
||||
});
|
||||
|
||||
viewRegistry.add('project_project_kanban', ProjectProjectKanbanView);
|
||||
|
||||
// TASKS
|
||||
|
||||
const ProjectTaskKanbanColumn = KanbanColumn.extend({
|
||||
/**
|
||||
* @override
|
||||
* @private
|
||||
*/
|
||||
_onDeleteColumn: function (event) {
|
||||
event.preventDefault();
|
||||
this.trigger_up('kanban_column_delete_wizard');
|
||||
},
|
||||
});
|
||||
|
||||
const ProjectTaskKanbanRenderer = KanbanRenderer.extend({
|
||||
config: Object.assign({}, KanbanRenderer.prototype.config, {
|
||||
KanbanColumn: ProjectTaskKanbanColumn,
|
||||
}),
|
||||
});
|
||||
|
||||
export const ProjectKanbanController = KanbanController.extend({
|
||||
custom_events: Object.assign({}, KanbanController.prototype.custom_events, {
|
||||
'kanban_column_delete_wizard': '_onDeleteColumnWizard',
|
||||
@@ -45,25 +76,15 @@ export const ProjectKanbanController = KanbanController.extend({
|
||||
}).then(function (res) {
|
||||
self.do_action(res);
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const ProjectKanbanView = KanbanView.extend({
|
||||
config: Object.assign({}, KanbanView.prototype.config, {
|
||||
config: _.extend({}, KanbanView.prototype.config, {
|
||||
Controller: ProjectKanbanController,
|
||||
Renderer: ProjectTaskKanbanRenderer,
|
||||
ControlPanel: ProjectControlPanel,
|
||||
}),
|
||||
});
|
||||
|
||||
KanbanColumn.include({
|
||||
_onDeleteColumn: function (event) {
|
||||
event.preventDefault();
|
||||
if (this.modelName === 'project.task') {
|
||||
this.trigger_up('kanban_column_delete_wizard');
|
||||
return;
|
||||
}
|
||||
this._super.apply(this, arguments);
|
||||
}
|
||||
});
|
||||
|
||||
viewRegistry.add('project_kanban', ProjectKanbanView);
|
||||
viewRegistry.add('project_task_kanban', ProjectKanbanView);
|
||||
|
||||
@@ -543,7 +543,7 @@
|
||||
<field name="name">project.project.kanban</field>
|
||||
<field name="model">project.project</field>
|
||||
<field name="arch" type="xml">
|
||||
<kanban class="oe_background_grey o_kanban_dashboard o_project_kanban o_emphasize_colors" on_create="project.open_create_project" sample="1">
|
||||
<kanban class="oe_background_grey o_kanban_dashboard o_project_kanban o_emphasize_colors" on_create="project.open_create_project" js_class="project_project_kanban" sample="1">
|
||||
<field name="name"/>
|
||||
<field name="partner_id"/>
|
||||
<field name="commercial_partner_id"/>
|
||||
@@ -918,7 +918,7 @@
|
||||
<field name="name">project.task.kanban</field>
|
||||
<field name="model">project.task</field>
|
||||
<field name="arch" type="xml">
|
||||
<kanban default_group_by="stage_id" class="o_kanban_small_column o_kanban_project_tasks" on_create="quick_create" quick_create_view="project.quick_create_task_form" examples="project" js_class="project_kanban" sample="1">
|
||||
<kanban default_group_by="stage_id" class="o_kanban_small_column o_kanban_project_tasks" on_create="quick_create" quick_create_view="project.quick_create_task_form" examples="project" js_class="project_task_kanban" sample="1">
|
||||
<field name="color"/>
|
||||
<field name="priority"/>
|
||||
<field name="stage_id" options='{"group_by_tooltip": {"description": "Description"}}'/>
|
||||
|
||||
Reference in New Issue
Block a user