Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Jul 25, 2018
1 parent 22d5d19 commit f566b8a
Showing 1 changed file with 22 additions and 41 deletions.
63 changes: 22 additions & 41 deletions src/python/ripe_demo/static/js/ripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
});
};

Expand All @@ -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);
});
};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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") {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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") {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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") {
Expand Down

0 comments on commit f566b8a

Please sign in to comment.