diff --git a/addons/web/static/src/js/views/list_view.js b/addons/web/static/src/js/views/list_view.js index 219a9308547..63fe3591b99 100644 --- a/addons/web/static/src/js/views/list_view.js +++ b/addons/web/static/src/js/views/list_view.js @@ -305,6 +305,8 @@ var ListView = View.extend( /** @lends instance.web.ListView# */ { } this.sidebar.add_items('other', _.compact([ { label: _t("Export"), callback: this.on_sidebar_export }, + this.fields_view.fields.active && {label: _t("Archive"), callback: this.do_archive_selected}, + this.fields_view.fields.active && {label: _t("Unarchive"), callback: this.do_unarchive_selected}, this.is_action_enabled('delete') && { label: _t('Delete'), callback: this.do_delete_selected } ])); @@ -754,6 +756,30 @@ var ListView = View.extend( /** @lends instance.web.ListView# */ { this.do_warn(_t("Warning"), _t("You must select at least one record.")); } }, + /** + * Handles archiving/unarchiving of selected lines + */ + do_archive_selected: function () { + var records = this.groups.get_selection().records; + this.do_archive(records, true); + }, + do_unarchive_selected: function () { + var records = this.groups.get_selection().records; + this.do_archive(records, false); + }, + do_archive: function (records, archive) { + var active_value = !archive; + var record_ids = []; + _.each(records, function(record) { + if (record.active != active_value) { + record_ids.push(record.id); + } + }); + if (record_ids.length) { + this.dataset.call('write', [record_ids, {active: active_value}]) + .done(_.bind(this.reload, this)); + } + }, /** * Computes the aggregates for the current list view, either on the * records provided or on the records of the internal diff --git a/addons/web_kanban/static/src/js/kanban_column.js b/addons/web_kanban/static/src/js/kanban_column.js index 64a78afa425..f64e1e7bcdf 100644 --- a/addons/web_kanban/static/src/js/kanban_column.js +++ b/addons/web_kanban/static/src/js/kanban_column.js @@ -24,6 +24,8 @@ var KanbanColumn = Widget.extend({ }, 'click .o_column_edit': 'edit_column', 'click .o_column_delete': 'delete_column', + 'click .o_column_archive': 'archive_records', + 'click .o_column_unarchive': 'unarchive_records', 'click .o_kanban_quick_add': 'add_quick_create', 'click .o_kanban_load_more': 'load_more', }, @@ -49,6 +51,7 @@ var KanbanColumn = Widget.extend({ this.grouped_by_m2o = options.grouped_by_m2o; this.editable = options.editable; this.deletable = options.deletable; + this.has_active_field = options.has_active_field; this.records_editable = options.records_editable; this.records_deletable = options.records_deletable; this.relation = options.relation; @@ -175,6 +178,16 @@ var KanbanColumn = Widget.extend({ } }, + archive_records: function(event) { + event.preventDefault(); + this.trigger_up('kanban_column_archive_records', {archive: true}); + }, + + unarchive_records: function(event) { + event.preventDefault(); + this.trigger_up('kanban_column_archive_records', {archive: false}); + }, + delete_column: function (event) { event.preventDefault(); var buttons = [ diff --git a/addons/web_kanban/static/src/js/kanban_view.js b/addons/web_kanban/static/src/js/kanban_view.js index b2f3f55c10a..62d3e7a7666 100644 --- a/addons/web_kanban/static/src/js/kanban_view.js +++ b/addons/web_kanban/static/src/js/kanban_view.js @@ -43,6 +43,7 @@ var KanbanView = View.extend({ 'kanban_record_update': 'update_record', 'kanban_column_add_record': 'add_record_to_column', 'kanban_column_delete': 'delete_column', + 'kanban_column_archive_records': 'archive_records', 'column_add_record': 'column_add_record', 'quick_create_add_column': 'add_new_column', 'kanban_load_more': 'load_more', @@ -271,6 +272,9 @@ var KanbanView = View.extend({ } return this._super(action); }, + has_active_field: function() { + return this.fields_view.fields.active; + }, _is_quick_create_enabled: function() { if (!this.quick_creatable || !this.is_action_enabled('create')) return false; @@ -394,6 +398,7 @@ var KanbanView = View.extend({ return { editable: this.is_action_enabled('group_edit'), deletable: this.is_action_enabled('group_delete'), + has_active_field: this.has_active_field(), grouped_by_m2o: this.grouped_by_m2o, relation: this.relation, qweb: this.qweb, @@ -574,6 +579,23 @@ var KanbanView = View.extend({ }); }, + archive_records: function(event) { + if (!this.has_active_field()) { + return; + } + var active_value = !event.data.archive; + var record_ids = []; + _.each(event.target.records, function(kanban_record) { + if (kanban_record.record.active.value != active_value) { + record_ids.push(kanban_record.id); + } + }); + if (record_ids.length) { + this.dataset.call('write', [record_ids, {active: active_value}]) + .done(this.do_reload); + } + }, + reload_record: function (record) { var self = this; this.dataset.read_ids([record.id], this.fields_keys.concat(['__last_update'])).done(function(records) { diff --git a/addons/web_kanban/static/src/xml/web_kanban.xml b/addons/web_kanban/static/src/xml/web_kanban.xml index ff82335f67b..e07298e95b5 100644 --- a/addons/web_kanban/static/src/xml/web_kanban.xml +++ b/addons/web_kanban/static/src/xml/web_kanban.xml @@ -23,6 +23,10 @@