diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/upload/umbpropertyfileupload.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/upload/umbpropertyfileupload.directive.js index 52983efd87..b8afc4b35e 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/upload/umbpropertyfileupload.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/upload/umbpropertyfileupload.directive.js @@ -51,6 +51,19 @@ vm.fileUploadForm.$setDirty(); } + function notifyInit(val, files) { + if (!val) { + val = null; + } + if (!files) { + files = null; + } + + if (vm.onInit) { + vm.onInit({ value: val, files: files }); + } + } + /** Called when the component initializes */ function onInit() { $scope.$on("filesSelected", onFilesSelected); @@ -85,7 +98,7 @@ if (existingClientFiles.length > 0) { updateModelFromSelectedFiles(existingClientFiles).then(function(newVal) { //notify the callback - vm.onValueChanged({ value: newVal, files: vm.files }); + notifyInit(newVal, vm.files); }); } else if (vm.value) { @@ -101,12 +114,16 @@ f.fileSrc = getThumbnail(f); return f; }); + + //notify the callback + notifyInit(); } else { vm.files = []; - } - //vm.clearFiles = false; + //notify the callback + notifyInit(); + } } ///** Method required by the valPropertyValidator directive (returns true if the property editor has at least one file selected) */ @@ -250,8 +267,9 @@ culture: "@?", propertyAlias: "@", value: "<", + hideSelection: "<", onValueChanged: "&", - hideSelection: "<" + onInit: "&" }, transclude: true, controllerAs: 'vm', diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js index 206ca08dac..33840e87d9 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js @@ -332,12 +332,15 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) { */ getById: function (id) { return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "contentApiBaseUrl", - "GetById", - { id: id })), - 'Failed to retrieve data for content id ' + id); + $http.get( + umbRequestHelper.getApiUrl( + "contentApiBaseUrl", + "GetById", + { id: id })), + 'Failed to retrieve data for content id ' + id) + .then(function(result) { + return $q.when(umbDataFormatter.formatContentGetData(result)); + }); }, getBlueprintById: function (id) { diff --git a/src/Umbraco.Web.UI.Client/src/common/services/umbdataformatter.service.js b/src/Umbraco.Web.UI.Client/src/common/services/umbdataformatter.service.js index 38c02338ee..77ca2b6157 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/umbdataformatter.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/umbdataformatter.service.js @@ -383,6 +383,52 @@ saveModel.templateAlias = propTemplate ? propTemplate : null; return saveModel; + }, + + /** + * This formats the server GET response for a content display item + * @param {} displayModel + * @returns {} + */ + formatContentGetData: function(displayModel) { + + //We need to check for invariant properties among the variant variants. + //When we detect this, we want to make sure that the property object instance is the + //same reference object between all variants instead of a copy (which it will be when + //return from the JSON structure). + + if (displayModel.variants && displayModel.variants.length > 1) { + + var invariantProperties = []; + + //collect all invariant properties on the first first variant + var firstVariant = displayModel.variants[0]; + _.each(firstVariant.tabs, function(tab, tabIndex) { + _.each(tab.properties, function (property, propIndex) { + //in theory if there's more than 1 variant, that means they would all have a language + //but we'll do our safety checks anyways here + if (firstVariant.language && !property.culture) { + invariantProperties.push({ + tabIndex: tabIndex, + propIndex: propIndex, + property: property + }); + } + }); + }); + + + //now assign this same invariant property instance to the same index of the other variants property array + for (var j = 1; j < displayModel.variants.length; j++) { + var variant = displayModel.variants[j]; + + _.each(invariantProperties, function (invProp) { + variant.tabs[invProp.tabIndex].properties[invProp.propIndex] = invProp.property; + }); + } + } + + return displayModel; } }; } diff --git a/src/Umbraco.Web.UI.Client/src/views/components/upload/umb-property-file-upload.html b/src/Umbraco.Web.UI.Client/src/views/components/upload/umb-property-file-upload.html index 5729bf0908..f205dffa57 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/upload/umb-property-file-upload.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/upload/umb-property-file-upload.html @@ -8,9 +8,7 @@
{{vm.files.length}}
-
+