ajax seems to work and we now seem to track completion of challenges
This commit is contained in:
4
app.js
4
app.js
@ -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();
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -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)
|
||||
});
|
||||
});
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user