laundry/laundry_app/static/js/laundry.js
Tyler Hallada 0175764b17 Don't save svg, return rendering at api endpoint.
One less layer of needless indirection is nice, but I did this so that I could
use this app on heroku, which does not allow saving files to the file-system.
2014-07-28 22:32:38 -04:00

44 lines
1.6 KiB
JavaScript

var request = undefined;
var pending = false;
$(document).ready(function () {
if ($.cookie('hall') !== undefined) {
$('#hall-select').val($.cookie('hall'));
}
update_charts($('#hall-select option:selected').text());
$('#hall-select').change(function () {
$.cookie('hall', $('#hall-select option:selected').text(), {expires: 1825});
update_charts($('#hall-select option:selected').text());
});
});
$(document).ajaxStart(function () { pending = true; });
$(document).ajaxStop(function () { pending = false; });
function update_charts(selected) {
if (!pending) {
if (request !== undefined) {
request.abort();
}
$('.current-chart').empty();
var svg = $('<embed id="current-svg" type="image/svg+xml">');
$('.current-chart').append('<img id="loading" style="margin-top: 5%" src="http://www.google.com/images/loading.gif" />');
request = $.ajax({
url: '/ajax/current/' + halls[selected]
}).done(function (result) {
svg.attr('src', '/ajax/current/' + halls[selected]);
$('#loading').remove();
console.log(svg);
$('.current-chart').append(svg);
}).error(function (jqXHR, textStatus, errorThrown) {
$('#loading').remove();
$('.current-chart').append(
'<p class="error">Oops. My webscraping script broke. Either ' +
'eSuds is down or changed their website or Mason switched ' +
'the laundry rooms up. I\'ve been emailed and will try to ' +
'fix it soon. :)</p>');
});
}
}