[FIX] web_kanban: prevent drag'n'drop
Prevent drag'n'drop in the following cases: - Group by field is read-only - Group by field is a date or datetime This is necessary to avoid, for example, changing the state of a sales order or an invoice without going through all the business logic. Related to #7047 opw-671697
This commit is contained in:
@@ -52,6 +52,7 @@ var KanbanColumn = Widget.extend({
|
||||
this.grouped_by_m2o = options.grouped_by_m2o;
|
||||
this.editable = options.editable;
|
||||
this.deletable = options.deletable;
|
||||
this.draggable = record_options.draggable;
|
||||
this.has_active_field = options.has_active_field;
|
||||
this.records_editable = options.records_editable;
|
||||
this.records_deletable = options.records_deletable;
|
||||
@@ -82,7 +83,7 @@ var KanbanColumn = Widget.extend({
|
||||
}
|
||||
this.$header.tooltip();
|
||||
|
||||
if (config.device.size_class > config.device.SIZES.XS) {
|
||||
if (config.device.size_class > config.device.SIZES.XS && this.draggable !== false) {
|
||||
// deactivate sortable in mobile mode. It does not work anyway,
|
||||
// and it breaks horizontal scrolling in kanban views. Someday, we
|
||||
// should find a way to use the touch events to make sortable work.
|
||||
|
||||
@@ -3,6 +3,7 @@ odoo.define('web_kanban.KanbanView', function (require) {
|
||||
|
||||
var core = require('web.core');
|
||||
var data = require('web.data');
|
||||
var data_manager = require('web.data_manager');
|
||||
var Model = require('web.DataModel');
|
||||
var Dialog = require('web.Dialog');
|
||||
var form_common = require('web.form_common');
|
||||
@@ -64,6 +65,7 @@ var KanbanView = View.extend({
|
||||
this.qweb.default_dict = _.clone(QWeb.default_dict);
|
||||
|
||||
this.limit = this.options.limit || 40;
|
||||
this.fields = {};
|
||||
this.fields_keys = _.keys(this.fields_view.fields);
|
||||
this.grouped = undefined;
|
||||
this.group_by_field = undefined;
|
||||
@@ -88,6 +90,8 @@ var KanbanView = View.extend({
|
||||
},
|
||||
|
||||
willStart: function() {
|
||||
var self = this;
|
||||
var fields_def = data_manager.load_fields(this.dataset);
|
||||
// add qweb templates
|
||||
for (var i=0, ii=this.fields_view.arch.children.length; i < ii; i++) {
|
||||
var child = this.fields_view.arch.children[i];
|
||||
@@ -102,7 +106,9 @@ var KanbanView = View.extend({
|
||||
}
|
||||
}
|
||||
}
|
||||
return this._super();
|
||||
return $.when(fields_def, this._super()).then(function (fields) {
|
||||
self.fields = fields;
|
||||
});
|
||||
},
|
||||
|
||||
start: function() {
|
||||
@@ -415,8 +421,24 @@ var KanbanView = View.extend({
|
||||
|
||||
render_grouped: function (fragment) {
|
||||
var self = this;
|
||||
|
||||
// Drag'n'drop activation/deactivation
|
||||
var group_by_field_attrs = this.fields[this.group_by_field];
|
||||
|
||||
// Deactivate the drag'n'drop if:
|
||||
// - field is a date or datetime since we group by month
|
||||
// - field is readonly
|
||||
var draggable = true;
|
||||
if (group_by_field_attrs) {
|
||||
if (group_by_field_attrs.type === "date" || group_by_field_attrs.type === "datetime") {
|
||||
var draggable = false;
|
||||
}
|
||||
else if (group_by_field_attrs.readonly !== undefined) {
|
||||
var draggable = !(group_by_field_attrs.readonly);
|
||||
}
|
||||
}
|
||||
var record_options = _.extend(this.record_options, {
|
||||
draggable: true,
|
||||
draggable: draggable,
|
||||
});
|
||||
|
||||
var column_options = this.get_column_options();
|
||||
|
||||
Reference in New Issue
Block a user