Commit 45b82f3a by Chris Dodge

update creating a new unit to use an empty template. Also twiddle the units.html…

update creating a new unit to use an empty template. Also twiddle the units.html and base.js where we put the unit Location on the <li> element
parent 1240325c
......@@ -45,6 +45,8 @@ from auth.authz import get_user_by_email, add_user_to_course_group, remove_user_
from auth.authz import ADMIN_ROLE_NAME, EDITOR_ROLE_NAME
from .utils import get_course_location_for_item
from xmodule.templates import all_templates
log = logging.getLogger(__name__)
......@@ -126,9 +128,14 @@ def course_index(request, org, course, name):
course = modulestore().get_item(location)
sections = course.get_children()
# This knowledge of what the 'new template' should be seems like it needs to be kept deeper down in the
# code. We should probably refactor
template = modulestore().get_item(Location('i4x', 'edx', 'templates', 'vertical', 'Empty'))
return render_to_response('overview.html', {
'sections': sections,
'upload_asset_callback_url': upload_asset_callback_url
'upload_asset_callback_url': upload_asset_callback_url,
'create_new_unit_template': template.location
})
......@@ -144,8 +151,14 @@ def edit_subsection(request, location):
if item.location.category != 'sequential':
return HttpResponseBadRequest
# This knowledge of what the 'new template' should be seems like it needs to be kept deeper down in the
# code. We should probably refactor
template = modulestore().get_item(Location('i4x', 'edx', 'templates', 'vertical', 'Empty'))
return render_to_response('edit_subsection.html',
{'subsection':item})
{'subsection':item,
'create_new_unit_template' : template.location
})
@login_required
def edit_unit(request, location):
......@@ -407,6 +420,20 @@ def delete_item(request):
return HttpResponse()
@login_required
@expect_json
def create_item(request):
# parent_location should be the location of the parent container
parent_location = request.POST['parent_id']
# which type of item to create
category = request.POST['category']
# check permissions for this user within this course
if not has_access(request.user, parent_location):
raise PermissionDenied()
@login_required
@expect_json
......@@ -446,6 +473,10 @@ def save_item(request):
def clone_item(request):
parent_location = Location(request.POST['parent_location'])
template = Location(request.POST['template'])
display_name = None
if 'display_name' in request.POST:
display_name = request.POST['display_name']
if not has_access(request.user, parent_location):
raise PermissionDenied()
......@@ -457,6 +488,10 @@ def clone_item(request):
# TODO: This needs to be deleted when we have proper storage for static content
new_item.metadata['data_dir'] = parent.metadata['data_dir']
# replace the display name with an optional parameter passed in from the caller
if display_name is not None:
new_item.metadata['display_name'] = display_name
modulestore().update_metadata(new_item.location.url(), new_item.own_metadata)
modulestore().update_children(parent_location, parent.definition.get('children', []) + [new_item.location.url()])
......
......@@ -24,19 +24,39 @@ $(document).ready(function() {
$('.assets .upload-button').bind('click', showUploadModal);
$('.upload-modal .close-button').bind('click', hideModal);
$('.unit .item-actions .delete-button').bind('click', deleteUnit);
$('.new-unit-item').bind('click', createNewUnit);
});
function createNewUnit(e) {
e.preventDefault();
parent = $(this).data('parent');
template = $(this).data('template');
$.post('/clone_item',
{'parent_location' : parent,
'template' : template,
'display_name': 'New Unit',
},
function(data) {
// redirect to the edit page
window.location = "/edit/" + data['id'];
});
}
function deleteUnit(e) {
e.preventDefault();
var id = $(this).data('id');
var _this = $(this);
if(!confirm('Are you sure you wish to delete this item. It cannot be reversed!'))
return;
var _li_el = $(this).parents('li.leaf');
var id = _li_el.data('id');
$.post('/delete_item',
{'id': id, 'delete_children' : 'true'},
function(data) {
// remove 'leaf' class containing <li> element
var parent = _this.parents('li.leaf');
parent.remove();
_li_el.remove();
});
}
......
......@@ -6,7 +6,7 @@ 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 unit">
<li class="leaf unit" data-id="${unit.location}">
<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>
......@@ -19,7 +19,7 @@ This def will enumerate through a passed in subsection and list all of the units
</li>
% endfor
<li>
<a href="#" class="new-unit-item wip">
<a href="#" class="new-unit-item wip" data-template="${create_new_unit_template}" data-parent="${subsection.location}">
<span class="new-unit-icon"></span>New Unit
</a>
</li>
......
......@@ -13,6 +13,7 @@ urlpatterns = ('',
url(r'^subsection/(?P<location>.*?)$', 'contentstore.views.edit_subsection', name='edit_subsection'),
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'^create_item$', 'contentstore.views.create_item', name='create_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>[^/]+)$',
......
......@@ -45,5 +45,9 @@ class VerticalModule(XModule):
class VerticalDescriptor(SequenceDescriptor):
module_class = VerticalModule
# cdodge: override the SequenceDescript's template_dir_name to point to default template directory
template_dir_name = "default"
js = {'coffee': [resource_string(__name__, 'js/src/vertical/edit.coffee')]}
js_module_name = "VerticalDescriptor"
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