diff options
| author | Hardik Prajapati <hap@odoo.com> | 2020-05-08 12:32:14 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2020-06-29 18:51:47 +0000 |
| commit | c3080e54ed88092815acbec628c77253fbd6616b (patch) | |
| tree | 2a06afa493830e29a8847ed79a100d4b09e3694f /addons/web | |
| parent | 499a649b162995ad2bf54f2bb1a50951653ed5ad (diff) | |
[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>
Diffstat (limited to 'addons/web')
| -rw-r--r-- | addons/web/static/src/js/components/dropdown_menu.js | 7 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/form/form_controller.js | 6 | ||||
| -rw-r--r-- | addons/web/static/src/xml/base.xml | 1 | ||||
| -rw-r--r-- | addons/web/static/tests/views/form_tests.js | 52 |
4 files changed, 62 insertions, 4 deletions
diff --git a/addons/web/static/src/js/components/dropdown_menu.js b/addons/web/static/src/js/components/dropdown_menu.js index 0684a1fd69d..c536f3caba7 100644 --- a/addons/web/static/src/js/components/dropdown_menu.js +++ b/addons/web/static/src/js/components/dropdown_menu.js @@ -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'; 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 eeb1153b16f..30eea51d740 100644 --- a/addons/web/static/src/js/views/form/form_controller.js +++ b/addons/web/static/src/js/views/form/form_controller.js @@ -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: () => { diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 0c3c5813a87..7cb009b95fb 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -624,6 +624,7 @@ title="env._t('Action')" items="actionItems" icon="'fa fa-cog'" + closeOnSelected="true" /> </div> </t> diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index 99c49fc9519..227980cc634 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -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); |
