diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-12-21 12:29:50 +0100 |
|---|---|---|
| committer | Alexandre Kühn <alex.e.kuhn@gmail.com> | 2018-02-01 14:51:58 +0100 |
| commit | 02ec09cb1c3e2d7bc7968f40c18f2208d7f3f498 (patch) | |
| tree | 10d91136786b13666e78cfb94b12f1609d6f883d /addons/web/static/src/js/core/mixins.js | |
| parent | 0cd656b5af38051df3f7d6319e99705150bb1cd8 (diff) | |
[REF][IMP] *: mail js refactoring
This commit improves the JS code of the mail module,
which comes maily from the new coding guidelines
and the addition of "JS services".
JS services are important objects that do not fit
well in the component tree, such as chat_manager
or ajax.
The benefits of JS services are improved readability
of the code, reduced coupling, and more testable
modules. In particular, discuss was hard to
Summary of the changes:
- ClientAction has been renamed into Discuss
- Clear instantiation of chatManager
- New coding guidelines in most mail modules
- JS Services can interact with each other
- Chat Manager and Window Manager are services
- Window Manager renamed to Chat Window Manager
- bus.bus is now encapsulated in Bus Service (a service)
- The test infrastructure has been tweaked with JS Services
- Chat Mixin has been removed
A future improvement would be to translate some 'trigger' into 'trigger_up'.
Diffstat (limited to 'addons/web/static/src/js/core/mixins.js')
| -rw-r--r-- | addons/web/static/src/js/core/mixins.js | 125 |
1 files changed, 0 insertions, 125 deletions
diff --git a/addons/web/static/src/js/core/mixins.js b/addons/web/static/src/js/core/mixins.js index 23958d9e0f2..e4738fc2f43 100644 --- a/addons/web/static/src/js/core/mixins.js +++ b/addons/web/static/src/js/core/mixins.js @@ -3,7 +3,6 @@ odoo.define('web.mixins', function (require) { var Class = require('web.Class'); var utils = require('web.utils'); -var AbstractService = require('web.AbstractService'); /** * Mixin to structure objects' life-cycles folowing a parent-children @@ -409,134 +408,10 @@ var PropertiesMixin = _.extend({}, EventDispatcherMixin, { } }); -var ServiceProvider = { - services: {}, - init: function () { - var self = this; - _.each(AbstractService.prototype.Services, function (Service) { - var service = new Service(); - self.services[service.name] = service; - }); - this.custom_events = _.clone(this.custom_events); - this.custom_events.call_service = this._call_service.bind(this); - }, - _call_service: function (event) { - var service = this.services[event.data.service]; - var args = (event.data.args || []).concat(event.target); - var result = service[event.data.method].apply(service, args); - event.data.callback(result); - }, -}; - return { ParentedMixin: ParentedMixin, EventDispatcherMixin: EventDispatcherMixin, PropertiesMixin: PropertiesMixin, - ServiceProvider: ServiceProvider, }; }); - -odoo.define('web.ServicesMixin', function (require) { -"use strict"; - -var rpc = require('web.rpc'); - -/** - * @mixin - * @name ServicesMixin - */ -var ServicesMixin = { - call: function (service, method) { - var args = Array.prototype.slice.call(arguments, 2); - var result; - this.trigger_up('call_service', { - service: service, - method: method, - args: args, - callback: function (r) { - result = r; - }, - }); - return result; - }, - /** - * Builds and executes RPC query. Returns a deferred's promise resolved with - * the RPC result. - * - * @param {string} params either a route or a model - * @param {string} options if a model is given, this argument is a method - * @returns {Promise} - */ - _rpc: function (params, options) { - var query = rpc.buildQuery(params); - var def = this.call('ajax', 'rpc', query.route, query.params, options); - return def ? def.promise() : $.Deferred().promise(); - }, - loadFieldView: function (dataset, view_id, view_type, options) { - return this.loadViews(dataset.model, dataset.get_context().eval(), [[view_id, view_type]], options).then(function (result) { - return result[view_type]; - }); - }, - loadViews: function (modelName, context, views, options) { - var def = $.Deferred(); - this.trigger_up('load_views', { - modelName: modelName, - context: context, - views: views, - options: options, - on_success: def.resolve.bind(def), - }); - return def; - }, - loadFilters: function (dataset, action_id) { - var def = $.Deferred(); - this.trigger_up('load_filters', { - dataset: dataset, - action_id: action_id, - on_success: def.resolve.bind(def), - }); - return def; - }, - // Session stuff - getSession: function () { - var session; - this.trigger_up('get_session', { - callback: function (result) { - session = result; - } - }); - return session; - }, - /** - * Informs the action manager to do an action. This supposes that the action - * manager can be found amongst the ancestors of the current widget. - * If that's not the case this method will simply return an unresolved - * deferred. - * - * @param {any} action - * @param {any} options - * @returns {Deferred} - */ - do_action: function (action, options) { - var def = $.Deferred(); - - this.trigger_up('do_action', { - action: action, - options: options, - on_success: function (result) { def.resolve(result); }, - on_fail: function (result) { def.reject(result); }, - }); - return def; - }, - do_notify: function (title, message, sticky, className) { - this.trigger_up('notification', {title: title, message: message, sticky: sticky, className: className}); - }, - do_warn: function (title, message, sticky, className) { - this.trigger_up('warning', {title: title, message: message, sticky: sticky, className: className}); - }, -}; - -return ServicesMixin; - -}); |
