diff --git a/resources/js/functions.js b/resources/js/functions.js
index 681dfe179..1178035fd 100644
--- a/resources/js/functions.js
+++ b/resources/js/functions.js
@@ -321,106 +321,181 @@ function updatePointer() {
// TRAININGS
$(document).ready(function() {
- // Stop early if the element does not exist, i.e.,
- // we're not on the front page nor on the Trainings page
- if ($('.training-items-list').length === 0) {
- return;
- }
+ var MONTH_NAMES = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
+ var MONTH_NAMES_SHORT = MONTH_NAMES.map(function (month) {
+ return month.substr(0, 3);
+ });
- var isFrontPage = $('.upcoming-training').length !== 0;
- var MAX_TRAININGS = isFrontPage ? 5 : 999;
+ function getTrainings() {
+ function loadTrainings(url) {
+ return $.getJSON(url)
+ .then(function (data) {
+ // filter out extra ajax info
+ return data;
+ }, function (jqXHR, textStatus, errorThrown) {
+ // log the error to the console
+ console.error("Couldn't load training feed " + url + " : " + textStatus, errorThrown);
+
+ // recover so we can keep processing
+ return [];
+ });
+ }
- {% comment %} Grab all the upcoming training sessions defined in _trainings {% endcomment %}
- var scalaLangTrainings = [
- {% for training in site.trainings %}{% if training.date >= site.time %}
- {
- "title": "{{ training.title | escape }}",
- "url": "{{ training.link-out | escape }}",
- "location": "{{ training.location | upcase | escape }}",
- "when": new Date("{{ training.when | escape }}"),
- "organizer": "{{ training.organizer | escape }}"
- },
- {% endif %}{% endfor%}
- ];
-
- function doPopulateTrainingsPane(lightBendTrainings) {
- var MONTH_NAMES = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
-
- // combine and sort our trainings by date
- var allTrainings = scalaLangTrainings.concat(lightBendTrainings)
- .sort(function (lhs, rhs) {
- var lhsDate = lhs.when.valueOf();
- var rhsDate = rhs.when.valueOf();
-
- if (lhsDate === rhsDate) {
- return 0;
+ // load our trainings
+ var ourTrainingsPromise = loadTrainings("/resources/json/trainings.json")
+ .then(function (trainings) {
+ return trainings.map(function (training) {
+ var parsedTraining = Object.assign({}, training);
+
+ // parse our date
+ parsedTraining.when = new Date(training.when);
+
+ return parsedTraining;
+ }).filter(function(training) {
+ // make sure our date occurs in the future
+ return training.when >= new Date();
+ })
+ }, function (error) {
+ console.error("Couldn't parse our training data", error);
+ // if our data is bad recover with an empty array
+ return [];
+ });
+
+ // load the trainings from lightbend
+ var lightbendTrainingsPromise = loadTrainings("/resources/php/typesafe-feed-trainings.php")
+ .then(function(data) {
+ var trainings = (data && data.length > 0) ? data[0] : [];
+
+ // flatten and filter our sessions by date
+ var flattenedTrainings = [];
+ for (var i = 0; i < trainings.length; i++) {
+ var training = trainings[i];
+ for (var j = 0; j < training.sessions.length; j++) {
+ var session = training.sessions[j];
+
+ // make sure this session occurs in the future
+ var when = new Date(session.when);
+ if (when >= new Date()) {
+ flattenedTrainings.push({
+ title: training.title,
+ url: session.url,
+ location: session.where.toUpperCase(),
+ when: when,
+ organizer: session.organizer
+ });
+ }
+ }
}
- return (lhsDate > rhsDate) ? 1 : -1;
+ return flattenedTrainings;
+ }, function (error) {
+ console.error("Couldn't parse Lightbend training data", error);
+ // if our data is bad recover with an empty array
+ return [];
});
- var listContainer = $('.training-items-list');
- listContainer.empty();
- for (var i = 0; i < Math.min(allTrainings.length, MAX_TRAININGS); i++) {
- var training = allTrainings[i];
- // add fallbacks if we can't parse our dates
- var month = '?';
- var day = '?';
- if (!isNaN(training.when.valueOf())) {
- month = MONTH_NAMES[training.when.getMonth()];
- day = training.when.getDate();
- }
-
- // build up our training item
- var content = '' +
- '' +
- '' + month + '' +
- '' + day + '' +
- '' +
- '' + training.title + '
' +
- '' +
- '
' +
- '' + training.title + '
' +
+ '' +
+ '
' +
+ '
' + training.location + '
' + + '' + training.organizer + '
' + + '