From 2b29c5fb18b41127f6205d873c905a5d3017954d Mon Sep 17 00:00:00 2001 From: Thomas Young Date: Wed, 20 May 2015 11:19:04 +0200 Subject: [PATCH 1/4] scroll to newly created section and make first input element active on creation of a new textbook in the textbooks list page (fix for https://openedx.atlassian.net/browse/TNL-130) --- cms/static/js/views/list_textbooks.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cms/static/js/views/list_textbooks.js b/cms/static/js/views/list_textbooks.js index 40f3cc4322..f10b20a972 100644 --- a/cms/static/js/views/list_textbooks.js +++ b/cms/static/js/views/list_textbooks.js @@ -1,5 +1,5 @@ -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'); @@ -32,7 +32,15 @@ define(["js/views/baseview", "jquery", "js/views/edit_textbook", "js/views/show_ }, addOne: function(e) { 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); From e294e01da3b0bb9fb1f5deb1e14ca1e443ade1ce Mon Sep 17 00:00:00 2001 From: Thomas Young Date: Wed, 20 May 2015 16:43:47 +0200 Subject: [PATCH 2/4] added myself to AUTHORS --- AUTHORS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index bbf29a91e0..6dae7116d4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -212,4 +212,5 @@ Jolyon Bloomfield Kyle McCormick Jim Cai Richard Moch -Randy Ostler \ No newline at end of file +Randy Ostler +Thomas Young From 6aa1a84921486209936fe78cb2ed0a4f0d80152d Mon Sep 17 00:00:00 2001 From: Thomas Young Date: Thu, 21 May 2015 17:54:55 +0200 Subject: [PATCH 3/4] added jasmine tests for focusing on and scrolling to newly added textbook --- .../coffee/spec/views/textbook_spec.coffee | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/cms/static/coffee/spec/views/textbook_spec.coffee b/cms/static/coffee/spec/views/textbook_spec.coffee index 4bb5115fe8..7769eb7a05 100644 --- a/cms/static/coffee/spec/views/textbook_spec.coffee +++ b/cms/static/coffee/spec/views/textbook_spec.coffee @@ -1,8 +1,8 @@ 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, ListTexbook, EditChapter, Prompt, Notification, AjaxHelpers, modal_helpers) -> +(Textbook, Chapter, ChapterSet, Course, TextbookSet, ShowTextbook, EditTextbook, ListTextbooks, 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($("