| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 this.swarming = this.swarming || function() { | 5 this.swarming = this.swarming || function() { |
| 6 | 6 |
| 7 var swarming = {}; | 7 var swarming = {}; |
| 8 | 8 |
| 9 // naturalCompare tries to use natural sorting (e.g. sort ints by value). | 9 // naturalCompare tries to use natural sorting (e.g. sort ints by value). |
| 10 swarming.naturalCompare = function(a, b) { | 10 swarming.naturalCompare = function(a, b) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 var c = comp(a, b); | 46 var c = comp(a, b); |
| 47 if (c === 0) { | 47 if (c === 0) { |
| 48 return a.__sortIdx - b.__sortIdx; | 48 return a.__sortIdx - b.__sortIdx; |
| 49 } | 49 } |
| 50 return c; | 50 return c; |
| 51 }); | 51 }); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // postWithToast makes a post request and updates the error-toast | 54 // postWithToast makes a post request and updates the error-toast |
| 55 // element with the response, regardless of failure. See error-toast.html | 55 // element with the response, regardless of failure. See error-toast.html |
| 56 // for more information. | 56 // for more information. The body param should be an object or undefined. |
| 57 swarming.postWithToast = function(url, msg, auth_headers) { | 57 swarming.postWithToast = function(url, msg, auth_headers, body) { |
| 58 // Keep toast displayed until we hear back from the request. | 58 // Keep toast displayed until we hear back from the request. |
| 59 sk.errorMessage(msg, 0); | 59 sk.errorMessage(msg, 0); |
| 60 | 60 |
| 61 sk.request("POST", url, undefined, auth_headers).then(function(response) { | 61 auth_headers["content-type"] = "application/json; charset=UTF-8"; |
| 62 if (body) { |
| 63 body = JSON.stringify(body); |
| 64 } |
| 65 |
| 66 return sk.request("POST", url, body, auth_headers).then(function(response) { |
| 62 sk.errorMessage("Request sent. Response: "+response, 3000); | 67 sk.errorMessage("Request sent. Response: "+response, 3000); |
| 68 return response; |
| 63 }).catch(function(reason) { | 69 }).catch(function(reason) { |
| 64 console.log("Request failed", reason); | 70 console.log("Request failed", reason); |
| 65 sk.errorMessage("Request failed. Reason: "+reason, 5000); | 71 sk.errorMessage("Request failed. Reason: "+reason, 5000); |
| 72 return Promise.reject(reason); |
| 66 }); | 73 }); |
| 67 } | 74 } |
| 68 | 75 |
| 69 return swarming; | 76 return swarming; |
| 70 }(); | 77 }(); |
| OLD | NEW |