Commit 82b6ddb7 by chrisndodge

Merge pull request #126 from edx/hasnain-naveed/PHX-133-avoid-multiple-click

PHX-133/avoid multiple click
parents db8efa82 9fc8672b
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
{% endblocktrans %} {% endblocktrans %}
</p> </p>
<i class="fa fa-arrow-circle-right start-timed-exam" data-ajax-url="{{enter_exam_endpoint}}" data-exam-id="{{exam_id}}" data-attempt-proctored=true data-start-immediately=false></i> <i class="fa fa-arrow-circle-right"></i>
</button> </button>
<button class="gated-sequence start-timed-exam" data-ajax-url="{{enter_exam_endpoint}}" data-exam-id="{{exam_id}}" data-attempt-proctored=false data-start-immediately=true> <button class="gated-sequence start-timed-exam" data-ajax-url="{{enter_exam_endpoint}}" data-exam-id="{{exam_id}}" data-attempt-proctored=false data-start-immediately=true>
<span><i class="fa fa-unlock"></i></span> <span><i class="fa fa-unlock"></i></span>
...@@ -38,44 +38,75 @@ ...@@ -38,44 +38,75 @@
even if you achieve a passing grade. even if you achieve a passing grade.
{% endblocktrans %} {% endblocktrans %}
</p> </p>
<i class="fa fa-arrow-circle-right start-timed-exam" data-ajax-url="{{enter_exam_endpoint}}" data-exam-id="{{exam_id}}" data-attempt-proctored=false data-start-immediately=true></i> <i class="fa fa-arrow-circle-right"></i>
</button> </button>
</div> </div>
{% include 'proctoring/seq_proctored_exam_footer.html' %} {% include 'proctoring/seq_proctored_exam_footer.html' %}
<script type="text/javascript"> <script type="text/javascript">
$('.start-timed-exam').click(
function(event) {
var action_url = $(this).data('ajax-url');
var exam_id = $(this).data('exam-id');
var attempt_proctored = $(this).data('attempt-proctored');
var start_immediately = $(this).data('start-immediately');
if (!attempt_proctored) { var inProcess = false;
var msg = gettext(
"Are you sure you want to take this exam without proctoring? " + var disableClickEvent = function () {
"You will no longer be eligible to use this course for academic credit." inProcess = true;
); $('body').css('cursor', 'wait');
if (!confirm(msg)) { $('.start-timed-exam').css('cursor', 'wait');
return; };
var enableClickEvent = function () {
inProcess = false;
$('body').css('cursor', 'auto');
$('.start-timed-exam').css('cursor', 'auto');
};
$('.start-timed-exam').click(function () {
if (!inProcess) {
disableClickEvent();
var action_url = $(this).data('ajax-url');
var exam_id = $(this).data('exam-id');
var attempt_proctored = $(this).data('attempt-proctored');
var start_immediately = $(this).data('start-immediately');
if (!attempt_proctored) {
var msg = gettext(
"Are you sure you want to take this exam without proctoring? " +
"You will no longer be eligible to use this course for academic credit."
);
if (!confirm(msg)) {
enableClickEvent();
return;
}
} }
}
if (typeof action_url === "undefined" ) { if (typeof action_url === "undefined") {
enableClickEvent();
return false;
}
var self = $(this);
$.post(
action_url,
{
"exam_id": exam_id,
"attempt_proctored": attempt_proctored,
"start_clock": start_immediately
},
function (data) {
// reload the page, because we've unlocked it
location.reload();
}
).fail(function(){
enableClickEvent();
var msg = gettext(
"There has been a problem starting your exam.\n\n" +
"Possible reasons are that your account has not been fully activated,\n" +
"you have are experiencing a network connection problem, or there has been\n" +
"a service disruption. Please check these and try again."
);
alert(msg);
});
} else {
return false; return false;
} }
$.post(
action_url,
{
"exam_id": exam_id,
"attempt_proctored": attempt_proctored,
"start_clock": start_immediately
},
function(data) {
// reload the page, because we've unlocked it
location.reload();
}
);
} }
); );
</script> </script>
...@@ -28,27 +28,58 @@ ...@@ -28,27 +28,58 @@
{% include 'proctoring/seq_proctored_exam_footer.html' %} {% include 'proctoring/seq_proctored_exam_footer.html' %}
<script type="text/javascript"> <script type="text/javascript">
$('.start-timed-exam').click(
function(event) { var inProcess = false;
var action_url = $(this).data('ajax-url');
var exam_id = $(this).data('exam-id'); var disableClickEvent = function () {
var attempt_proctored = $(this).data('attempt-proctored'); inProcess = true;
var start_immediately = $(this).data('start-immediately'); $('body').css('cursor', 'wait');
if (typeof action_url === "undefined" ) { $('.start-timed-exam').css('cursor', 'wait');
};
var enableClickEvent = function () {
inProcess = false;
$('body').css('cursor', 'auto');
$('.start-timed-exam').css('cursor', 'auto');
};
$('.start-timed-exam').click(function () {
if (!inProcess) {
disableClickEvent();
var action_url = $(this).data('ajax-url');
var exam_id = $(this).data('exam-id');
var attempt_proctored = $(this).data('attempt-proctored');
var start_immediately = $(this).data('start-immediately');
if (typeof action_url === "undefined") {
enableClickEvent();
return false;
}
var self = $(this);
$.post(
action_url,
{
"exam_id": exam_id,
"attempt_proctored": attempt_proctored,
"start_clock": start_immediately
},
function (data) {
// reload the page, because we've unlocked it
location.reload();
}
).fail(function(){
enableClickEvent();
var msg = gettext(
"There has been a problem starting your exam.\n\n" +
"Possible reasons are that your account has not been fully activated,\n" +
"you have are experiencing a network connection problem, or there has been\n" +
"a service disruption. Please check these and try again."
);
alert(msg);
});
} else {
return false; return false;
} }
$.post(
action_url,
{
"exam_id": exam_id,
"attempt_proctored": attempt_proctored,
"start_clock": start_immediately
},
function(data) {
// reload the page, because we've unlocked it
location.reload();
}
);
} }
); );
</script> </script>
...@@ -24,22 +24,50 @@ ...@@ -24,22 +24,50 @@
{% include 'proctoring/seq_timed_exam_footer.html' %} {% include 'proctoring/seq_timed_exam_footer.html' %}
<script type="text/javascript"> <script type="text/javascript">
$('.start-timed-exam').click(
function(event) {
var action_url = $(this).data('ajax-url');
var exam_id = $(this).data('exam-id');
$.post( var inProcess = false;
action_url,
{ var disableClickEvent = function () {
"exam_id": exam_id, inProcess = true;
"start_clock": true $('body').css('cursor', 'wait');
}, $('.start-timed-exam').css('cursor', 'wait');
function(data) { };
// reload the page, because we've unlocked it
location.reload(); var enableClickEvent = function () {
} inProcess = false;
); $('body').css('cursor', 'auto');
$('.start-timed-exam').css('cursor', 'auto');
};
$('.start-timed-exam').click(function () {
if (!inProcess) {
disableClickEvent();
var action_url = $(this).data('ajax-url');
var exam_id = $(this).data('exam-id');
$.post(
action_url,
{
"exam_id": exam_id,
"start_clock": true
},
function (data) {
// reload the page, because we've unlocked it
location.reload();
}
).fail(function(){
enableClickEvent();
var msg = gettext(
"There has been a problem starting your exam.\n\n" +
"Possible reasons are that your account has not been fully activated,\n" +
"you have are experiencing a network connection problem, or there has been\n" +
"a service disruption. Please check these and try again."
);
alert(msg);
});
} else {
return false;
}
} }
); );
</script> </script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment