summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/services/ajax_service.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js/services/ajax_service.js')
-rw-r--r--addons/web/static/src/js/services/ajax_service.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/addons/web/static/src/js/services/ajax_service.js b/addons/web/static/src/js/services/ajax_service.js
new file mode 100644
index 00000000..da3d436c
--- /dev/null
+++ b/addons/web/static/src/js/services/ajax_service.js
@@ -0,0 +1,41 @@
+odoo.define('web.AjaxService', function (require) {
+"use strict";
+
+var AbstractService = require('web.AbstractService');
+var ajax = require('web.ajax');
+var core = require('web.core');
+var session = require('web.session');
+
+var AjaxService = AbstractService.extend({
+ /**
+ * @param {Object} libs - @see ajax.loadLibs
+ * @param {Object} [context] - @see ajax.loadLibs
+ * @param {Object} [tplRoute] - @see ajax.loadLibs
+ */
+ loadLibs: function (libs, context, tplRoute) {
+ return ajax.loadLibs(libs, context, tplRoute);
+ },
+ rpc: function (route, args, options, target) {
+ 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;
+ },
+});
+
+core.serviceRegistry.add('ajax', AjaxService);
+
+return AjaxService;
+
+});