Fixed up the file uploading and the readonly property editors and saving/updating their data/control based on the data changed on the server side.

U4-2680 Fix file uploading
This commit is contained in:
Shannon
2013-08-21 17:54:30 +10:00
parent 466b2a1cb2
commit 5581af2d25
17 changed files with 362 additions and 146 deletions

View File

@@ -66,20 +66,39 @@ namespace Umbraco.Web.PropertyEditors
UmbracoSettings.ImageAutoFillImageProperties.SelectSingleNode(
string.Format("uploadField [@alias = \"{0}\"]", p.Alias));
if (uploadFieldConfigNode != null && p.Value != null && p.Value is string && ((string)p.Value).IsNullOrWhiteSpace() == false)
if (uploadFieldConfigNode != null)
{
//there might be multiple, we can only process the first one!
var split = ((string) p.Value).Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
if (split.Any())
//now we need to check if there is a value
if (p.Value is string && ((string) p.Value).IsNullOrWhiteSpace() == false)
{
var umbracoFile = new UmbracoMediaFile(IOHelper.MapPath(split[0]));
FillProperties(uploadFieldConfigNode, model, umbracoFile);
//there might be multiple, we can only process the first one!
var split = ((string) p.Value).Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
if (split.Any())
{
var umbracoFile = new UmbracoMediaFile(IOHelper.MapPath(split[0]));
FillProperties(uploadFieldConfigNode, model, umbracoFile);
}
}
else
{
//there's no value so need to reset to zero
ResetProperties(uploadFieldConfigNode, model);
}
}
}
}
}
private static void ResetProperties(XmlNode uploadFieldConfigNode, IContentBase content)
{
// only add dimensions to web images
UpdateContentProperty(uploadFieldConfigNode, content, "widthFieldAlias", string.Empty);
UpdateContentProperty(uploadFieldConfigNode, content, "heightFieldAlias", string.Empty);
UpdateContentProperty(uploadFieldConfigNode, content, "lengthFieldAlias", string.Empty);
UpdateContentProperty(uploadFieldConfigNode, content, "extensionFieldAlias", string.Empty);
}
private static void FillProperties(XmlNode uploadFieldConfigNode, IContentBase content, UmbracoMediaFile um)
{
// only add dimensions to web images

View File

@@ -28,7 +28,12 @@ namespace Umbraco.Web.PropertyEditors
/// <summary>
/// Overrides the deserialize value so that we can save the file accordingly
/// </summary>
/// <param name="editorValue"></param>
/// <param name="editorValue">
/// This is value passed in from the editor. We normally don't care what the editorValue.Value is set to because
/// we are more interested in the files collection associated with it, however we do care about the value if we
/// are clearing files. By default the editorValue.Value will just be set to the name of the file (but again, we
/// just ignore this and deal with the file collection in editorValue.AdditionalData.ContainsKey("files") )
/// </param>
/// <param name="currentValue">
/// The current value persisted for this property. This will allow us to determine if we want to create a new
/// file path or use the existing file path.
@@ -36,16 +41,20 @@ namespace Umbraco.Web.PropertyEditors
/// <returns></returns>
public override object DeserializeValue(ContentPropertyData editorValue, object currentValue)
{
if (currentValue == null)
{
currentValue = string.Empty;
}
//if the value is the same then just return the current value
if (currentValue != null && editorValue.Value == currentValue.ToString())
//if the value is the same then just return the current value so we don't re-process everything
if (string.IsNullOrEmpty(currentValue.ToString()) == false && editorValue.Value == currentValue.ToString())
{
return currentValue;
}
//check the editorValue value to see if we need to clear the files or not
//check the editorValue value to see if we need to clear the files or not.
var clear = false;
if (editorValue.Value.IsNullOrWhiteSpace() == false)
if (editorValue.Value.IsNullOrWhiteSpace() == false && editorValue.Value.StartsWith("{clearFiles:"))
{
try
{
@@ -59,7 +68,7 @@ namespace Umbraco.Web.PropertyEditors
}
var currentPersistedValues = new string[] {};
if (currentValue != null)
if (string.IsNullOrEmpty(currentValue.ToString()) == false)
{
currentPersistedValues = currentValue.ToString().Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
}