| OLD | NEW |
| 1 <!-- | 1 <!-- |
| 2 Copyright 2016 The LUCI Authors. All rights reserved. | 2 Copyright 2016 The LUCI Authors. All rights reserved. |
| 3 Use of this source code is governed under the Apache License, Version 2.0 | 3 Use of this source code is governed under the Apache License, Version 2.0 |
| 4 that can be found in the LICENSE file. | 4 that can be found in the LICENSE file. |
| 5 | 5 |
| 6 It contains the definition of the following Behaviors: | 6 It contains the definition of the following Behaviors: |
| 7 | 7 |
| 8 SwarmingBehaviors.CommonBehavior | 8 SwarmingBehaviors.CommonBehavior |
| 9 | 9 |
| 10 To use it, include | 10 To use it, include |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // because computed values in Polymer don't fire if a property is | 32 // because computed values in Polymer don't fire if a property is |
| 33 // undefined. Clients should check that bindTo is not falsey. | 33 // undefined. Clients should check that bindTo is not falsey. |
| 34 _getJsonAsync: function(bindTo, url, busy, headers, params) { | 34 _getJsonAsync: function(bindTo, url, busy, headers, params) { |
| 35 if (!bindTo || !url) { | 35 if (!bindTo || !url) { |
| 36 console.log("Need at least a polymer element to bind to and a url"); | 36 console.log("Need at least a polymer element to bind to and a url"); |
| 37 return; | 37 return; |
| 38 } | 38 } |
| 39 if (busy) { | 39 if (busy) { |
| 40 this.set(busy, true); | 40 this.set(busy, true); |
| 41 } | 41 } |
| 42 url = url + "?" + sk.query.fromParamSet(params); | 42 if (params) { |
| 43 url = url + "?" + sk.query.fromParamSet(params); |
| 44 } |
| 43 sk.request("GET", url, "", headers).then(JSON.parse).then(function(json)
{ | 45 sk.request("GET", url, "", headers).then(JSON.parse).then(function(json)
{ |
| 44 this.set(bindTo, json); | 46 this.set(bindTo, json); |
| 45 if (busy) { | 47 if (busy) { |
| 46 this.set(busy, false); | 48 this.set(busy, false); |
| 47 } | 49 } |
| 48 }.bind(this)).catch(function(reason){ | 50 }.bind(this)).catch(function(reason){ |
| 49 console.log("Reason for failure of request to " + url, reason); | 51 console.log("Reason for failure of request to " + url, reason); |
| 50 this.set(bindTo, false); | 52 this.set(bindTo, false); |
| 51 if (busy) { | 53 if (busy) { |
| 52 this.set(busy, false); | 54 this.set(busy, false); |
| 53 } | 55 } |
| 54 }.bind(this)); | 56 }.bind(this)); |
| 55 }, | 57 }, |
| 56 | 58 |
| 57 _not: function(a) { | 59 _not: function(a) { |
| 58 return !a; | 60 return !a; |
| 59 }, | 61 }, |
| 60 | 62 |
| 61 _or: function() { | 63 _or: function() { |
| 62 var result = false; | 64 var result = false; |
| 63 // can't use .foreach, as arguments isn't really an Array. | 65 // can't use .foreach, as arguments isn't really an Array. |
| 64 for (var i = 0; i < arguments.length; i++) { | 66 for (var i = 0; i < arguments.length; i++) { |
| 65 result = result || arguments[i]; | 67 result = result || arguments[i]; |
| 66 } | 68 } |
| 67 return result; | 69 return result; |
| 68 }, | 70 }, |
| 69 }; | 71 }; |
| 70 })(); | 72 })(); |
| 71 </script> | 73 </script> |
| OLD | NEW |