screenspook/server/public/javascripts/client.js~
2012-07-04 16:19:52 +02:00

46 lines
1.5 KiB
JavaScript

$(document).ready(function() {
var pendingShotsTemplateSrc = $("#pending-shots-template").html();
var pendingShotsTemplate = Handlebars.compile(pendingShotsTemplateSrc);
var acceptedShotsTemplateSrc = $("#accepted-shots-template").html();
var acceptedShotsTemplate = Handlebars.compile(acceptedShotsTemplateSrc);
var setupAcceptShot = function() {
$('.acceptShot').bind('click', function(event) {
var shotId = event.currentTarget.dataset.shotid;
console.log('accept' , shotId);
var el = event.currentTarget;
$.ajax({
url: '/accept/' + shotId,
success: function(data, textStatus, jqXHR) {
if (data.ok) {
// hide the complete shot.
console.log('accepted');
$(el).parent().parent().fadeOut(500, reload);
}
},
dataType: 'json'
});
});
};
var reload = function() {
$.ajax({
url : '/overview',
success: function(data) {
$('#pendingShots').html(pendingShotsTemplate({items:data.pendingShots}));
$('#acceptedShots').html(acceptedShotsTemplate({items:data.acceptedShots}));
setupAcceptShot();
$('.shot').fancybox();
}
});
};
$('.reloadButton').bind('click', reload);
reload();
});