-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRefresh-Meteor.js
142 lines (130 loc) · 4.6 KB
/
Refresh-Meteor.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
Tasks = new Mongo.Collection("tasks");
Courses = new Mongo.Collection('courses');
if (Meteor.isServer) {}
if (Meteor.isClient) {
Session.setDefault('currentPage', false);
Array.prototype.last = function() {
return this[this.length - 1];
}
Template.register.events({
'submit form': function(event) {
event.preventDefault();
var emailVar = event.target.registerEmail.value;
var passwordVar = event.target.registerPassword.value;
Accounts.createUser({
email: emailVar,
password: passwordVar
}, function(error) {
$("#errors").html("There was an error registering you: <strong>" + error.reason + "</strong>");
console.log(error.reason);
});
}
});
Template.login.events({
'submit form': function(event, template) {
console.log("Logging in...");
event.preventDefault();
var emailVar = event.target.loginEmail.value;
var passwordVar = event.target.loginPassword.value;
Meteor.loginWithPassword(emailVar, passwordVar, function(error) {
if (Meteor.user()) {
console.log("Logged in");
Session.set('currentPage', "dashboard");
} else {
console.log("Not logged in");
$("#form-messages").html("There was an error logging in: <strong>" + error.reason + "</strong>");
}
});
},
'click #register': function(event, template) {
Session.set('currentPage', "register");
}
});
Template.nav.events({
'click #logout': function(event) {
console.log("Logging out...");
event.preventDefault();
Meteor.logout();
Session.set('currentPage', "login");
},
'click #learn': function(event) {
event.preventDefault();
Session.set('currentPage', "learn");
},
'click #dashboard': function(event) {
event.preventDefault();
Session.set('currentPage', "dashboard");
},
'click #home': function(event) {
event.preventDefault();
Session.set('currentPage', "dashboard");
}
});
Template.register.events({
'click #login': function(event) {
event.preventDefault();
Session.set('currentPage', "login");
}
});
Template.dashboard.events({
'click #choose': function(event) {
event.preventDefault();
Session.set('currentPage', "choose");
}
});
function selectBoard(event) {
var newVal = $(event.target).val();
Session.set("board", newVal);
console.log("Got change on board selection: " + newVal);
examBoardCIE(function(data) {
console.log(data)
});
}
Template.choose.events({
'change #selectBoard': function(event) {
selectBoard(event);
},
'click #selectBoard': function(event) {
selectBoard(event)
},
'change #selectSubject': function(event) {
var newVal = $(event.target).val();
Session.set("subject", newVal);
console.log("Got change on subject selection: " + newVal);
},
'change #selectSyllabus': function(event) {
var newVal = $(event.target).val();
Session.set("syllabus", newVal);
console.log("Got change on syllabus selection: " + newVal);
}
})
Template.container_template.helpers({
whichOne: function() {
console.log("Redirect to: " + Session.get('currentPage'));
if (Session.get('currentPage')) {
return Session.get('currentPage');
}
if (Meteor.user()) {
currentPage = Session.set('currentPage', false);
return "dashboard";
}
if (!Meteor.user()) {
currentPage = Session.set('currentPage', false);
return "login";
}
}
});
Template.dashboard.rendered = function() {
if (!this._rendered) {
this._rendered = true;
var courseData = Courses.find({
name: Meteor.userId()
}).fetch()
for (i = 0; i < courseData.length; i++) {
console.log(courseData[i].course);
var courseID = courseData[i].course.split("-")[0];
var year = courseData[i].course.split("-")[1];
}
}
}
}