Unscheduled: click here to set
-
% for subsection in section.get_children():
-
- +
diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index 5217b5ae6e..a5aab97f05 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -142,6 +142,9 @@ def course_index(request, org, course, name): return render_to_response('overview.html', { 'sections': sections, + 'parent_location': course.location, + 'new_section_template': Location('i4x', 'edx', 'templates', 'sequential', 'Empty'), + 'new_subsection_template': Location('i4x', 'edx', 'templates', 'sequential', 'Empty'), # for now they are the same, but the could be different at some point... 'upload_asset_callback_url': upload_asset_callback_url, 'create_new_unit_template': Location('i4x', 'edx', 'templates', 'vertical', 'Empty') }) diff --git a/cms/static/js/base.js b/cms/static/js/base.js index c56e24c482..42afe992d5 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -35,13 +35,18 @@ $(document).ready(function() { // expand/collapse methods for optional date setters $('.set-date').bind('click', showDateSetter); $('.remove-date').bind('click', removeDateSetter); - + // add new/delete section + $('.new-courseware-section-button').bind('click', addNewSection); + $('.delete-section-button').bind('click', deleteSection); + + // add new/delete subsection + $('.new-subsection-item').bind('click', addNewSubsection); + $('.delete-subsection-button').bind('click', deleteSubsection); // add/remove policy metadata button click handlers $('.add-policy-data').bind('click', addPolicyMetadata); $('.remove-policy-data').bind('click', removePolicyMetadata); $('.sync-date').bind('click', syncReleaseDate); - }); function syncReleaseDate(e) { @@ -166,6 +171,7 @@ function saveSubsection(e) { }); } + function createNewUnit(e) { e.preventDefault(); @@ -185,18 +191,30 @@ function createNewUnit(e) { function deleteUnit(e) { e.preventDefault(); + _deleteItem($(this).parents('li.leaf')); +} - if(!confirm('Are you sure you wish to delete this item. It cannot be reversed!')) - return; +function deleteSubsection(e) { + e.preventDefault(); + _deleteItem($(this).parents('li.branch')); +} - var _li_el = $(this).parents('li.leaf'); - var id = _li_el.data('id'); +function deleteSection(e) { + e.preventDefault(); + _deleteItem($(this).parents('section.branch')); +} + +function _deleteItem($el) { + if(!confirm('Are you sure you wish to delete this item. It cannot be reversed!')) + return; + + var id = $el.data('id'); $.post('/delete_item', - {'id': id, 'delete_children' : true}, - function(data) { - _li_el.remove(); - }); + {'id': id, 'delete_children' : true}, + function(data) { + $el.remove(); + }); } function showUploadModal(e) { @@ -328,3 +346,82 @@ function hideToastMessage(e) { e.preventDefault(); $(this).closest('.toast-notification').remove(); } + +function addNewSection(e) { + e.preventDefault(); + var $newSection = $($('#new-section-template').html()); + $('.new-courseware-section-button').after($newSection); + $newSection.find('.new-section-name').focus().select(); + $newSection.find('.new-section-name-save').bind('click', saveNewSection); + $newSection.find('.new-section-name-cancel').bind('click', cancelNewSection); +} + +function saveNewSection(e) { + e.preventDefault(); + + parent = $(this).data('parent'); + template = $(this).data('template'); + + display_name = $(this).prev('.new-section-name').val(); + + $.post('/clone_item', + {'parent_location' : parent, + 'template' : template, + 'display_name': display_name, + }, + function(data) { + if (data.id != undefined) + location.reload(); + }); +} + +function cancelNewSection(e) { + e.preventDefault(); + $(this).parents('section.new-section').remove(); +} + +function addNewSubsection(e) { + e.preventDefault(); + var $section = $(this).closest('.courseware-section'); + var $newSubsection = $($('#new-subsection-template').html()); + $section.find('.unit-list > ol').append($newSubsection); + $section.find('.new-subsection-name-input').focus().select(); + + var $saveButton = $newSubsection.find('.new-subsection-name-save'); + $saveButton.bind('click', saveNewSubsection); + + parent = $(this).parents("section.branch").data("id"); + + $saveButton.data('parent', parent) + $saveButton.data('template', $(this).data('template')); + + $newSubsection.find('.new-subsection-name-cancel').bind('click', cancelNewSubsection); +} + +function saveNewSubsection(e) { + e.preventDefault(); + + parent = $(this).data('parent'); + template = $(this).data('template'); + + + display_name = $(this).prev('.subsection-name').find('.new-subsection-name-input').val() + + $.post('/clone_item', + {'parent_location' : parent, + 'template' : template, + 'display_name': display_name, + }, + function(data) { + if (data.id != undefined) { + location.reload(); + } + }); + + +} + +function cancelNewSubsection(e) { + e.preventDefault(); + $(this).parents('li.branch').remove(); +} diff --git a/cms/templates/base.html b/cms/templates/base.html index cb827b9876..915394f458 100644 --- a/cms/templates/base.html +++ b/cms/templates/base.html @@ -13,6 +13,8 @@ + + <%block name="header_extras">%block>
diff --git a/cms/templates/overview.html b/cms/templates/overview.html index d650f5e6df..93a4ff2678 100644 --- a/cms/templates/overview.html +++ b/cms/templates/overview.html @@ -4,6 +4,42 @@ <%namespace name="units" file="widgets/units.html" /> +<%block name="header_extras"> + + + + + +%block> <%block name="content">