Hook up the component delete button to the backend. Don't break if the process of updating a parent unit after deleting is interrupted (leaving a pointer to a missing module)

This commit is contained in:
Calen Pennington
2012-10-03 14:08:51 -04:00
parent 79a7cc9f03
commit d80c931772
8 changed files with 46 additions and 5 deletions

View File

@@ -6,10 +6,10 @@ class CMS.Views.ModuleEdit extends Backbone.View
"click .component-editor .cancel-button": 'clickCancelButton'
"click .component-editor .save-button": 'clickSaveButton'
"click .component-actions .edit-button": 'clickEditButton'
"click .component-actions .delete-button": 'onDelete'
initialize: ->
@module = @options.module
@onDelete = @options.onDelete
@render()
$component_editor: => @$el.find('.component-editor')

View File

@@ -18,9 +18,10 @@ class CMS.Views.UnitEdit extends Backbone.View
update: (event, ui) => @saveOrder()
)
@$('.component').each((idx, element) ->
@$('.component').each((idx, element) =>
new CMS.Views.ModuleEdit(
el: element,
onDelete: @deleteComponent,
model: new CMS.Models.Module(
id: $(element).data('id'),
)
@@ -70,3 +71,13 @@ class CMS.Views.UnitEdit extends Backbone.View
@model.save(
children: @components()
)
deleteComponent: (event) =>
$component = $(event.currentTarget).parents('.component')
$.post('/delete_item', {
id: $component.data('id')
}, =>
$component.remove()
@saveOrder()
)