interlude/schedule.js

60 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2014-11-01 04:00:16 +02:00
function Schedule(hallId) {
2014-05-13 07:27:47 +03:00
var events = [];
2014-11-01 04:00:16 +02:00
this.update = function() {
$.getJSON("https://cfp.openfest.org/schedule.json", function(data) {
var scheduleEvents = $.map(data[hallId], function(event) {
2014-11-01 04:55:30 +02:00
event['startTime'] = moment(event['startTime']).subtract(2, 'hours');
event['endTime'] = moment(event['endTime']).subtract(2, 'hours');
2014-11-01 04:00:16 +02:00
return event;
});
events = scheduleEvents;
});
}
2014-05-13 07:27:47 +03:00
this.upcomingEvents = function() {
return _.select(events, function(event) {
return event.startTime.isAfter(moment());
});
}
this.nextEvent = function() {
return _.first(this.upcomingEvents());
}
2014-06-21 05:08:15 +03:00
this.currentEvent = function() {
2014-06-21 10:55:38 +03:00
var latestEvent = _.last(this.pastEvents());
if (typeof(latestEvent) != 'undefined' && latestEvent.endTime.isAfter(moment())) {
2014-06-21 10:55:38 +03:00
return latestEvent;
} else {
return undefined;
}
2014-06-21 05:08:15 +03:00
}
2014-05-13 15:43:58 +03:00
this.futureEvents = function() {
return this.upcomingEvents().splice(1);
}
this.pastEvents = function() {
return _.select(events, function(event) {
return event.startTime.isBefore(moment());
});
}
this.allEvents = function() {
2014-05-13 07:27:47 +03:00
return events;
}
}
2014-11-01 04:00:16 +02:00
$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results==null){
return null;
}
else{
return results[1] || 0;
}
}
2014-08-24 08:58:07 +03:00
2014-11-01 04:00:16 +02:00
var schedule = new Schedule(parseInt($.urlParam('roomId')));