mirror of
https://github.com/Febbweiss/CloudBudget-AngularJS.git
synced 2026-03-05 14:55:39 +00:00
44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
(function() {
|
|
'use strict';
|
|
|
|
angular
|
|
.module('config', [])
|
|
.config(config);
|
|
|
|
config.$inject = ['$httpProvider', 'growlProvider'];
|
|
|
|
var regexIso8601 = /^(\d{4}|\+\d{6})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2}):(\d{2}):(\d{2})\.(\d{1,})(Z|([\-+])(\d{2}):(\d{2}))?)?)?)?$/;
|
|
|
|
function convertDateStringsToDates(input) {
|
|
// Ignore things that aren't objects.
|
|
if (typeof input !== "object") return input;
|
|
|
|
for (var key in input) {
|
|
if (!input.hasOwnProperty(key)) continue;
|
|
|
|
var value = input[key];
|
|
var match;
|
|
// Check for string properties which look like dates.
|
|
if (typeof value === "string" && (match = value.match(regexIso8601))) {
|
|
var milliseconds = Date.parse(match[0])
|
|
if (!isNaN(milliseconds)) {
|
|
input[key] = new Date(milliseconds);
|
|
}
|
|
} else if (typeof value === "object") {
|
|
// Recurse into object
|
|
convertDateStringsToDates(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
function config($httpProvider, growlProvider) {
|
|
$httpProvider.defaults.transformResponse.push(function(responseData){
|
|
convertDateStringsToDates(responseData);
|
|
return responseData;
|
|
});
|
|
|
|
growlProvider.globalReversedOrder(true);
|
|
growlProvider.globalTimeToLive(5000);
|
|
growlProvider.globalDisableCountDown(true);
|
|
};
|
|
})(); |