Mutualise some common JS functions
This commit is contained in:
parent
3df8d24e33
commit
e9fd9c4e9a
4 changed files with 71 additions and 136 deletions
|
@ -1,80 +1,4 @@
|
|||
angular.module("FICApp", ["ngSanitize", "ngAnimate"]);
|
||||
|
||||
angular.module("FICApp")
|
||||
.filter("objectLength", function() {
|
||||
return function(input) {
|
||||
if (input !== undefined)
|
||||
return Object.keys(input).length;
|
||||
else
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
String.prototype.capitalize = function() {
|
||||
return this
|
||||
.toLowerCase()
|
||||
.replace(
|
||||
/(^|\s)([a-z])/g,
|
||||
function(m,p1,p2) { return p1+p2.toUpperCase(); }
|
||||
);
|
||||
}
|
||||
|
||||
angular.module("FICApp")
|
||||
.controller("TimeController", function($scope, $rootScope, $http, $timeout) {
|
||||
$rootScope.time = {};
|
||||
$rootScope.recvTime = function(response) {
|
||||
sessionStorage.userService = angular.toJson({
|
||||
"cu": Math.floor(response.headers("x-fic-time") * 1000),
|
||||
"he": (new Date()).getTime(),
|
||||
});
|
||||
}
|
||||
|
||||
function updTime() {
|
||||
$timeout.cancel($scope.cb);
|
||||
$scope.cb = $timeout(updTime, 1000);
|
||||
if (sessionStorage.userService && $rootScope.settings) {
|
||||
var time = angular.fromJson(sessionStorage.userService);
|
||||
var settings = $rootScope.settings;
|
||||
var srv_cur = new Date(Date.now() + (time.cu - time.he));
|
||||
|
||||
if (Math.floor(settings.start / 1000) == Math.floor(srv_cur / 1000)) {
|
||||
$rootScope.refresh(true);
|
||||
}
|
||||
|
||||
var remain = 0;
|
||||
if (settings.start == 0) {
|
||||
$rootScope.time = {};
|
||||
return
|
||||
} else if (settings.start > srv_cur) {
|
||||
$rootScope.startIn = Math.floor((settings.start - srv_cur) / 1000);
|
||||
remain = settings.end - settings.start;
|
||||
} else if (settings.end > srv_cur) {
|
||||
$rootScope.startIn = 0;
|
||||
remain = settings.end - srv_cur;
|
||||
}
|
||||
|
||||
remain = remain / 1000;
|
||||
|
||||
if (remain < 0) {
|
||||
remain = 0;
|
||||
$rootScope.time.end = true;
|
||||
$rootScope.time.expired = true;
|
||||
} else if (remain < 60) {
|
||||
$rootScope.time.end = false;
|
||||
$rootScope.time.expired = true;
|
||||
} else {
|
||||
$rootScope.time.end = false;
|
||||
$rootScope.time.expired = false;
|
||||
}
|
||||
|
||||
$rootScope.time.remaining = remain;
|
||||
$rootScope.time.hours = Math.floor(remain / 3600);
|
||||
$rootScope.time.minutes = Math.floor((remain % 3600) / 60);
|
||||
$rootScope.time.seconds = Math.floor(remain % 60);
|
||||
}
|
||||
}
|
||||
updTime();
|
||||
})
|
||||
angular.module("FICApp", ["ngSanitize", "ngAnimate"])
|
||||
.controller("EventsController", function($scope, $http, $interval) {
|
||||
$scope.events = [];
|
||||
var refreshEvents = function() {
|
||||
|
|
Reference in a new issue