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
fedbf458
Commit
fedbf458
authored
Jun 25, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent saving when textbook is in invalid state
parent
74b9703d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
10 deletions
+34
-10
cms/static/coffee/spec/views/textbook_spec.coffee
+27
-5
cms/static/js/models/textbook.js
+1
-1
cms/static/js/views/textbook.js
+4
-2
cms/templates/js/edit-textbook.underscore
+2
-2
No files found.
cms/static/coffee/spec/views/textbook_spec.coffee
View file @
fedbf458
...
...
@@ -96,31 +96,53 @@ describe "CMS.Views.EditTextbook", ->
it
"should save properly"
,
->
@
view
.
render
()
@
view
.
$
(
"input[name=textbook-name]"
).
val
(
"starfish"
)
@
view
.
$
(
"input[name=chapter1-
name
]"
).
val
(
"foobar"
)
@
view
.
$
(
"input[name=chapter1-
asset-path
]"
).
val
(
"foobar"
)
@
view
.
$
(
"form"
).
submit
()
expect
(
@
model
.
get
(
"name"
)).
toEqual
(
"starfish"
)
expect
(
@
model
.
get
(
"chapters"
).
at
(
0
).
get
(
"
name
"
)).
toEqual
(
"foobar"
)
expect
(
@
model
.
get
(
"chapters"
).
at
(
0
).
get
(
"
asset_path
"
)).
toEqual
(
"foobar"
)
expect
(
@
model
.
save
).
toHaveBeenCalled
()
it
"should not save on invalid"
,
->
@
view
.
render
()
@
view
.
$
(
"input[name=textbook-name]"
).
val
(
""
)
@
view
.
$
(
"input[name=chapter1-asset-path]"
).
val
(
"foobar.pdf"
)
@
view
.
$
(
"form"
).
submit
()
expect
(
@
model
.
validationError
).
toBeTruthy
()
expect
(
@
model
.
save
).
not
.
toHaveBeenCalled
()
it
"does not save on cancel"
,
->
@
model
.
get
(
"chapters"
).
add
([{
name
:
"a"
,
asset_path
:
"b"
}])
@
view
.
render
()
@
view
.
$
(
"input[name=textbook-name]"
).
val
(
"starfish"
)
@
view
.
$
(
"input[name=chapter1-
name]"
).
val
(
"foobar
"
)
@
view
.
$
(
"input[name=chapter1-
asset-path]"
).
val
(
"foobar.pdf
"
)
@
view
.
$
(
".action-cancel"
).
click
()
expect
(
@
model
.
get
(
"name"
)).
not
.
toEqual
(
"starfish"
)
expect
(
@
model
.
get
(
"chapters"
).
at
(
0
).
get
(
"name"
)).
not
.
toEqual
(
"foobar"
)
expect
(
@
model
.
get
(
"chapters"
).
first
().
get
(
"asset_path"
)).
not
.
toEqual
(
"foobar"
)
expect
(
@
model
.
save
).
not
.
toHaveBeenCalled
()
it
"should be possible to correct validation errors"
,
->
@
view
.
render
()
@
view
.
$
(
"input[name=textbook-name]"
).
val
(
""
)
@
view
.
$
(
"input[name=chapter1-asset-path]"
).
val
(
"foobar.pdf"
)
@
view
.
$
(
"form"
).
submit
()
expect
(
@
model
.
validationError
).
toBeTruthy
()
expect
(
@
model
.
save
).
not
.
toHaveBeenCalled
()
@
view
.
$
(
"input[name=textbook-name]"
).
val
(
"starfish"
)
@
view
.
$
(
"input[name=chapter1-name]"
).
val
(
"foobar"
)
@
view
.
$
(
"form"
).
submit
()
expect
(
@
model
.
validationError
).
toBeFalsy
()
expect
(
@
model
.
save
).
toHaveBeenCalled
()
it
"removes all empty chapters on cancel if the model has a non-empty chapter"
,
->
chapters
=
@
model
.
get
(
"chapters"
)
chapters
.
at
(
0
).
set
(
"name"
,
"non-empty"
)
@
model
.
setOriginalAttributes
()
@
view
.
render
()
chapters
.
add
([{},
{},
{}])
# add three empty chapters
expect
(
chapters
.
length
).
toEqual
(
4
)
@
view
.
$
(
".action-cancel"
).
click
()
expect
(
chapters
.
length
).
toEqual
(
1
)
expect
(
chapters
.
at
(
0
).
get
(
'name'
)).
toEqual
(
"non-empty"
)
expect
(
chapters
.
first
(
).
get
(
'name'
)).
toEqual
(
"non-empty"
)
it
"removes all empty chapters on cancel except one if the model has no non-empty chapters"
,
->
chapters
=
@
model
.
get
(
"chapters"
)
...
...
cms/static/js/models/textbook.js
View file @
fedbf458
...
...
@@ -21,7 +21,7 @@ CMS.Models.Textbook = Backbone.AssociatedModel.extend({
this
.
_originalAttributes
=
this
.
parse
(
this
.
toJSON
());
},
reset
:
function
()
{
this
.
set
(
this
.
_originalAttributes
);
this
.
set
(
this
.
_originalAttributes
,
{
parse
:
true
}
);
},
isEmpty
:
function
()
{
return
!
this
.
get
(
'name'
)
&&
this
.
get
(
'chapters'
).
isEmpty
();
...
...
cms/static/js/views/textbook.js
View file @
fedbf458
...
...
@@ -65,6 +65,7 @@ CMS.Views.ShowTextbook = Backbone.View.extend({
CMS
.
Views
.
EditTextbook
=
Backbone
.
View
.
extend
({
initialize
:
function
()
{
this
.
template
=
_
.
template
(
$
(
"#edit-textbook-tpl"
).
text
());
this
.
listenTo
(
this
.
model
,
"invalid"
,
this
.
render
);
var
chapters
=
this
.
model
.
get
(
'chapters'
);
this
.
listenTo
(
chapters
,
"add"
,
this
.
addOne
);
this
.
listenTo
(
chapters
,
"reset"
,
this
.
addAll
);
...
...
@@ -75,7 +76,7 @@ CMS.Views.EditTextbook = Backbone.View.extend({
render
:
function
()
{
this
.
$el
.
html
(
this
.
template
({
name
:
this
.
model
.
escape
(
'name'
),
error
s
:
null
error
:
this
.
model
.
validationError
}));
this
.
addAll
();
return
this
;
...
...
@@ -119,13 +120,14 @@ CMS.Views.EditTextbook = Backbone.View.extend({
setAndClose
:
function
(
e
)
{
if
(
e
&&
e
.
preventDefault
)
{
e
.
preventDefault
();
}
this
.
setValues
();
if
(
!
this
.
model
.
isValid
())
{
return
;
}
var
saving
=
new
CMS
.
Views
.
Notification
.
Saving
({
title
:
gettext
(
"Saving…"
)
});
var
that
=
this
;
this
.
model
.
save
({},
{
success
:
function
()
{
that
.
setOriginalAttributes
();
that
.
model
.
setOriginalAttributes
();
that
.
close
();
},
complete
:
function
()
{
...
...
cms/templates/js/edit-textbook.underscore
View file @
fedbf458
<form class="edit-textbook" id="edit_textbook_form">
<div class="wrapper-form">
<% if (error
s
) { %>
<% if (error) { %>
<div id="edit_textbook_error" class="message message-status message-status error" name="edit_textbook_error">
<%= error
s
%>
<%= error %>
</div>
<% } %>
...
...
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