2014-10-17 19:23:53 -07:00
|
|
|
$(document).ready(function() {
|
2014-11-06 22:47:35 -08:00
|
|
|
|
2015-01-24 00:44:08 -05:00
|
|
|
var CSRF_HEADER = 'X-CSRF-Token';
|
2014-11-06 22:47:35 -08:00
|
|
|
|
2015-01-24 00:44:08 -05:00
|
|
|
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-challenge-dialog').modal('show');
|
|
|
|
// Only post to server if there is an authenticated user
|
|
|
|
if ($('.signup-btn-nav').length < 1) {
|
|
|
|
l = location.pathname.split('/');
|
|
|
|
cn = l[l.length - 1];
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
data: {challengeNumber: cn},
|
|
|
|
url: '/completed-challenge/'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-27 02:51:59 -05:00
|
|
|
|
|
|
|
|
2015-01-24 03:11:01 -05:00
|
|
|
function completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash) {
|
2015-01-24 00:44:08 -05:00
|
|
|
$('#complete-bonfire-dialog').modal('show');
|
|
|
|
// Only post to server if there is an authenticated user
|
|
|
|
if ($('.signup-btn-nav').length < 1) {
|
2015-01-28 17:17:45 -05:00
|
|
|
|
|
|
|
$.post(
|
|
|
|
'/completed-bonfire',
|
|
|
|
{
|
2015-01-24 03:11:01 -05:00
|
|
|
bonfireInfo: {
|
|
|
|
completedWith : didCompleteWith,
|
|
|
|
solution: bonfireSolution,
|
|
|
|
bonfireHash: thisBonfireHash
|
|
|
|
}
|
|
|
|
},
|
2015-01-28 17:17:45 -05:00
|
|
|
function(res) {
|
|
|
|
if (res) {
|
2015-01-28 14:48:18 -08:00
|
|
|
window.location.href = '/bonfires'
|
2015-01-28 17:17:45 -05:00
|
|
|
}
|
|
|
|
})
|
2015-01-24 00:44:08 -05:00
|
|
|
}
|
2015-01-24 03:11:01 -05:00
|
|
|
}
|
2015-01-24 00:44:08 -05:00
|
|
|
|
2015-01-28 17:17:45 -05:00
|
|
|
$('.next-bonfire-button').on('click', function() {
|
|
|
|
var bonfireSolution = myCodeMirror.getValue();
|
|
|
|
var thisBonfireHash = passedBonfireHash || null;
|
|
|
|
var didCompleteWith = $('#completed-with').val() || null;
|
|
|
|
|
|
|
|
completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-01-24 00:44:08 -05:00
|
|
|
$('.all-challenges').on('click', function() {
|
|
|
|
$('#all-challenges-dialog').modal('show');
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.all-bonfires').on('click', function() {
|
|
|
|
$('#all-bonfires-dialog').modal('show');
|
|
|
|
});
|
|
|
|
|
2015-01-24 03:11:01 -05:00
|
|
|
$('.next-challenge-button').on('click', function() {
|
2015-01-24 00:44:08 -05:00
|
|
|
l = location.pathname.split('/');
|
|
|
|
window.location = '/challenges/' + (parseInt(l[l.length - 1]) + 1);
|
2014-11-06 17:38:47 -08:00
|
|
|
});
|
2015-01-24 03:11:01 -05:00
|
|
|
|
2015-01-28 02:22:12 -05:00
|
|
|
|
2015-01-24 20:49:59 -05:00
|
|
|
|
|
|
|
// Bonfire instructions functions
|
|
|
|
$('#more-info').on('click', function() {
|
|
|
|
$('#brief-instructions').hide();
|
|
|
|
$('#long-instructions').show().removeClass('hide');
|
|
|
|
|
|
|
|
});
|
|
|
|
$('#less-info').on('click', function() {
|
|
|
|
$('#brief-instructions').show();
|
|
|
|
$('#long-instructions').hide();
|
|
|
|
});
|
2014-11-06 17:38:47 -08:00
|
|
|
});
|
|
|
|
|
2015-01-06 02:27:08 -05:00
|
|
|
var profileValidation = angular.module('profileValidation',['ui.bootstrap']);
|
2015-01-05 20:09:23 -08:00
|
|
|
profileValidation.controller('profileValidationController', ['$scope', '$http',
|
|
|
|
function($scope, $http) {
|
2015-01-06 00:52:30 -05:00
|
|
|
$http.get('/account/api').success(function(data) {
|
2015-01-05 20:09:23 -08:00
|
|
|
$scope.user = data.user;
|
2015-01-12 11:48:36 -08:00
|
|
|
$scope.user.profile.username = $scope.user.profile.username ? $scope.user.profile.username.toLowerCase() : undefined;
|
2015-01-09 20:03:24 -08:00
|
|
|
$scope.storedUsername = data.user.profile.username;
|
|
|
|
$scope.storedEmail = data.user.email;
|
2015-01-12 11:48:36 -08:00
|
|
|
$scope.user.email = $scope.user.email ? $scope.user.email.toLowerCase() : undefined;
|
|
|
|
$scope.user.profile.twitterHandle = $scope.user.profile.twitterHandle ? $scope.user.profile.twitterHandle.toLowerCase() : undefined;
|
2015-01-11 22:19:56 -08:00
|
|
|
$scope.asyncComplete = true;
|
2015-01-05 20:09:23 -08:00
|
|
|
});
|
2015-01-05 19:01:58 -08:00
|
|
|
}
|
|
|
|
]);
|
2015-01-06 10:28:57 -05:00
|
|
|
|
2015-01-24 04:14:41 -05:00
|
|
|
profileValidation.controller('pairedWithController', ['$scope',
|
|
|
|
function($scope) {
|
2015-01-24 12:51:53 -05:00
|
|
|
$scope.existingUser = null;
|
2015-01-24 04:14:41 -05:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-01-09 17:52:19 -08:00
|
|
|
profileValidation.controller('emailSignUpController', ['$scope',
|
|
|
|
function($scope) {
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-01-09 18:09:49 -08:00
|
|
|
profileValidation.controller('emailSignInController', ['$scope',
|
|
|
|
function($scope) {
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-01-13 12:50:00 -08:00
|
|
|
profileValidation.controller('nonprofitFormController', ['$scope',
|
|
|
|
function($scope) {
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-01-14 13:28:20 -08:00
|
|
|
profileValidation.controller('doneWithFirst100HoursFormController', ['$scope',
|
|
|
|
function($scope) {
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2015-01-09 17:52:19 -08:00
|
|
|
profileValidation.directive('uniqueUsername', function($http) {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
require: 'ngModel',
|
|
|
|
link: function (scope, element, attrs, ngModel) {
|
|
|
|
element.bind("keyup", function (event) {
|
|
|
|
ngModel.$setValidity('unique', true);
|
|
|
|
if (element.val()) {
|
|
|
|
$http.get("/api/checkUniqueUsername/" + element.val()).success(function (data) {
|
2015-01-09 20:03:24 -08:00
|
|
|
if (element.val() == scope.storedUsername) {
|
|
|
|
ngModel.$setValidity('unique', true);
|
|
|
|
} else if (data) {
|
2015-01-09 17:52:19 -08:00
|
|
|
ngModel.$setValidity('unique', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-01-09 20:03:24 -08:00
|
|
|
}
|
2015-01-09 17:52:19 -08:00
|
|
|
});
|
2015-01-24 04:14:41 -05:00
|
|
|
// TODO: FIX THIS
|
|
|
|
profileValidation.directive('existingUsername', function($http) {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
require: 'ngModel',
|
|
|
|
link: function (scope, element, attrs, ngModel) {
|
|
|
|
element.bind("keyup", function (event) {
|
2015-01-24 19:16:28 -05:00
|
|
|
if (element.val().length > 0) {
|
|
|
|
ngModel.$setValidity('exists', false);
|
|
|
|
} else {
|
|
|
|
ngModel.$setPristine();
|
|
|
|
}
|
2015-01-24 04:14:41 -05:00
|
|
|
if (element.val()) {
|
2015-01-24 12:51:53 -05:00
|
|
|
$http.get("/api/checkExistingUsername/" + element.val() + ' ').success(function (data) {
|
2015-01-24 04:14:41 -05:00
|
|
|
if (element.val() == scope.existingUsername) {
|
|
|
|
ngModel.$setValidity('exists', false);
|
2015-01-24 12:51:53 -05:00
|
|
|
} else if (data) {
|
|
|
|
ngModel.$setValidity('exists', true);
|
2015-01-24 04:14:41 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-01-09 17:52:19 -08:00
|
|
|
|
2015-01-09 18:09:49 -08:00
|
|
|
profileValidation.directive('uniqueEmail', function($http) {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
require: 'ngModel',
|
|
|
|
link: function (scope, element, attrs, ngModel) {
|
|
|
|
element.bind("keyup", function (event) {
|
|
|
|
ngModel.$setValidity('unique', true);
|
|
|
|
if (element.val()) {
|
|
|
|
$http.get("/api/checkUniqueEmail/" + encodeURIComponent(element.val())).success(function (data) {
|
2015-01-09 20:03:24 -08:00
|
|
|
if (element.val() == scope.storedEmail) {
|
|
|
|
ngModel.$setValidity('unique', true);
|
|
|
|
} else if (data) {
|
2015-01-09 18:09:49 -08:00
|
|
|
ngModel.$setValidity('unique', false);
|
|
|
|
}
|
|
|
|
});
|
2015-01-09 20:03:24 -08:00
|
|
|
};
|
2015-01-09 18:09:49 -08:00
|
|
|
});
|
|
|
|
}
|
2015-01-09 20:03:24 -08:00
|
|
|
}
|
2015-01-09 18:09:49 -08:00
|
|
|
});
|