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) {
|
2015-08-12 21:17:46 +03:00
|
|
|
event['startTime'] = moment(event['startTime']);
|
2015-08-12 21:03:56 +03:00
|
|
|
return event;
|
|
|
|
});
|
2015-08-12 21:17:46 +03:00
|
|
|
|
|
|
|
$.each(scheduleEvents, function(index, event) {
|
|
|
|
var nextEvent = scheduleEvents[index + 1];
|
|
|
|
if (typeof(nextEvent) != 'undefined') {
|
|
|
|
event['endTime'] = moment(nextEvent['startTime']).subtract(10, 'minutes');
|
|
|
|
} else {
|
|
|
|
event['endTime'] = moment(event['startTime']).add(40, 'minutes');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-08-12 21:03:56 +03:00
|
|
|
events = scheduleEvents;
|
2015-08-12 21:17:46 +03:00
|
|
|
console.log(events);
|
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')));
|