From bb06a926bba6822bc01e0991a0b72148f246a07e Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Tue, 18 Sep 2012 13:19:30 -0400 Subject: [PATCH] Make saving also save the children in the #sortable element (TODO: name the #sortable element better) --- cms/djangoapps/contentstore/views.py | 9 +++++++-- cms/djangoapps/github_sync/__init__.py | 7 ++++++- cms/static/coffee/src/models/module.coffee | 4 ++++ cms/static/coffee/src/views/module_edit.coffee | 18 +++++++++++------- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index 505b897497..053e358645 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -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 diff --git a/cms/djangoapps/github_sync/__init__.py b/cms/djangoapps/github_sync/__init__.py index e3215cbec1..a4dbe29fb6 100644 --- a/cms/djangoapps/github_sync/__init__.py +++ b/cms/djangoapps/github_sync/__init__.py @@ -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) diff --git a/cms/static/coffee/src/models/module.coffee b/cms/static/coffee/src/models/module.coffee index 159172e852..ae24b5aefc 100644 --- a/cms/static/coffee/src/models/module.coffee +++ b/cms/static/coffee/src/models/module.coffee @@ -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...) diff --git a/cms/static/coffee/src/views/module_edit.coffee b/cms/static/coffee/src/views/module_edit.coffee index d212f7cb17..62460b3220 100644 --- a/cms/static/coffee/src/views/module_edit.coffee +++ b/cms/static/coffee/src/views/module_edit.coffee @@ -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(); + update: (event, ui) => + @model.updateChildren(@$children.find('.module-edit').map( + (idx, el) -> $(el).data('id') + ).toArray()) + ) + @$children.disableSelection() - - save: (event) -> + save: (event) => event.preventDefault() @model.save().done((previews) => alert("Your changes have been saved.")