[FIX] web: update action on archive/unarchive
Before this commit, when archiving a record through the action menu, the 'Archive' link was not updated to 'Unarchive' and same when unarchive was clicked, the link was not updated to 'Archive'. After this commit, when archiving a record through the action menu, the 'Archive' link is updated to 'Unarchive', same way when unarchiving a record link is updated to 'Archive'. This commit also introduces a new prop 'closeOnSelected' to the Dropdown component, to specify whether the dropdown should be closed when an item is selected, and makes Action Menu dropdown closed on item selected. task-2251739 closes odoo/odoo#53835 X-original-commit: dc5d02ade7747c74c31566c74932ef45c30e9356 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Co-authored-by: Mohammed Shekha <msh@odoo.com>
This commit is contained in:
committed by
Aaron Bohy
co-authored by
Mohammed Shekha
parent
499a649b16
commit
c3080e54ed
@@ -110,7 +110,11 @@ odoo.define('web.DropdownMenu', function (require) {
|
||||
* @private
|
||||
* @param {OwlEvent} ev
|
||||
*/
|
||||
_onItemSelected(ev) { }
|
||||
_onItemSelected(/* ev */) {
|
||||
if (this.props.closeOnSelected) {
|
||||
this.state.open = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -143,6 +147,7 @@ odoo.define('web.DropdownMenu', function (require) {
|
||||
optional: 1,
|
||||
},
|
||||
title: { type: String, optional: 1 },
|
||||
closeOnSelected: { type: Boolean, optional: 1 },
|
||||
};
|
||||
DropdownMenu.template = 'web.DropdownMenu';
|
||||
|
||||
|
||||
@@ -188,15 +188,15 @@ var FormController = BasicController.extend({
|
||||
* @override
|
||||
* @private
|
||||
**/
|
||||
_getActionMenuItems: function () {
|
||||
_getActionMenuItems: function (state) {
|
||||
if (!this.hasActionMenus || this.mode === 'edit') {
|
||||
return null;
|
||||
}
|
||||
const props = this._super(...arguments);
|
||||
const activeField = this.model.getActiveField(this.initialState);
|
||||
const activeField = this.model.getActiveField(state);
|
||||
const otherActionItems = [];
|
||||
if (this.archiveEnabled && activeField) {
|
||||
if (this.initialState.data[activeField]) {
|
||||
if (state.data[activeField]) {
|
||||
otherActionItems.push({
|
||||
description: _t("Archive"),
|
||||
callback: () => {
|
||||
|
||||
@@ -624,6 +624,7 @@
|
||||
title="env._t('Action')"
|
||||
items="actionItems"
|
||||
icon="'fa fa-cog'"
|
||||
closeOnSelected="true"
|
||||
/>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
@@ -2136,6 +2136,58 @@ QUnit.module('Views', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('archive/unarchive a record', async function (assert) {
|
||||
assert.expect(10);
|
||||
|
||||
// add active field on partner model to have archive option
|
||||
this.data.partner.fields.active = {string: 'Active', type: 'char', default: true};
|
||||
|
||||
const form = await createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
res_id: 1,
|
||||
viewOptions: { hasActionMenus: true },
|
||||
arch: '<form><field name="active"/><field name="foo"/></form>',
|
||||
mockRPC: function (route, args) {
|
||||
assert.step(args.method);
|
||||
if (args.method === 'action_archive') {
|
||||
this.data.partner.records[0].active = false;
|
||||
return Promise.resolve();
|
||||
}
|
||||
if (args.method === 'action_unarchive') {
|
||||
this.data.partner.records[0].active = true;
|
||||
return Promise.resolve();
|
||||
}
|
||||
return this._super(...arguments);
|
||||
},
|
||||
});
|
||||
|
||||
await cpHelpers.toggleActionMenu(form);
|
||||
assert.containsOnce(form, '.o_cp_action_menus a:contains(Archive)');
|
||||
|
||||
await cpHelpers.toggleMenuItem(form, "Archive");
|
||||
assert.containsOnce(document.body, '.modal');
|
||||
|
||||
await testUtils.dom.click($('.modal-footer .btn-primary'));
|
||||
await cpHelpers.toggleActionMenu(form);
|
||||
assert.containsOnce(form, '.o_cp_action_menus a:contains(Unarchive)');
|
||||
|
||||
await cpHelpers.toggleMenuItem(form, "Unarchive");
|
||||
await cpHelpers.toggleActionMenu(form);
|
||||
assert.containsOnce(form, '.o_cp_action_menus a:contains(Archive)');
|
||||
|
||||
assert.verifySteps([
|
||||
'read',
|
||||
'action_archive',
|
||||
'read',
|
||||
'action_unarchive',
|
||||
'read',
|
||||
]);
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('can duplicate a record', async function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user