scinote-web/app/assets/javascripts/sitewide/utils.js

27 lines
522 B
JavaScript

/*
* Converts JSON data received from the server to flat array of values.
*/
function jsonToValuesArray(jsonData) {
errMsgs =[];
for (var key in jsonData) {
var values = jsonData[key];
$.each(values, function(idx, val) {
errMsgs.push(val);
});
}
return errMsgs;
}
/*
* Calls callback function on AJAX success (because built-in functions don't
* work!)
*/
$.fn.onAjaxComplete = function (cb) {
$(this)
.on("ajax:success", function() {
cb();
})
.on("ajax:error", function() {
cb();
});
}