-
Notifications
You must be signed in to change notification settings - Fork 0
/
x.js
128 lines (117 loc) · 2.74 KB
/
x.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
123
124
125
126
127
128
angular.module('scheduleApp', ['firebase'])
.controller('mainController', function($scope, $firebase) {
// get # of real time users
var listRef = new Firebase("https://burning-torch-4263.firebaseio.com/presence/");
var userRef = listRef.push();
// Add ourselves to presence list when online.
var presenceRef = new Firebase("https://burning-torch-4263.firebaseio.com/.info/connected");
presenceRef.on("value", function(snap) {
if (snap.val()) {
userRef.set(true);
// Remove ourselves when we disconnect.
userRef.onDisconnect().remove();
}
});
listRef.on("value", function(snap) {
$scope.online = snap.numChildren();
});
// connect to firebase
var ref = new Firebase("https://burning-torch-4263.firebaseio.com/days");
var fb = $firebase(ref);
// sync as object
var syncObject = fb.$asObject();
// three way data binding
syncObject.$bindTo($scope, 'days');
// function to set the default data
$scope.reset = function() {
fb.$set({
monday: {
name: 'Monday',
slots: {
900: {
time: '9:00am',
booked: false
},
0110: {
time: '11:00am',
booked: false
},
100: {
time: '1:00pm',
booked: false
},
300: {
time: '3:00pm',
booked: false
},
500: {
time: '5:00pm',
booked: false
},
700: {
time: '7:00pm',
booked: false
}
}
},
tuesday: {
name: 'Tuesday',
slots: {
900: {
time: '9:00am',
booked: false
},
0110: {
time: '11:00am',
booked: false
},
100: {
time: '1:00pm',
booked: false
},
300: {
time: '3:00pm',
booked: false
},
500: {
time: '5:00pm',
booked: false
},
700: {
time: '7:00pm',
booked: false
}
}
},
wednesday: {
name: 'Wednesday',
slots: {
900: {
time: '9:00am',
booked: false
},
0110: {
time: '11:00am',
booked: false
},
100: {
time: '1:00pm',
booked: false
},
300: {
time: '3:00pm',
booked: false
},
500: {
time: '5:00pm',
booked: false
},
700: {
time: '7:00pm',
booked: false
}
}
}
});
};
});