From dd7022eccd99b5ba9688f63b517d23c405f23797 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Thu, 4 Jul 2019 07:40:18 +0000 Subject: [IMP] base,web*: searchpanel in all multi record views Before this rev. the searchpanel could only be activated in kanban views (and it was specified in the kanban arch). From now on, the searchpanel can be activated in any multi record view. It's arch is moved to the search view arch (inside the tag). Task 1985921 Co-authored-by: Aaron Bohy --- .../web/static/src/js/views/abstract_controller.js | 76 ++++++++++++++++++---- 1 file changed, 62 insertions(+), 14 deletions(-) (limited to 'addons/web/static/src/js/views/abstract_controller.js') diff --git a/addons/web/static/src/js/views/abstract_controller.js b/addons/web/static/src/js/views/abstract_controller.js index d8cc6baa8f5..58a011599d1 100644 --- a/addons/web/static/src/js/views/abstract_controller.js +++ b/addons/web/static/src/js/views/abstract_controller.js @@ -28,6 +28,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, { open_record: '_onOpenRecord', search: '_onSearch', switch_view: '_onSwitchView', + search_panel_domain_updated: '_onSearchPanelDomainUpdated', }, events: { 'click a[type="action"]': '_onActionClicked', @@ -58,6 +59,11 @@ var AbstractController = mvc.Controller.extend(ActionMixin, { this.viewType = params.viewType; // use a DropPrevious to correctly handle concurrent updates this.dp = new concurrency.DropPrevious(); + + // the following attributes are used when there is a searchPanel + this._searchPanel = params.searchPanel; + this.controlPanelDomain = params.controlPanelDomain || []; + this.searchPanelDomain = this._searchPanel ? this._searchPanel.getDomain() : []; }, /** * Simply renders and updates the url. @@ -66,6 +72,11 @@ var AbstractController = mvc.Controller.extend(ActionMixin, { */ start: function () { var self = this; + if (this._searchPanel) { + this.$('.o_content') + .addClass('o_controller_with_searchpanel') + .prepend(this._searchPanel.$el); + } this.$el.addClass('o_view_controller'); @@ -123,7 +134,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, { */ canBeRemoved: function () { // AAB: get rid of this option when on_hashchange mechanism is improved - return this.discardChanges(undefined, { readonlyIfRealDiscard: true }); + return this.discardChanges(undefined, {readonlyIfRealDiscard: true}); }, /** * Discards the changes made on the record associated to the given ID, or @@ -154,6 +165,9 @@ var AbstractController = mvc.Controller.extend(ActionMixin, { if (this._controlPanel) { state.cpState = this._controlPanel.exportState(); } + if (this._searchPanel) { + state.spState = this._searchPanel.exportState(); + } return state; }, /** @@ -180,20 +194,33 @@ var AbstractController = mvc.Controller.extend(ActionMixin, { * @param {Object} [params] This object will simply be given to the update * @returns {Promise} */ - reload: function (params) { + reload: async function (params) { params = params || {}; - var self = this; - var def; + var searchPanelUpdateProm; var controllerState = params.controllerState || {}; var cpState = controllerState.cpState; if (this._controlPanel && cpState) { - def = this._controlPanel.importState(cpState).then(function (searchQuery) { + await this._controlPanel.importState(cpState).then(function (searchQuery) { params = _.extend({}, params, searchQuery); }); } - return Promise.resolve(def).then(function () { - return self.update(params, {}); - }); + var postponeRendering = false; + if (this._searchPanel) { + this.controlPanelDomain = params.domain || this.controlPanelDomain; + if (controllerState.spState) { + this._searchPanel.importState(controllerState.spState); + this.searchPanelDomain = this._searchPanel.getDomain(); + } else { + searchPanelUpdateProm = this._searchPanel.update({searchDomain: this._getSearchDomain()}); + postponeRendering = !params.noRender; + params.noRender = true; // wait for searchpanel to be ready to render + } + params.domain = this.controlPanelDomain.concat(this.searchPanelDomain); + } + await Promise.all([this.update(params, {}), searchPanelUpdateProm]); + if (postponeRendering) { + return this.renderer._render(); + } }, /** * For views that require a pager, this method will be called to allow the @@ -266,6 +293,18 @@ var AbstractController = mvc.Controller.extend(ActionMixin, { // Private //-------------------------------------------------------------------------- + /** + * Return the current search domain. This is the searchDomain used to update + * the searchpanel. It returns the domain coming from the controlpanel. This + * function can be overridden to add sub-domains coming from other parts of + * the interface. + * + * @private + * @returns {Array[]} + */ + _getSearchDomain: function () { + return this.controlPanelDomain; + }, /** * This method is the way a view can notifies the outside world that * something has changed. The main use for this is to update the url, for @@ -302,7 +341,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, { if (this.bannerRoute !== undefined) { var self = this; return this.dp - .add(this._rpc({ route: this.bannerRoute })) + .add(this._rpc({route: this.bannerRoute})) .then(function (response) { if (!response.html) { self.$el.removeClass('o_has_banner'); @@ -370,7 +409,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, { */ _renderSwitchButtons: function () { var self = this; - var views = _.filter(this.actionViews, { multiRecord: this.isMultiRecord }); + var views = _.filter(this.actionViews, {multiRecord: this.isMultiRecord}); if (views.length <= 1) { return $(); @@ -389,7 +428,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, { var $switchButtonsFiltered = config.device.isMobile ? $switchButtons.find('button') : $switchButtons.filter('button'); $switchButtonsFiltered.click(_.debounce(function (event) { var viewType = $(event.target).data('view-type'); - self.trigger_up('switch_view', { view_type: viewType }); + self.trigger_up('switch_view', {view_type: viewType}); }, 200, true)); // set active view's icon as view switcher button's icon in mobile @@ -519,8 +558,8 @@ var AbstractController = mvc.Controller.extend(ActionMixin, { * @private * @param {OdooEvent} ev */ - _onNavigationMove : function (ev) { - switch(ev.data.direction) { + _onNavigationMove: function (ev) { + switch (ev.data.direction) { case 'down' : ev.stopPropagation(); this.giveFocus(); @@ -543,7 +582,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, { */ _onOpenRecord: function (ev) { ev.stopPropagation(); - var record = this.model.get(ev.data.id, { raw: true }); + var record = this.model.get(ev.data.id, {raw: true}); this.trigger_up('switch_view', { view_type: 'form', res_id: record.res_id, @@ -565,6 +604,15 @@ var AbstractController = mvc.Controller.extend(ActionMixin, { ev.stopPropagation(); this.reload(_.extend({offset: 0}, ev.data)); }, + /** + * @private + * @param {OdooEvent} ev + * @param {Array[]} ev.data.domain the current domain of the searchPanel + */ + _onSearchPanelDomainUpdated: function (ev) { + this.searchPanelDomain = ev.data.domain; + this.reload({offset: 0}); + }, /** * Intercepts the 'switch_view' event to add the controllerID into the data, * and lets the event bubble up. -- cgit v1.2.3