-
Notifications
You must be signed in to change notification settings - Fork 3
/
memberviewmodel.js
executable file
·33 lines (33 loc) · 1.3 KB
/
memberviewmodel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function Member(memberName){
var self = this;
self.name= memberName;
self.present = ko.observable(true);
self.allocatedTime = ko.observable(0);
//the members remaining time to speak.
self.remainingTime = ko.observable(0);
self.completed = ko.observable(false);
self.remainingTimeText = ko.pureComputed(function (){
if(self.completed()){
var timeSpent = self.allocatedTime() - self.remainingTime();
return moment.duration(timeSpent, "seconds").format(MOMENTJS_DURATION_TIME_WITH_SECONDS_FORMAT, {trim: false});
}
else{
if (self.remainingTime()>=1){
return moment.duration(self.remainingTime(), "seconds").format(MOMENTJS_DURATION_TIME_WITH_SECONDS_FORMAT, {trim: false}) + " remaining";
}
else if (self.remainingTime() < 1 && self.remainingTime() >= -1){
return "TIMES UP!";
}
else if (self.remainingTime() < -1){
return "OVERTIME: "+ moment.duration(self.remainingTime(), "seconds").format(MOMENTJS_DURATION_TIME_WITH_SECONDS_FORMAT, {trim: false});
}
}
});
self.togglePresent= function(){
self.present(!self.present());
};
self.remainingTimeProgress = ko.pureComputed(function (){
var val = Math.abs(Math.floor((self.remainingTime()/self.allocatedTime()*100)));
return (val > 100 ? 100: val);
});
}