Commit 28a2dd9a by Chris Dodge

support reordering of static tabs in studio

parent 163400e2
...@@ -903,6 +903,36 @@ def static_pages(request, org, course, coursename): ...@@ -903,6 +903,36 @@ def static_pages(request, org, course, coursename):
def edit_static(request, org, course, coursename): def edit_static(request, org, course, coursename):
return render_to_response('edit-static-page.html', {}) return render_to_response('edit-static-page.html', {})
@login_required
@expect_json
def reorder_tabs(request):
tabs = request.POST['tabs']
logging.debug('tabs = {0} {1}'.format(tabs.__class__, tabs))
if len(tabs) > 0:
course = get_course_for_item(tabs[0])
if not has_access(request.user, course.location):
raise PermissionDenied()
# first filter out all non-static tabs from the tabs list
course_tabs = [t for t in course.tabs if t['type'] != 'static_tab']
# OK, re-assemble the static tabs in the new order
for tab in tabs:
item = modulestore('direct').get_item(Location(tab))
course_tabs.append({ 'type':'static_tab',
'name' : item.metadata.get('display_name'),
'url_slug' : item.location.name}
)
course.tabs = course_tabs
modulestore('direct').update_metadata(course.location, course.metadata)
return HttpResponse()
@login_required @login_required
@ensure_csrf_cookie @ensure_csrf_cookie
def edit_tabs(request, org, course, coursename): def edit_tabs(request, org, course, coursename):
...@@ -914,12 +944,19 @@ def edit_tabs(request, org, course, coursename): ...@@ -914,12 +944,19 @@ def edit_tabs(request, org, course, coursename):
if not has_access(request.user, location): if not has_access(request.user, location):
raise PermissionDenied() raise PermissionDenied()
static_tabs = modulestore('direct').get_items(static_tabs_loc)
# see tabs have been uninitialized (e.g. supporing courses created before tab support in studio) # see tabs have been uninitialized (e.g. supporing courses created before tab support in studio)
if course_item.tabs is None or len(course_item.tabs) == 0: if course_item.tabs is None or len(course_item.tabs) == 0:
initialize_course_tabs(course_item) initialize_course_tabs(course_item)
# first get all static tabs from the tabs list
# we do this because this is also the order in which items are displayed in the LMS
static_tabs_refs = [t for t in course_item.tabs if t['type'] == 'static_tab']
static_tabs = []
for static_tab_ref in static_tabs_refs:
static_tab_loc = Location(location)._replace(category='static_tab', name=static_tab_ref['url_slug'])
static_tabs.append(modulestore('direct').get_item(static_tab_loc))
components = [ components = [
static_tab.location.url() static_tab.location.url()
for static_tab for static_tab
......
...@@ -15,7 +15,7 @@ class CMS.Views.TabsEdit extends Backbone.View ...@@ -15,7 +15,7 @@ class CMS.Views.TabsEdit extends Backbone.View
@$('.components').sortable( @$('.components').sortable(
handle: '.drag-handle' handle: '.drag-handle'
update: (event, ui) => alert 'not yet implemented!' update: @tabMoved
helper: 'clone' helper: 'clone'
opacity: '0.5' opacity: '0.5'
placeholder: 'component-placeholder' placeholder: 'component-placeholder'
...@@ -24,6 +24,20 @@ class CMS.Views.TabsEdit extends Backbone.View ...@@ -24,6 +24,20 @@ class CMS.Views.TabsEdit extends Backbone.View
items: '> .component' items: '> .component'
) )
tabMoved: (event, ui) =>
tabs = []
@$('.component').each((idx, element) =>
tabs.push($(element).data('id'))
)
$.ajax({
type:'POST',
url: '/reorder_tabs',
data: JSON.stringify({
tabs : tabs
}),
contentType: 'application/json'
})
addNewTab: (event) => addNewTab: (event) =>
event.preventDefault() event.preventDefault()
......
...@@ -17,6 +17,7 @@ urlpatterns = ('', ...@@ -17,6 +17,7 @@ urlpatterns = ('',
url(r'^publish_draft$', 'contentstore.views.publish_draft', name='publish_draft'), url(r'^publish_draft$', 'contentstore.views.publish_draft', name='publish_draft'),
url(r'^unpublish_unit$', 'contentstore.views.unpublish_unit', name='unpublish_unit'), url(r'^unpublish_unit$', 'contentstore.views.unpublish_unit', name='unpublish_unit'),
url(r'^create_new_course', 'contentstore.views.create_new_course', name='create_new_course'), url(r'^create_new_course', 'contentstore.views.create_new_course', name='create_new_course'),
url(r'^reorder_tabs', 'contentstore.views.reorder_tabs', name='reorder_tabs'),
url(r'^(?P<org>[^/]+)/(?P<course>[^/]+)/course/(?P<name>[^/]+)$', url(r'^(?P<org>[^/]+)/(?P<course>[^/]+)/course/(?P<name>[^/]+)$',
'contentstore.views.course_index', name='course_index'), 'contentstore.views.course_index', name='course_index'),
......
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