scinote-web/app/assets/javascripts/sitewide/utils.js
2016-08-31 17:57:06 +02:00

27 lines
534 B
JavaScript

/*
* Converts JSON data received from the server to flat array of values.
*/
function jsonToValuesArray(jsonData) {
var 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();
});
}