jam-cloud/web/app/assets/javascripts/landing/congratulations.js

71 lines
2.3 KiB
JavaScript

(function(context,$) {
"use strict";
var congratulations = {};
function listClients() {
var rest = context.JK.Rest();
var currentOS = context.JK.detectOS();
var downloads = $('.downloads');
rest.getClientDownloads()
.done(function(data) {
downloads.removeClass('spinner-large');
var count = 0;
for ( var property in data ) count++;
if(count == 0) {
alert("Currently unable to list client software downloads.");
}
else {
$.each(data, function(key, item) {
// if the currentOS we detect from browser is found within the product of an available client
// we flag it with this boolean
var matchesUserOS = currentOS != null && key.toLowerCase().indexOf(currentOS.toLowerCase()) > -1;
var options = {
emphasis: matchesUserOS ? "currentOS" : "",
uri: item.uri,
platform: key.substring('JamClient/'.length)
}
var download = context._.template($('#client-download-link').html(), options, {variable: 'data'});
if(matchesUserOS) {
// make sure the current user OS is at the top
downloads.prepend(download);
}
else {
downloads.append(download)
}
});
}
})
.fail(function() {
downloads.removeClass('spinner-large');
alert("Currently unable to list client software downloads due to error.");
})
}
congratulations.initialize = function initialize(musician, registrationType) {
if(musician) {
listClients();
}
if(registrationType) {
$(function() {
// ga() object isn't ready until the page is loaded
context.JK.GA.trackRegister(musician, registrationType);
});
}
}
context.congratulations = congratulations;
})(window, jQuery)