summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2019-10-29 08:37:01 +0000
committerfw-bot <otis@odoo.com>2019-10-29 15:16:17 +0000
commit0562940f2c0cfb5483ba1043fffc86988d97445a (patch)
treec42160ae000457c51d3b6f168479bc7ea4c52ccf
parent72fa7d7015dadb44e14c60f0ef08cf45654c1ddf (diff)
[FIX] mail: dicuss can save favorite filters
In discuss, make a search with some stuff, and try to save that filter as favorite Before this commit, there was a crash, because the Discuss action did not implement what the controllers do to save favorites. After this commit, it is possible to save a filter as favorite OPW 2087258 closes odoo/odoo#39519 X-original-commit: 5514a414324675bf5c2cc0360e429a7d2548b16f Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
-rw-r--r--addons/mail/static/src/js/discuss.js4
-rw-r--r--addons/mail/static/tests/discuss_tests.js58
-rw-r--r--addons/web/static/src/js/chrome/action_mixin.js24
-rw-r--r--addons/web/static/src/js/views/abstract_controller.js20
4 files changed, 86 insertions, 20 deletions
diff --git a/addons/mail/static/src/js/discuss.js b/addons/mail/static/src/js/discuss.js
index ca926096c38..44a915955da 100644
--- a/addons/mail/static/src/js/discuss.js
+++ b/addons/mail/static/src/js/discuss.js
@@ -240,12 +240,12 @@ var ModeratorRejectMessageDialog = Dialog.extend({
var Discuss = AbstractAction.extend({
contentTemplate: 'mail.discuss',
- custom_events: {
+ custom_events: _.extend({}, AbstractAction.prototype.custom_events, {
discard_extended_composer: '_onDiscardExtendedComposer',
message_moderation: '_onMessageModeration',
search: '_onSearch',
update_moderation_buttons: '_onUpdateModerationButtons',
- },
+ }),
events: {
'click .o_mail_sidebar_title .o_add': '_onAddThread',
'blur .o_mail_add_thread input': '_onAddThreadBlur',
diff --git a/addons/mail/static/tests/discuss_tests.js b/addons/mail/static/tests/discuss_tests.js
index 2b41f72e599..4261f1a5461 100644
--- a/addons/mail/static/tests/discuss_tests.js
+++ b/addons/mail/static/tests/discuss_tests.js
@@ -1966,5 +1966,63 @@ QUnit.test('messages marked as read move to "History" mailbox', async function (
discuss.destroy();
});
+QUnit.test('save filter discuss', async function (assert) {
+ assert.expect(3);
+
+ var messageFetchCount = 0;
+ const discuss = await createDiscuss({
+ context: {},
+ params: {},
+ data: this.data,
+ services: this.services,
+ archs: {
+ 'mail.message,false,search': '<search>' +
+ '<field name="body" string="Content" filter_domain="[\'|\', (\'subject\', \'ilike\', self), (\'body\', \'ilike\', self)]"/>' +
+ '</search>',
+ },
+ session: {
+ partner_id: 3
+ },
+ mockRPC: async function (route, args) {
+ if (args.method === 'message_fetch' && messageFetchCount === 1) {
+ assert.deepEqual(args.args[0], [
+ ["needaction", "=", true],
+ "|",
+ ["subject", "ilike", "she was born in a hurricane"],
+ ["body", "ilike", "she was born in a hurricane"],
+ ], 'The fetch domain is correct');
+ }
+ return this._super.apply(this,arguments);
+ },
+ intercepts: {
+ create_filter: function (ev) {
+ assert.deepEqual(
+ JSON.parse(ev.data.filter.domain), [
+ "|",
+ ["subject", "ilike", "she was born in a hurricane"],
+ ["body", "ilike", "she was born in a hurricane"]
+ ], 'The filter should have been saved with the right domain');
+ }
+ }
+ });
+
+ assert.containsOnce(discuss, '.o_searchview_input_container', 'search view input present');
+
+ $('.o_searchview_input').val("she was born in a hurricane").trigger('keyup');
+ await testUtils.nextTick();
+
+ messageFetchCount = 1;
+ $('.o_searchview_input').trigger($.Event('keydown', { which: $.ui.keyCode.ENTER }));
+ await testUtils.nextTick();
+
+ await testUtils.dom.click(discuss.$('.o_favorites_menu_button'));
+ await testUtils.dom.click(discuss.$('.o_add_favorite'));
+
+ await testUtils.fields.editInput(discuss.$('.o_favorite_name input'), 'War');
+ await testUtils.dom.click(discuss.$('.o_save_favorite button'));
+
+ discuss.destroy();
+});
+
});
});
diff --git a/addons/web/static/src/js/chrome/action_mixin.js b/addons/web/static/src/js/chrome/action_mixin.js
index fa13e64e63e..b4a02879154 100644
--- a/addons/web/static/src/js/chrome/action_mixin.js
+++ b/addons/web/static/src/js/chrome/action_mixin.js
@@ -35,6 +35,15 @@ var ActionMixin = {
contentTemplate: null,
/**
+ * Events built by and managed by Odoo Framework
+ *
+ * It is expected that any Widget Class implementing this mixin
+ * will also implement the ParentedMixin which actually manages those
+ */
+ custom_events: {
+ get_controller_query_params: '_onGetControllerQueryParams',
+ },
+ /**
* If an action wants to use a control panel, it will be created and
* registered in this _controlPanel key (the widget). The way this control
* panel is created is up to the implementation (so, view controllers or
@@ -178,6 +187,21 @@ var ActionMixin = {
this._title = title;
this.updateControlPanel({title: this._title}, {clear: false});
},
+ /**
+ * FIXME: this logic should be rethought
+ *
+ * Handles a context request: provides to the caller the state of the
+ * current controller.
+ *
+ * @private
+ * @param {OdooEvent} ev
+ * @param {function} ev.data.callback used to send the requested state
+ */
+ _onGetControllerQueryParams: function (ev) {
+ ev.stopPropagation();
+ var state = this.getOwnedQueryParams();
+ ev.data.callback(state || {});
+ },
};
return ActionMixin;
diff --git a/addons/web/static/src/js/views/abstract_controller.js b/addons/web/static/src/js/views/abstract_controller.js
index 43a485fb009..780b0bcf1b6 100644
--- a/addons/web/static/src/js/views/abstract_controller.js
+++ b/addons/web/static/src/js/views/abstract_controller.js
@@ -24,14 +24,13 @@ var session = require('web.session');
var QWeb = core.qweb;
var AbstractController = mvc.Controller.extend(ActionMixin, {
- custom_events: {
- get_controller_query_params: '_onGetControllerQueryParams',
+ custom_events: _.extend({}, ActionMixin.custom_events, {
navigation_move: '_onNavigationMove',
open_record: '_onOpenRecord',
search: '_onSearch',
switch_view: '_onSwitchView',
search_panel_domain_updated: '_onSearchPanelDomainUpdated',
- },
+ }),
events: {
'click a[type="action"]': '_onActionClicked',
},
@@ -547,21 +546,6 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
}
},
/**
- * FIXME: this logic should be rethought
- *
- * Handles a context request: provides to the caller the state of the
- * current controller.
- *
- * @private
- * @param {OdooEvent} ev
- * @param {function} ev.data.callback used to send the requested state
- */
- _onGetControllerQueryParams: function (ev) {
- ev.stopPropagation();
- var state = this.getOwnedQueryParams();
- ev.data.callback(state || {});
- },
- /**
* Called either from the control panel to focus the controller
* or from the view to focus the search bar
*