diff options
| author | qsm-odoo <qsm@odoo.com> | 2017-02-24 13:31:42 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | 7e91154e8ecc3b42f841ed34152d9ff9ca67bfbc (patch) | |
| tree | 1aac39ef1c8719f1755d120bf0b860306d9e1e19 /addons/web/static/src/js/core | |
| parent | b717c6786429ccd68678462f3d0d994ffe3301b3 (diff) | |
[IMP] web: some more linting to follow guidelines
Diffstat (limited to 'addons/web/static/src/js/core')
| -rw-r--r-- | addons/web/static/src/js/core/mixins.js | 92 | ||||
| -rw-r--r-- | addons/web/static/src/js/core/session.js | 64 |
2 files changed, 78 insertions, 78 deletions
diff --git a/addons/web/static/src/js/core/mixins.js b/addons/web/static/src/js/core/mixins.js index 5caac9a2c8c..266888a3948 100644 --- a/addons/web/static/src/js/core/mixins.js +++ b/addons/web/static/src/js/core/mixins.js @@ -13,7 +13,7 @@ var AbstractService = require('web.AbstractService'); */ var ParentedMixin = { __parentedMixin : true, - init: function() { + init: function () { this.__parentedDestroyed = false; this.__parentedChildren = []; this.__parentedParent = null; @@ -26,7 +26,7 @@ var ParentedMixin = { * previous parent will not return the current object anymore when its * getChildren() method is called. */ - setParent : function(parent) { + setParent : function (parent) { if (this.getParent()) { if (this.getParent().__parentedMixin) { this.getParent().__parentedChildren = _.without(this @@ -41,19 +41,19 @@ var ParentedMixin = { /** * Return the current parent of the object (or null). */ - getParent : function() { + getParent : function () { return this.__parentedParent; }, /** * Return a list of the children of the current object. */ - getChildren : function() { + getChildren : function () { return _.clone(this.__parentedChildren); }, /** * Returns true if destroy() was called on the current object. */ - isDestroyed : function() { + isDestroyed : function () { return this.__parentedDestroyed; }, /** @@ -72,7 +72,7 @@ var ParentedMixin = { with no arguments or never resolved if the current object is destroyed. */ - alive: function(promise, reject) { + alive: function (promise, reject) { var self = this; return $.Deferred(function (def) { promise.then(function () { @@ -96,8 +96,8 @@ var ParentedMixin = { * Inform the object it should destroy itself, releasing any * resource it could have reserved. */ - destroy : function() { - _.each(this.getChildren(), function(el) { + destroy : function () { + _.each(this.getChildren(), function (el) { el.destroy(); }); this.setParent(undefined); @@ -115,7 +115,7 @@ var ParentedMixin = { }, }; -function OdooEvent (target, name, data) { +function OdooEvent(target, name, data) { this.target = target; this.name = name; this.data = Object.create(null); @@ -147,7 +147,7 @@ OdooEvent.prototype.is_stopped = function () { * */ var Events = Class.extend({ - on : function(events, callback, context) { + on : function (events, callback, context) { var ev; events = events.split(/\s+/); var calls = this._callbacks || (this._callbacks = {}); @@ -161,7 +161,7 @@ var Events = Class.extend({ return this; }, - off : function(events, callback, context) { + off : function (events, callback, context) { var ev, calls, node; if (!events) { delete this._callbacks; @@ -183,9 +183,9 @@ var Events = Class.extend({ return this; }, - callbackList: function() { + callbackList: function () { var lst = []; - _.each(this._callbacks || {}, function(el, eventName) { + _.each(this._callbacks || {}, function (el, eventName) { var node = el; while ((node = node.next) && node.next) { lst.push([eventName, node.callback, node.context]); @@ -194,7 +194,7 @@ var Events = Class.extend({ return lst; }, - trigger : function(events) { + trigger : function (events) { var event, node, calls, tail, args, all, rest; if (!(calls = this._callbacks)) return this; @@ -237,18 +237,18 @@ var Events = Class.extend({ */ var EventDispatcherMixin = _.extend({}, ParentedMixin, { __eventDispatcherMixin: true, - init: function() { + init: function () { ParentedMixin.init.call(this); this.__edispatcherEvents = new Events(); this.__edispatcherRegisteredEvents = []; }, - on: function(events, dest, func) { + on: function (events, dest, func) { var self = this; if (typeof func !== "function") { throw new Error("Event handler must be a function."); } events = events.split(/\s+/); - _.each(events, function(eventName) { + _.each(events, function (eventName) { self.__edispatcherEvents.on(eventName, func, dest); if (dest && dest.__eventDispatcherMixin) { dest.__edispatcherRegisteredEvents.push({name: eventName, func: func, source: self}); @@ -256,20 +256,20 @@ var EventDispatcherMixin = _.extend({}, ParentedMixin, { }); return this; }, - off: function(events, dest, func) { + off: function (events, dest, func) { var self = this; events = events.split(/\s+/); - _.each(events, function(eventName) { + _.each(events, function (eventName) { self.__edispatcherEvents.off(eventName, func, dest); if (dest && dest.__eventDispatcherMixin) { - dest.__edispatcherRegisteredEvents = _.filter(dest.__edispatcherRegisteredEvents, function(el) { + dest.__edispatcherRegisteredEvents = _.filter(dest.__edispatcherRegisteredEvents, function (el) { return !(el.name === eventName && el.func === func && el.source === self); }); } }); return this; }, - once: function(events, dest, func) { + once: function (events, dest, func) { // similar to this.on(), but func is executed only once var self = this; if (typeof func !== "function") { @@ -280,28 +280,28 @@ var EventDispatcherMixin = _.extend({}, ParentedMixin, { self.off(events, dest, what); }); }, - trigger: function() { + trigger: function () { this.__edispatcherEvents.trigger.apply(this.__edispatcherEvents, arguments); return this; }, - trigger_up: function(name, info) { + trigger_up: function (name, info) { var event = new OdooEvent(this, name, info); this._trigger_up(event); }, - _trigger_up: function(event) { + _trigger_up: function (event) { var parent; this.__edispatcherEvents.trigger(event.name, event); if (!event.is_stopped() && (parent = this.getParent())) { parent._trigger_up(event); } }, - destroy: function() { + destroy: function () { var self = this; - _.each(this.__edispatcherRegisteredEvents, function(event) { + _.each(this.__edispatcherRegisteredEvents, function (event) { event.source.__edispatcherEvents.off(event.name, event.func, self); }); this.__edispatcherRegisteredEvents = []; - _.each(this.__edispatcherEvents.callbackList(), function(cal) { + _.each(this.__edispatcherEvents.callbackList(), function (cal) { this.off(cal[0], cal[2], cal[1]); }, this); this.__edispatcherEvents.off(); @@ -310,11 +310,11 @@ var EventDispatcherMixin = _.extend({}, ParentedMixin, { }); var PropertiesMixin = _.extend({}, EventDispatcherMixin, { - init: function() { + init: function () { EventDispatcherMixin.init.call(this); this.__getterSetterInternalMap = {}; }, - set: function(arg1, arg2, arg3) { + set: function (arg1, arg2, arg3) { var map; var options; if (typeof arg1 === "string") { @@ -327,7 +327,7 @@ var PropertiesMixin = _.extend({}, EventDispatcherMixin, { } var self = this; var changed = false; - _.each(map, function(val, key) { + _.each(map, function (val, key) { var tmp = self.__getterSetterInternalMap[key]; if (tmp === val) return; @@ -354,30 +354,30 @@ var PropertiesMixin = _.extend({}, EventDispatcherMixin, { if (changed) self.trigger("change", self); }, - get: function(key) { + get: function (key) { return this.__getterSetterInternalMap[key]; } }); var ServicesMixin = { - call: function(service, method) { + 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) { + callback: function (r) { result = r; }, }); return result; }, // AJAX calls - performRPC: function(route, args) { + performRPC: function (route, args) { return this.call('ajax', 'rpc', route, args); }, - performModelRPC: function(model, method, args, kwargs) { + performModelRPC: function (model, method, args, kwargs) { return this.performRPC('/web/dataset/call_kw/' + model + '/' + method, { model: model, method: method, @@ -385,12 +385,12 @@ var ServicesMixin = { kwargs: kwargs || {}, }); }, - loadFieldView: function(dataset, view_id, view_type, options) { + loadFieldView: function (dataset, view_id, view_type, options) { return this.loadViews(dataset.model, dataset.get_context(), [[view_id, view_type]], options).then(function (result) { return result[view_type]; }); }, - loadViews: function(modelName, context, views, options) { + loadViews: function (modelName, context, views, options) { var def = $.Deferred(); this.trigger_up('load_views', { modelName: modelName, @@ -401,7 +401,7 @@ var ServicesMixin = { }); return def; }, - loadFilters: function(dataset, action_id) { + loadFilters: function (dataset, action_id) { var def = $.Deferred(); this.trigger_up('load_filters', { dataset: dataset, @@ -411,10 +411,10 @@ var ServicesMixin = { return def; }, // Session stuff - getSession: function() { + getSession: function () { var session; this.trigger_up('get_session', { - callback: function(result) { + callback: function (result) { session = result; } }); @@ -429,32 +429,32 @@ var ServicesMixin = { var def = $.Deferred(); options = options || {}; var oldOnSuccess = options.on_success; - options.on_success = function(result) { + options.on_success = function (result) { oldOnSuccess(result); def.resolve(result); }; this.trigger_up('do_action', {'action': action, options: options}); return def; }, - do_notify: function(title, message, sticky) { + do_notify: function (title, message, sticky) { this.trigger_up('notification', {title: title, message: message, sticky: sticky}); }, - do_warn: function(title, message, sticky) { + do_warn: function (title, message, sticky) { this.trigger_up('warning', {title: title, message: message, sticky: sticky}); }, }; var ServiceProvider = { services: {}, - init: function() { + init: function () { var self = this; - _.each(AbstractService.prototype.Services, function(Service) { + _.each(AbstractService.prototype.Services, function (Service) { var service = new Service(); self.services[service.name] = service; }); this.custom_events.call_service = this._call_service.bind(this); }, - _call_service: function(event) { + _call_service: function (event) { var service = this.services[event.data.service]; var result = service[event.data.method].apply(service, event.data.args); event.data.callback(result); diff --git a/addons/web/static/src/js/core/session.js b/addons/web/static/src/js/core/session.js index ca56eb62439..9ee5726cfc8 100644 --- a/addons/web/static/src/js/core/session.js +++ b/addons/web/static/src/js/core/session.js @@ -27,7 +27,7 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { by this session object. Specifying this option automatically implies that the option "override_session" is set to true. */ - init: function(parent, origin, options) { + init: function (parent, origin, options) { mixins.EventDispatcherMixin.init.call(this, parent); options = options || {}; this.module_list = (options.modules && options.modules.slice()) || (window.odoo._modules && window.odoo._modules.slice()) || []; @@ -49,7 +49,7 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { this.currencies = {}; this._groups_def = {}; }, - setup: function(origin, options) { + setup: function (origin, options) { // must be able to customize server var window_origin = location.protocol + "//" + location.host; origin = origin ? origin.replace( /\/+$/, '') : window_origin; @@ -68,7 +68,7 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { /** * Setup a session */ - session_bind: function(origin) { + session_bind: function (origin) { var self = this; this.setup(origin); qweb.default_dict._s = this.origin; @@ -91,21 +91,21 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { if (this.is_frontend) return def; var self = this; - return def.then(function() { + return def.then(function () { var modules = self.module_list.join(','); var deferred = self.load_qweb(modules); if(self.session_is_valid()) { - return deferred.then(function() { return self.load_modules(); }); + return deferred.then(function () { return self.load_modules(); }); } return $.when( deferred, - self.rpc('/web/webclient/bootstrap_translations', {mods: self.module_list}).then(function(trans) { + self.rpc('/web/webclient/bootstrap_translations', {mods: self.module_list}).then(function (trans) { _t.database.set_bundle(trans); }) ); }); }, - session_is_valid: function() { + session_is_valid: function () { var db = $.deparam.querystring().db; if (db && this.db !== db) { return false; @@ -115,19 +115,19 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { /** * The session is validated by restoration of a previous session */ - session_authenticate: function() { + session_authenticate: function () { var self = this; - return $.when(this._session_authenticate.apply(this, arguments)).then(function() { + return $.when(this._session_authenticate.apply(this, arguments)).then(function () { return self.load_modules(); }); }, /** * The session is validated either by login or by restoration of a previous session */ - _session_authenticate: function(db, login, password) { + _session_authenticate: function (db, login, password) { var self = this; var params = {db: db, login: login, password: password}; - return this.rpc("/web/session/authenticate", params).then(function(result) { + return this.rpc("/web/session/authenticate", params).then(function (result) { if (!result.uid) { return $.Deferred().reject(); } @@ -135,11 +135,11 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { _.extend(self, result); }); }, - session_logout: function() { + session_logout: function () { $.bbq.removeState(); return this.rpc("/web/session/destroy", {}); }, - user_has_group: function(group) { + user_has_group: function (group) { if (!this.uid) { return $.when(false); } @@ -188,7 +188,7 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { * Load additional web addons of that instance and init them * */ - load_modules: function() { + load_modules: function () { var self = this; var modules = odoo._modules; var all_modules = _.uniq(self.module_list.concat(modules)); @@ -203,19 +203,19 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { loaded, self.rpc('/web/webclient/csslist', {mods: to_load}).done(self.load_css.bind(self)), self.load_qweb(to_load), - self.rpc('/web/webclient/jslist', {mods: to_load}).done(function(files) { + self.rpc('/web/webclient/jslist', {mods: to_load}).done(function (files) { file_list = file_list.concat(files); }) ); } return loaded.then(function () { return self.load_js(file_list); - }).done(function() { + }).done(function () { self.on_modules_loaded(); self.trigger('module_loaded'); }); }, - load_translations: function() { + load_translations: function () { return _t.database.load_translations(this, this.module_list, this.user_context.lang); }, load_css: function (files) { @@ -224,7 +224,7 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { ajax.loadCSS(self.url(file, null)); }); }, - load_js: function(files) { + load_js: function (files) { var self = this; var d = $.Deferred(); if (files.length !== 0) { @@ -236,7 +236,7 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { } return d; }, - load_qweb: function(mods) { + load_qweb: function (mods) { this.qweb_mutex.exec(function () { return $.get('/web/webclient/qweb?mods=' + mods).then(function (doc) { if (!doc) { return; } @@ -245,7 +245,7 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { }); return this.qweb_mutex.def; }, - on_modules_loaded: function() { + on_modules_loaded: function () { var openerp = window.openerp; for(var j=0; j<this.module_list.length; j++) { var mod = this.module_list[j]; @@ -264,7 +264,7 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { this.module_loaded[mod] = true; } }, - get_currency: function(currency_id) { + get_currency: function (currency_id) { return this.currencies[currency_id]; }, get_file: function (options) { @@ -286,7 +286,7 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { _.extend(this, result); return $.when(); }, - check_session_id: function() { + check_session_id: function () { var self = this; if (this.avoid_recursion) return $.when(); @@ -297,9 +297,9 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { // Even if some browsers could support cookies when using jsonp that behavior is // not consistent and the browser creators are tending to removing that feature. this.avoid_recursion = true; - return this.rpc("/gen_session_id", {}).then(function(result) { + return this.rpc("/gen_session_id", {}).then(function (result) { self.session_id = result; - }).always(function() { + }).always(function () { self.avoid_recursion = false; }); } else { @@ -322,18 +322,18 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { * @param {Function} error_callback function to execute on RPC call failure * @returns {jQuery.Deferred} jquery-provided ajax deferred */ - rpc: function(url, params, options) { + rpc: function (url, params, options) { var self = this; options = _.clone(options || {}); var shadow = options.shadow || false; - options.headers = _.extend({}, options.headers) + options.headers = _.extend({}, options.headers); if (odoo.debug) { options.headers["X-Debug-Mode"] = $.deparam($.param.querystring()).debug; } delete options.shadow; - return self.check_session_id().then(function() { + return self.check_session_id().then(function () { // TODO: remove if (! _.isString(url)) { _.extend(options, url); @@ -365,7 +365,7 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { if (! shadow) self.trigger('response'); return result; - }, function(type, error, textStatus, errorThrown) { + }, function (type, error, textStatus, errorThrown) { if (type === "server") { if (! shadow) self.trigger('response'); @@ -384,8 +384,8 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { return $.Deferred().reject(nerror, $.Event()); } }); - return p.fail(function() { // Allow deferred user to disable rpc_error call in fail - p.fail(function(error, event) { + return p.fail(function () { // Allow deferred user to disable rpc_error call in fail + p.fail(function (error, event) { if (!event.isDefaultPrevented()) { self.trigger('error', error, event); } @@ -393,14 +393,14 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { }); }); }, - url: function(path, params) { + url: function (path, params) { params = _.extend(params || {}); if (this.override_session || (! this.origin_server)) params.session_id = this.session_id; var qs = $.param(params); if (qs.length > 0) qs = "?" + qs; - var prefix = _.any(['http://', 'https://', '//'], function(el) { + var prefix = _.any(['http://', 'https://', '//'], function (el) { return path.length >= el.length && path.slice(0, el.length) === el; }) ? '' : this.prefix; return prefix + path + qs; |
