forked from offenesdresden/offenesdresden.de
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.js
171 lines (161 loc) · 4.82 KB
/
events.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
function pad(s, l, p) {
s = "" + s;
while(s.length < l)
s = p + s;
return s;
}
function addevent(){ /* todo:maybe preferable add a layer to current pages content than opening a window */
window.open("addevent.html", "Event hinzufügen", "status=0, width=300, height=570");
}
function isoDate(day, month, year, hour, minute){
if(day > 31 || month > 12 || hour > 23 || minute > 59){
return false;
}
month = leadingZero(month);
day = leadingZero(day);
hour = leadingZero(hour);
minute = leadingZero(minute);
var iso = year+"-"+month+"-"+day+"T"+hour+":"+minute+":00";
return iso;
}
function checkDate(){
var startdate = document.getElementById("startdate").value.split(".");
var enddate = document.getElementById("enddate").value.split(".");
var starttime = document.getElementById("starttime").value.split(":");
var endtime = document.getElementById("endtime").value.split(":");
var current = new Date();
start = Date.parse(isoDate(startdate[0], startdate[1], startdate[2], starttime[0], starttime[1]));
end = Date.parse(isoDate(enddate[0], enddate[1], enddate[2], endtime[0], endtime[1]));
if(start < current || end < start || isNaN(start) || isNaN(end)){
return false;
}else{
return true;
}
}
function checkFilled(){
var userinput = [];
userinput[0] = document.getElementById("title").value;
userinput[1] = document.getElementById("location").value;
userinput[2] = document.getElementById("link").value;
userinput[3] = document.getElementById("mail").value;
for(var i = 0; i < 4; i++){
if(userinput[i].length == 0){
return false;
}
}
return true;
}
function validate(){
var form = document.getElementById("eventform");
var check = checkFilled();
if(checkDate() && checkFilled()){
form.removeAttribute("onSubmit");
form.setAttribute("action", "http://jkliemann.de/offenesdresden.de/addevent.php");
}else{
alert("Falsche Eingabe!");
}
}
function leadingZero(date){
date = parseInt(date);
if(date < 10){
return "0" + date;
}else{
return date;
}
}
function setDate(){
var day = [];
var month = [];
var year = [];
var hour = [];
var date = new Date();
day[0] = date.getDate();
day[1] = day[0];
month[0] = date.getMonth() + 1;
month[1] = month[0];
year[0] = date.getFullYear();
year[1] = year[0];
hour[0] = date.getHours() + 1;
hour[1] = hour[0] + 2;
var minute = "00";
if(hour[1] > 23){
var i = 1;
if(hour[0] > 23){
i = 0;
}
for(i; i < 2; i++){
hour[i] = hour[i] % 24;
day[i] = day[i] + 1;
}
}
if(day[1] > 31){
var i = 1;
if(day[0] > 31){
i = 0;
}
for(i; i < 2; i++){
day[i] = day[i] % 31;
month[i] = month[i] + 1;
}
}
if(month[1] > 12){
var i = 1;
if(month[0] > 12){
i = 0;
}
for(i; i < 2; i++){
month[i] = month[i] % 12;
year[i] = year[i] + 1;
}
}
for(var i = 0; i < 2; i++){
day[i] = leadingZero(day[i]);
month[i] = leadingZero(month[i]);
hour[i] = leadingZero(hour[i]);
minute[i] = leadingZero(minute[i]);
}
document.getElementById("startdate").value=day[0]+"."+month[0]+"."+year[0];
document.getElementById("starttime").value=hour[0]+":"+minute;
document.getElementById("enddate").value=day[1]+"."+month[1]+"."+year[1];
document.getElementById("endtime").value=hour[1]+":"+minute;
}
function setLocation(){
document.getElementById("location").value="GHCQ (http://www.c3d2.de/space.html)";
}
function setDefault(){
setLocation();
setDate();
}
$.ajax({ url: "events.json" }).done(function(events) {
var now = Date.now();
var article = $('<article class="events"><h2>Nächste Treffen</h2><p> Jeden 1. und 3. Mittwoch im Monat bist auch Du herzlich eingeladen. Gern kannst Du auch schon vorher bescheid sagen, das Du kommst, via <a href="http://www.meetup.com/OK-Lab-Dresden">meetup</a>.</p></article>');
var ul = $("<ul></ul>");
events.forEach(function(event) {
event.time = new Date(event.date).getTime();
});
events = events.filter(function(event) {
return event.time >= now;
}).sort(function(e1, e2) {
return e1.time - e2.time;
});
events.forEach(function(event) {
var li = $('<li><p class="title"></p><p><span class="date"></span> <a>Ort</a></p></li>');
li.find('.title').text(event.title);
var d = new Date(event.date);
li.find('.date').text(
d.getDate() + "." +
(d.getMonth() + 1) + "." +
d.getFullYear() + " " +
pad(d.getHours(), 2, "0") + ":" +
pad(d.getMinutes(), 2, "0")
);
li.find('a').attr('href', event.location);
ul.append(li);
});
ul.append($('<li><a href onClick="addevent()">Termin einreichen</a>.</li>'));
article.append(ul);
article.append($('<p>Die Termine sind auch <a href="events.json">maschinenlesbar erhältlich</a>.</p>'));
$('#main').prepend(article);
}).fail(function() {
console.error("ajax", arguments);
});