diff options
| author | Géry Debongnie <ged@odoo.com> | 2017-03-05 10:05:56 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | 905e01921f3c3ef43ace6fc537d1d8c0d280002c (patch) | |
| tree | 265c43ab21c5401a5d9f0f3d64d86f1ac417451c /addons/base_import/static/src | |
| parent | 54d4c73af4ad05c7640d28c1892247c9538b8017 (diff) | |
[REF] web, *: redesign all JS views
This commit introduce a full redesign of all JS views. We started
basically from scratch. The goal was to unify all the various views
under a common framework, to make them testable, to make then usable in
different conditions (in studio, or in the frontend), and to make our
lives easier.
Some important points are:
- we introduced new coding guidelines (camelCase, 80 chars width, ...)
- we have a brand new testing framework (still QUnit based)
- kanban view moved to the web addon
- calendar view (formerly web_calender) moved to web as well
- the tree view was removed
- all new code should be documented
We hope that this code is the start of a new era for the Odoo web
client, we want to have a high quality codebase, well documented, well
tested, well designed.
Work done by the framework team: mostly aab, ged, chm, dmo, qsm
Diffstat (limited to 'addons/base_import/static/src')
| -rw-r--r-- | addons/base_import/static/src/js/base_import.js | 92 | ||||
| -rw-r--r-- | addons/base_import/static/src/xml/base_import.xml | 7 |
2 files changed, 33 insertions, 66 deletions
diff --git a/addons/base_import/static/src/js/base_import.js b/addons/base_import/static/src/js/base_import.js index 76120c0f0c2..c965dade072 100644 --- a/addons/base_import/static/src/js/base_import.js +++ b/addons/base_import/static/src/js/base_import.js @@ -5,7 +5,7 @@ var ControlPanelMixin = require('web.ControlPanelMixin'); var core = require('web.core'); var time = require('web.time'); var ListView = require('web.ListView'); -var KanbanView = require('web_kanban.KanbanView'); +var ListController = require('web.ListController'); var Model = require('web.DataModel'); var session = require('web.session'); var Widget = require('web.Widget'); @@ -47,73 +47,45 @@ function jsonp(form, attributes, callback) { $(form).ajaxSubmit(attributes); } -function execute_import_action () { - var self = this; - this.do_action({ - type: 'ir.actions.client', - tag: 'import', - params: { - model: this.dataset.model, - // this.dataset.get_context() could be a compound? - // not sure. action's context should be evaluated - // so safer bet. Odd that timezone & al in it - // though - context: this.getParent().action.context, - } - }, { - on_reverse_breadcrumb: function () { - return self.reload(); - }, - }); - return false; -} - // if true, the 'Import', 'Export', etc... buttons will be shown -ListView.prototype.defaults.import_enabled = true; ListView.include({ - /** - * Extend the render_buttons function of ListView by adding an event listener - * on the import button. - * @return {jQuery} the rendered buttons - */ - render_buttons: function() { - var self = this; - var add_button = false; - if (!this.$buttons) { // Ensures that this is only done once - add_button = true; - } - this._super.apply(this, arguments); // Sets this.$buttons - if(add_button) { - this.$buttons.on('click', '.o_button_import', execute_import_action.bind(this)); - } - } + init: function(arch, fields, params) { + this._super.apply(this, arguments); + var importEnabled = 'import_enabled' in params ? params.import_enabled : true; + this.controllerParams.importEnabled = importEnabled; + }, }); -// Enable import button on kanban view. -KanbanView.prototype.defaults.import_enabled = true; -KanbanView.include({ +ListController.include({ + init: function(parent, model, renderer, params) { + this._super.apply(this, arguments); + this.importEnabled = params.importEnabled; + }, /** - * Extend the render_buttons function of KanbanView by adding an event listener + * Extend the renderButtons function of ListView by adding an event listener * on the import button. * @return {jQuery} the rendered buttons */ - render_buttons: function() { - var self = this; - var add_button = false; - if (!this.$buttons) { // Ensures that this is only done once - add_button = true; - } + renderButtons: function() { this._super.apply(this, arguments); // Sets this.$buttons - if(add_button && this.$buttons) { - this.$buttons.on('click', '.o_button_import', execute_import_action.bind(this)); - } - }, - set_default_options: function (options) { - this._super(_.defaults(options || {}, { - import_enabled: true, + if (!this.$buttons) { return; } + + this.$buttons.on('click', '.o_button_import', this.do_action.bind(this, { + type: 'ir.actions.client', + tag: 'import', + params: { + model: this.modelName, + // this.dataset.get_context() could be a compound? + // not sure. action's context should be evaluated + // so safer bet. Odd that timezone & al in it + // though + context: this.context, + } + }, { + on_reverse_breadcrumb: this.reload.bind(this), })); - }, + } }); var DataImport = Widget.extend(ControlPanelMixin, { @@ -196,7 +168,7 @@ var DataImport = Widget.extend(ControlPanelMixin, { self.id = id; self.$('input[name=import_id]').val(id); - self.render_buttons(); + self.renderButtons(); var status = { breadcrumbs: self.action_manager.get_breadcrumbs(), cp_content: {$buttons: self.$buttons}, @@ -210,7 +182,7 @@ var DataImport = Widget.extend(ControlPanelMixin, { 'res_model': this.res_model }]); }, - render_buttons: function() { + renderButtons: function() { var self = this; this.$buttons = $(QWeb.render("ImportView.buttons", this)); this.$buttons.filter('.o_import_validate').on('click', this.validate.bind(this)); @@ -524,7 +496,7 @@ var DataImport = Widget.extend(ControlPanelMixin, { return $(el).select2('val') || false; }).get(); var tracking_disable = 'tracking_disable' in kwargs ? kwargs.tracking_disable : !this.$('#oe_import_tracking').prop('checked') - delete kwargs.tracking_disable + delete kwargs.tracking_disable; kwargs.context = _.extend( {}, this.parent_context, {tracking_disable: tracking_disable} diff --git a/addons/base_import/static/src/xml/base_import.xml b/addons/base_import/static/src/xml/base_import.xml index 93e7519bd95..c7f49d5c9e8 100644 --- a/addons/base_import/static/src/xml/base_import.xml +++ b/addons/base_import/static/src/xml/base_import.xml @@ -144,7 +144,7 @@ <t t-if="error.moreinfo" t-raw="info(error.moreinfo)"/> </t> <t t-name="ImportView.import_button"> - <button t-if='widget.options.import_enabled' type="button" class="btn btn-sm btn-default o_button_import"> + <button t-if='widget.importEnabled' type="button" class="btn btn-sm btn-default o_button_import"> Import </button> </t> @@ -153,9 +153,4 @@ <t t-call="ImportView.import_button"/> </t> </t> - <t t-extend="KanbanView.buttons"> - <t t-jquery="button.o-kanban-button-new" t-operation="after"> - <t t-call="ImportView.import_button"/> - </t> - </t> </templates> |
