ajax seems to work and we now seem to track completion of challenges

This commit is contained in:
Michael Q Larson
2014-11-06 22:47:35 -08:00
parent 86d433aaba
commit e36a98cf2a
3 changed files with 24 additions and 7 deletions

4
app.js
View File

@ -166,8 +166,8 @@ app.get('/api/linkedin', passportConf.isAuthenticated, passportConf.isAuthorized
app.get('/api/instagram', passportConf.isAuthenticated, passportConf.isAuthorized, apiController.getInstagram); app.get('/api/instagram', passportConf.isAuthenticated, passportConf.isAuthorized, apiController.getInstagram);
app.get('/api/yahoo', apiController.getYahoo); app.get('/api/yahoo', apiController.getYahoo);
app.post('/completed_challenge', function(req, res){ app.post('/completed_challenge', function(req, res){
req.user.challengesCompleted.push(req) req.user.challengesCompleted.push(parseInt(req.body.cn));
console.log("pushed #{req} to user"); req.user.save();
}); });
/** /**

View File

@ -1,29 +1,46 @@
$(document).ready(function() { $(document).ready(function() {
var CSRF_HEADER = 'X-CSRF-Token';
var setCSRFToken = function(securityToken) {
jQuery.ajaxPrefilter(function(options, _, xhr) {
if ( !xhr.crossDomain )
xhr.setRequestHeader(CSRF_HEADER, securityToken);
});
};
setCSRFToken($('meta[name="csrf-token"]').attr('content'));
$('.start-challenge').on("click", function() { $('.start-challenge').on("click", function() {
$(this).parent().remove(); $(this).parent().remove();
$('.challenge-content').removeClass('hidden-element').addClass('animated fadeInDown'); $('.challenge-content').removeClass('hidden-element').addClass('animated fadeInDown');
}); });
$('.completed-challenge').on("click", function() { $('.completed-challenge').on("click", function() {
$('#complete-dialog').modal('show'); $('#complete-dialog').modal('show');
}); });
$('.skip-challenge').on("click", function() { $('.skip-challenge').on("click", function() {
$('#skip-dialog').modal('show'); $('#skip-dialog').modal('show');
}); });
$('.complete-button').on("click", function() { $('.complete-button').on("click", function() {
l = location.pathname.split('/'); l = location.pathname.split('/');
cn = l[l.length - 1]
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
data: l, data: {cn: cn},
url: '/completed_challenge', url: '/completed_challenge/',
success: function(data) { success: function(data) {
console.log('success'); console.log('success');
console.log(JSON.stringify(data)); console.log(JSON.stringify(data));
} }
}); });
window.location = "/challenge?=" + (parseInt(l[l.length-1]) + 1) window.location = "/challenges/" + (parseInt(l[l.length-1]) + 1)
}); });
$('.skip-button').on("click", function() { $('.skip-button').on("click", function() {
l = location.pathname.split; l = location.pathname.split('/');
window.location = "/challenges/" + (parseInt(l[l.length-1]) + 1) window.location = "/challenges/" + (parseInt(l[l.length-1]) + 1)
}); });
}); });

View File

@ -36,7 +36,7 @@ block content
h1.animated.zoomInDown Nicely done! h1.animated.zoomInDown Nicely done!
.animated.zoomInUp.delay-1 .animated.zoomInUp.delay-1
span.landing-icon.ion-checkmark-circled.text-success span.landing-icon.ion-checkmark-circled.text-success
a.animated.fadeIn.delay-2.btn.btn-primary.btn-block.complete-button(aria-hidden='true') Take me to my next challenge a.animated.fadeIn.delay-2.btn.btn-primary.btn-block.complete-button(name='_csrf', value=_csrf, aria-hidden='true') Take me to my next challenge
#skip-dialog.modal #skip-dialog.modal
.modal-dialog.animated.zoomIn.fast-animation .modal-dialog.animated.zoomIn.fast-animation
.modal-content .modal-content