Commit 623c756b by Calen Pennington

Enable section and subsection reordering (with no drag between them)

parent a160f614
...@@ -32,9 +32,11 @@ $(document).ready(function() { ...@@ -32,9 +32,11 @@ $(document).ready(function() {
$('.save-subsection').bind('click', saveSubsection); $('.save-subsection').bind('click', saveSubsection);
// making the unit list sortable // making the unit list sortable
$('.sortable-unit-list').sortable(); $('.sortable-unit-list').sortable({
$('.sortable-unit-list').disableSelection(); axis: 'y',
$('.sortable-unit-list').bind('sortstop', onUnitReordered); handle: '.drag-handle',
update: onUnitReordered
});
// expand/collapse methods for optional date setters // expand/collapse methods for optional date setters
$('.set-date').bind('click', showDateSetter); $('.set-date').bind('click', showDateSetter);
...@@ -58,6 +60,20 @@ $(document).ready(function() { ...@@ -58,6 +60,20 @@ $(document).ready(function() {
e.preventDefault(); e.preventDefault();
$('.import .file-input').click(); $('.import .file-input').click();
}); });
// Subsection reordering
$('.unit-list ol').sortable({
axis: 'y',
handle: '.section-item .drag-handle',
update: onSubsectionReordered
});
// Section reordering
$('.courseware-overview').sortable({
axis: 'y',
handle: 'header .drag-handle',
update: onSectionReordered
});
}); });
function showImportSubmit(e) { function showImportSubmit(e) {
...@@ -110,12 +126,7 @@ function onUnitReordered() { ...@@ -110,12 +126,7 @@ function onUnitReordered() {
var subsection_id = $(this).data('subsection-id'); var subsection_id = $(this).data('subsection-id');
var _els = $(this).children('li:.leaf'); var _els = $(this).children('li:.leaf');
var children = _els.map(function(idx, el) { return $(el).data('id'); }).get();
var children = new Array();
for(var i=0;i<_els.length;i++) {
el = _els[i];
children[i] = $(el).data('id');
}
// call into server to commit the new order // call into server to commit the new order
$.ajax({ $.ajax({
...@@ -127,6 +138,38 @@ function onUnitReordered() { ...@@ -127,6 +138,38 @@ function onUnitReordered() {
}); });
} }
function onSubsectionReordered() {
var section_id = $(this).data('section-id');
var _els = $(this).children('li:.branch');
var children = _els.map(function(idx, el) { return $(el).data('id'); }).get();
// call into server to commit the new order
$.ajax({
url: "/save_item",
type: "POST",
dataType: "json",
contentType: "application/json",
data:JSON.stringify({ 'id' : section_id, 'metadata' : null, 'data': null, 'children' : children})
});
}
function onSectionReordered() {
var course_id = $(this).data('course-id');
var _els = $(this).children('section:.branch');
var children = _els.map(function(idx, el) { return $(el).data('id'); }).get();
// call into server to commit the new order
$.ajax({
url: "/save_item",
type: "POST",
dataType: "json",
contentType: "application/json",
data:JSON.stringify({ 'id' : course_id, 'metadata' : null, 'data': null, 'children' : children})
});
}
function getEdxTimeFromDateTimeInputs(date_id, time_id, format) { function getEdxTimeFromDateTimeInputs(date_id, time_id, format) {
var input_date = $('#'+date_id).val(); var input_date = $('#'+date_id).val();
var input_time = $('#'+time_id).val(); var input_time = $('#'+time_id).val();
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
<div class="inner-wrapper"> <div class="inner-wrapper">
<h1>Courseware</h1> <h1>Courseware</h1>
<div class="page-actions"></div> <div class="page-actions"></div>
<article class="courseware-overview"> <article class="courseware-overview" data-course-id="${context_course.location.url()}">
<a href="#" class="new-courseware-section-button"><span class="plus-icon"></span> New Section</a> <a href="#" class="new-courseware-section-button"><span class="plus-icon"></span> New Section</a>
% for section in sections: % for section in sections:
<section class="courseware-section branch" data-id="${section.location}"> <section class="courseware-section branch" data-id="${section.location}">
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
</div> </div>
<div class="item-actions"> <div class="item-actions">
<a href="#" class="delete-button delete-section-button"><span class="delete-icon"></span></a> <a href="#" class="delete-button delete-section-button"><span class="delete-icon"></span></a>
<a href="#" class="drag-handle wip"></a> <a href="#" class="drag-handle"></a>
</div> </div>
</header> </header>
<div class="unit-list"> <div class="unit-list">
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
<span class="new-folder-icon"></span>New Subsection <span class="new-folder-icon"></span>New Subsection
</a> </a>
</div> </div>
<ol> <ol data-section-id="${section.location.url()}">
% for subsection in section.get_children(): % for subsection in section.get_children():
<li class="branch collapsed" data-id="${subsection.location}"> <li class="branch collapsed" data-id="${subsection.location}">
<div class="section-item"> <div class="section-item">
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
</div> </div>
<div class="item-actions"> <div class="item-actions">
<a href="#" class="delete-button delete-subsection-button"><span class="delete-icon"></span></a> <a href="#" class="delete-button delete-subsection-button"><span class="delete-icon"></span></a>
<a href="#" class="drag-handle wip"></a> <a href="#" class="drag-handle"></a>
</div> </div>
</div> </div>
${units.enum_units(subsection)} ${units.enum_units(subsection)}
......
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