Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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-platform
Commits
70a01177
Commit
70a01177
authored
Jun 26, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show a warning if the user tries to leave the page with unsaved textbook changes
parent
fedbf458
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
0 deletions
+21
-0
cms/static/coffee/spec/models/textbook_spec.coffee
+12
-0
cms/static/js/models/textbook.js
+3
-0
cms/templates/textbooks.html
+6
-0
No files found.
cms/static/coffee/spec/models/textbook_spec.coffee
View file @
70a01177
...
...
@@ -26,6 +26,18 @@ describe "CMS.Models.Textbook", ->
it
"should have a URL set"
,
->
expect
(
_
.
result
(
@
model
,
"url"
)).
toBeTruthy
()
it
"should not be dirty by default"
,
->
expect
(
@
model
.
isDirty
()).
toBeFalsy
()
it
"should be dirty after it's been changed"
,
->
@
model
.
set
(
"name"
,
"foobar"
)
expect
(
@
model
.
isDirty
()).
toBeTruthy
()
it
"should not be dirty after calling setOriginalAttributes"
,
->
@
model
.
set
(
"name"
,
"foobar"
)
@
model
.
setOriginalAttributes
()
expect
(
@
model
.
isDirty
()).
toBeFalsy
()
describe
"CMS.Models.Textbook input/output"
,
->
# replace with Backbone.Assocations.deepAttributes when
...
...
cms/static/js/models/textbook.js
View file @
70a01177
...
...
@@ -23,6 +23,9 @@ CMS.Models.Textbook = Backbone.AssociatedModel.extend({
reset
:
function
()
{
this
.
set
(
this
.
_originalAttributes
,
{
parse
:
true
});
},
isDirty
:
function
()
{
return
!
_
.
isEqual
(
this
.
_originalAttributes
,
this
.
parse
(
this
.
toJSON
()));
},
isEmpty
:
function
()
{
return
!
this
.
get
(
'name'
)
&&
this
.
get
(
'chapters'
).
isEmpty
();
},
...
...
cms/templates/textbooks.html
View file @
70a01177
...
...
@@ -30,6 +30,12 @@ $(function() {
$
(
".nav-actions .new-button"
).
click
(
function
(
e
)
{
tbView
.
addOne
(
e
);
})
$
(
window
).
on
(
"beforeunload"
,
function
()
{
var
dirty
=
textbooks
.
find
(
function
(
textbook
)
{
return
textbook
.
isDirty
();
});
if
(
dirty
)
{
return
"You have unsaved changes. Do you really want to leave this page?"
;
}
})
})
</script>
</
%
block>
...
...
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