Commit 5029f460 by Peter Fogg

Use Backbone notifications for component delete.

parent 9fe4cb73
...@@ -67,3 +67,21 @@ Feature: Component Adding ...@@ -67,3 +67,21 @@ Feature: Component Adding
When I will confirm all alerts When I will confirm all alerts
And I delete all components And I delete all components
Then I see no components Then I see no components
Scenario: I see a prompt on delete
Given I have opened a new course in studio
And I am editing a new unit
And I add the following components:
| Component |
| Discussion |
And I delete a component
Then I see a prompt
Scenario: I see a notification on save
Given I have opened a new course in studio
And I am editing a new unit
And I add the following components:
| Component |
| Discussion |
And I edit and save a component
Then I see a notification
...@@ -41,6 +41,22 @@ def see_no_components(steps): ...@@ -41,6 +41,22 @@ def see_no_components(steps):
assert world.is_css_not_present('li.component') assert world.is_css_not_present('li.component')
@step(u'I delete a component')
def delete_one_component(step):
world.css_click('a.delete-button')
@step(u'I edit and save a component')
def edit_and_save_component(step):
world.css_click('.edit-button')
world.css_click('.save-button')
@step(u'I see a (.*)$')
def i_see_a_notification(step, notification_type):
assert world.is_css_present('.wrapper-%s' % notification_type)
def step_selector_list(data_type, path, index=1): def step_selector_list(data_type, path, index=1):
selector_list = ['a[data-type="{}"]'.format(data_type)] selector_list = ['a[data-type="{}"]'.format(data_type)]
if index != 1: if index != 1:
......
...@@ -84,11 +84,15 @@ class CMS.Views.ModuleEdit extends Backbone.View ...@@ -84,11 +84,15 @@ class CMS.Views.ModuleEdit extends Backbone.View
data.metadata = _.extend(data.metadata || {}, @changedMetadata()) data.metadata = _.extend(data.metadata || {}, @changedMetadata())
@hideModal() @hideModal()
saving = new CMS.Views.Notification.Mini
title: gettext('Saving') + '…'
saving.show()
@model.save(data).done( => @model.save(data).done( =>
# # showToastMessage("Your changes have been saved.", null, 3) # # showToastMessage("Your changes have been saved.", null, 3)
@module = null @module = null
@render() @render()
@$el.removeClass('editing') @$el.removeClass('editing')
saving.hide()
).fail( -> ).fail( ->
showToastMessage(gettext("There was an error saving your changes. Please try again."), null, 3) showToastMessage(gettext("There was an error saving your changes. Please try again."), null, 3)
) )
......
...@@ -115,27 +115,43 @@ class CMS.Views.UnitEdit extends Backbone.View ...@@ -115,27 +115,43 @@ class CMS.Views.UnitEdit extends Backbone.View
@model.save() @model.save()
deleteComponent: (event) => deleteComponent: (event) =>
if not confirm 'Are you sure you want to delete this component? This action cannot be undone.' msg = new CMS.Views.Prompt.Confirmation(
return title: gettext('Are you sure you want to delete this component?'),
$component = $(event.currentTarget).parents('.component') message: gettext('This action cannot be undone.'),
$.post('/delete_item', { actions:
id: $component.data('id') primary:
}, => text: gettext('OK'),
analytics.track "Deleted a Component", click: (view) =>
course: course_location_analytics view.hide()
unit_id: unit_location_analytics deleting = new CMS.Views.Notification.Mini
id: $component.data('id') title: gettext('Deleting') + '…',
deleting.show()
$component.remove() $component = $(event.currentTarget).parents('.component')
# b/c we don't vigilantly keep children up to date $.post('/delete_item', {
# get rid of it before it hurts someone id: $component.data('id')
# sorry for the js, i couldn't figure out the coffee equivalent }, =>
`_this.model.save({children: _this.components()}, deleting.hide()
{success: function(model) { analytics.track "Deleted a Component",
model.unset('children'); course: course_location_analytics
}} unit_id: unit_location_analytics
);` id: $component.data('id')
$component.remove()
# b/c we don't vigilantly keep children up to date
# get rid of it before it hurts someone
# sorry for the js, i couldn't figure out the coffee equivalent
`_this.model.save({children: _this.components()},
{success: function(model) {
model.unset('children');
}}
);`
)
secondary:
text: gettext('Cancel'),
click: (view) ->
view.hide()
) )
msg.show()
deleteDraft: (event) -> deleteDraft: (event) ->
@wait(true) @wait(true)
......
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