Fixes: U4-4999 Image cropper - Image file duplicated each time the page (content) is saved/published
This commit is contained in:
@@ -25,6 +25,9 @@ function fileUploadController($scope, $element, $compile, imageHelper, fileManag
|
||||
|
||||
/** this method is used to initialize the data and to re-initialize it if the server value is changed */
|
||||
function initialize(index) {
|
||||
|
||||
clearFiles();
|
||||
|
||||
if (!index) {
|
||||
index = 1;
|
||||
}
|
||||
@@ -116,9 +119,6 @@ function fileUploadController($scope, $element, $compile, imageHelper, fileManag
|
||||
initialize($scope.rebuildInput.index + 1);
|
||||
}
|
||||
|
||||
//if (newVal !== "{clearFiles: true}" && newVal !== $scope.originalValue && !newVal.startsWith("{selectedFiles:")) {
|
||||
// initialize($scope.rebuildInput.index + 1);
|
||||
//}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -88,6 +88,13 @@ angular.module('umbraco')
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//here we declare a special method which will be called whenever the value has changed from the server
|
||||
$scope.model.onValueChanged = function (newVal, oldVal) {
|
||||
//clear current uploaded files
|
||||
fileManager.setFiles($scope.model.alias, []);
|
||||
};
|
||||
|
||||
var unsubscribe = $scope.$on("formSubmitting", function () {
|
||||
$scope.done();
|
||||
});
|
||||
|
||||
@@ -10,6 +10,7 @@ using System.Threading.Tasks;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Media;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Editors;
|
||||
@@ -50,11 +51,22 @@ namespace Umbraco.Web.PropertyEditors
|
||||
JObject oldJson = null;
|
||||
|
||||
//get the old src path
|
||||
if (currentValue != null)
|
||||
if (string.IsNullOrEmpty(currentValue.ToString()) == false)
|
||||
{
|
||||
oldJson = currentValue as JObject;
|
||||
try
|
||||
{
|
||||
oldJson = JObject.Parse(currentValue.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//for some reason the value is invalid so continue as if there was no value there
|
||||
LogHelper.WarnWithException<ImageCropperPropertyValueEditor>("Could not parse current db value to a JObject", ex);
|
||||
}
|
||||
|
||||
if (oldJson != null && oldJson["src"] != null)
|
||||
{
|
||||
oldFile = oldJson["src"].Value<string>();
|
||||
}
|
||||
}
|
||||
|
||||
//get the new src path
|
||||
@@ -62,7 +74,9 @@ namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
newJson = editorValue.Value as JObject;
|
||||
if (newJson != null && newJson["src"] != null)
|
||||
{
|
||||
newFile = newJson["src"].Value<string>();
|
||||
}
|
||||
}
|
||||
|
||||
//compare old and new src path
|
||||
|
||||
Reference in New Issue
Block a user