diff --git a/.gitignore b/.gitignore index e3bc4fa3d1..54827f7960 100644 --- a/.gitignore +++ b/.gitignore @@ -79,3 +79,4 @@ src/Umbraco.Web.UI.Client/build/* src/Umbraco.Web.UI.Client/build/* src/Umbraco.Web.UI.Client/build/belle/ src/Umbraco.Web.UI/UserControls/ +build/_BuildOutput/ diff --git a/src/Umbraco.Web.UI.Client/build/belle/views/propertyeditors/umbraco/rte/rte.controller.js b/src/Umbraco.Web.UI.Client/build/belle/views/propertyeditors/umbraco/rte/rte.controller.js index 861c0a9155..db87d14c9d 100644 --- a/src/Umbraco.Web.UI.Client/build/belle/views/propertyeditors/umbraco/rte/rte.controller.js +++ b/src/Umbraco.Web.UI.Client/build/belle/views/propertyeditors/umbraco/rte/rte.controller.js @@ -1,6 +1,6 @@ angular.module("umbraco") .controller("Umbraco.Editors.RTEController", - function($rootScope, $scope, dialogService, $log){ + function($rootScope, $scope, dialogService, $log, umbImageHelper){ require( [ 'tinymce' @@ -33,15 +33,11 @@ angular.module("umbraco") //really simple example on how to intergrate a service with tinyMCE $(data.selection).each(function (i, img) { - var imageProperty = _.find(img.properties, function(item) { - return item.alias == 'umbracoFile'; - }); - - var imageData = $scope.$eval(imageProperty.value); + var imagePropVal = umbImageHelper.getImagePropertyVaue({imageModel: img, scope: $scope}); var data = { - src: (imageData != null && imageData.length && imageData.length > 0) - ? imageData[0].file + src: (imagePropVal != null && imagePropVal != "") + ? imagePropVal : "nothing.jpg", style: 'width: 100px; height: 100px', id: '__mcenew' diff --git a/src/Umbraco.Web.UI.Client/src/common/services/utill.service.js b/src/Umbraco.Web.UI.Client/src/common/services/utill.service.js index 711157924e..a04afdfbae 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/utill.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/utill.service.js @@ -7,6 +7,31 @@ **/ function umbImageHelper() { return { + /** Returns the actual image path associated with the image property if there is one */ + getImagePropertyVaue: function(options) { + if (!options && !options.imageModel && !options.scope) { + throw "The options objet does not contain the required parameters: imageModel, scope"; + } + if (options.imageModel.contentTypeAlias.toLowerCase() == "image") { + var imageProp = _.find(options.imageModel.properties, function (item) { + return item.alias == 'umbracoFile'; + }); + var imageVal; + //Legacy images will be saved as a string, not an array so we will convert the legacy values + // to our required structure. + if (imageProp.value.startsWith('[')) { + imageVal = options.scope.$eval(imageProp.value); + } + else { + imageVal = [{ file: imageProp.value, isImage: this.detectIfImageByExtension(imageProp.value) }]; + } + + if (imageVal.length && imageVal.length > 0 && imageVal[0].isImage) { + return imageVal[0].file; + } + } + return ""; + }, /** formats the display model used to display the content to the model used to save the content */ getThumbnail: function (options) { @@ -14,20 +39,22 @@ function umbImageHelper() { throw "The options objet does not contain the required parameters: imageModel, scope"; } - if (options.imageModel.contentTypeAlias.toLowerCase() === "image") { - var imageProp = _.find(options.imageModel.properties, function (item) { - return item.alias === 'umbracoFile'; - }); - var imageVal = options.scope.$eval(imageProp.value); - if (imageVal.length && imageVal.length >0 && imageVal[0].isImage) { - return this.getThumbnailFromPath(imageVal[0].file); - } + var imagePropVal = this.getImagePropertyVaue(options); + if (imagePropVal != "") { + return this.getThumbnailFromPath(imagePropVal); } return ""; }, getThumbnailFromPath: function(imagePath) { var ext = imagePath.substr(imagePath.lastIndexOf('.')); - return imagePath.substr(0, imagePath.lastIndexOf('.')) + "_thumb" + ext; + return imagePath.substr(0, imagePath.lastIndexOf('.')) + "_thumb" + ".jpg"; + }, + detectIfImageByExtension: function(imagePath) { + var lowered = imagePath; + if (lowered.endsWith(".jpg") || lowered.endsWith(".gif") || lowered.endsWith(".jpeg") || lowered.endsWith(".png")) { + return true; + } + return false; } }; } diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/umbraco/rte/rte.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/umbraco/rte/rte.controller.js index 861c0a9155..db87d14c9d 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/umbraco/rte/rte.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/umbraco/rte/rte.controller.js @@ -1,6 +1,6 @@ angular.module("umbraco") .controller("Umbraco.Editors.RTEController", - function($rootScope, $scope, dialogService, $log){ + function($rootScope, $scope, dialogService, $log, umbImageHelper){ require( [ 'tinymce' @@ -33,15 +33,11 @@ angular.module("umbraco") //really simple example on how to intergrate a service with tinyMCE $(data.selection).each(function (i, img) { - var imageProperty = _.find(img.properties, function(item) { - return item.alias == 'umbracoFile'; - }); - - var imageData = $scope.$eval(imageProperty.value); + var imagePropVal = umbImageHelper.getImagePropertyVaue({imageModel: img, scope: $scope}); var data = { - src: (imageData != null && imageData.length && imageData.length > 0) - ? imageData[0].file + src: (imagePropVal != null && imagePropVal != "") + ? imagePropVal : "nothing.jpg", style: 'width: 100px; height: 100px', id: '__mcenew' diff --git a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/FileUploadEditor.js b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/FileUploadEditor.js index 8f87d2864e..cb5eb5c062 100644 --- a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/FileUploadEditor.js +++ b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Js/FileUploadEditor.js @@ -25,11 +25,7 @@ define(['namespaceMgr'], function () { if (!$scope.model.value.startsWith('[')) { //check if it ends with a common image extensions - var lowered = $scope.model.value.toLowerCase(); - var isImage = false; - if (lowered.endsWith(".jpg") || lowered.endsWith(".gif") || lowered.endsWith(".jpeg") || lowered.endsWith(".png")) { - isImage = true; - } + var isImage = umbImageHelper.detectIfImageByExtension($scope.model.value); $scope.model.value = "[{\"file\": \"" + $scope.model.value + "\",\"isImage\":" + isImage +"}]"; } @@ -39,9 +35,10 @@ define(['namespaceMgr'], function () { $scope.persistedFiles = []; } - $scope.getThumbnail = function (file) { - return umbImageHelper.getThumbnailFromPath(file.file); - }; + _.each($scope.persistedFiles, function(file) { + file.thumbnail = umbImageHelper.getThumbnailFromPath(file.file); + }); + $scope.clearFiles = false; diff --git a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Views/FileUploadEditor.html b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Views/FileUploadEditor.html index 586304e3ce..f352b350a1 100644 --- a/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Views/FileUploadEditor.html +++ b/src/Umbraco.Web.UI/App_Plugins/MyPackage/PropertyEditors/Views/FileUploadEditor.html @@ -14,7 +14,7 @@