Commit 6b45b4c7 by Chris Dodge

bind the disabling/enabling of the unit name input field based on whether the…

bind the disabling/enabling of the unit name input field based on whether the page state is public or not. We shouldn't be able to edit when public.
parent e35d1483
...@@ -581,7 +581,10 @@ def save_item(request): ...@@ -581,7 +581,10 @@ def save_item(request):
data = request.POST['data'] data = request.POST['data']
store.update_item(item_location, data) store.update_item(item_location, data)
if request.POST.get('children') is not None: # cdodge: note calling request.POST.get('children') will return None if children is an empty array
# so it lead to a bug whereby the last component to be deleted in the UI was not actually
# deleting the children object from the children collection
if 'children' in request.POST and request.POST['children'] is not None:
children = request.POST['children'] children = request.POST['children']
store.update_children(item_location, children) store.update_children(item_location, children)
......
...@@ -169,12 +169,21 @@ class CMS.Views.UnitEdit.NameEdit extends Backbone.View ...@@ -169,12 +169,21 @@ class CMS.Views.UnitEdit.NameEdit extends Backbone.View
initialize: => initialize: =>
@model.on('change:metadata', @render) @model.on('change:metadata', @render)
@model.on('change:state', @setEnabled)
@setEnabled()
@saveName @saveName
@$spinner = $('<span class="spinner-in-field-icon"></span>'); @$spinner = $('<span class="spinner-in-field-icon"></span>');
render: => render: =>
@$('.unit-display-name-input').val(@model.get('metadata').display_name) @$('.unit-display-name-input').val(@model.get('metadata').display_name)
setEnabled: =>
disabled = @model.get('state') == 'public'
if disabled
@$('.unit-display-name-input').attr('disabled', true)
else
@$('.unit-display-name-input').removeAttr('disabled')
saveName: => saveName: =>
# Treat the metadata dictionary as immutable # Treat the metadata dictionary as immutable
metadata = $.extend({}, @model.get('metadata')) metadata = $.extend({}, @model.get('metadata'))
...@@ -196,7 +205,7 @@ class CMS.Views.UnitEdit.NameEdit extends Backbone.View ...@@ -196,7 +205,7 @@ class CMS.Views.UnitEdit.NameEdit extends Backbone.View
if @timer if @timer
clearTimeout @timer clearTimeout @timer
@timer = setTimeout( => @timer = setTimeout( =>
@model.save(metadata: metadata) @model.save(metadata: metadata, children: null)
@timer = null @timer = null
@$spinner.delay(500).fadeOut(150) @$spinner.delay(500).fadeOut(150)
, 500) , 500)
......
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