Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-ora2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-ora2
Commits
072ae5cb
Commit
072ae5cb
authored
Mar 31, 2014
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent duplicate submissions on client side by disabling submit button
parent
d59288cb
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
9 deletions
+69
-9
apps/openassessment/xblock/static/js/openassessment.min.js
+0
-0
apps/openassessment/xblock/static/js/spec/oa_response.js
+45
-0
apps/openassessment/xblock/static/js/src/oa_response.js
+24
-9
No files found.
apps/openassessment/xblock/static/js/openassessment.min.js
View file @
072ae5cb
This diff is collapsed.
Click to expand it.
apps/openassessment/xblock/static/js/spec/oa_response.js
View file @
072ae5cb
...
...
@@ -124,4 +124,49 @@ describe("OpenAssessment.ResponseView", function() {
view
.
submit
();
expect
(
server
.
submit
).
toHaveBeenCalledWith
(
'Test response'
);
});
it
(
"disables the submit button on submission"
,
function
()
{
// Prevent the server's response from resolving,
// so we can see what happens before view gets re-rendered.
spyOn
(
server
,
'submit'
).
andCallFake
(
function
()
{
return
$
.
Deferred
(
function
(
defer
)
{}).
promise
();
});
view
.
response
(
'Test response'
);
view
.
submit
();
expect
(
view
.
submitEnabled
()).
toBe
(
false
);
});
it
(
"re-enables the submit button on submission error"
,
function
()
{
// Simulate a server error
spyOn
(
server
,
'submit'
).
andCallFake
(
function
()
{
return
$
.
Deferred
(
function
(
defer
)
{
defer
.
rejectWith
(
this
,
[
'ENOUNKNOWN'
,
'Error occurred!'
]);
}).
promise
();
});
view
.
response
(
'Test response'
);
view
.
submit
();
// Expect the submit button to have been re-enabled
expect
(
view
.
submitEnabled
()).
toBe
(
true
);
});
it
(
"moves to the next step on duplicate submission error"
,
function
()
{
// Simulate a "multiple submissions" server error
spyOn
(
server
,
'submit'
).
andCallFake
(
function
()
{
return
$
.
Deferred
(
function
(
defer
)
{
defer
.
rejectWith
(
this
,
[
'ENOMULTI'
,
'Multiple submissions error'
]);
}).
promise
();
});
spyOn
(
view
,
'load'
);
spyOn
(
baseView
,
'renderPeerAssessmentStep'
);
view
.
response
(
'Test response'
);
view
.
submit
();
// Expect the current and next step to have been reloaded
expect
(
view
.
load
).
toHaveBeenCalled
();
expect
(
baseView
.
renderPeerAssessmentStep
).
toHaveBeenCalled
();
});
});
apps/openassessment/xblock/static/js/src/oa_response.js
View file @
072ae5cb
...
...
@@ -213,20 +213,35 @@ OpenAssessment.ResponseView.prototype = {
Send a response submission to the server and update the view.
**/
submit
:
function
()
{
// Immediately disable the submit button to prevent multiple submission
this
.
submitEnabled
(
false
);
// Send the submission to the server
var
submission
=
$
(
'#submission__answer__value'
,
this
.
element
).
val
();
this
.
baseView
.
toggleActionError
(
'response'
,
null
);
var
view
=
this
;
var
baseView
=
this
.
baseView
;
this
.
server
.
submit
(
submission
).
done
(
// When we have successfully sent the submission, move on to the next step
function
(
studentId
,
attemptNum
)
{
view
.
load
();
baseView
.
renderPeerAssessmentStep
();
}
).
fail
(
function
(
errCode
,
errMsg
)
{
baseView
.
toggleActionError
(
'submit'
,
errMsg
);
});
var
moveToNextStep
=
function
()
{
view
.
load
();
baseView
.
renderPeerAssessmentStep
();
};
this
.
server
.
submit
(
submission
)
.
done
(
moveToNextStep
)
.
fail
(
function
(
errCode
,
errMsg
)
{
// If the error is "multiple submissions", then we should move to the next
// step. Otherwise, the user will be stuck on the current step with no
// way to continue.
if
(
errCode
==
'ENOMULTI'
)
{
moveToNextStep
();
}
else
{
// Display the error
baseView
.
toggleActionError
(
'submit'
,
errMsg
);
// Re-enable the submit button to allow the user to retry
view
.
submitEnabled
(
true
);
}
});
}
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment