-
Notifications
You must be signed in to change notification settings - Fork 1
/
scheduler.html
86 lines (75 loc) · 2.58 KB
/
scheduler.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<button id="loadFromFile">Load sessions from file</button>
<ul id="sessions"></ul>
<button id="generateJson">Generate JSON</button>
<div id="json"></div>
<script src="jquery-2.1.1.min.js"></script>
<script src="Session.js"></script>
<script src="ScheduledSession.js"></script>
<script type="text/javascript">
var scheduledSessions = {};
function retrieveSessions() {
var address = "accepted_sessions.json";
$.getJSON(address)
.done(function(accepted_sessions) {
$.each(accepted_sessions.sessions, function(i) {
var scheduled = new ScheduledSession({session:this});
sessionItem(scheduled).appendTo("#sessions");
scheduledSessions[this.id] = scheduled;
});
})
.fail(function() {
console.log("error retrieving accepted_sessions");
});
}
function updateSession(sessionId){
var li = $("#" + sessionId);
var session = scheduledSessions[sessionId];
session.room = li.find(".room").val();
session.day = li.find(".day").val();
session.hour = li.find(".hour").val();
session.minutes = li.find(".minutes").val();
}
function sessionItem (scheduled) {
var li = $("<li>").attr("id", scheduled.session.id);
$("<h4>").text(scheduled.session.title).appendTo(li);
$("<input>").addClass("room").attr("placeholder", "Room").val(scheduled.room).appendTo(li);
$("<input>").addClass("day").attr("placeholder", "Day").val(scheduled.day).appendTo(li);
$("<input>").addClass("hour").attr("placeholder", "Hour").val(scheduled.hour).appendTo(li);
$("<input>").addClass("minutes").val(scheduled.minutes).appendTo(li);
return li;
}
function loadFromLocalStorage () {
var storedSessions = localStorage.getItem("abSchedule");
if (storedSessions != null) {
var parsedSessions = JSON.parse(storedSessions);
for (var id in parsedSessions) {
var current = new ScheduledSession(parsedSessions[id]);
scheduledSessions[id] = current;
sessionItem(current).appendTo("#sessions");
}
}
}
//MAIN
loadFromLocalStorage();
$("#loadFromFile").click(retrieveSessions);
$("#sessions").on("blur", ".minutes", function () {
updateSession($(this).closest("li").attr("id"));
localStorage.setItem("abSchedule", JSON.stringify(scheduledSessions));
});
$("#generateJson").click(function () {
var sessionsArray = [];
for (var id in scheduledSessions) {
sessionsArray.push(scheduledSessions[id]);
}
$("#json").text(JSON.stringify(sessionsArray));
});
</script>
</body>
</html>