forked from ashteya/ionic-tutorial-lokijs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
overview.controller.js
122 lines (101 loc) · 3.34 KB
/
overview.controller.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
var v, bs;
(function() {
angular.module('starter')
.controller('OverviewController', ['$scope', '$ionicModal', '$ionicPlatform',
'BirthdayService','$timeout', OverviewController]);
function OverviewController($scope, $ionicModal, $ionicPlatform, birthdayService,$timeout) {
var vm = this;
v = vm;
bs = birthdayService;
vm.online = true;
vm.fb = birthdayService.getBdArray();
vm.isSync = isSync;
vm.emulateFb = emulateFb;
vm.emu = [];
// $ionicPlatform.ready(function() {
// // Initialize the database.
// birthdayService.initDB();
// // Get all birthday records from the database.
// birthdayService.getAllBirthdays()
// .then(function(birthdays) {
// vm.birthdays = birthdays;
// });
// });
vm.fb.$loaded()
.then(function(res) {
console.info('loaded from controlller');
$timeout(function(){
console.info('timeout');
vm.emu = res;
}, 2000);
})
function isSync(key) {
if (birthdayService.getTempById(key)) {
return true;
} else {
return false;
}
}
function emulateFb(lokiObj) {
if (lokiObj.fbVal) {
console.log('lokiObj', lokiObj);
lokiObj.fbVal.$id = lokiObj.fbKey;
}
}
function activate() {
birthdayService.getBirthdays()
.then(function(birthdays) {
console.log('birthday received');
vm.birthdays = birthdays;
vm.emu=birthdays;
});
birthdayService.getTemp()
.then(function(temp) {
vm.temp = temp;
});
}
activate();
// Initialize the modal view.
$ionicModal.fromTemplateUrl('add-or-edit-birthday.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
vm.showAddBirthdayModal = function() {
$scope.birthday = {};
$scope.action = 'Add';
$scope.isAdd = true;
$scope.modal.show();
};
vm.showEditBirthdayModal = function(birthday) {
$scope.birthday = birthday;
$scope.action = 'Edit';
$scope.isAdd = false;
$scope.modal.show();
};
vm.setOnline = function(online) {
if (online) {
Firebase.goOnline();
} else {
Firebase.goOffline();
}
};
$scope.saveBirthday = function() {
if ($scope.isAdd) {
birthdayService.addBirthday($scope.birthday);
} else {
birthdayService.updateBirthday($scope.birthday);
}
$scope.modal.hide();
};
$scope.deleteBirthday = function() {
birthdayService.deleteBirthday($scope.birthday);
$scope.modal.hide();
};
$scope.$on('$destroy', function() {
$scope.modal.remove();
});
return vm;
}
})();