summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorYannick Tivisse <yti@odoo.com>2019-07-01 16:36:40 +0200
committerYannick Tivisse <yti@odoo.com>2019-07-12 13:01:35 +0200
commitee5e972586795114f4adeead47746397a181c549 (patch)
treefccec897a4a8cc6b9c2bb02d63435905d63cee35 /addons/web/static/src
parentfa45f88726066b62dfbb45964e4f87bcb6c193f9 (diff)
[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.
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/views/form/form_controller.js64
1 files changed, 63 insertions, 1 deletions
diff --git a/addons/web/static/src/js/views/form/form_controller.js b/addons/web/static/src/js/views/form/form_controller.js
index 89477f9c974..67d1a6aa130 100644
--- a/addons/web/static/src/js/views/form/form_controller.js
+++ b/addons/web/static/src/js/views/form/form_controller.js
@@ -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'),
@@ -264,6 +282,23 @@ var FormController = BasicController.extend({
//--------------------------------------------------------------------------
/**
+ * 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;