-
Notifications
You must be signed in to change notification settings - Fork 0
/
controllers.js
69 lines (62 loc) · 2.3 KB
/
controllers.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function CCDCtrl($scope, ccdStorage ) {
$scope.currentGrade = ccdStorage.loadCurrentGrade();
$scope.currentDay = ccdStorage.loadCurrentDay();
$scope.config.daysPerGrade = ccdStorage.loadDaysPerGrade();
$scope.config.language = ccdStorage.loadLanguage();
$scope.selected = {};
$scope.evaluate = function () {
var complete = true;
$scope.grades[$scope.currentGrade].principles.forEach(function (entry) {
if ($scope.selected[entry.id] != true) {
complete = false;
}
});
$scope.grades[$scope.currentGrade].practices.forEach(function (entry) {
if ($scope.selected[entry.id] != true) {
complete = false;
}
});
if (complete) {
$scope.currentDay += 1;
if ($scope.currentDay > $scope.config.daysPerGrade) {
$scope.currentDay = 1;
gotoNextGrade();
window.scrollTo(0, 0);
toast('Get started for the next grade!');
} else {
window.scrollTo(0, 0);
toast('Good work and continue on the next day');
}
} else {
$scope.currentDay = 1;
window.scrollTo(0, 0);
toast('Don\'t get all, try again!');
}
$scope.selected = {};
ccdStorage.store($scope.currentGrade, $scope.currentDay);
};
var gotoNextGrade = function () {
$scope.currentGrade = $scope.grades[$scope.currentGrade].next;
};
$scope.saveConfig = function () {
ccdStorage.saveConfig($scope.config);
};
$scope.translate = function (msgKey) {
return $scope.translations[$scope.config.language][msgKey];
};
var toast = function(msg){
$("<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h3>"+msg+"</h3></div>")
.css({ display: "block",
opacity: 0.90,
position: "fixed",
padding: "7px",
"text-align": "center",
width: "270px",
left: ($(window).width() - 284)/2,
top: $(window).height()/2 })
.appendTo( $.mobile.pageContainer ).delay( 1500 )
.fadeOut( 400, function(){
$(this).remove();
});
};
}