-
Notifications
You must be signed in to change notification settings - Fork 0
/
election.html
137 lines (121 loc) · 4.83 KB
/
election.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
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Storm</title>
<link rel="stylesheet" href="stylesheets/styles.css">
<link rel="stylesheet" href="stylesheets/github-dark.css">
<link rel="stylesheet" href="stylesheets/custom.css">
<script src='https://cdn.firebase.com/js/client/2.2.1/firebase.js'></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="javascripts/main.js"></script>
<script src="javascripts/util.js"></script>
<script src="javascripts/clock.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
</head>
<body>
<div class="container">
<div id="topbar">
<span id="goal"></span>
</div>
<div id="sidebar">
<div id="clock">--:--</div>
<div id="definition" class="stage">1) Definition</div>
<div id="ideation" class="stage">2) Ideation</div>
<div id="discussion" class="stage">3) Discussion</div>
<div id="election" class="stage active">4) Election</div>
<div id="decision" class="stage">5) Decision</div>
<div class="criteria-list">
Criteria
<ol>
<li id="criteria1">one</li>
<li id="criteria2">two</li>
<li id="criteria3">three</li>
</ol>
</div>
</div>
<div id="main" class="scrollable">
<div id="title" class="section-title">Election</div>
<div id="description">
Vote for your top three ideas (1 = favorite). You may only select 3.<br>
Your vote will be automatically submitted when the timer hits zero.
</div>
<form id="ballot" action="">
</form>
<script>
var key = getFirebaseKey();
var ref = new Firebase(getSessionUrl(key));
ref.once("value", function(snapshot) {
var session = snapshot.val();
initElectionClock(session.date, session.time, session.duration);
$("#goal").html(session.goal);
$("#criteria1").html(session.criteria1);
$("#criteria2").html(session.criteria2);
$("#criteria3").html(session.criteria3);
var ideas = session.ideas;
for (i = ideas.length-1; i > -1; i--) {
if (ideas[i]) {
$("#ballot").append(generateBallotEntry(i, ideas[i].title, ideas[i].description));
}
}
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
function submitVotes() {
var voteOneIdx = $('input[name=one]:checked', '#ballot').val();
var voteTwoIdx = $('input[name=two]:checked', '#ballot').val();
var voteThreeIdx = $('input[name=three]:checked', '#ballot').val();
var key = getFirebaseKey();
var ideasRef = new Firebase(getIdeasUrl(key));
ideasRef.transaction(function(currentData) {
if (currentData === null) {
return currentData;
}
else {
if (voteOneIdx) {
if (currentData[voteOneIdx].votes)
currentData[voteOneIdx].votes += 3;
else
currentData[voteOneIdx].votes = 3;
}
if (voteTwoIdx) {
if (currentData[voteTwoIdx].votes)
currentData[voteTwoIdx].votes += 2;
else
currentData[voteTwoIdx].votes = 2;
}
if (voteThreeIdx) {
if (currentData[voteThreeIdx].votes)
currentData[voteThreeIdx].votes += 1;
else
currentData[voteThreeIdx].votes = 1;
}
return currentData;
}
}, onSubmitToFirebaseComplete);
}
function onSubmitToFirebaseComplete(error, committed, snapshot) {
if (error || !committed) {
alert("Sorry, an error occurred");
}
else {
// redirect to the discussion page
if (isDeployed()) {
window.location.replace("http://www.willhennessy.com/storm/decision?session="+getFirebaseKey());
} else {
window.location.replace("/Users/willhennessy/Documents/CS%20598%20-%20Social/storm/decision.html?session="+getFirebaseKey());
}
}
}
</script>
</div>
</div>
<div class="wrapper">
</div>
<!--[if !IE]><script>fixScale(document);</script><![endif]-->
</body>
</html>