interlude/schedule.js

75 lines
2.0 KiB
JavaScript
Raw 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) {
event['startTime'] = moment(event['startTime']);
event['endTime'] = moment(event['endTime']);
return event;
});
events = scheduleEvents;
});
}
2014-05-13 07:27:47 +03:00
this.addEvent = function(event) {
events.push(event);
events = _.sortBy(events, function(event) {
return event.startTime.unix()
});
}
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());
2014-06-21 05:08:15 +03:00
var nextEvent = this.nextEvent();
2014-08-20 14:36:12 +03:00
if (typeof nextEvent != 'undefined' && moment(nextEvent.startTime).subtract('minutes', 10).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;
}
this.addDelay = function(time) {
_.each(this.upcomingEvents(), function(event, index, agenda) {
event.startTime.add(time);
});
}
}
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')));
schedule.update();