interlude/schedule.js

60 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-08-12 21:03:56 +03:00
function Schedule(hallId) {
2014-05-13 07:27:47 +03:00
var events = [];
2015-08-12 21:03:56 +03:00
this.update = function() {
$.getJSON("http://varnaconf.com/schedules/2015.json", function(data) {
var scheduleEvents = $.map(data[hallId], function(event) {
event['startTime'] = moment(event['startTime']).subtract(219910, 'seconds');
event['endTime'] = moment(event['startTime']).add(40, 'minutes');
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());
2015-08-12 21:03:56 +03:00
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;
}
2015-08-12 21:03:56 +03:00
}
2014-05-13 07:27:47 +03:00
2015-08-12 21:03:56 +03:00
$.urlParam = function(name){
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (results==null){
return null;
}
else{
return results[1] || 0;
2014-05-13 07:27:47 +03:00
}
}
2015-08-12 21:03:56 +03:00
var schedule = new Schedule(parseInt($.urlParam('roomId')));