delete unit in overview and subsection_edit pages
This commit is contained in:
@@ -209,10 +209,6 @@ def preview_component(request, location):
|
||||
})
|
||||
|
||||
|
||||
@login_required
|
||||
def delete_unit(request, location):
|
||||
pass
|
||||
|
||||
|
||||
def user_author_string(user):
|
||||
'''Get an author string for commits by this user. Format:
|
||||
@@ -382,12 +378,33 @@ def get_module_previews(request, descriptor):
|
||||
preview_html.append(module.get_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
|
||||
@expect_json
|
||||
def delete_item(request):
|
||||
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()
|
||||
|
||||
|
||||
|
||||
@@ -20,8 +20,24 @@ $(document).ready(function() {
|
||||
$('.unit-history ol a').bind('click', showHistoryModal);
|
||||
$modal.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) {
|
||||
e.preventDefault();
|
||||
$(this).toggleClass('expand').toggleClass('collapse');
|
||||
|
||||
@@ -6,13 +6,13 @@ This def will enumerate through a passed in subsection and list all of the units
|
||||
<%def name="enum_units(subsection)">
|
||||
<ol>
|
||||
% for unit in subsection.get_children():
|
||||
<li class="leaf">
|
||||
<li class="leaf unit">
|
||||
<div class="section-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>
|
||||
</a>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
@@ -25,3 +25,6 @@ This def will enumerate through a passed in subsection and list all of the units
|
||||
</li>
|
||||
</ol>
|
||||
</%def>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ urlpatterns = ('',
|
||||
url(r'^$', 'contentstore.views.index', name='index'),
|
||||
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'^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'),
|
||||
|
||||
Reference in New Issue
Block a user