From fb06344290504b2bc29214cdcbcce58718bc0811 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 24 Oct 2012 14:57:13 -0400 Subject: [PATCH 1/4] Allow for deletion of all components in a draft --- cms/djangoapps/contentstore/views.py | 6 +++--- cms/static/coffee/src/models/module.coffee | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index d699647152..eb090d3333 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -574,11 +574,11 @@ def save_item(request): store = _modulestore(Location(item_location)); - if request.POST['data']: + if request.POST['data'] is not None: data = request.POST['data'] store.update_item(item_location, data) - if request.POST['children']: + if request.POST['children'] is not None: children = request.POST['children'] store.update_children(item_location, children) @@ -587,7 +587,7 @@ def save_item(request): # NOTE, that the postback is not the complete metadata, as there's system metadata which is # not presented to the end-user for editing. So let's fetch the original and # 'apply' the submitted metadata, so we don't end up deleting system metadata - if request.POST['metadata']: + if request.POST['metadata'] is not None: posted_metadata = request.POST['metadata'] # fetch original existing_item = modulestore().get_item(item_location) diff --git a/cms/static/coffee/src/models/module.coffee b/cms/static/coffee/src/models/module.coffee index 41bd3f4b7d..d344bda17d 100644 --- a/cms/static/coffee/src/models/module.coffee +++ b/cms/static/coffee/src/models/module.coffee @@ -1,6 +1,6 @@ class CMS.Models.Module extends Backbone.Model url: '/save_item' defaults: - data: '' - children: '' - metadata: {} + data: null + children: null + metadata: null From 2dd77656cc9c70c820775b691115685cefc0aaa8 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 24 Oct 2012 14:58:44 -0400 Subject: [PATCH 2/4] Make all edits on unit page happen immediately, and restore the delete draft button --- cms/static/coffee/src/views/unit.coffee | 39 +++++-------------------- cms/static/sass/_unit.scss | 22 +++++++------- cms/templates/unit.html | 11 ++++--- 3 files changed, 23 insertions(+), 49 deletions(-) diff --git a/cms/static/coffee/src/views/unit.coffee b/cms/static/coffee/src/views/unit.coffee index a0576e9178..0270cebd47 100644 --- a/cms/static/coffee/src/views/unit.coffee +++ b/cms/static/coffee/src/views/unit.coffee @@ -5,11 +5,10 @@ class CMS.Views.UnitEdit extends Backbone.View 'click .new-component-templates .new-component-template a': 'saveNewComponent' 'click .new-component-templates .cancel-button': 'closeNewComponent' 'click .new-component-button': 'showNewComponentForm' - 'click #save-draft': 'saveDraft' - 'click #delete-draft': 'deleteDraft' - 'click #create-draft': 'createDraft' - 'click #publish-draft': 'publishDraft' - 'change #visibility': 'setVisibility' + 'click .delete-draft': 'deleteDraft' + 'click .create-draft': 'createDraft' + 'click .publish-draft': 'publishDraft' + 'change .visibility-select': 'setVisibility' initialize: => @visibilityView = new CMS.Views.UnitEdit.Visibility( @@ -17,11 +16,6 @@ class CMS.Views.UnitEdit extends Backbone.View model: @model ) - @saveView = new CMS.Views.UnitEdit.SaveDraftButton( - el: @$('#save-draft') - model: @model - ) - @locationView = new CMS.Views.UnitEdit.LocationState( el: @$('.section-item.editing a') model: @model @@ -41,7 +35,7 @@ class CMS.Views.UnitEdit extends Backbone.View @$('.components').sortable( handle: '.drag-handle' - update: (event, ui) => @model.set('children', @components()) + update: (event, ui) => @model.save(children: @components()) helper: 'clone' opacity: '0.5' placeholder: 'component-placeholder' @@ -58,7 +52,6 @@ class CMS.Views.UnitEdit extends Backbone.View id: $(element).data('id'), ) ) - update: (event, ui) => @model.set('children', @components()) ) # New component creation @@ -124,7 +117,7 @@ class CMS.Views.UnitEdit extends Backbone.View id: $component.data('id') }, => $component.remove() - @model.set('children', @components()) + @model.save(children: @components()) ) deleteDraft: (event) -> @@ -167,7 +160,7 @@ class CMS.Views.UnitEdit extends Backbone.View $.post(target_url, { id: @$el.data('id') }, => - @model.set('state', @$('#visibility').val()) + @model.set('state', @$('.visibility-select').val()) ) class CMS.Views.UnitEdit.NameEdit extends Backbone.View @@ -187,7 +180,6 @@ class CMS.Views.UnitEdit.NameEdit extends Backbone.View metadata = $.extend({}, @model.get('metadata')) metadata.display_name = @$('.unit-display-name-input').val() $('.unit-location .editing .unit-name').html(metadata.display_name) - @model.set 'metadata', metadata inputField = this.$el.find('input') @@ -204,7 +196,7 @@ class CMS.Views.UnitEdit.NameEdit extends Backbone.View if @timer clearTimeout @timer @timer = setTimeout( => - @model.save() + @model.save(metadata: metadata) @timer = null @$spinner.delay(500).fadeOut(150) , 500) @@ -223,18 +215,3 @@ class CMS.Views.UnitEdit.Visibility extends Backbone.View render: => @$el.val(@model.get('state')) - -class CMS.Views.UnitEdit.SaveDraftButton extends Backbone.View - initialize: => - @model.on('change:children', @enable) - @model.on('change:metadata', @enable) - @model.on('sync', @disable) - - @disable() - - disable: => - @$el.addClass('disabled') - - enable: => - @$el.removeClass('disabled') - @model.save() \ No newline at end of file diff --git a/cms/static/sass/_unit.scss b/cms/static/sass/_unit.scss index 8bebc335ef..a5208305a3 100644 --- a/cms/static/sass/_unit.scss +++ b/cms/static/sass/_unit.scss @@ -269,7 +269,7 @@ font-weight: 700; } - .save-button { + .ave-button { margin-top: 10px; margin: 15px 8px 0 0; } @@ -321,16 +321,15 @@ @include orange-button; } - .save-button { + .delete-button { @include blue-button; - display: none; } - #delete-draft { + .delete-draft { display: inline-block; } - .save-button, + .delete-button, .preview-button, .publish-button, .view-button { @@ -447,11 +446,10 @@ } .edit-state-public { - #save-draft, - #delete-draft, + .delete-draft, .component-actions, .new-component-item, - #published-alert, + .editing-draft-alert, .publish-draft-message, .preview-button { display: none; @@ -467,10 +465,10 @@ } .edit-state-private { - #delete-draft, - #publish-draft, - #published-alert, - #create-draft, + .delete-draft, + .publish-draft, + .editing-draft-alert, + .create-draft, .view-button { display: none; } diff --git a/cms/templates/unit.html b/cms/templates/unit.html index f78b802627..a94557b760 100644 --- a/cms/templates/unit.html +++ b/cms/templates/unit.html @@ -17,7 +17,7 @@ <%block name="content">
-
+

