Skip to content
Snippets Groups Projects
Commit ee5e9725 authored by Yannick Tivisse's avatar Yannick Tivisse
Browse files

[IMP] web: Always display (un)archive buttons in Action on form views

Purpose
=======

While cleaning the stat buttons across all modules, we decided to move
the (un)archiving from stat button to actions in the 'Action' dropdown.

Specification
=============

If the record has an 'active' field, display an action 'Archive' in the
dropdown if the record is active, else display an action 'Unarchive'.

The 'Archive' action should ask to the user if he's sure he wants to
make this action.
parent fa45f887
No related branches found
No related tags found
No related merge requests found
......@@ -183,6 +183,24 @@ var FormController = BasicController.extend({
var self = this;
if (this.hasSidebar) {
var otherItems = [];
if (this.archiveEnabled) {
var classname = "o_sidebar_item_archive" + (this.initialState.data.active ? "" : " o_hidden")
otherItems.push({
label: _t("Archive"),
callback: function () {
Dialog.confirm(self, _t("Are you sure that you want to archive this record?"), {
confirm_callback: self._toggleArchiveState.bind(self, true),
});
},
classname: classname,
});
classname = "o_sidebar_item_unarchive" + (this.initialState.data.active ? " o_hidden" : "")
otherItems.push({
label: _t("Unarchive"),
callback: this._toggleArchiveState.bind(this, false),
classname: classname,
});
}
if (this.is_action_enabled('delete')) {
otherItems.push({
label: _t('Delete'),
......@@ -263,6 +281,23 @@ var FormController = BasicController.extend({
// Private
//--------------------------------------------------------------------------
/**
* Archive the current selection
*
* @private
* @param {string[]} ids
* @param {boolean} archive
* @returns {Promise}
*/
_archive: function (ids, archive) {
if (ids.length === 0) {
return Promise.resolve();
}
return this.model
.toggleActive(ids, !archive, this.handle)
.then(this.update.bind(this, {}, {reload: false}));
},
/**
* Assign on the buttons save and discard additionnal behavior to facilitate
* the work of the users doing input only using the keyboard
......@@ -428,7 +463,6 @@ var FormController = BasicController.extend({
self._setTitle(title);
self._updateButtons();
self._updateSidebar();
self.autofocus();
});
},
......@@ -457,6 +491,25 @@ var FormController = BasicController.extend({
_updateSidebar: function () {
if (this.sidebar) {
this.sidebar.do_toggle(this.mode === 'readonly');
// Hide/Show Archive/Unarchive dropdown items
// We could have toggled the o_hidden class on the
// item theirselves, but the items are redrawed
// at each update, based on the initial definition
var archive_item = _.find(this.sidebar.items.other, function(item) {
return item.classname && item.classname.includes('o_sidebar_item_archive')
})
var unarchive_item = _.find(this.sidebar.items.other, function(item) {
return item.classname && item.classname.includes('o_sidebar_item_unarchive')
})
if (archive_item && unarchive_item) {
if (this.renderer.state.data.active) {
archive_item.classname = 'o_sidebar_item_archive';
unarchive_item.classname = 'o_sidebar_item_unarchive o_hidden';
} else {
archive_item.classname = 'o_sidebar_item_archive o_hidden';
unarchive_item.classname = 'o_sidebar_item_unarchive';
}
}
}
},
......@@ -712,6 +765,15 @@ var FormController = BasicController.extend({
self.renderer.confirmChange(state, state.id, [field]);
});
},
/**
* Called when clicking on 'Archive' or 'Unarchive' in the sidebar.
*
* @private
* @param {boolean} archive
*/
_toggleArchiveState: function (archive) {
this._archive([this.handle], archive);
},
});
return FormController;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment