diff --git a/src/python/ripe_demo/static/js/ripe.js b/src/python/ripe_demo/static/js/ripe.js index 8909641dd..b1e8b5bb7 100644 --- a/src/python/ripe_demo/static/js/ripe.js +++ b/src/python/ripe_demo/static/js/ripe.js @@ -777,9 +777,7 @@ ripe.Ripe.prototype.signin = function(username, password, options, callback) { } }); options = this._build(options); - return this._cacheURL(options.url, options, function(result) { - callback && callback(result); - }); + return this._cacheURL(options.url, options, callback); }; ripe.Ripe.prototype.getConfig = function(options, callback) { @@ -803,19 +801,19 @@ ripe.Ripe.prototype.getDefaults = function(options, callback) { options = typeof options === "function" ? {} : options; options = this._getDefaultsOptions(options); options = this._build(options); - return this._cacheURL(options.url, options, function(result) { - callback(result ? result.parts : null); + return this._cacheURL(options.url, options, function(result, isValid) { + callback && callback(isValid ? result.parts : result, isValid); }); }; ripe.Ripe.prototype.getOptionals = function(options, callback) { - return this.getDefaults(options, function(defaults) { + return this.getDefaults(options, function(defaults, isValid) { var optionals = []; for (var name in defaults) { var part = defaults[name]; part.optional && optionals.push(name); } - callback(optionals); + callback && callback(optionals, isValid); }); }; @@ -824,8 +822,8 @@ ripe.Ripe.prototype.getCombinations = function(options, callback) { options = typeof options === "function" ? {} : options; options = this._getCombinationsOptions(options); options = this._build(options); - return this._cacheURL(options.url, options, function(result) { - callback && callback(result.combinations); + return this._cacheURL(options.url, options, function(result, isValid) { + callback && callback(isValid ? result.combinations : result, isValid); }); }; @@ -899,9 +897,12 @@ ripe.Ripe.prototype._requestURL = function(url, options, callback) { var request = new XMLHttpRequest(); request.addEventListener("load", function() { + var result = null; var isValid = this.status === 200; - var result = JSON.parse(this.responseText); - callback && callback.call(context, isValid ? result : null, isValid, this); + try { + result = JSON.parse(this.responseText); + } catch (error) {} + callback && callback.call(context, result, isValid, this); }); request.open(method, url); @@ -1410,9 +1411,7 @@ ripe.Ripe.prototype.oauthAccessToken = function(code, options, callback) { } }); options = this._build(options); - return this._cacheURL(options.url, options, function(result) { - callback && callback(result); - }); + return this._cacheURL(options.url, options, callback); }; ripe.Ripe.prototype.oauthLogin = function(accessToken, options, callback) { @@ -1426,9 +1425,7 @@ ripe.Ripe.prototype.oauthLogin = function(accessToken, options, callback) { access_token: accessToken } }); - return this._cacheURL(options.url, options, function(result) { - callback && callback(result); - }); + return this._cacheURL(options.url, options, callback); }; if (typeof require !== "undefined") { @@ -1448,9 +1445,7 @@ ripe.Ripe.prototype.getOrders = function(options, callback) { auth: true }); options = this._build(options); - return this._cacheURL(options.url, options, function(result) { - callback && callback(result); - }); + return this._cacheURL(options.url, options, callback); }; ripe.Ripe.prototype.getOrder = function(number, options, callback) { @@ -1463,9 +1458,7 @@ ripe.Ripe.prototype.getOrder = function(number, options, callback) { auth: true }); options = this._build(options); - return this._cacheURL(options.url, options, function(result) { - callback && callback(result); - }); + return this._cacheURL(options.url, options, callback); }; ripe.Ripe.prototype.createOrder = function(number, options, callback) { @@ -1514,9 +1507,7 @@ ripe.Ripe.prototype.setOrderStatus = function(number, status, options, callback) method: "PUT" }); options = this._build(options); - return this._cacheURL(options.url, options, function(result) { - callback && callback(result); - }); + return this._cacheURL(options.url, options, callback); }; if (typeof require !== "undefined") { @@ -1535,9 +1526,7 @@ ripe.Ripe.prototype.getSizes = function(options, callback) { method: "GET" }); options = this._build(options); - return this._cacheURL(options.url, options, function(result) { - callback && callback(result); - }); + return this._cacheURL(options.url, options, callback); }; ripe.Ripe.prototype.sizeToNative = function(scale, value, gender, options, callback) { @@ -1554,9 +1543,7 @@ ripe.Ripe.prototype.sizeToNative = function(scale, value, gender, options, callb } }); options = this._build(options); - return this._cacheURL(options.url, options, function(result) { - callback && callback(result); - }); + return this._cacheURL(options.url, options, callback); }; ripe.Ripe.prototype.sizeToNativeB = function(scales, values, genders, options, callback) { @@ -1586,9 +1573,7 @@ ripe.Ripe.prototype.sizeToNativeB = function(scales, values, genders, options, c }); options = this._build(options); - return this._cacheURL(options.url, options, function(result) { - callback && callback(result); - }); + return this._cacheURL(options.url, options, callback); }; ripe.Ripe.prototype.nativeToSize = function(scale, value, gender, options, callback) { @@ -1605,9 +1590,7 @@ ripe.Ripe.prototype.nativeToSize = function(scale, value, gender, options, callb } }); options = this._build(options); - return this._cacheURL(options.url, options, function(result) { - callback && callback(result); - }); + return this._cacheURL(options.url, options, callback); }; ripe.Ripe.prototype.nativeToSizeB = function(scales, values, genders, options, callback) { @@ -1637,9 +1620,7 @@ ripe.Ripe.prototype.nativeToSizeB = function(scales, values, genders, options, c }); options = this._build(options); - return this._cacheURL(options.url, options, function(result) { - callback && callback(result); - }); + return this._cacheURL(options.url, options, callback); }; if (typeof require !== "undefined") {