Commit baaafb9d by chrisndodge

Merge pull request #815 from MITx/feature/cale/cas-component-delete

Feature/cale/cas component delete
parents 153d5d69 d80c9317
......@@ -385,6 +385,14 @@ def get_module_previews(request, descriptor):
@login_required
@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):
item_location = request.POST['id']
......@@ -413,12 +421,7 @@ def save_item(request):
existing_item.metadata.update(posted_metadata)
modulestore().update_metadata(item_location, existing_item.metadata)
descriptor = modulestore().get_item(item_location)
preview_html = get_module_previews(request, descriptor)[0]
return HttpResponse(json.dumps({
'preview': preview_html
}))
return HttpResponse()
@login_required
......
......@@ -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()
)
${preview}
<div class="component-actions">
<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>
<a href="#" class="drag-handle"></a>
<div class="component-editor">
......
......@@ -14,6 +14,7 @@ urlpatterns = ('',
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'^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'^(?P<org>[^/]+)/(?P<course>[^/]+)/course/(?P<name>[^/]+)$',
'contentstore.views.course_index', name='course_index'),
......
......@@ -332,6 +332,14 @@ class ModuleStore(object):
"""
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):
'''
Returns a list containing the top level XModuleDescriptors of the courses
......
......@@ -309,6 +309,14 @@ class MongoModuleStore(ModuleStoreBase):
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):
'''Find all locations that are the parents of this location. Needed
for path_to_location().
......
......@@ -13,6 +13,7 @@ from xmodule.modulestore import Location
from xmodule.timeparse import parse_time
from xmodule.contentstore.content import StaticContent, XASSET_SRCREF_PREFIX
from xmodule.modulestore.exceptions import ItemNotFoundError
log = logging.getLogger('mitx.' + __name__)
......@@ -531,7 +532,11 @@ class XModuleDescriptor(Plugin, HTMLSnippet, ResourceTemplates):
if self._child_instances is None:
self._child_instances = []
for child_loc in self.definition.get('children', []):
child = self.system.load_item(child_loc)
try:
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
# proper inheritance support in mongo. The xml
# 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