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
1b957168
Commit
1b957168
authored
Apr 15, 2014
by
Will Daly
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #273 from edx/will/navigate-away-warning
Navigate away warning
parents
ffce323b
19884019
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
2 deletions
+81
-2
apps/openassessment/xblock/static/js/openassessment.min.js
+0
-0
apps/openassessment/xblock/static/js/spec/oa_response.js
+34
-0
apps/openassessment/xblock/static/js/src/oa_response.js
+47
-2
No files found.
apps/openassessment/xblock/static/js/openassessment.min.js
View file @
1b957168
This diff is collapsed.
Click to expand it.
apps/openassessment/xblock/static/js/spec/oa_response.js
View file @
1b957168
...
...
@@ -229,4 +229,38 @@ describe("OpenAssessment.ResponseView", function() {
expect
(
view
.
load
).
toHaveBeenCalled
();
expect
(
baseView
.
renderPeerAssessmentStep
).
toHaveBeenCalled
();
});
it
(
"enables the unsaved work warning when the user changes the response text"
,
function
()
{
// Initially, the unsaved work warning should be disabled
expect
(
view
.
unsavedWarningEnabled
()).
toBe
(
false
);
// Change the text, then expect the unsaved warning to be enabled.
view
.
response
(
'Lorem ipsum'
);
view
.
responseChanged
();
// Expect the unsaved work warning to be enabled
expect
(
view
.
unsavedWarningEnabled
()).
toBe
(
true
);
});
it
(
"disables the unsaved work warning when the user saves a response"
,
function
()
{
// Change the text, then expect the unsaved warning to be enabled.
view
.
response
(
'Lorem ipsum'
);
view
.
responseChanged
();
expect
(
view
.
unsavedWarningEnabled
()).
toBe
(
true
);
// Save the response and expect the unsaved warning to be disabled
view
.
save
();
expect
(
view
.
unsavedWarningEnabled
()).
toBe
(
false
);
});
it
(
"disables the unsaved work warning when the user submits a response"
,
function
()
{
// Change the text, then expect the unsaved warning to be enabled.
view
.
response
(
'Lorem ipsum'
);
view
.
responseChanged
();
expect
(
view
.
unsavedWarningEnabled
()).
toBe
(
true
);
// Submit the response and expect the unsaved warning to be disabled
view
.
submit
();
expect
(
view
.
unsavedWarningEnabled
()).
toBe
(
false
);
});
});
apps/openassessment/xblock/static/js/src/oa_response.js
View file @
1b957168
...
...
@@ -108,7 +108,10 @@ OpenAssessment.ResponseView.prototype = {
/**
Enable/disable the save button.
Check that whether the save button is enabled.
Check whether the save button is enabled.
Also enables/disables a beforeunload handler to warn
users about navigating away from the page with unsaved changes.
Args:
enabled (bool): If specified, set the state of the button.
...
...
@@ -153,6 +156,39 @@ OpenAssessment.ResponseView.prototype = {
},
/**
Enable/disable the "navigate away" warning to alert the user of unsaved changes.
Args:
enabled (bool): If specified, set whether the warning is enabled.
Returns:
bool: Whether the warning is enabled.
Examples:
>> view.unsavedWarningEnabled(true); // enable the "unsaved" warning
>> view.unsavedWarningEnabled();
>> true
**/
unsavedWarningEnabled
:
function
(
enabled
)
{
if
(
typeof
enabled
===
'undefined'
)
{
return
(
window
.
onbeforeunload
!==
null
);
}
else
{
if
(
enabled
)
{
window
.
onbeforeunload
=
function
()
{
return
(
"If you leave this page without saving or submitting your response, "
+
"you'll lose any work you've done on the response."
);
};
}
else
{
window
.
onbeforeunload
=
null
;
}
}
},
/**
Set the response text.
Retrieve the response text.
...
...
@@ -181,10 +217,12 @@ OpenAssessment.ResponseView.prototype = {
var
isBlank
=
(
currentResponse
!==
''
);
this
.
submitEnabled
(
isBlank
);
// Update the save button and status only if the response has changed
// Update the save button, save status, and "unsaved changes" warning
// only if the response has changed
if
(
$
.
trim
(
this
.
savedResponse
)
!==
currentResponse
)
{
this
.
saveEnabled
(
isBlank
);
this
.
saveStatus
(
gettext
(
'This response has not been saved.'
));
this
.
unsavedWarningEnabled
(
true
);
}
},
...
...
@@ -196,6 +234,9 @@ OpenAssessment.ResponseView.prototype = {
this
.
saveStatus
(
gettext
(
'Saving...'
));
this
.
baseView
.
toggleActionError
(
'save'
,
null
);
// Disable the "unsaved changes" warning
this
.
unsavedWarningEnabled
(
false
);
var
view
=
this
;
var
savedResponse
=
this
.
response
();
this
.
server
.
save
(
savedResponse
).
done
(
function
()
{
...
...
@@ -265,6 +306,10 @@ OpenAssessment.ResponseView.prototype = {
moveToNextStep
:
function
()
{
this
.
load
();
this
.
baseView
.
renderPeerAssessmentStep
();
// Disable the "unsaved changes" warning if the user
// tries to navigate to another page.
this
.
unsavedWarningEnabled
(
false
);
},
/**
...
...
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