Fix issue with duplicate submits

This commit is contained in:
SaintPeter
2016-02-12 19:20:35 -08:00
parent d3ca16d4ec
commit a97b3fce8a

View File

@ -6,6 +6,68 @@ window.common = (function(global) {
common = { init: [] } common = { init: [] }
} = global; } = global;
function submitChallengeHandler(e) {
e.preventDefault();
var solution = common.editor.getValue();
$('#submit-challenge')
.attr('disabled', 'true')
.removeClass('btn-primary')
.addClass('btn-warning disabled');
var $checkmarkContainer = $('#checkmark-container');
$checkmarkContainer.css({ height: $checkmarkContainer.innerHeight() });
$('#challenge-checkmark')
.addClass('zoomOutUp')
// .removeClass('zoomInDown')
.delay(1000)
.queue(function(next) {
$(this).replaceWith(
'<div id="challenge-spinner" ' +
'class="animated zoomInUp inner-circles-loader">' +
'submitting...</div>'
);
next();
});
let timezone = 'UTC';
try {
timezone = moment.tz.guess();
} catch (err) {
err.message = `
known bug, see: https://github.com/moment/moment-timezone/issues/294:
${err.message}
`;
console.error(err);
}
const data = JSON.stringify({
id: common.challengeId,
name: common.challengeName,
challengeType: +common.challengeType,
solution,
timezone
});
$.ajax({
url: '/completed-challenge/',
type: 'POST',
data,
contentType: 'application/json',
dataType: 'json'
})
.success(function(res) {
if (res) {
window.location =
'/challenges/next-challenge?id=' + common.challengeId;
}
})
.fail(function() {
window.location.replace(window.location.href);
});
}
common.showCompletion = function showCompletion() { common.showCompletion = function showCompletion() {
ga( ga(
@ -17,72 +79,11 @@ window.common = (function(global) {
true true
); );
var solution = common.editor.getValue();
var didCompleteWith = $('#completed-with').val() || null;
$('#complete-courseware-dialog').modal('show'); $('#complete-courseware-dialog').modal('show');
$('#complete-courseware-dialog .modal-header').click(); $('#complete-courseware-dialog .modal-header').click();
$('#submit-challenge').click(function(e) { $('#submit-challenge').off('click');
e.preventDefault(); $('#submit-challenge').on('click', submitChallengeHandler);
$('#submit-challenge')
.attr('disabled', 'true')
.removeClass('btn-primary')
.addClass('btn-warning disabled');
var $checkmarkContainer = $('#checkmark-container');
$checkmarkContainer.css({ height: $checkmarkContainer.innerHeight() });
$('#challenge-checkmark')
.addClass('zoomOutUp')
// .removeClass('zoomInDown')
.delay(1000)
.queue(function(next) {
$(this).replaceWith(
'<div id="challenge-spinner" ' +
'class="animated zoomInUp inner-circles-loader">' +
'submitting...</div>'
);
next();
});
let timezone = 'UTC';
try {
timezone = moment.tz.guess();
} catch (err) {
err.message = `
known bug, see: https://github.com/moment/moment-timezone/issues/294:
${err.message}
`;
console.error(err);
}
const data = JSON.stringify({
id: common.challengeId,
name: common.challengeName,
completedWith: didCompleteWith,
challengeType: +common.challengeType,
solution,
timezone
});
$.ajax({
url: '/completed-challenge/',
type: 'POST',
data,
contentType: 'application/json',
dataType: 'json'
})
.success(function(res) {
if (res) {
window.location =
'/challenges/next-challenge?id=' + common.challengeId;
}
})
.fail(function() {
window.location.replace(window.location.href);
});
});
}; };
return common; return common;