Commit 9fe4cb73 by Peter Fogg

Use Backbone notifications for course section delete.

parent 9a61038c
...@@ -239,6 +239,12 @@ def save_button_disabled(step): ...@@ -239,6 +239,12 @@ def save_button_disabled(step):
assert world.css_has_class(button_css, disabled) assert world.css_has_class(button_css, disabled)
@step('I confirm the prompt')
def confirm_the_prompt(step):
prompt_css = 'a.button.action-primary'
world.css_click(prompt_css)
def type_in_codemirror(index, text): def type_in_codemirror(index, text):
world.css_click(".CodeMirror", index=index) world.css_click(".CodeMirror", index=index)
g = world.css_find("div.CodeMirror.CodeMirror-focused > div > textarea") g = world.css_find("div.CodeMirror.CodeMirror-focused > div > textarea")
......
...@@ -33,4 +33,5 @@ Feature: Create Section ...@@ -33,4 +33,5 @@ Feature: Create Section
And I have added a new section And I have added a new section
When I will confirm all alerts When I will confirm all alerts
And I press the "section" delete icon And I press the "section" delete icon
And I confirm the prompt
Then the section does not exist Then the section does not exist
...@@ -38,4 +38,5 @@ Feature: Create Subsection ...@@ -38,4 +38,5 @@ Feature: Create Subsection
And I see my subsection on the Courseware page And I see my subsection on the Courseware page
When I will confirm all alerts When I will confirm all alerts
And I press the "subsection" delete icon And I press the "subsection" delete icon
And I confirm the prompt
Then the subsection does not exist Then the subsection does not exist
...@@ -40,17 +40,31 @@ describe "Course Overview", -> ...@@ -40,17 +40,31 @@ describe "Course Overview", ->
</div> </div>
"""#" """#"
appendSetFixtures """
<section class="courseware-section branch" data-id="a-location-goes-here">
<li class="branch collapsed id-holder" data-id="an-id-goes-here">
<a href="#" class="delete-section-button"></a>
</li>
</section>
"""#"
spyOn(window, 'saveSetSectionScheduleDate').andCallThrough() spyOn(window, 'saveSetSectionScheduleDate').andCallThrough()
# Have to do this here, as it normally gets bound in document.ready() # Have to do this here, as it normally gets bound in document.ready()
$('a.save-button').click(saveSetSectionScheduleDate) $('a.save-button').click(saveSetSectionScheduleDate)
$('a.delete-section-button').click(deleteSection)
@notificationSpy = spyOn(CMS.Views.Notification.Mini.prototype, 'show').andCallThrough() @notificationSpy = spyOn(CMS.Views.Notification.Mini.prototype, 'show').andCallThrough()
window.analytics = jasmine.createSpyObj('analytics', ['track']) window.analytics = jasmine.createSpyObj('analytics', ['track'])
window.course_location_analytics = jasmine.createSpy() window.course_location_analytics = jasmine.createSpy()
sinon.useFakeXMLHttpRequest() @xhr = sinon.useFakeXMLHttpRequest()
requests = @requests = []
@xhr.onCreate = (req) -> requests.push(req)
afterEach -> afterEach ->
delete window.analytics delete window.analytics
delete window.course_location_analytics delete window.course_location_analytics
@xhr.restore()
@notificationSpy.reset()
it "should save model when save is clicked", -> it "should save model when save is clicked", ->
$('a.edit-button').click() $('a.edit-button').click()
...@@ -61,3 +75,15 @@ describe "Course Overview", -> ...@@ -61,3 +75,15 @@ describe "Course Overview", ->
$('a.edit-button').click() $('a.edit-button').click()
$('a.save-button').click() $('a.save-button').click()
expect(@notificationSpy).toHaveBeenCalled() expect(@notificationSpy).toHaveBeenCalled()
it "should delete model when delete is clicked", ->
deleteSpy = spyOn(window, '_deleteItem').andCallThrough()
$('a.delete-section-button').click()
$('a.action-primary').click()
expect(deleteSpy).toHaveBeenCalled()
expect(@requests[0].url).toEqual('/delete_item')
it "should show a confirmation on delete", ->
$('a.delete-section-button').click()
$('a.action-primary').click()
expect(@notificationSpy).toHaveBeenCalled()
...@@ -356,39 +356,61 @@ function createNewUnit(e) { ...@@ -356,39 +356,61 @@ function createNewUnit(e) {
function deleteUnit(e) { function deleteUnit(e) {
e.preventDefault(); e.preventDefault();
_deleteItem($(this).parents('li.leaf')); _deleteItem($(this).parents('li.leaf'), 'Unit');
} }
function deleteSubsection(e) { function deleteSubsection(e) {
e.preventDefault(); e.preventDefault();
_deleteItem($(this).parents('li.branch')); _deleteItem($(this).parents('li.branch'), 'Subsection');
} }
function deleteSection(e) { function deleteSection(e) {
e.preventDefault(); e.preventDefault();
_deleteItem($(this).parents('section.branch')); _deleteItem($(this).parents('section.branch'), 'Section');
} }
function _deleteItem($el) { function _deleteItem($el, type) {
if (!confirm(gettext('Are you sure you wish to delete this item. It cannot be reversed!'))) return; var confirm = new CMS.Views.Prompt.Confirmation({
title: gettext('Are you sure you wish to delete this ' + type + '?'),
var id = $el.data('id'); message: gettext('It cannot be reversed!'),
actions: {
analytics.track('Deleted an Item', { primary: {
'course': course_location_analytics, text: gettext('OK'),
'id': id click: function(view) {
}); view.hide();
var id = $el.data('id');
$.post('/delete_item', {
'id': id, analytics.track('Deleted an Item', {
'delete_children': true, 'course': course_location_analytics,
'delete_all_versions': true 'id': id
}, });
function(data) { var deleting = new CMS.Views.Notification.Mini({
$el.remove(); title: gettext('Deleting') + '&hellip;'
});
deleting.show();
$.post('/delete_item',
{'id': id,
'delete_children': true,
'delete_all_versions': true},
function(data) {
$el.remove();
deleting.hide();
}
);
}
},
secondary: {
text: gettext('Cancel'),
click: function(view) {
view.hide();
}
}
}
}); });
confirm.show();
} }
function markAsLoaded() { function markAsLoaded() {
......
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