[ADD] web, web_kanban: add archive/unarchive
In kanban views, add archive/unarchive for all records in a column. In list views, add archive/unarchive in sidebar.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
<li t-if="widget.editable and widget.id"><a class="o_column_edit" href="#">Edit</a></li>
|
||||
<li t-if="widget.deletable and widget.id"><a class="o_column_delete" href="#">Delete</a></li>
|
||||
</t>
|
||||
<t t-if="widget.has_active_field and widget.data_records.length">
|
||||
<li><a class="o_column_archive" href="#">Archive Records</a></li>
|
||||
<li><a class="o_column_unarchive" href="#">Unarchive Records</a></li>
|
||||
</t>
|
||||
</ul>
|
||||
</span>
|
||||
<t t-if="widget.quick_create">
|
||||
|
||||
Reference in New Issue
Block a user