diff options
| author | Géry Debongnie <ged@odoo.com> | 2017-03-31 15:27:08 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | 03fabb0c4aefa57ee3a584f45b0af1d64ae01f48 (patch) | |
| tree | 6a0104c06a0c2aae26a84449ea0e00fc237c540c /addons/base_import/static/src/js | |
| parent | 1fadf4a793920870e7dd8fb4c95f4b314fdd28fe (diff) | |
[REF] base_import: split import button code out of action
Diffstat (limited to 'addons/base_import/static/src/js')
| -rw-r--r-- | addons/base_import/static/src/js/import_action.js (renamed from addons/base_import/static/src/js/base_import.js) | 107 | ||||
| -rw-r--r-- | addons/base_import/static/src/js/import_buttons.js | 120 |
2 files changed, 120 insertions, 107 deletions
diff --git a/addons/base_import/static/src/js/base_import.js b/addons/base_import/static/src/js/import_action.js index 7292d898ad5..9c35620c486 100644 --- a/addons/base_import/static/src/js/base_import.js +++ b/addons/base_import/static/src/js/import_action.js @@ -3,10 +3,6 @@ odoo.define('base_import.import', function (require) { var ControlPanelMixin = require('web.ControlPanelMixin'); var core = require('web.core'); -var KanbanController = require('web.KanbanController'); -var KanbanView = require('web.KanbanView'); -var ListController = require('web.ListController'); -var ListView = require('web.ListView'); var session = require('web.session'); var time = require('web.time'); var Widget = require('web.Widget'); @@ -48,109 +44,6 @@ function jsonp(form, attributes, callback) { $(form).ajaxSubmit(attributes); } -// Mixins that enable the 'Import' feature -var ImportViewMixin = { - init: function (viewInfo, params) { - var importEnabled = 'import_enabled' in params ? params.import_enabled : true; - // if true, the 'Import' button will be visible - this.controllerParams.importEnabled = importEnabled; - }, -}; -var ImportControllerMixin = { - init: function (parent, model, renderer, params) { - this.importEnabled = params.importEnabled; - }, - - //-------------------------------------------------------------------------- - // Private - //-------------------------------------------------------------------------- - - /** - * Adds an event listener on the import button. - * - * @private - */ - _bindImport: function () { - if (!this.$buttons) { - return; - } - var self = this; - this.$buttons.on('click', '.o_button_import', function () { - var state = self.model.get(self.handle, {raw: true}); - self.do_action({ - type: 'ir.actions.client', - tag: 'import', - params: { - model: self.modelName, - context: state.getContext(), - } - }, { - on_reverse_breadcrumb: self.reload.bind(self), - }); - }); - } -}; - -// Activate 'Import' feature on List views -ListView.include({ - init: function () { - this._super.apply(this, arguments); - ImportViewMixin.init.apply(this, arguments); - }, -}); - -ListController.include({ - init: function () { - this._super.apply(this, arguments); - ImportControllerMixin.init.apply(this, arguments); - }, - - //-------------------------------------------------------------------------- - // Public - //-------------------------------------------------------------------------- - - /** - * Extends the renderButtons function of ListView by adding an event listener - * on the import button. - * - * @override - */ - renderButtons: function () { - this._super.apply(this, arguments); // Sets this.$buttons - ImportControllerMixin._bindImport.call(this); - } -}); - -// Activate 'Import' feature on Kanban views -KanbanView.include({ - init: function () { - this._super.apply(this, arguments); - ImportViewMixin.init.apply(this, arguments); - }, -}); - -KanbanController.include({ - init: function () { - this._super.apply(this, arguments); - ImportControllerMixin.init.apply(this, arguments); - }, - - //-------------------------------------------------------------------------- - // Public - //-------------------------------------------------------------------------- - - /** - * Extends the renderButtons function of ListView by adding an event listener - * on the import button. - * - * @override - */ - renderButtons: function () { - this._super.apply(this, arguments); // Sets this.$buttons - ImportControllerMixin._bindImport.call(this); - } -}); - var DataImport = Widget.extend(ControlPanelMixin, { template: 'ImportView', opts: [ diff --git a/addons/base_import/static/src/js/import_buttons.js b/addons/base_import/static/src/js/import_buttons.js new file mode 100644 index 00000000000..77d5d0e876e --- /dev/null +++ b/addons/base_import/static/src/js/import_buttons.js @@ -0,0 +1,120 @@ +odoo.define('base_import.import_buttons', function (require) { +"use strict"; + +var KanbanController = require('web.KanbanController'); +var KanbanView = require('web.KanbanView'); +var ListController = require('web.ListController'); +var ListView = require('web.ListView'); + + +// Mixins that enable the 'Import' feature +var ImportViewMixin = { + /** + * @override + */ + init: function (viewInfo, params) { + var importEnabled = 'import_enabled' in params ? params.import_enabled : true; + // if true, the 'Import' button will be visible + this.controllerParams.importEnabled = importEnabled; + }, +}; + +var ImportControllerMixin = { + /** + * @override + */ + init: function (parent, model, renderer, params) { + this.importEnabled = params.importEnabled; + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Adds an event listener on the import button. + * + * @private + */ + _bindImport: function () { + if (!this.$buttons) { + return; + } + var self = this; + this.$buttons.on('click', '.o_button_import', function () { + var state = self.model.get(self.handle, {raw: true}); + self.do_action({ + type: 'ir.actions.client', + tag: 'import', + params: { + model: self.modelName, + context: state.getContext(), + } + }, { + on_reverse_breadcrumb: self.reload.bind(self), + }); + }); + } +}; + +// Activate 'Import' feature on List views +ListView.include({ + init: function () { + this._super.apply(this, arguments); + ImportViewMixin.init.apply(this, arguments); + }, +}); + +ListController.include({ + init: function () { + this._super.apply(this, arguments); + ImportControllerMixin.init.apply(this, arguments); + }, + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * Extends the renderButtons function of ListView by adding an event listener + * on the import button. + * + * @override + */ + renderButtons: function () { + this._super.apply(this, arguments); // Sets this.$buttons + ImportControllerMixin._bindImport.call(this); + } +}); + +// Activate 'Import' feature on Kanban views +KanbanView.include({ + init: function () { + this._super.apply(this, arguments); + ImportViewMixin.init.apply(this, arguments); + }, +}); + +KanbanController.include({ + init: function () { + this._super.apply(this, arguments); + ImportControllerMixin.init.apply(this, arguments); + }, + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * Extends the renderButtons function of ListView by adding an event listener + * on the import button. + * + * @override + */ + renderButtons: function () { + this._super.apply(this, arguments); // Sets this.$buttons + ImportControllerMixin._bindImport.call(this); + } +}); + +}); |
