diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index ba362ec91a..f33324cf18 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -161,12 +161,28 @@ def edit_subsection(request, location): if item.location.category != 'sequential': return HttpResponseBadRequest - logging.debug('Start = {0}'.format(item.start)) + parent_locs = modulestore().get_parent_locations(location) + + # we're for now assuming a single parent + if len(parent_locs) != 1: + logging.error('Multiple (or none) parents have been found for {0}'.format(location)) + + # this should blow up if we don't find any parents, which would be erroneous + parent = modulestore().get_item(parent_locs[0]) + + # remove all metadata from the generic dictionary that is presented in a more normalized UI + + policy_metadata = dict((key,value) for key, value in item.metadata.iteritems() + if key not in ['display_name', 'start', 'due', 'format'] and key not in item.system_metadata_fields) + + logging.debug(policy_metadata) return render_to_response('edit_subsection.html', {'subsection': item, 'create_new_unit_template': Location('i4x', 'edx', 'templates', 'vertical', 'Empty'), - 'lms_link': lms_link + 'lms_link': lms_link, + 'parent_item' : parent, + 'policy_metadata' : policy_metadata }) @@ -485,9 +501,12 @@ def save_item(request): # update existing metadata with submitted metadata (which can be partial) # IMPORTANT NOTE: if the client passed pack 'null' (None) for a piece of metadata that means 'remove it' for metadata_key in posted_metadata.keys(): - # NOTE: We don't want clients to be able to delete 'system metadata' which are not intended to be user - # editable - if posted_metadata[metadata_key] is None and metadata_key not in existing_item.system_metadata_fields: + + # let's strip out any metadata fields from the postback which have been identified as system metadata + # and therefore should not be user-editable, so we should accept them back from the client + if metadata_key in existing_item.system_metadata_fields: + del posted_metadata[metadata_key] + elif posted_metadata[metadata_key] is None: # remove both from passed in collection as well as the collection read in from the modulestore if metadata_key in existing_item.metadata: del existing_item.metadata[metadata_key] diff --git a/cms/static/js/base.js b/cms/static/js/base.js index 3127c1bd90..c56e24c482 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -36,8 +36,40 @@ $(document).ready(function() { $('.set-date').bind('click', showDateSetter); $('.remove-date').bind('click', removeDateSetter); + // add/remove policy metadata button click handlers + $('.add-policy-data').bind('click', addPolicyMetadata); + $('.remove-policy-data').bind('click', removePolicyMetadata); + + $('.sync-date').bind('click', syncReleaseDate); + }); +function syncReleaseDate(e) { + e.preventDefault(); + $("#start_date").val(""); + $("#start_time").val(""); +} + +function addPolicyMetadata(e) { + e.preventDefault(); + var template =$('#add-new-policy-element-template > li'); + var newNode = template.clone(); + var _parent_el = $(this).parent('ol:.policy-list'); + newNode.insertBefore('.add-policy-data'); + $('.remove-policy-data').bind('click', removePolicyMetadata); +} + +function removePolicyMetadata(e) { + e.preventDefault(); + policy_name = $(this).data('policy-name'); + var _parent_el = $(this).parent('li:.policy-list-element'); + if ($(_parent_el).hasClass("new-policy-list-element")) + _parent_el.remove(); + else + _parent_el.appendTo("#policy-to-delete"); +} + + // This method only changes the ordering of the child objects in a subsection function onUnitReordered() { var subsection_id = $(this).data('subsection-id'); @@ -86,7 +118,7 @@ function saveSubsection(e) { var id = $(this).data('id'); - // pull all metadata editable fields on page + // pull all 'normalized' metadata editable fields on page var metadata_fields = $('input[data-metadata-name]'); metadata = {}; @@ -95,6 +127,20 @@ function saveSubsection(e) { metadata[$(el).data("metadata-name")] = el.value; } + // now add 'free-formed' metadata which are presented to the user as dual input fields (name/value) + $('ol.policy-list > li.policy-list-element').each( function(i, element) { + name = $(element).children('.policy-list-name').val(); + val = $(element).children('.policy-list-value').val(); + metadata[name] = val; + }); + + // now add any 'removed' policy metadata which is stored in a separate hidden div + // 'null' presented to the server means 'remove' + $("#policy-to-delete > li.policy-list-element").each(function(i, element) { + name = $(element).children('.policy-list-name').val(); + if (name != "") + metadata[name] = null; + }); // Piece back together the date/time UI elements into one date/time string // NOTE: our various "date/time" metadata elements don't always utilize the same formatting string diff --git a/cms/static/sass/_base.scss b/cms/static/sass/_base.scss index e57c8338d5..ac93a0f60f 100644 --- a/cms/static/sass/_base.scss +++ b/cms/static/sass/_base.scss @@ -132,13 +132,15 @@ label { } .new-unit-item, -.new-subsection-item { +.new-subsection-item, +.new-policy-item { @include grey-button; margin: 5px 8px; padding: 3px 10px 4px 10px; font-size: 10px; .new-folder-icon, + .new-policy-icon, .new-unit-icon { position: relative; top: 2px; diff --git a/cms/static/sass/_graphics.scss b/cms/static/sass/_graphics.scss index 2214c333e0..83f8816b47 100644 --- a/cms/static/sass/_graphics.scss +++ b/cms/static/sass/_graphics.scss @@ -170,6 +170,14 @@ background: url(../img/new-unit-icon.png) right no-repeat; } +.new-policy-icon { + display: inline-block; + width: 23px; + height: 12px; + margin-right: 8px; + background: url(../img/new-unit-icon.png) right no-repeat; +} + .textbook-icon { display: inline-block; width: 32px; @@ -243,4 +251,4 @@ margin-left: 10px; vertical-align: middle; background: url(../img/blue-spinner.gif) no-repeat; -} \ No newline at end of file +} diff --git a/cms/templates/edit_subsection.html b/cms/templates/edit_subsection.html index 3fa1e135dd..e6eeed0963 100644 --- a/cms/templates/edit_subsection.html +++ b/cms/templates/edit_subsection.html @@ -19,25 +19,42 @@
-
- - -
-
- - -
-
- - ${units.enum_units(subsection)} -
-
- - -
+
+ + +
+
+ + +
+
+ + ${units.enum_units(subsection)} +
+
+ +
    + % for policy_name in policy_metadata.keys(): +
  1. + +
  2. + % endfor + + + New Policy Data + +
+
+ + + +