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/yahoo', apiController.getYahoo);
app.post('/completed_challenge', function(req, res){
req.user.challengesCompleted.push(req)
console.log("pushed #{req} to user");
req.user.challengesCompleted.push(parseInt(req.body.cn));
req.user.save();
});
/**

View File

@ -1,29 +1,46 @@
$(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() {
$(this).parent().remove();
$('.challenge-content').removeClass('hidden-element').addClass('animated fadeInDown');
});
$('.completed-challenge').on("click", function() {
$('#complete-dialog').modal('show');
});
$('.skip-challenge').on("click", function() {
$('#skip-dialog').modal('show');
});
$('.complete-button').on("click", function() {
l = location.pathname.split('/');
cn = l[l.length - 1]
$.ajax({
type: 'POST',
data: l,
url: '/completed_challenge',
data: {cn: cn},
url: '/completed_challenge/',
success: function(data) {
console.log('success');
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() {
l = location.pathname.split;
l = location.pathname.split('/');
window.location = "/challenges/" + (parseInt(l[l.length-1]) + 1)
});
});

View File

@ -36,7 +36,7 @@ block content
h1.animated.zoomInDown Nicely done!
.animated.zoomInUp.delay-1
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
.modal-dialog.animated.zoomIn.fast-animation
.modal-content