U4-4447: Make image properties populate when uploading from ImageCropper

This commit is contained in:
arknu
2014-03-18 22:31:05 +01:00
parent 4bcf3983c5
commit 1948fe12b3
2 changed files with 24 additions and 14 deletions

View File

@@ -66,7 +66,7 @@ namespace Umbraco.Web.PropertyEditors
static void AutoFillProperties(IContentBase model)
{
var mediaFileSystem = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
foreach (var p in model.Properties)
foreach (var p in model.Properties.Where(x => x.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.UploadFieldAlias))
{
var uploadFieldConfigNode =
UmbracoConfig.For.UmbracoSettings().Content.ImageAutoFillProperties

View File

@@ -63,7 +63,7 @@ namespace Umbraco.Web.PropertyEditors
static void AutoFillProperties(IContentBase model)
{
var mediaFileSystem = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
foreach (var p in model.Properties.Where(x => x.PropertyType.Alias == Constants.PropertyEditors.ImageCropperAlias))
foreach (var p in model.Properties.Where(x => x.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.ImageCropperAlias))
{
var uploadFieldConfigNode =
UmbracoConfig.For.UmbracoSettings().Content.ImageAutoFillProperties
@@ -71,18 +71,28 @@ namespace Umbraco.Web.PropertyEditors
if (uploadFieldConfigNode != null)
{
if (p.Value != null){
var json = p.Value as JObject;
if (json != null && json["src"] != null)
model.PopulateFileMetaDataProperties(uploadFieldConfigNode, json["src"].Value<string>());
else if (p.Value is string)
{
var config = ApplicationContext.Current.Services.DataTypeService.GetPreValuesByDataTypeId(p.PropertyType.DataTypeDefinitionId).FirstOrDefault();
var crops = !string.IsNullOrEmpty(config) ? config : "[]";
p.Value = "{src: '" + p.Value + "', crops: " + crops + "}";
model.PopulateFileMetaDataProperties(uploadFieldConfigNode, p.Value);
}
}else
if (p.Value != null)
{
JObject json = null;
try
{
json = JObject.Parse((string)p.Value);
}
catch (Newtonsoft.Json.JsonException ex)
{
}
if (json != null && json["src"] != null)
model.PopulateFileMetaDataProperties(uploadFieldConfigNode, json["src"].Value<string>());
else if (p.Value is string)
{
var config = ApplicationContext.Current.Services.DataTypeService.GetPreValuesByDataTypeId(p.PropertyType.DataTypeDefinitionId).FirstOrDefault();
var crops = !string.IsNullOrEmpty(config) ? config : "[]";
p.Value = "{src: '" + p.Value + "', crops: " + crops + "}";
model.PopulateFileMetaDataProperties(uploadFieldConfigNode, p.Value);
}
}
else
model.ResetFileMetaDataProperties(uploadFieldConfigNode);
}
}