You are editing a draft. % if published_date: This unit was originally published on ${published_date}. @@ -75,21 +75,20 @@

-
-

This unit has been published. To make changes, you must edit a draft.

-

This is a draft of the published unit. To update the live version, you must replace it with this draft.

+

This unit has been published. To make changes, you must edit a draft.

+

This is a draft of the published unit. To update the live version, you must replace it with this draft.

This unit is scheduled to be released to students on ${release_date} with the subsection "${subsection.display_name}"

From 9dc6cdbda0d60ee78ae1f35e3e1b0f2875d79a5a Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 24 Oct 2012 15:18:03 -0400 Subject: [PATCH 3/4] Remove vestigial save-subsection button --- cms/static/js/base.js | 15 ++++++--------- cms/templates/edit_subsection.html | 4 +--- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/cms/static/js/base.js b/cms/static/js/base.js index 17a0b33ca3..cf0b49ef90 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -33,7 +33,6 @@ $(document).ready(function() { $('.unit .item-actions .delete-button').bind('click', deleteUnit); $('.new-unit-item').bind('click', createNewUnit); - $('.save-subsection').bind('click', saveSubsection); // autosave when a field is updated on the subsection page $body.on('keyup', '.subsection-display-name-input, .unit-subtitle, .policy-list-value', checkForNewValue); @@ -169,7 +168,7 @@ function savePolicyMetadata(e) { e.preventDefault(); var $policyElement = $(this).parents('.policy-list-element'); - $('.save-subsection').click(); + saveSubsection() $policyElement.removeClass('new-policy-list-element'); $policyElement.find('.policy-list-name').attr('disabled', 'disabled'); $policyElement.removeClass('editing'); @@ -202,7 +201,7 @@ function removePolicyMetadata(e) { } else { _parent_el.appendTo("#policy-to-delete"); } - $('.save-subsection').click(); + saveSubsection() } @@ -299,7 +298,7 @@ function checkForNewValue(e) { this.saveTimer = setTimeout(function() { $changedInput = $(e.target); - $('.save-subsection').click(); + saveSubsection() this.saveTimer = null; }, 500); } @@ -312,14 +311,12 @@ function autosaveInput(e) { this.saveTimer = setTimeout(function() { $changedInput = $(e.target); - $('.save-subsection').click(); + saveSubsection() this.saveTimer = null; }, 500); } -function saveSubsection(e) { - e.preventDefault(); - +function saveSubsection() { if($changedInput && !$changedInput.hasClass('no-spinner')) { $spinner.css({ 'position': 'absolute', @@ -331,7 +328,7 @@ function saveSubsection(e) { $spinner.show(); } - var id = $(this).data('id'); + var id = $('.subsection-body').data('id'); // pull all 'normalized' metadata editable fields on page var metadata_fields = $('input[data-metadata-name]'); diff --git a/cms/templates/edit_subsection.html b/cms/templates/edit_subsection.html index b3e4031822..e1dd91c162 100644 --- a/cms/templates/edit_subsection.html +++ b/cms/templates/edit_subsection.html @@ -18,7 +18,7 @@
-
+
@@ -37,7 +37,6 @@ % for policy_name in policy_metadata.keys():
  • - Save Cancel
  • @@ -101,7 +100,6 @@
    - Save Preview Drafts %if can_view_live: View Live From 171b6b56fe78d090facebcd9f358d9df8d1e31ea Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 24 Oct 2012 15:31:00 -0400 Subject: [PATCH 4/4] Fix typo --- cms/static/sass/_unit.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cms/static/sass/_unit.scss b/cms/static/sass/_unit.scss index a5208305a3..220bec507d 100644 --- a/cms/static/sass/_unit.scss +++ b/cms/static/sass/_unit.scss @@ -269,7 +269,7 @@ font-weight: 700; } - .ave-button { + .save-button { margin-top: 10px; margin: 15px 8px 0 0; }