From bfeccd88f8cbc99057c0096f598b7e871a8cf592 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Sat, 29 Sep 2012 00:37:15 -0400 Subject: [PATCH] Enable creation of new components --- cms/djangoapps/contentstore/views.py | 13 +------ .../coffee/src/views/module_edit.coffee | 15 +++++++- cms/static/js/base.js | 38 +++++++++---------- cms/templates/unit.html | 6 +-- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index 7ff13fea96..5667ffb8e3 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -145,15 +145,7 @@ def edit_unit(request, location): else: lms_link = None -<<<<<<< HEAD - - return render_to_response('unit.html', { - 'module': item, - 'editable_preview': get_module_previews(request, item)[0], - }) -======= component_templates = defaultdict(list) ->>>>>>> Separate unit page from vertical implementation for editing templates = modulestore().get_items(Location('i4x', 'edx', 'templates')) for template in templates: @@ -170,7 +162,7 @@ def edit_unit(request, location): ] return render_to_response('unit.html', { - 'unit_name': item.display_name, + 'unit': item, 'components': components, 'component_templates': component_templates, }) @@ -432,7 +424,7 @@ def clone_item(request): modulestore().update_metadata(new_item.location.url(), new_item.own_metadata) modulestore().update_children(parent_location, parent.definition.get('children', []) + [new_item.location.url()]) - return HttpResponse() + return preview_component(request, new_item.location) ''' cdodge: this method allows for POST uploading of files into the course asset library, which will @@ -523,4 +515,3 @@ def upload_asset(request, org, course, coursename): logging.error('Failed to generate thumbnail for {0}. Continuing...'.format(name)) return HttpResponse('Upload completed') - diff --git a/cms/static/coffee/src/views/module_edit.coffee b/cms/static/coffee/src/views/module_edit.coffee index b36a099aa3..3116dfbb55 100644 --- a/cms/static/coffee/src/views/module_edit.coffee +++ b/cms/static/coffee/src/views/module_edit.coffee @@ -32,12 +32,23 @@ class CMS.Views.ModuleEdit extends Backbone.View return _metadata - render: -> - @$el.load("/preview_component/#{@model.id}", => + cloneTemplate: (template, name) -> + @$el.load("/clone_item", { + parent_location: @$el.parent().data('id') + template: template + name: name + }, => @loadModules() @delegateEvents() ) + render: -> + if @model.id + @$el.load("/preview_component/#{@model.id}", => + @loadModules() + @delegateEvents() + ) + clickSaveButton: (event) => event.preventDefault() data = @module.save() diff --git a/cms/static/js/base.js b/cms/static/js/base.js index 006891be5b..822628c9dd 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -10,7 +10,8 @@ $(document).ready(function() { $modal = $('.history-modal'); $modalCover = $('.modal-cover'); $newComponentItem = $('.new-component-item'); - $newComponentChooser = $('.new-component'); + $newComponentTypePicker = $('.new-component'); + $newComponentTemplatePickers = $('.new-component-templates'); $newComponentButton = $('.new-component-button'); $('li.component').each(function(idx, element) { @@ -26,7 +27,10 @@ $(document).ready(function() { $('.visibility-options').bind('change', setVisibility); $newComponentButton.bind('click', showNewComponentForm); - $newComponentChooser.find('.new-component-type a').bind('click', showComponentTemplates); + $newComponentTypePicker.find('.new-component-type a').bind('click', showComponentTemplates); + $newComponentTypePicker.find('.cancel-button').bind('click', closeNewComponent); + $newComponentTemplatePickers.find('.new-component-template a').bind('click', saveNewComponent); + $newComponentTemplatePickers.find('.cancel-button').bind('click', closeNewComponent); $('.unit-history ol a').bind('click', showHistoryModal); $modal.bind('click', hideHistoryModal); @@ -58,21 +62,22 @@ function showNewComponentForm(e) { e.preventDefault(); $newComponentItem.addClass('adding'); $(this).slideUp(150); - $newComponentChooser.slideDown(150); + $newComponentTypePicker.slideDown(250); } function showComponentTemplates(e) { e.preventDefault(); var type = $(this).data('type'); - $newComponentChooser.slideUp(250); + $newComponentTypePicker.slideUp(250); $('.new-component-'+type).slideDown(250); } -function cancelNewComponent(e) { +function closeNewComponent(e) { e.preventDefault(); - $newComponentStep2.slideUp(250); + $newComponentTypePicker.slideUp(250); + $newComponentTemplatePickers.slideUp(250); $newComponentButton.slideDown(250); $newComponentItem.removeClass('adding'); $newComponentItem.find('.rendered-component').remove(); @@ -81,22 +86,15 @@ function cancelNewComponent(e) { function saveNewComponent(e) { e.preventDefault(); - var $newComponent = $newComponentItem.clone(); - $newComponent.removeClass('adding').removeClass('new-component-item'); - $newComponent.find('.new-component-step-2').removeClass('new-component-step-2').addClass('component-editor'); - setTimeout(function() { - $newComponent.find('.component-editor').slideUp(250); - }, 10); - $newComponent.append('
EditDelete
'); - $newComponent.find('.new-component-step-1').remove(); - $newComponent.find('.new-component-button').remove(); + editor = new CMS.Views.ModuleEdit({ + model: new CMS.Models.Module() + }) - $newComponentStep2.slideUp(250); - $newComponentButton.slideDown(250); - $newComponentItem.removeClass('adding'); - $newComponentItem.find('.rendered-component').remove(); + $('.components').append(editor.$el) - $newComponentItem.before($newComponent); + editor.cloneTemplate($(this).data('location')) + + closeNewComponent(e); } function showHistoryModal(e) { diff --git a/cms/templates/unit.html b/cms/templates/unit.html index e01ab2cafb..156fe2e30e 100644 --- a/cms/templates/unit.html +++ b/cms/templates/unit.html @@ -9,10 +9,10 @@ -
    +
      % for id in components:
    1. % endfor @@ -56,7 +56,7 @@

      Properties

      -
      +