diff --git a/addons/mail/static/src/js/tools/debug_manager.js b/addons/mail/static/src/js/tools/debug_manager.js new file mode 100644 index 00000000000..4c768e8bb2d --- /dev/null +++ b/addons/mail/static/src/js/tools/debug_manager.js @@ -0,0 +1,30 @@ +odoo.define('mail.DebugManager', function (require) { +"use strict"; + +var core = require('web.core'); +var DebugManager = require('web.DebugManager'); + +var _t = core._t; +/** + * adds a new method available for the debug manager, called by the "Manage Messages" button. + * + */ +DebugManager.include({ + getMailMessages: function () { + var self = this; + var selectedIDs = this._controller.getSelectedIds(); + if (!selectedIDs.length) { + console.warn(_t("No message available")); + return; + } + this.do_action({ + res_model: 'mail.message', + name: _t('Manage Messages'), + views: [[false, 'list'], [false, 'form']], + type: 'ir.actions.act_window', + domain: [['res_id', '=', selectedIDs[0]], ['model', '=', this._controller.modelName]], + }); + }, +}); + +}); diff --git a/addons/mail/static/src/xml/thread.xml b/addons/mail/static/src/xml/thread.xml index a79085c1756..26faf42ba13 100644 --- a/addons/mail/static/src/xml/thread.xml +++ b/addons/mail/static/src/xml/thread.xml @@ -1,6 +1,14 @@ + + + + Manage Messages + + + @@ -118,6 +120,8 @@ + + diff --git a/addons/web/static/src/js/tools/debug_manager.js b/addons/web/static/src/js/tools/debug_manager.js index 5b944724c11..dcdfc1a73bc 100644 --- a/addons/web/static/src/js/tools/debug_manager.js +++ b/addons/web/static/src/js/tools/debug_manager.js @@ -353,7 +353,20 @@ DebugManager.include({ })); }.bind(this)); }, - + get_attachments: function() { + var selectedIDs = this._controller.getSelectedIds(); + if (!selectedIDs.length) { + console.warn(_t("No attachment available")); + return; + } + this.do_action({ + res_model: 'ir.attachment', + name: _t('Manage Attachments'), + views: [[false, 'list'], [false, 'form']], + type: 'ir.actions.act_window', + domain: [['res_model', '=', this._action.res_model], ['res_id', '=', selectedIDs[0]]], + }); + }, get_metadata: function() { var self = this; var selectedIDs = this._controller.getSelectedIds(); diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 04ad1907f0b..8dbbe0410e7 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -267,6 +267,7 @@ Set Defaults View Metadata + Manage Attachments Fields View Get diff --git a/addons/web/static/tests/helpers/test_utils.js b/addons/web/static/tests/helpers/test_utils.js index 803c671ff56..b1a0467254a 100644 --- a/addons/web/static/tests/helpers/test_utils.js +++ b/addons/web/static/tests/helpers/test_utils.js @@ -16,6 +16,7 @@ var basic_fields = require('web.basic_fields'); var config = require('web.config'); var ControlPanel = require('web.ControlPanel'); var core = require('web.core'); +var DebugManager = require('web.DebugManager'); var dom = require('web.dom'); var session = require('web.session'); var MockServer = require('web.MockServer'); @@ -116,6 +117,37 @@ var createActionManager = function (params) { return actionManager; }; +/** + * Create and return an instance of DebugManager with all rpcs going through a + * mock method, assuming that the user has access rights, and is an admin. + * + * @param {Object} [params={}] + */ +var createDebugManager = function (params) { + params = params || {}; + _.extend(params, { + mockRPC: function (route, args) { + if (args.method === 'check_access_rights') { + return $.when(true); + } + if (args.method === 'xmlid_to_res_id') { + return $.when(true); + } + return this._super.apply(this, arguments); + }, + session: { + user_has_group: function (group) { + if (group === 'base.group_no_one') { + return $.when(true); + } + return this._super.apply(this, arguments); + }, + }, + }); + var debugManager = new DebugManager(); + addMockEnvironment(debugManager, params); + return debugManager; +}; /** * performs a fields_view_get, and mocks the postprocessing done by the @@ -869,6 +901,7 @@ return $.when( return { addMockEnvironment: addMockEnvironment, createActionManager: createActionManager, + createDebugManager: createDebugManager, createAsyncView: createAsyncView, createModel: createModel, createParent: createParent, diff --git a/addons/web/static/tests/tools/debug_manager_tests.js b/addons/web/static/tests/tools/debug_manager_tests.js index 424ebe1517f..8e41481734f 100644 --- a/addons/web/static/tests/tools/debug_manager_tests.js +++ b/addons/web/static/tests/tools/debug_manager_tests.js @@ -1,44 +1,13 @@ odoo.define('web.debugManagerTests', function (require) { "use strict"; -var DebugManager = require('web.DebugManager'); var testUtils = require('web.test_utils'); -/** - * Create and return an instance of DebugManager with all rpcs going through a - * mock method, assuming that the user has access rights, and is an admin. - * - * @param {Object} [params={}] - */ -var createDebugManager = function (params) { - params = params || {}; - _.extend(params, { - mockRPC: function (route, args) { - if (args.method === 'check_access_rights') { - return $.when(true); - } - if (args.method === 'xmlid_to_res_id') { - return $.when(true); - } - return this._super.apply(this, arguments); - }, - session: { - user_has_group: function (group) { - if (group === 'base.group_no_one') { - return $.when(true); - } - return this._super.apply(this, arguments); - }, - }, - }); - var debugManager = new DebugManager(); - testUtils.addMockEnvironment(debugManager, params); - return debugManager; -}; +var createDebugManager = testUtils.createDebugManager; QUnit.module('DebugManager', {}, function () { - QUnit.test("edit view menu item", function (assert) { + QUnit.test("list: edit view menu item", function (assert) { assert.expect(3); var debugManager = createDebugManager(); @@ -68,5 +37,52 @@ QUnit.module('DebugManager', {}, function () { debugManager.destroy(); }); + + QUnit.test("form: Manage Attachments option", function (assert) { + assert.expect(3); + + var debugManager = createDebugManager({ + intercepts: { + do_action: function (event) { + assert.deepEqual(event.data.action, { + domain: [["res_model", "=", "test.model"],["res_id", "=", 5]], + name: "Manage Attachments", + res_model: "ir.attachment", + type: "ir.actions.act_window", + views: [[false, "list"],[false, "form"]], + }); + }, + }, + }); + + debugManager.appendTo($('#qunit-fixture')); + + // Simulate update debug manager from web client + var action = { + views: [{ + displayName: "Form", + fieldsView: { + view_id: 2, + }, + type: "form", + }], + res_model: "test.model", + }; + var view = { + viewType: "form", + getSelectedIds: function () { + return [5]; + }, + }; + debugManager.update('action', action, view); + + var $attachmentMenu = debugManager.$('a[data-action=get_attachments]'); + assert.strictEqual($attachmentMenu.length, 1, "should have Manage Attachments menu item"); + assert.strictEqual($attachmentMenu.text().trim(), "Manage Attachments", + "should have correct menu item text"); + $attachmentMenu.click(); + + debugManager.destroy(); + }); }); });