Show More
@@ -1,62 +1,70 b'' | |||
|
1 | 1 | // # Copyright (C) 2010-2016 RhodeCode GmbH |
|
2 | 2 | // # |
|
3 | 3 | // # This program is free software: you can redistribute it and/or modify |
|
4 | 4 | // # it under the terms of the GNU Affero General Public License, version 3 |
|
5 | 5 | // # (only), as published by the Free Software Foundation. |
|
6 | 6 | // # |
|
7 | 7 | // # This program is distributed in the hope that it will be useful, |
|
8 | 8 | // # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 | 9 | // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 | 10 | // # GNU General Public License for more details. |
|
11 | 11 | // # |
|
12 | 12 | // # You should have received a copy of the GNU Affero General Public License |
|
13 | 13 | // # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
14 | 14 | // # |
|
15 | 15 | // # This program is dual-licensed. If you wish to learn more about the |
|
16 | 16 | // # RhodeCode Enterprise Edition, including its added features, Support services, |
|
17 | 17 | // # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
18 | 18 | |
|
19 | 19 | /** |
|
20 | 20 | * turns objects into GET query string |
|
21 | 21 | */ |
|
22 | 22 | var toQueryString = function(o) { |
|
23 | 23 | if(typeof o === 'string') { |
|
24 | 24 | return o; |
|
25 | 25 | } |
|
26 | 26 | if(typeof o !== 'object') { |
|
27 | 27 | return false; |
|
28 | 28 | } |
|
29 | 29 | var _p, _qs = []; |
|
30 | 30 | for(_p in o) { |
|
31 | 31 | _qs.push(encodeURIComponent(_p) + '=' + encodeURIComponent(o[_p])); |
|
32 | 32 | } |
|
33 | 33 | return _qs.join('&'); |
|
34 | 34 | }; |
|
35 | 35 | |
|
36 | 36 | /** |
|
37 | 37 | * ajax call wrappers |
|
38 | 38 | */ |
|
39 | var ajaxGET = function(url, success) { | |
|
39 | var ajaxGET = function(url, success, failure) { | |
|
40 | 40 | var sUrl = url; |
|
41 | 41 | var request = $.ajax({url: sUrl, headers: {'X-PARTIAL-XHR': true}}) |
|
42 | 42 | .done(function(data){ |
|
43 | 43 | success(data); |
|
44 | 44 | }) |
|
45 | .fail(function(data, textStatus, xhr){ | |
|
46 | alert("error processing request: " + textStatus); | |
|
45 | .fail(function(data, textStatus, xhr) { | |
|
46 | if (failure) { | |
|
47 | failure(data, textStatus, xhr); | |
|
48 | } else { | |
|
49 | alert("error processing request: " + textStatus); | |
|
50 | } | |
|
47 | 51 | }); |
|
48 | 52 | return request; |
|
49 | 53 | }; |
|
50 | var ajaxPOST = function(url,postData,success) { | |
|
54 | var ajaxPOST = function(url, postData, success, failure) { | |
|
51 | 55 | var sUrl = url; |
|
52 | 56 | var postData = toQueryString(postData); |
|
53 | 57 | var request = $.ajax({type: 'POST', data: postData, url: sUrl, |
|
54 | 58 | headers: {'X-PARTIAL-XHR': true}}) |
|
55 | 59 | .done(function(data){ |
|
56 | 60 | success(data); |
|
57 | 61 | }) |
|
58 | 62 | .fail(function(data, textStatus, xhr){ |
|
59 | alert("error processing request: " + textStatus); | |
|
63 | if (failure) { | |
|
64 | failure(data, textStatus, xhr); | |
|
65 | } else { | |
|
66 | alert("error processing request: " + textStatus); | |
|
67 | } | |
|
60 | 68 | }); |
|
61 | 69 | return request; |
|
62 | 70 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now