diff options
| author | fwi-odoo <fwi@odoo.com> | 2017-04-25 13:55:38 +0200 |
|---|---|---|
| committer | fwi-odoo <fwi@odoo.com> | 2017-05-03 13:41:07 +0200 |
| commit | a53335fdb2fe6e9232bde66f06e9499bece452d4 (patch) | |
| tree | 662cb9a587ed2b076f0ffe4896d2e75ce120ae34 /addons/web/static/src/js/views | |
| parent | 30384249e11d1d74b19bf2b63d4fd9fe6a99bad1 (diff) | |
[FIX] web, document: adapt toolbar to the new views
- Fix the toolbar behaviour since there is no more dataset in the widget.
- Improve the communication beetwen the controller and the toolbar.
- Move the code linked to the document upload in the right file.
- Adapt the tests to mock the search_read done by ´document´ addon
- Adapt the mock server to be able to give a custom toolbar action
Diffstat (limited to 'addons/web/static/src/js/views')
5 files changed, 85 insertions, 23 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js index 33f6727987e..87e8d1a6664 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -19,6 +19,7 @@ var _t = core._t; var BasicController = AbstractController.extend(FieldManagerMixin, { custom_events: _.extend({}, AbstractController.prototype.custom_events, FieldManagerMixin.custom_events, { reload: '_onReload', + sidebar_data_asked: '_onSidebarDataAsked' }), /** * @override @@ -127,6 +128,14 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { }); }, /** + * Method that will be overriden by the views with the ability to have selected ids + * + * @returns [] + */ + getSelectedIds: function () { + return []; + }, + /** * @override */ renderPager: function ($node, options) { @@ -288,6 +297,19 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { } }, /** + * Returns the new sidebar env + * + * @private + * @return {Object} the new sidebar env + */ + _getSidebarEnv: function () { + return { + context: this.model.get(this.handle).getContext(), + activeIds: this.getSelectedIds(), + model: this.modelName, + }; + }, + /** * Used by list and kanban views to determine whether or not to display * the no content helper (if there is no data in the state to display) * @@ -389,9 +411,15 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { /** * Helper method, to get the current environment variables from the model * and notifies the component chain (by bubbling an event up) + * + * @private */ _updateEnv: function () { var env = this.model.get(this.handle, {env: true}); + if (this.sidebar) { + var sidebarEnv = this._getSidebarEnv(); + this.sidebar.updateEnv(sidebarEnv); + } this.trigger_up('env_updated', env); }, /** @@ -457,6 +485,17 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { this.reload({fieldNames: data.fieldNames}); } }, + /** + * Handler used to get all the data necessary when a custom action is + * performed through the sidebar. + * + * @private + * @param {OdooEvent} event + */ + _onSidebarDataAsked: function (event) { + var sidebarEnv = this._getSidebarEnv(); + event.data.callback(sidebarEnv); + }, }); return BasicController; 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 e3b129c7915..f15bdfa5382 100644 --- a/addons/web/static/src/js/views/form/form_controller.js +++ b/addons/web/static/src/js/views/form/form_controller.js @@ -21,6 +21,9 @@ var FormController = BasicController.extend({ }), /** * @override + * + * @param {boolean} params.hasSidebar + * @param {Object} params.toolbarActions */ init: function (parent, model, renderer, params) { this._super.apply(this, arguments); @@ -29,7 +32,7 @@ var FormController = BasicController.extend({ this.footerToButtons = params.footerToButtons; this.defaultButtons = params.defaultButtons; this.hasSidebar = params.hasSidebar; - this.toolbar = params.toolbar; + this.toolbarActions = params.toolbarActions || {}; }, //-------------------------------------------------------------------------- @@ -71,13 +74,12 @@ var FormController = BasicController.extend({ * Returns the current res_id, wrapped in a list. This is only used by the * sidebar (and the debugmanager) * - * @todo This should be private. Need to change sidebar code + * @override * * @returns {number[]} either [current res_id] or [] */ getSelectedIds: function () { var env = this.model.get(this.handle, {env: true}); - // FIX ME : fix sidebar widget return env.currentId ? [env.currentId] : []; }, /** @@ -137,12 +139,6 @@ var FormController = BasicController.extend({ **/ renderSidebar: function ($node) { if (!this.sidebar && this.hasSidebar) { - this.sidebar = new Sidebar(this, { - editable: this.is_action_enabled('edit') - }); - if (this.toolbar) { - this.sidebar.add_toolbar(this.toolbar); - } var otherItems = []; if (this.is_action_enabled('delete')) { otherItems.push({ @@ -156,7 +152,16 @@ var FormController = BasicController.extend({ callback: this._onDuplicateRecord.bind(this), }); } - this.sidebar.add_items('other', otherItems); + this.sidebar = new Sidebar(this, { + editable: this.is_action_enabled('edit'), + viewType: 'form', + env: { + context: this.model.get(this.handle).getContext(), + activeIds: this.getSelectedIds(), + model: this.modelName, + }, + actions: _.extend(this.toolbarActions, {other: otherItems}), + }); this.sidebar.appendTo($node); // Show or hide the sidebar according to the view mode diff --git a/addons/web/static/src/js/views/form/form_view.js b/addons/web/static/src/js/views/form/form_view.js index 4fff1a74ee4..aa6bdf69755 100644 --- a/addons/web/static/src/js/views/form/form_view.js +++ b/addons/web/static/src/js/views/form/form_view.js @@ -30,7 +30,7 @@ var FormView = BasicView.extend({ this.loadParams.parentID = params.parentID; this.controllerParams.hasSidebar = params.sidebar; - this.controllerParams.toolbar = false; + this.controllerParams.toolbarActions = viewInfo.toolbar; this.controllerParams.footerToButtons = params.footer_to_buttons; if ('action' in params && 'flags' in params.action) { this.controllerParams.footerToButtons = params.action.flags.footer_to_buttons; diff --git a/addons/web/static/src/js/views/list/list_controller.js b/addons/web/static/src/js/views/list/list_controller.js index 50f47a73fc0..f2b15cca349 100644 --- a/addons/web/static/src/js/views/list/list_controller.js +++ b/addons/web/static/src/js/views/list/list_controller.js @@ -30,16 +30,15 @@ var ListController = BasicController.extend({ * @constructor * @override * @param {Object} params - * @param {Object} params * @param {boolean} params.editable * @param {boolean} params.hasSidebar - * @param {boolean} params.hasToolbar + * @param {Object} params.toolbarActions * @param {boolean} params.noLeaf */ init: function (parent, model, renderer, params) { this._super.apply(this, arguments); this.hasSidebar = params.hasSidebar; - this.hasToolbar = params.hasToolbar; + this.toolbarActions = params.toolbarActions || {}; this.editable = params.editable; this.noLeaf = params.noLeaf; this.selectedRecords = []; // there is no selected record by default @@ -72,7 +71,7 @@ var ListController = BasicController.extend({ * if the header checkbox has been checked. This is done by evaluating the * search results, and then adding the dataset domain (i.e. action domain). * - * @todo This is done only for the sidebar. The full mechanism is wrong, + * @todo This is done only for the data export. The full mechanism is wrong, * this method should be private, most of the code in the sidebar should be * moved to the controller, and we should not use the getParent method... * @@ -99,7 +98,7 @@ var ListController = BasicController.extend({ * Returns the list of currently selected res_ids (with the check boxes on * the left) * - * @todo This should be private. Need to change sidebar code + * @override * * @returns {number[]} list of res_ids */ @@ -135,12 +134,6 @@ var ListController = BasicController.extend({ */ renderSidebar: function ($node) { if (this.hasSidebar && !this.sidebar) { - this.sidebar = new Sidebar(this, { - editable: this.is_action_enabled('edit') - }); - if (this.hasToolbar) { - this.sidebar.add_toolbar(this.fields_view.toolbar); - } var other = [{ label: _t("Export"), callback: this._onExportData.bind(this) @@ -160,8 +153,16 @@ var ListController = BasicController.extend({ label: _t('Delete'), callback: this._onDeleteSelectedRecords.bind(this) }); + this.sidebar = new Sidebar(this, { + editable: this.is_action_enabled('edit'), + env: { + context: this.model.get(this.handle).getContext(), + activeIds: this.getSelectedIds(), + model: this.modelName, + }, + actions: _.extend(this.toolbarActions, {other: other}), + }); } - this.sidebar.add_items('other', other); this.sidebar.appendTo($node); this._toggleSidebar(); @@ -233,6 +234,15 @@ var ListController = BasicController.extend({ return this.renderer.confirmSave(state, id); }, /** + * @override + * @private + */ + _getSidebarEnv: function() { + var env = this._super.apply(this, arguments); + var record = this.model.get(this.handle); + return _.extend(env, {domain: record.getDomain()}); + }, + /** * Allows to change the mode of a single row. * * @override @@ -381,6 +391,13 @@ var ListController = BasicController.extend({ this._toggleSidebar(); }, /** + * @override + */ + _onSidebarDataAsked: function (event) { + var env = this._getSidebarEnv(); + event.data.callback(env); + }, + /** * Called when clicking on 'Archive' or 'Unarchive' in the sidebar. * * @private diff --git a/addons/web/static/src/js/views/list/list_view.js b/addons/web/static/src/js/views/list/list_view.js index 7b597c712bc..61612282bf5 100644 --- a/addons/web/static/src/js/views/list/list_view.js +++ b/addons/web/static/src/js/views/list/list_view.js @@ -41,6 +41,7 @@ var ListView = BasicView.extend({ this.controllerParams.editable = arch.attrs.editable; this.controllerParams.hasSidebar = params.sidebar; + this.controllerParams.toolbarActions = viewInfo.toolbar; this.controllerParams.activeActions.delete = true; this.controllerParams.noLeaf = !!this.loadParams.context.group_by_no_leaf; this.controllerParams.mode = mode; |
