From 7a9c16ffee3e1154f78cfa04719d752f74fa8a77 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 18 Mar 2016 14:56:29 +0100 Subject: [PATCH] [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 --- .../web_kanban/static/src/js/kanban_column.js | 3 +- .../web_kanban/static/src/js/kanban_view.js | 28 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/addons/web_kanban/static/src/js/kanban_column.js b/addons/web_kanban/static/src/js/kanban_column.js index 754f5dc812c..7718991b10f 100644 --- a/addons/web_kanban/static/src/js/kanban_column.js +++ b/addons/web_kanban/static/src/js/kanban_column.js @@ -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. diff --git a/addons/web_kanban/static/src/js/kanban_view.js b/addons/web_kanban/static/src/js/kanban_view.js index 3ae65d76be9..e35976a1fa6 100644 --- a/addons/web_kanban/static/src/js/kanban_view.js +++ b/addons/web_kanban/static/src/js/kanban_view.js @@ -423,8 +423,34 @@ var KanbanView = View.extend({ render_grouped: function (fragment) { var self = this; + + // FORWARDPORT UP TO SAAS-10, NOT IN MASTER! + // Drag'n'drop activation/deactivation + var group_by_field_attrs = this.fields_view.fields[this.group_by_field]; + + // Group_by field might not be in the Kanban view, so we need to get it somewhere else... + // This somewhere else is on the search view. + if (group_by_field_attrs === undefined) { + if (this.ViewManager.searchview.groupby_menu && this.ViewManager.searchview.groupby_menu.groupable_fields) { + group_by_field_attrs = _.find(this.ViewManager.searchview.groupby_menu.groupable_fields, function(field) { + return field.name === self.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();