Commit bb06a926 by Calen Pennington

Make saving also save the children in the #sortable element (TODO: name the…

Make saving also save the children in the #sortable element (TODO: name the #sortable element better)
parent c1ce5a87
......@@ -276,8 +276,13 @@ def save_item(request):
if not has_access(request.user, item_location):
raise Http404 # TODO (vshnayder): better error
data = json.loads(request.POST['data'])
modulestore().update_item(item_location, data)
if request.POST['data']:
data = json.loads(request.POST['data'])
modulestore().update_item(item_location, data)
if request.POST['children']:
children = json.loads(request.POST['children'])
modulestore().update_children(item_location, children)
# Export the course back to github
# This uses wildcarding to find the course, which requires handling
......
......@@ -86,7 +86,12 @@ def export_to_github(course, commit_message, author_str=None):
If author_str is specified, uses it in the commit.
'''
course_dir = course.metadata.get('data_dir', course.location.course)
repo_settings = load_repo_settings(course_dir)
try:
repo_settings = load_repo_settings(course_dir)
except InvalidRepo:
log.warning("Invalid repo {0}, not exporting data to xml".format(course_dir))
return
git_repo = setup_repo(repo_settings)
fs = OSFS(git_repo.working_dir)
......
......@@ -2,6 +2,7 @@ class CMS.Models.Module extends Backbone.Model
url: '/save_item'
defaults:
data: ''
children: ''
loadModule: (element) ->
elt = $(element).find('.xmodule_edit').first()
......@@ -10,6 +11,9 @@ class CMS.Models.Module extends Backbone.Model
editUrl: ->
"/edit_item?#{$.param(id: @get('id'))}"
updateChildren: (children) ->
@set(children: JSON.stringify(children))
save: (args...) ->
@set(data: JSON.stringify(@module.save())) if @module
super(args...)
......@@ -13,18 +13,22 @@ class CMS.Views.ModuleEdit extends Backbone.View
# Load preview modules
XModule.loadModules('display')
@$children = @$el.find('#sortable')
@enableDrag()
enableDrag: ->
enableDrag: =>
# Enable dragging things in the #sortable div (if there is one)
if $("#sortable").length > 0
$("#sortable").sortable({
if @$children.length > 0
@$children.sortable(
placeholder: "ui-state-highlight"
})
$("#sortable").disableSelection();
save: (event) ->
update: (event, ui) =>
@model.updateChildren(@$children.find('.module-edit').map(
(idx, el) -> $(el).data('id')
).toArray())
)
@$children.disableSelection()
save: (event) =>
event.preventDefault()
@model.save().done((previews) =>
alert("Your changes have been saved.")
......
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