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:
@@ -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')
|
||||
|
||||
@@ -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()
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user