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

28 lines
534 B
JavaScript
Raw Normal View History

/*
* Converts JSON data received from the server to flat array of values.
*/
function jsonToValuesArray(jsonData) {
2016-08-31 23:52:45 +08:00
var errMsgs = [];
for (var key in jsonData) {
var values = jsonData[key];
2016-08-31 23:52:45 +08:00
$.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) {
2016-08-31 23:52:45 +08:00
$(this)
.on('ajax:success', function () {
cb();
})
.on('ajax:error', function () {
cb();
});
}