-
Notifications
You must be signed in to change notification settings - Fork 2
/
hello.js
113 lines (85 loc) · 2.52 KB
/
hello.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
// On the server,
// it is backed by a MongoDB collection named "cities".
Cities = new Mongo.Collection("cities");
if (Meteor.isClient) {
Router.route('/', function () {
this.render('hello');
});
// Load Google Maps
Meteor.startup(function() {
GoogleMaps.load();
});
Template.leaderboard.helpers({
cities: function () {
return Cities.find({}, {sort: {createdAt: -1}});
}
});
Template.leaderboard.events({
"click .delete": function () {
Cities.remove(this._id);
},
"submit .new-task": function (event) {
// This function is called when the new task form is submitted
var text = event.target.text.value;
if (text == "" || text == null) {
return;
}
var formattedCityJson;
var formattedCity;
//TODO Change error throwing mechanism for false requests.
Meteor.call('fetchFromService', text, function (err, respJson) {
if (err) {
window.alert("Error: " + err.reason);
console.log("error occured on receiving data on server. ", err);
} else {
console.log("respJson: ", respJson);
if(respJson.status == "OK") {
formattedCityJson = respJson;
formattedCity = formattedCityJson.results[0].formatted_address;
Cities.insert({
name: formattedCity,
createdAt: new Date() // current time
});
}
else{
window.alert("Invalid City name/code. ");
}
console.log("formatted City: ", formattedCity);
}
});
// Clear form
event.target.text.value = "";
// Prevent default form submit
return false;
},
"click .request": function (event) {
// This function is called when Find Optimal Route button is pressed.
console.log("Button Clicked");
Router.route('/route', function() {
this.render('ROUTE');
});
if(Cities.length < 1){
// TODO Set error message.
return;
}
// Debug
document.getElementById("request").innerHTML = "Button Pressed";
// Get all Cities names.
var citiesReq = Cities.find(
)
}
});
Template.city.helpers({
selected: function () {
return Session.equals("selectedPlayer", this._id) ? "selected" : '';
}
});
Template.city.events({
'click': function () {
Session.set("selectedPlayer", this._id);
}
});
}
// On server startup, create some cities if the database is empty.
if (Meteor.isServer) {
}