Commit fe9ae312 by Matjaz Gregoric Committed by E. Kolpakov

Add 'Add Component' button to library page.

It looks like the 'New Course'/'New Library' buttons on the studio home page.

Clicking the 'Add Component' button scrolls down to the 'Add New Component' buttons.
parent 0b8471d6
...@@ -494,6 +494,15 @@ define(["jquery", "underscore", "underscore.string", "js/common_helpers/ajax_hel ...@@ -494,6 +494,15 @@ define(["jquery", "underscore", "underscore.string", "js/common_helpers/ajax_hel
containerPage.$(".new-component .new-component-type a.single-template")[index].click(); containerPage.$(".new-component .new-component-type a.single-template")[index].click();
}; };
it('Attaches a handler to new component button', function() {
containerPage = getContainerPage();
containerPage.render();
// Stub jQuery.scrollTo module.
$.scrollTo = jasmine.createSpy('jQuery.scrollTo');
containerPage.$('.new-component-button').click();
expect($.scrollTo).toHaveBeenCalled();
});
it('sends the correct JSON to the server', function () { it('sends the correct JSON to the server', function () {
renderContainerPage(this, mockContainerXBlockHtml); renderContainerPage(this, mockContainerXBlockHtml);
clickNewComponent(0); clickNewComponent(0);
......
...@@ -66,6 +66,7 @@ define(["jquery", "js/common_helpers/ajax_helpers", "js/spec_helpers/view_helper ...@@ -66,6 +66,7 @@ define(["jquery", "js/common_helpers/ajax_helpers", "js/spec_helpers/view_helper
expect($('.create-course .wrap-error')).toHaveClass('is-shown'); expect($('.create-course .wrap-error')).toHaveClass('is-shown');
expect($('#course_creation_error')).toContainText('error message'); expect($('#course_creation_error')).toContainText('error message');
expect($('.new-course-save')).toHaveClass('is-disabled'); expect($('.new-course-save')).toHaveClass('is-disabled');
expect($('.new-course-save')).toHaveAttr('aria-disabled', 'true');
}); });
it("saves new libraries", function () { it("saves new libraries", function () {
...@@ -97,6 +98,7 @@ define(["jquery", "js/common_helpers/ajax_helpers", "js/spec_helpers/view_helper ...@@ -97,6 +98,7 @@ define(["jquery", "js/common_helpers/ajax_helpers", "js/spec_helpers/view_helper
fillInLibraryFields.apply(this, values_with_blank); fillInLibraryFields.apply(this, values_with_blank);
expect($('.create-library li.field.text input[value=]').parent()).toHaveClass('error'); expect($('.create-library li.field.text input[value=]').parent()).toHaveClass('error');
expect($('.new-library-save')).toHaveClass('is-disabled'); expect($('.new-library-save')).toHaveClass('is-disabled');
expect($('.new-library-save')).toHaveAttr('aria-disabled', 'true');
$('.new-library-save').click(); $('.new-library-save').click();
expect(requests.length).toEqual(requests_count); // Expect no new requests expect(requests.length).toEqual(requests_count); // Expect no new requests
} }
...@@ -123,6 +125,7 @@ define(["jquery", "js/common_helpers/ajax_helpers", "js/spec_helpers/view_helper ...@@ -123,6 +125,7 @@ define(["jquery", "js/common_helpers/ajax_helpers", "js/spec_helpers/view_helper
expect($('.create-library .wrap-error')).toHaveClass('is-shown'); expect($('.create-library .wrap-error')).toHaveClass('is-shown');
expect($('#library_creation_error')).toContainText('error message'); expect($('#library_creation_error')).toContainText('error message');
expect($('.new-library-save')).toHaveClass('is-disabled'); expect($('.new-library-save')).toHaveClass('is-disabled');
expect($('.new-library-save')).toHaveAttr('aria-disabled', 'true');
}); });
it("can switch tabs", function() { it("can switch tabs", function() {
......
...@@ -16,7 +16,8 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views ...@@ -16,7 +16,8 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views
events: { events: {
"click .edit-button": "editXBlock", "click .edit-button": "editXBlock",
"click .duplicate-button": "duplicateXBlock", "click .duplicate-button": "duplicateXBlock",
"click .delete-button": "deleteXBlock" "click .delete-button": "deleteXBlock",
"click .new-component-button": "scrollToNewComponentButtons"
}, },
options: { options: {
...@@ -321,6 +322,11 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views ...@@ -321,6 +322,11 @@ define(["jquery", "underscore", "gettext", "js/views/pages/base_page", "js/views
temporaryView.unbind(); // Remove the temporary view temporaryView.unbind(); // Remove the temporary view
} }
}); });
},
scrollToNewComponentButtons: function(event) {
event.preventDefault();
$.scrollTo(this.$('.add-xblock-component'));
} }
}); });
......
...@@ -33,6 +33,12 @@ ...@@ -33,6 +33,12 @@
</a> </a>
</li> </li>
% endif % endif
<li class="nav-item">
<a href="#" class="button new-button new-component-button">
<i class="icon-plus icon-inline"></i>
<span class="action-button-text">${_("Add Component")}</span>
</a>
</li>
</ul> </ul>
</nav> </nav>
</header> </header>
......
...@@ -43,7 +43,19 @@ from django.utils.translation import ugettext as _ ...@@ -43,7 +43,19 @@ from django.utils.translation import ugettext as _
<div class="wrapper-xblock-field incontext-editor is-editable" <div class="wrapper-xblock-field incontext-editor is-editable"
data-field="display_name" data-field-display-name="${_("Display Name")}"> data-field="display_name" data-field-display-name="${_("Display Name")}">
<h1 class="page-header-title xblock-field-value incontext-editor-value"><span class="title-value">${context_library.display_name_with_default | h}</span></h1> <h1 class="page-header-title xblock-field-value incontext-editor-value"><span class="title-value">${context_library.display_name_with_default | h}</span></h1>
</div>
</div> </div>
<nav class="nav-actions">
<h3 class="sr">${_("Page Actions")}</h3>
<ul>
<li class="nav-item">
<a href="#" class="button new-button new-component-button">
<i class="icon-plus icon-inline"></i> <span class="action-button-text">${_("Add Component")}</span>
</a>
</li>
</ul>
</nav>
</header> </header>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment