diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-10-16 18:41:43 +0200 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-10-19 10:50:17 +0200 |
commit | f8ae4195cb259f285ce2546fe4921a470f61b276 (patch) | |
tree | d481e77e9e4b487a3b3c0843324aa920c5e939a9 /server/sonar-web/src/main/js/helpers | |
parent | f0f585d25d40d6117e586167f5f42c93978060f8 (diff) | |
download | sonarqube-f8ae4195cb259f285ce2546fe4921a470f61b276.tar.gz sonarqube-f8ae4195cb259f285ce2546fe4921a470f61b276.zip |
SONAR-6928 Rewrite the System Info page
Diffstat (limited to 'server/sonar-web/src/main/js/helpers')
-rw-r--r-- | server/sonar-web/src/main/js/helpers/request.js | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/server/sonar-web/src/main/js/helpers/request.js b/server/sonar-web/src/main/js/helpers/request.js index 74a5eaaf3bc..00029d3e991 100644 --- a/server/sonar-web/src/main/js/helpers/request.js +++ b/server/sonar-web/src/main/js/helpers/request.js @@ -46,18 +46,23 @@ class Request { submit () { let url = this.url; let options = _.defaults(this.options, OPTIONS); - let headers = _.defaults(this.headers, HEADERS); - options.headers = headers; + options.headers = _.defaults(this.headers, HEADERS); if (this.data) { - if (options.type === 'GET') { + if (options.method === 'GET') { url += '?' + queryString(this.data); } else { + options.headers['Content-Type'] = 'application/x-www-form-urlencoded'; options.body = queryString(this.data); } } return window.fetch(url, options); } + setMethod (method) { + this.options.method = method; + return this; + } + setData (data) { this.data = data; return this; @@ -112,4 +117,19 @@ export function getJSON (url, data) { .submit() .then(checkStatus) .then(parseJSON); -}
\ No newline at end of file +} + + +/** + * Shortcut to do a POST request and return response json + * @param url + * @param data + */ +export function postJSON (url, data) { + return request(url) + .setMethod('POST') + .setData(data) + .submit() + .then(checkStatus) + .then(parseJSON); +} |