-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
141 lines (131 loc) · 4.26 KB
/
script.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
// Firebase Initialization
var db = new Firebase('https://cs467group12map.firebaseio.com/');
var dataStore = db.child('data'); // For all data
var childRef;
var currIDs = [];
dataStore.on('value', function(snapshot) {
for (var id in snapshot.val()) {
currIDs.push(id);
}
});
// ID generation functions
// http://jsfiddle.net/greatbigmassive/PJwg8/
function generateID() {
var id = "";
var length = 15;
while (id.length < length && length > 0) {
var randomNumber = Math.random();
id += (randomNumber < 0.1 ? Math.floor(randomNumber * 100) : String.fromCharCode(Math.floor(randomNumber * 26) + (randomNumber > 0.5 ? 97 : 65)));
}
return id;
}
function saveIDToFirebase() {
var id = generateID();
while (currIDs.indexOf(id) >= 0) {
id = generateID();
}
var ref = dataStore.child(id);
$('.randID').text(id);
return ref;
}
// Reveal Different Rows
function revealRow(idOfRow) {
$('#' + idOfRow).css('display', 'block');
if (idOfRow.indexOf('id') >= 0) {
childRef = saveIDToFirebase();
$('#disclaimerRow').css('display', 'none');
} else if (idOfRow.indexOf('userInput') >= 0) {
$('#locHistory').css('display', 'none');
} else if (idOfRow.indexOf('locHistory') >= 0) {
$('#userInput').css('display', 'none');
} else if (idOfRow.indexOf('inputOptions') >= 0) {
$('#userInputFormSubmit').css('display', 'none');
} else if (idOfRow.indexOf('thanks') >= 0) {
$('#locHistory').css('display', 'none');
$('#userInput').css('display', 'none');
}
}
function confirmSubmissionGoogle() {
childRef.update({
type: 'google'
});
revealRow('thanks');
}
function confirmSubmissionUser() {
var events = $('#calendar').fullCalendar('clientEvents');
for (var i = 0; i < events.length; i++) {
var e = events[i];
childRef.child('locations').push({
start: e.start,
end: e.end,
type: e.type,
location: e.location
});
}
revealRow('thanks');
}
$(document).ready(function() {
// Calendar setup
$('#calendar').fullCalendar({
defaultView: 'agendaWeek',
defaultDate: Date.now(),
selectable: true,
selectHelper: true,
ignoreTimezone: true,
select: function(start, end) {
//http://jsfiddle.net/mccannf/azmjv/16/
$('#startTime').val(start);
$('#endTime').val(end);
console.log(start, end);
$('#eventModal').modal('show');
},
editable: true,
eventClick: function(event) {
console.log(event);
}
});
$.getJSON('json/majors.json', function(data) {
var items = [];
$.each(data, function(value) {
items.push('<option value="' + data[value] + '">' + data[value] + '</option>');
});
$('#majorDropdown').html(items.join(""));
});
$('#userInputFormSubmit').on('submit', function(event) {
event.preventDefault();
var major = $('#majorDropdown').val();
var year = $('#yearDropdown').val();
var requiresDoubleMajor = $('input[name=yesnoDoublemajor]:checked').val();
var apib = $('input[name=apib]:checked').val();
var addlMajors, addlMinors;
if ($('#addlMajors').val() !== undefined) {
addlMajors = $('#addlMajors').val().split('\n');
}
if ($('#addlMinors').val() !== undefined) {
addlMinors = $('#addlMinors').val().split('\n');
}
childRef.set({
major: major,
year: year,
requiresDoubleMajor: requiresDoubleMajor,
apib: apib,
addlMajors: addlMajors,
addlMinors: addlMinors,
type: 'user'
});
revealRow('inputOptions');
});
$('#userEventForm').on('submit', function(event) {
event.preventDefault();
$('#eventModal').modal('hide');
console.log($('#startTime').val());
console.log($('#endTime').val());
var eventData = {
location: $('#locationOfEvent').val(),
start: $('#startTime').val(),
end: $('#endTime').val(),
type: $('#activityTypeDropdown').val()
};
$('#calendar').fullCalendar('renderEvent', eventData, true);
});
});