Commit d80c9317 by Calen Pennington

Hook up the component delete button to the backend. Don't break if the process…

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)
parent 79a7cc9f
...@@ -385,6 +385,14 @@ def get_module_previews(request, descriptor): ...@@ -385,6 +385,14 @@ def get_module_previews(request, descriptor):
@login_required @login_required
@expect_json @expect_json
def delete_item(request):
item_location = request.POST['id']
modulestore().delete_item(item_location)
return HttpResponse()
@login_required
@expect_json
def save_item(request): def save_item(request):
item_location = request.POST['id'] item_location = request.POST['id']
......
...@@ -6,10 +6,10 @@ class CMS.Views.ModuleEdit extends Backbone.View ...@@ -6,10 +6,10 @@ class CMS.Views.ModuleEdit extends Backbone.View
"click .component-editor .cancel-button": 'clickCancelButton' "click .component-editor .cancel-button": 'clickCancelButton'
"click .component-editor .save-button": 'clickSaveButton' "click .component-editor .save-button": 'clickSaveButton'
"click .component-actions .edit-button": 'clickEditButton' "click .component-actions .edit-button": 'clickEditButton'
"click .component-actions .delete-button": 'onDelete'
initialize: -> initialize: ->
@module = @options.module @onDelete = @options.onDelete
@render() @render()
$component_editor: => @$el.find('.component-editor') $component_editor: => @$el.find('.component-editor')
......
...@@ -18,9 +18,10 @@ class CMS.Views.UnitEdit extends Backbone.View ...@@ -18,9 +18,10 @@ class CMS.Views.UnitEdit extends Backbone.View
update: (event, ui) => @saveOrder() update: (event, ui) => @saveOrder()
) )
@$('.component').each((idx, element) -> @$('.component').each((idx, element) =>
new CMS.Views.ModuleEdit( new CMS.Views.ModuleEdit(
el: element, el: element,
onDelete: @deleteComponent,
model: new CMS.Models.Module( model: new CMS.Models.Module(
id: $(element).data('id'), id: $(element).data('id'),
) )
...@@ -70,3 +71,13 @@ class CMS.Views.UnitEdit extends Backbone.View ...@@ -70,3 +71,13 @@ class CMS.Views.UnitEdit extends Backbone.View
@model.save( @model.save(
children: @components() children: @components()
) )
deleteComponent: (event) =>
$component = $(event.currentTarget).parents('.component')
$.post('/delete_item', {
id: $component.data('id')
}, =>
$component.remove()
@saveOrder()
)
${preview} ${preview}
<div class="component-actions"> <div class="component-actions">
<a href="#" class="edit-button"><span class="edit-icon white"></span>Edit</a> <a href="#" class="edit-button"><span class="edit-icon white"></span>Edit</a>
<a href="#" class="delete-button wip"><span class="delete-icon white"></span>Delete</a> <a href="#" class="delete-button"><span class="delete-icon white"></span>Delete</a>
</div> </div>
<a href="#" class="drag-handle"></a> <a href="#" class="drag-handle"></a>
<div class="component-editor"> <div class="component-editor">
......
...@@ -14,6 +14,7 @@ urlpatterns = ('', ...@@ -14,6 +14,7 @@ urlpatterns = ('',
url(r'^delete/(?P<location>.*?)$', 'contentstore.views.delete_unit', name='delete_unit'), url(r'^delete/(?P<location>.*?)$', 'contentstore.views.delete_unit', name='delete_unit'),
url(r'^preview_component/(?P<location>.*?)$', 'contentstore.views.preview_component', name='preview_component'), url(r'^preview_component/(?P<location>.*?)$', 'contentstore.views.preview_component', name='preview_component'),
url(r'^save_item$', 'contentstore.views.save_item', name='save_item'), url(r'^save_item$', 'contentstore.views.save_item', name='save_item'),
url(r'^delete_item$', 'contentstore.views.delete_item', name='delete_item'),
url(r'^clone_item$', 'contentstore.views.clone_item', name='clone_item'), url(r'^clone_item$', 'contentstore.views.clone_item', name='clone_item'),
url(r'^(?P<org>[^/]+)/(?P<course>[^/]+)/course/(?P<name>[^/]+)$', url(r'^(?P<org>[^/]+)/(?P<course>[^/]+)/course/(?P<name>[^/]+)$',
'contentstore.views.course_index', name='course_index'), 'contentstore.views.course_index', name='course_index'),
......
...@@ -332,6 +332,14 @@ class ModuleStore(object): ...@@ -332,6 +332,14 @@ class ModuleStore(object):
""" """
raise NotImplementedError raise NotImplementedError
def delete_item(self, location):
"""
Delete an item from this modulestore
location: Something that can be passed to Location
"""
raise NotImplementedError
def get_courses(self): def get_courses(self):
''' '''
Returns a list containing the top level XModuleDescriptors of the courses Returns a list containing the top level XModuleDescriptors of the courses
......
...@@ -309,6 +309,14 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -309,6 +309,14 @@ class MongoModuleStore(ModuleStoreBase):
self._update_single_item(location, {'metadata': metadata}) self._update_single_item(location, {'metadata': metadata})
def delete_item(self, location):
"""
Delete an item from this modulestore
location: Something that can be passed to Location
"""
self.collection.remove({'_id': Location(location).dict()})
def get_parent_locations(self, location): def get_parent_locations(self, location):
'''Find all locations that are the parents of this location. Needed '''Find all locations that are the parents of this location. Needed
for path_to_location(). for path_to_location().
......
...@@ -13,6 +13,7 @@ from xmodule.modulestore import Location ...@@ -13,6 +13,7 @@ from xmodule.modulestore import Location
from xmodule.timeparse import parse_time from xmodule.timeparse import parse_time
from xmodule.contentstore.content import StaticContent, XASSET_SRCREF_PREFIX from xmodule.contentstore.content import StaticContent, XASSET_SRCREF_PREFIX
from xmodule.modulestore.exceptions import ItemNotFoundError
log = logging.getLogger('mitx.' + __name__) log = logging.getLogger('mitx.' + __name__)
...@@ -531,7 +532,11 @@ class XModuleDescriptor(Plugin, HTMLSnippet, ResourceTemplates): ...@@ -531,7 +532,11 @@ class XModuleDescriptor(Plugin, HTMLSnippet, ResourceTemplates):
if self._child_instances is None: if self._child_instances is None:
self._child_instances = [] self._child_instances = []
for child_loc in self.definition.get('children', []): for child_loc in self.definition.get('children', []):
try:
child = self.system.load_item(child_loc) child = self.system.load_item(child_loc)
except ItemNotFoundError:
log.exception('Unable to load item {loc}, skipping'.format(loc=child_loc))
continue
# TODO (vshnayder): this should go away once we have # TODO (vshnayder): this should go away once we have
# proper inheritance support in mongo. The xml # proper inheritance support in mongo. The xml
# datastore does all inheritance on course load. # datastore does all inheritance on course load.
......
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