diff options
| author | Vincent Schippefilt <vsc@odoo.com> | 2019-03-06 14:02:32 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2019-03-06 20:07:17 +0100 |
| commit | ab56e637b7f97ddcdbcc9baea99ae097e342409c (patch) | |
| tree | 4cb47da9f7ef89b19d18429220a7507470ec12a9 /addons/web/static/src/js/services | |
| parent | eeed894fd50e477135e1ac9a82f6e98ce063ab90 (diff) | |
[REF] web: adapt code after jQuery update
Part of task 1896658
Co-authored-by: Aaron Bohy <aab@odoo.com>
Co-authored-by: Christophe Matthieu <chm@odoo.com>
Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Co-authored-by: David Monjoie <dmo@odoo.com>
Co-authored-by: Martin Geubelle <mge@odoo.com>
Co-authored-by: svs-odoo <svs@odoo.com>
Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/services')
| -rw-r--r-- | addons/web/static/src/js/services/ajax_service.js | 25 | ||||
| -rw-r--r-- | addons/web/static/src/js/services/core.js | 12 | ||||
| -rw-r--r-- | addons/web/static/src/js/services/crash_manager.js | 2 | ||||
| -rw-r--r-- | addons/web/static/src/js/services/data_manager.js | 16 | ||||
| -rw-r--r-- | addons/web/static/src/js/services/report_service.js | 2 |
5 files changed, 29 insertions, 28 deletions
diff --git a/addons/web/static/src/js/services/ajax_service.js b/addons/web/static/src/js/services/ajax_service.js index 0cecaae9da3..cb83dd9d553 100644 --- a/addons/web/static/src/js/services/ajax_service.js +++ b/addons/web/static/src/js/services/ajax_service.js @@ -7,19 +7,20 @@ var session = require('web.session'); var AjaxService = AbstractService.extend({ rpc: function (route, args, options, target) { - var def = $.Deferred(); - var promise = def.promise(); - var xhrDef = session.rpc(route, args, options); - promise.abort = xhrDef.abort.bind(xhrDef); - xhrDef.then(function () { - if (!target.isDestroyed()) { - def.resolve.apply(def, arguments); - } - }).fail(function () { - if (!target.isDestroyed()) { - def.reject.apply(def, arguments); - } + var rpcPromise; + var promise = new Promise(function (resolve, reject) { + rpcPromise = session.rpc(route, args, options); + rpcPromise.then(function (result) { + if (!target.isDestroyed()) { + resolve(result); + } + }).guardedCatch(function (reason) { + if (!target.isDestroyed()) { + reject(reason); + } + }); }); + promise.abort = rpcPromise.abort.bind(rpcPromise); return promise; }, }); diff --git a/addons/web/static/src/js/services/core.js b/addons/web/static/src/js/services/core.js index 3d6cfc4e684..ee37479e217 100644 --- a/addons/web/static/src/js/services/core.js +++ b/addons/web/static/src/js/services/core.js @@ -13,15 +13,15 @@ var translation = require('web.translation'); * * @type Boolean */ -var bus = new Bus (); +var bus = new Bus(); -_.each('click,dblclick,keydown,keypress,keyup'.split(','), function(evtype) { - $('html').on(evtype, function(ev) { +_.each('click,dblclick,keydown,keypress,keyup'.split(','), function (evtype) { + $('html').on(evtype, function (ev) { bus.trigger(evtype, ev); }); }); -_.each('resize,scroll'.split(','), function(evtype) { - $(window).on(evtype, function(ev) { +_.each('resize,scroll'.split(','), function (evtype) { + $(window).on(evtype, function (ev) { bus.trigger(evtype, ev); }); }); @@ -37,7 +37,7 @@ return { _lt: translation._lt, // registries - action_registry : new Registry(), + action_registry: new Registry(), crash_registry: new Registry(), serviceRegistry: new Registry(), /** diff --git a/addons/web/static/src/js/services/crash_manager.js b/addons/web/static/src/js/services/crash_manager.js index db88d688505..a29e21ca8ca 100644 --- a/addons/web/static/src/js/services/crash_manager.js +++ b/addons/web/static/src/js/services/crash_manager.js @@ -65,7 +65,7 @@ var CrashManager = core.Class.extend({ ajax.jsonRpc('/web/webclient/version_info', 'call', {}, {shadow:true}).then(function () { core.bus.trigger('connection_restored'); self.isConnected = true; - }).fail(function () { + }).guardedCatch(function () { // exponential backoff, with some jitter delay = (delay * 1.5) + 500*Math.random(); setTimeout(checkConnection, delay); diff --git a/addons/web/static/src/js/services/data_manager.js b/addons/web/static/src/js/services/data_manager.js index 348054691bc..b2f6ef1feb1 100644 --- a/addons/web/static/src/js/services/data_manager.js +++ b/addons/web/static/src/js/services/data_manager.js @@ -33,7 +33,7 @@ return core.Class.extend({ * * @param {int|string} [action_id] the action id or xmlid * @param {Object} [additional_context] used to load the action - * @return {Deferred} resolved with the action whose id or xmlid is action_id + * @return {Promise} resolved with the action whose id or xmlid is action_id */ load_action: function (action_id, additional_context) { var self = this; @@ -69,7 +69,7 @@ return core.Class.extend({ * - options.load_filters: whether or not to load the filters, * - options.action_id: the action_id (required to load filters), * - options.toolbar: whether or not a toolbar will be displayed, - * @return {Deferred} resolved with the requested views information + * @return {Promise} resolved with the requested views information */ load_views: function (params, options) { var self = this; @@ -108,12 +108,12 @@ return core.Class.extend({ var fvg = result.fields_views[view_descr[1]]; fvg.viewFields = fvg.fields; fvg.fields = result.fields; - self._cache.fields_views[fv_key] = $.when(fvg); + self._cache.fields_views[fv_key] = Promise.resolve(fvg); }); // Insert filters, if any, into the filters cache if (result.filters) { - self._cache.filters[filters_key] = $.when(result.filters); + self._cache.filters[filters_key] = Promise.resolve(result.filters); } return result.fields_views; @@ -130,7 +130,7 @@ return core.Class.extend({ * @param {string} params.modelName * @param {Object} params.context * @param {integer} params.actionId - * @return {Deferred} resolved with the requested filters + * @return {Promise} resolved with the requested filters */ load_filters: function (params) { var key = this._gen_key(params.modelName, params.actionId); @@ -143,7 +143,7 @@ return core.Class.extend({ }, model: 'ir.filters', method: 'get_filters', - }).fail(this._invalidate.bind(this, this._cache.filters, key)); + }).guardedCatch(this._invalidate.bind(this, this._cache.filters, key)); } return this._cache.filters[key]; }, @@ -152,7 +152,7 @@ return core.Class.extend({ * Calls 'create_or_replace' on 'ir_filters'. * * @param {Object} [filter] the filter description - * @return {Deferred} resolved with the id of the created or replaced filter + * @return {Promise} resolved with the id of the created or replaced filter */ create_filter: function (filter) { var self = this; @@ -175,7 +175,7 @@ return core.Class.extend({ * Calls 'unlink' on 'ir_filters'. * * @param {integer} filterId Id of the filter to remove - * @return {Deferred} + * @return {Promise} */ delete_filter: function (filterId) { var self = this; diff --git a/addons/web/static/src/js/services/report_service.js b/addons/web/static/src/js/services/report_service.js index 006c546041a..ed4907a6d6d 100644 --- a/addons/web/static/src/js/services/report_service.js +++ b/addons/web/static/src/js/services/report_service.js @@ -15,7 +15,7 @@ var ReportService = AbstractService.extend({ * Checks the state of the installation of wkhtmltopdf on the server. * Implements an internal cache to do the request only once. * - * @returns {Deferred} resolved with the state of wkhtmltopdf on the server + * @returns {Promise} resolved with the state of wkhtmltopdf on the server * (possible values are 'ok', 'broken', 'install', 'upgrade', 'workers'). */ checkWkhtmltopdf: function () { |
