Commit 5390a19f by Chris Dodge

delete unit in overview and subsection_edit pages

parent 35d1966d
...@@ -209,10 +209,6 @@ def preview_component(request, location): ...@@ -209,10 +209,6 @@ def preview_component(request, location):
}) })
@login_required
def delete_unit(request, location):
pass
def user_author_string(user): def user_author_string(user):
'''Get an author string for commits by this user. Format: '''Get an author string for commits by this user. Format:
...@@ -382,12 +378,33 @@ def get_module_previews(request, descriptor): ...@@ -382,12 +378,33 @@ def get_module_previews(request, descriptor):
preview_html.append(module.get_html()) preview_html.append(module.get_html())
return preview_html return preview_html
def _delete_item(item, recurse=False):
if recurse:
children = item.get_children()
for child in children:
_delete_item(child)
modulestore().delete_item(item.location);
@login_required @login_required
@expect_json @expect_json
def delete_item(request): def delete_item(request):
item_location = request.POST['id'] item_location = request.POST['id']
modulestore().delete_item(item_location)
# check permissions for this user within this course
if not has_access(request.user, item_location):
raise PermissionDenied()
# optional parameter to delete all children (default False)
delete_children = False
if 'delete_children' in request.POST:
delete_children = request.POST['delete_children'] in ['true', 'True']
item = modulestore().get_item(item_location)
_delete_item(item)
return HttpResponse() return HttpResponse()
......
...@@ -20,8 +20,24 @@ $(document).ready(function() { ...@@ -20,8 +20,24 @@ $(document).ready(function() {
$('.unit-history ol a').bind('click', showHistoryModal); $('.unit-history ol a').bind('click', showHistoryModal);
$modal.bind('click', hideHistoryModal); $modal.bind('click', hideHistoryModal);
$modalCover.bind('click', hideHistoryModal); $modalCover.bind('click', hideHistoryModal);
$('.unit .item-actions .delete-button').bind('click', deleteUnit);
}); });
function deleteUnit(e) {
e.preventDefault();
var id = $(this).data('id');
var _this = $(this);
$.post('/delete_item',
{'id': id, 'delete_children' : 'true'},
function(data) {
// remove 'leaf' class containing <li> element
var parent = _this.parents('li.leaf');
parent.remove();
});
}
function toggleSubmodules(e) { function toggleSubmodules(e) {
e.preventDefault(); e.preventDefault();
$(this).toggleClass('expand').toggleClass('collapse'); $(this).toggleClass('expand').toggleClass('collapse');
......
...@@ -6,13 +6,13 @@ This def will enumerate through a passed in subsection and list all of the units ...@@ -6,13 +6,13 @@ This def will enumerate through a passed in subsection and list all of the units
<%def name="enum_units(subsection)"> <%def name="enum_units(subsection)">
<ol> <ol>
% for unit in subsection.get_children(): % for unit in subsection.get_children():
<li class="leaf"> <li class="leaf unit">
<div class="section-item"> <div class="section-item">
<a href="${reverse('edit_unit', args=[unit.location])}" class="private-item"> <a href="${reverse('edit_unit', args=[unit.location])}" class="private-item">
<span class="${unit.category}-icon"></span>${unit.display_name} <span class="private-tag">- private</span> <span class="${unit.category}-icon"></span>${unit.display_name} <span class="private-tag">- private</span>
</a> </a>
<div class="item-actions"> <div class="item-actions">
<a href="${reverse('delete_unit', args=[unit.location])}" classs="edit-button wip"><span class="delete-icon"></span></a> <a href="#" class="delete-button" data-id="${unit.location}"><span class="delete-icon"></span></a>
<a href="#" class="drag-handle wip"></a> <a href="#" class="drag-handle wip"></a>
</div> </div>
</div> </div>
...@@ -25,3 +25,6 @@ This def will enumerate through a passed in subsection and list all of the units ...@@ -25,3 +25,6 @@ This def will enumerate through a passed in subsection and list all of the units
</li> </li>
</ol> </ol>
</%def> </%def>
...@@ -11,7 +11,6 @@ urlpatterns = ('', ...@@ -11,7 +11,6 @@ urlpatterns = ('',
url(r'^$', 'contentstore.views.index', name='index'), url(r'^$', 'contentstore.views.index', name='index'),
url(r'^edit/(?P<location>.*?)$', 'contentstore.views.edit_unit', name='edit_unit'), url(r'^edit/(?P<location>.*?)$', 'contentstore.views.edit_unit', name='edit_unit'),
url(r'^subsection/(?P<location>.*?)$', 'contentstore.views.edit_subsection', name='edit_subsection'), url(r'^subsection/(?P<location>.*?)$', 'contentstore.views.edit_subsection', name='edit_subsection'),
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'^delete_item$', 'contentstore.views.delete_item', name='delete_item'),
......
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