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
097f3fca
Commit
097f3fca
authored
May 29, 2015
by
David Baumgold
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8112 from crispweed/master
Scroll to new textbook and make input active, on textbook create
parents
361d82ad
fcb369a6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
7 deletions
+48
-7
AUTHORS
+2
-2
cms/static/coffee/spec/views/textbook_spec.coffee
+34
-2
cms/static/js/views/list_textbooks.js
+12
-3
No files found.
AUTHORS
View file @
097f3fca
...
...
@@ -212,4 +212,5 @@ Jolyon Bloomfield <jolyon@mit.edu>
Kyle McCormick <kylemccor@gmail.com>
Jim Cai <jimcai@stanford.edu>
Richard Moch <richard.moch@gmail.com>
Randy Ostler <rando305@gmail.com>
\ No newline at end of file
Randy Ostler <rando305@gmail.com>
Thomas Young <thomas@upcoder.com>
cms/static/coffee/spec/views/textbook_spec.coffee
View file @
097f3fca
define
[
"js/models/textbook"
,
"js/models/chapter"
,
"js/collections/chapter"
,
"js/models/course"
,
"js/collections/textbook"
,
"js/views/show_textbook"
,
"js/views/edit_textbook"
,
"js/views/list_textbooks"
,
"js/views/edit_chapter"
,
"js/views/feedback_prompt"
,
"js/views/feedback_notification"
,
"js/views/edit_chapter"
,
"js/views/feedback_prompt"
,
"js/views/feedback_notification"
,
"js/views/utils/view_utils"
,
"js/common_helpers/ajax_helpers"
,
"js/spec_helpers/modal_helpers"
,
"jasmine-stealth"
],
(
Textbook
,
Chapter
,
ChapterSet
,
Course
,
TextbookSet
,
ShowTextbook
,
EditTextbook
,
ListTex
book
,
EditChapter
,
Prompt
,
Notification
,
AjaxHelpers
,
modal_helpers
)
->
(
Textbook
,
Chapter
,
ChapterSet
,
Course
,
TextbookSet
,
ShowTextbook
,
EditTextbook
,
ListTex
tbooks
,
EditChapter
,
Prompt
,
Notification
,
ViewUtils
,
AjaxHelpers
,
modal_helpers
)
->
feedbackTpl
=
readFixtures
(
'system-feedback.underscore'
)
beforeEach
->
...
...
@@ -194,6 +194,38 @@ define ["js/models/textbook", "js/models/chapter", "js/collections/chapter", "js
@
view
.
$
(
".action-cancel"
).
click
()
expect
(
chapters
.
length
).
toEqual
(
1
)
describe
"ListTextbooks"
,
->
noTextbooksTpl
=
readFixtures
(
"no-textbooks.underscore"
)
editTextbooktpl
=
readFixtures
(
'edit-textbook.underscore'
)
beforeEach
->
appendSetFixtures
(
$
(
"<script>"
,
{
id
:
"no-textbooks-tpl"
,
type
:
"text/template"
}).
text
(
noTextbooksTpl
))
appendSetFixtures
(
$
(
"<script>"
,
{
id
:
"edit-textbook-tpl"
,
type
:
"text/template"
}).
text
(
editTextbooktpl
))
@
collection
=
new
TextbookSet
@
view
=
new
ListTextbooks
({
collection
:
@
collection
})
@
view
.
render
()
it
"should scroll to newly added textbook"
,
->
spyOn
(
ViewUtils
,
'setScrollOffset'
)
@
view
.
$
(
".new-button"
).
click
()
$sectionEl
=
@
view
.
$el
.
find
(
'section:last'
)
expect
(
$sectionEl
.
length
).
toEqual
(
1
)
expect
(
ViewUtils
.
setScrollOffset
).
toHaveBeenCalledWith
(
$sectionEl
,
0
)
it
"should focus first input element of newly added textbook"
,
->
spyOn
(
jQuery
.
fn
,
'focus'
).
andCallThrough
()
@
addMatchers
toHaveBeenCalledOnJQueryObject
:
(
actual
,
expected
)
->
pass
:
actual
.
calls
&&
actual
.
calls
.
mostRecent
()
&&
actual
.
calls
.
mostRecent
().
object
[
0
]
==
expected
[
0
]
@
view
.
$
(
".new-button"
).
click
()
$inputEl
=
@
view
.
$el
.
find
(
'section:last input:first'
)
expect
(
$inputEl
.
length
).
toEqual
(
1
)
# testing for element focused seems to be tricky
# (see http://stackoverflow.com/questions/967096)
# and the following doesn't seem to work
# expect($inputEl).toBeFocused()
# expect($inputEl.find(':focus').length).toEqual(1)
expect
(
jQuery
.
fn
.
focus
).
toHaveBeenCalledOnJQueryObject
(
$inputEl
)
# describe "ListTextbooks", ->
# noTextbooksTpl = readFixtures("no-textbooks.underscore")
...
...
cms/static/js/views/list_textbooks.js
View file @
097f3fca
define
([
"js/views/baseview"
,
"jquery"
,
"js/views/edit_textbook"
,
"js/views/show_textbook"
],
function
(
BaseView
,
$
,
EditTextbookView
,
ShowTextbookView
)
{
define
([
"js/views/baseview"
,
"jquery"
,
"js/views/edit_textbook"
,
"js/views/show_textbook"
,
"js/views/utils/view_utils"
],
function
(
BaseView
,
$
,
EditTextbookView
,
ShowTextbookView
,
ViewUtils
)
{
var
ListTextbooks
=
BaseView
.
extend
({
initialize
:
function
()
{
this
.
emptyTemplate
=
this
.
loadTemplate
(
'no-textbooks'
);
...
...
@@ -31,8 +31,17 @@ define(["js/views/baseview", "jquery", "js/views/edit_textbook", "js/views/show_
"click .new-button"
:
"addOne"
},
addOne
:
function
(
e
)
{
var
$sectionEl
,
$inputEl
;
if
(
e
&&
e
.
preventDefault
)
{
e
.
preventDefault
();
}
this
.
collection
.
add
([{
editing
:
true
}]);
this
.
collection
.
add
([{
editing
:
true
}]);
// (render() call triggered here)
// find the outer 'section' tag for the newly added textbook
$sectionEl
=
this
.
$el
.
find
(
'section:last'
);
// scroll to put this at top of viewport
ViewUtils
.
setScrollOffset
(
$sectionEl
,
0
);
// find the first input element in this section
$inputEl
=
$sectionEl
.
find
(
'input:first'
);
// activate the text box (so user can go ahead and start typing straight away)
$inputEl
.
focus
().
select
();
},
handleDestroy
:
function
(
model
,
collection
,
options
)
{
collection
.
remove
(
model
);
...
...
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