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
dc5123c8
Commit
dc5123c8
authored
Jun 24, 2013
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow multiple textbook edit forms on the page simultaneously
parent
404c36b8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
37 deletions
+15
-37
cms/static/coffee/spec/models/textbook_spec.coffee
+1
-5
cms/static/coffee/spec/views/textbook_spec.coffee
+7
-15
cms/static/js/models/textbook.js
+2
-7
cms/static/js/views/textbook.js
+5
-10
No files found.
cms/static/coffee/spec/models/textbook_spec.coffee
View file @
dc5123c8
...
...
@@ -53,6 +53,7 @@ describe "CMS.Models.Textbook input/output", ->
clientModelSpec
=
{
"name"
:
"My Textbook"
,
"showChapters"
:
false
,
"editing"
:
false
,
"chapters"
:
[{
"name"
:
"Chapter 1"
,
"asset_path"
:
"/ch1.pdf"
,
...
...
@@ -85,11 +86,6 @@ describe "CMS.Collections.TextbookSet", ->
@
collection
.
save
()
expect
(
@
collection
.
sync
).
toHaveBeenCalledWith
(
"update"
,
@
collection
,
undefined
)
it
"should respond to editOne events"
,
->
model
=
new
CMS
.
Models
.
Textbook
()
@
collection
.
trigger
(
'editOne'
,
model
)
expect
(
@
collection
.
editing
).
toEqual
(
model
)
describe
"CMS.Models.Chapter"
,
->
beforeEach
->
...
...
cms/static/coffee/spec/views/textbook_spec.coffee
View file @
dc5123c8
...
...
@@ -29,11 +29,9 @@ describe "CMS.Views.ShowTextbook", ->
@
view
.
render
()
expect
(
@
view
.
$el
).
toContainText
(
"Life Sciences"
)
it
"should trigger an editOne event on the collection when the edit button is clicked"
,
->
spyOn
(
@
collection
,
"trigger"
).
andCallThrough
()
it
"should set the 'editing' property on the model when the edit button is clicked"
,
->
@
view
.
render
().
$
(
".edit"
).
click
()
expect
(
@
collection
.
trigger
).
toHaveBeenCalledWith
(
"editOne"
,
@
model
)
expect
(
@
collection
.
editing
).
toEqual
(
@
model
)
expect
(
@
model
.
get
(
"editing"
)).
toBeTruthy
()
it
"should pop a delete confirmation when the delete button is clicked"
,
->
promptSpies
=
spyOnConstructor
(
CMS
.
Views
.
Prompt
,
"Warning"
,
[
"show"
,
"hide"
])
...
...
@@ -77,11 +75,10 @@ describe "CMS.Views.EditTextbook", ->
appendSetFixtures
(
$
(
"<script>"
,
{
id
:
"system-feedback-tpl"
,
type
:
"text/template"
}).
text
(
feedbackTpl
))
appendSetFixtures
(
sandbox
({
id
:
"page-notification"
}))
appendSetFixtures
(
sandbox
({
id
:
"page-prompt"
}))
@
model
=
new
CMS
.
Models
.
Textbook
({
name
:
"Life Sciences"
})
@
model
=
new
CMS
.
Models
.
Textbook
({
name
:
"Life Sciences"
,
editing
:
true
})
@
collection
=
new
CMS
.
Collections
.
TextbookSet
()
spyOn
(
@
collection
,
'save'
)
@
collection
.
add
(
@
model
)
@
collection
.
editing
=
@
model
@
view
=
new
CMS
.
Views
.
EditTextbook
({
model
:
@
model
})
spyOn
(
@
view
,
'render'
).
andCallThrough
()
...
...
@@ -114,7 +111,6 @@ describe "CMS.Views.EditTextbook", ->
expect
(
@
model
.
get
(
"name"
)).
not
.
toEqual
(
"starfish"
)
expect
(
@
model
.
get
(
"chapters"
).
at
(
0
).
get
(
"name"
)).
not
.
toEqual
(
"foobar"
)
expect
(
@
collection
.
save
).
not
.
toHaveBeenCalled
()
expect
(
@
collection
.
editing
).
toBeUndefined
()
it
"removes all empty chapters on cancel if the model has a non-empty chapter"
,
->
chapters
=
@
model
.
get
(
"chapters"
)
...
...
@@ -178,11 +174,11 @@ describe "CMS.Views.ListTextbooks", ->
expect
(
@
editSpies
.
constructor
).
not
.
toHaveBeenCalled
()
it
"should render an EditTextbook view for a textbook being edited"
,
->
# add three empty textbooks to the collection
@
collection
.
add
([{},
{},
{}])
# mark the second one as being edited
# add three empty textbooks to the collection
: the first and third
# should be shown, and the second should be edited
@
collection
.
add
([{
editing
:
false
},
{
editing
:
true
},
{
editing
:
false
}])
editing
=
@
collection
.
at
(
1
)
@
collection
.
trigger
(
'editOne'
,
editing
)
expect
(
editing
.
get
(
"editing"
)).
toBeTruthy
(
)
# reset spies
@
showSpies
.
constructor
.
reset
()
@
editSpies
.
constructor
.
reset
()
...
...
@@ -204,10 +200,6 @@ describe "CMS.Views.ListTextbooks", ->
@
view
.
$
(
".new-button"
).
click
()
expect
(
@
collection
.
length
).
toEqual
(
1
)
expect
(
@
collection
.
editing
).
toBeDefined
()
editing
=
@
collection
.
editing
expect
(
editing
).
toEqual
(
@
collection
.
at
(
0
))
expect
(
@
editSpies
.
constructor
).
toHaveBeenCalledWith
({
model
:
editing
})
expect
(
@
view
.
$el
).
toContain
(
@
editSpies
.
$el
)
expect
(
@
view
.
$el
).
not
.
toContain
(
@
showSpies
.
$el
)
...
...
cms/static/js/models/textbook.js
View file @
dc5123c8
...
...
@@ -3,7 +3,8 @@ CMS.Models.Textbook = Backbone.AssociatedModel.extend({
return
{
name
:
""
,
chapters
:
new
CMS
.
Collections
.
ChapterSet
([{}]),
showChapters
:
false
showChapters
:
false
,
editing
:
false
};
},
relations
:
[{
...
...
@@ -40,12 +41,6 @@ CMS.Models.Textbook = Backbone.AssociatedModel.extend({
CMS
.
Collections
.
TextbookSet
=
Backbone
.
Collection
.
extend
({
model
:
CMS
.
Models
.
Textbook
,
url
:
function
()
{
return
CMS
.
URL
.
TEXTBOOK
;
},
initialize
:
function
()
{
this
.
listenTo
(
this
,
"editOne"
,
this
.
editOne
);
},
editOne
:
function
(
textbook
)
{
this
.
editing
=
textbook
;
},
save
:
function
(
options
)
{
return
this
.
sync
(
'update'
,
this
,
options
);
}
...
...
cms/static/js/views/textbook.js
View file @
dc5123c8
...
...
@@ -17,7 +17,7 @@ CMS.Views.ShowTextbook = Backbone.View.extend({
},
editTextbook
:
function
(
e
)
{
if
(
e
&&
e
.
preventDefault
)
{
e
.
preventDefault
();
}
this
.
model
.
collection
.
trigger
(
"editOne"
,
this
.
model
);
this
.
model
.
set
(
"editing"
,
true
);
},
confirmDelete
:
function
(
e
)
{
if
(
e
&&
e
.
preventDefault
)
{
e
.
preventDefault
();
}
...
...
@@ -69,7 +69,6 @@ CMS.Views.EditTextbook = Backbone.View.extend({
this
.
listenTo
(
chapters
,
"add"
,
this
.
addOne
);
this
.
listenTo
(
chapters
,
"reset"
,
this
.
addAll
);
this
.
listenTo
(
chapters
,
"all"
,
this
.
render
);
this
.
listenTo
(
this
.
model
.
collection
,
"editOne"
,
this
.
remove
);
},
tagName
:
"section"
,
className
:
"textbook"
,
...
...
@@ -141,7 +140,6 @@ CMS.Views.EditTextbook = Backbone.View.extend({
},
close
:
function
()
{
var
textbooks
=
this
.
model
.
collection
;
delete
textbooks
.
editing
;
this
.
remove
();
// if the textbook has no content, remove it from the collection
if
(
this
.
model
.
isEmpty
())
{
...
...
@@ -157,8 +155,9 @@ CMS.Views.EditTextbook = Backbone.View.extend({
emptyChapters
=
_
.
tail
(
emptyChapters
);
}
chapters
.
remove
(
emptyChapters
);
// don't forget to tell the model that it's no longer being edited
this
.
model
.
set
(
"editing"
,
false
);
}
textbooks
.
trigger
(
'render'
);
return
this
;
}
});
...
...
@@ -178,7 +177,7 @@ CMS.Views.ListTextbooks = Backbone.View.extend({
var
that
=
this
;
textbooks
.
each
(
function
(
textbook
)
{
var
view
;
if
(
textbook
===
textbooks
.
editing
)
{
if
(
textbook
.
get
(
"editing"
)
)
{
view
=
new
CMS
.
Views
.
EditTextbook
({
model
:
textbook
});
}
else
{
view
=
new
CMS
.
Views
.
ShowTextbook
({
model
:
textbook
});
...
...
@@ -193,11 +192,7 @@ CMS.Views.ListTextbooks = Backbone.View.extend({
},
addOne
:
function
(
e
)
{
if
(
e
&&
e
.
preventDefault
)
{
e
.
preventDefault
();
}
// if the existing edited textbook is empty, don't do anything
if
(
this
.
collection
.
editing
&&
this
.
collection
.
editing
.
isEmpty
())
{
return
;
}
var
m
=
new
this
.
collection
.
model
();
this
.
collection
.
add
(
m
);
this
.
collection
.
trigger
(
"editOne"
,
m
);
this
.
collection
.
add
([{
editing
:
true
}]);
}
});
CMS
.
Views
.
EditChapter
=
Backbone
.
View
.
extend
({
...
...
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