diff options
| author | Géry Debongnie <ged@odoo.com> | 2019-08-23 13:19:24 +0000 |
|---|---|---|
| committer | Vincent Schippefilt <vsc@odoo.com> | 2019-12-09 11:09:10 +0000 |
| commit | 29726e8fd000cb09075f9b6b2a6a8d2ddaf4ef58 (patch) | |
| tree | 91718f6edc90cc069ee5ff3b44c4beb823d31104 /addons/web/static/src/js/env.js | |
| parent | 3b4592acfcd67f2b3e467c5e3f82d7b524b96843 (diff) | |
[ADD] web: add owl 1.0.0-beta1 to odoo
With this commit, we properly introduce the Owl library into our beloved
codebase. More information on the Owl library can be found in the project
repository: https://github.com/odoo/owl/
Co-authored-by: Aaron Bohy <aab@odoo.com>
Co-authored-by: Julien Mougenot <jum@odoo.com>
Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/env.js')
| -rw-r--r-- | addons/web/static/src/js/env.js | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/addons/web/static/src/js/env.js b/addons/web/static/src/js/env.js new file mode 100644 index 00000000000..c223fcc91ee --- /dev/null +++ b/addons/web/static/src/js/env.js @@ -0,0 +1,86 @@ +odoo.define("web.env", function (require) { + "use strict"; + + const { _lt, _t, bus } = require("web.core"); + const { blockUI, unblockUI } = require("web.framework"); + const { device, isDebug } = require("web.config"); + const { jsonRpc } = require('web.ajax'); + const rpc = require("web.rpc"); + const session = require("web.session"); + const utils = require("web.utils"); + + + const qweb = new owl.QWeb({ translateFn: _t }); + + function ajaxJsonRPC() { + return jsonRpc(...arguments); + } + + function getCookie() { + return utils.get_cookie(...arguments); + } + + function httpRequest(route, params = {}, readMethod = 'json') { + const formData = new FormData(); + for (const key in params) { + if (key === 'method') { + continue; + } + const value = params[key]; + if (Array.isArray(value) && value.length) { + for (const val of value) { + formData.append(key, val); + } + } else { + formData.append(key, value); + } + } + + return fetch(route, { + method: params.method || 'POST', + body: formData, + }).then(response => response[readMethod]()); + } + + function navigate(url, params) { + window.location = $.param.querystring(url, params); + } + + function performRPC(params, options) { + const query = rpc.buildQuery(params); + return session.rpc(query.route, query.params, options); + } + + function reloadPage() { + window.location.reload(); + } + + function setCookie() { + utils.set_cookie(...arguments); + } + + // There should be as much dependencies as possible in the env object. + // This will allow an easier testing of components. + // See https://github.com/odoo/owl/blob/master/doc/reference/environment.md#content-of-an-environment + // for more information on environments. + return { + _lt, + _t, + bus, + device, + isDebug, + qweb, + services: { + ajaxJsonRPC, + blockUI, + getCookie, + httpRequest, + navigate, + reloadPage, + rpc: performRPC, + setCookie, + unblockUI, + }, + session, + }; +}); |
