added null check for prop editors, got the RTE media picker working properly with correct styles and using the server data.
This commit is contained in:
@@ -1,20 +1,29 @@
|
||||
//used for the media picker dialog
|
||||
angular.module("umbraco")
|
||||
.controller("Umbraco.Dialogs.MediaPickerController",
|
||||
function($scope, mediaResource) {
|
||||
function ($scope, mediaResource, umbImageHelper) {
|
||||
|
||||
mediaResource.rootMedia()
|
||||
.then(function(data) {
|
||||
$scope.images = data;
|
||||
//update the thumbnail property
|
||||
_.each($scope.images, function(img) {
|
||||
img.thumbnail = umbImageHelper.getThumbnail({ imageModel: img, scope: $scope });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$scope.selectMediaItem = function(image) {
|
||||
if (image.contentTypeAlias.toLowerCase() == 'folder') {
|
||||
mediaResource.getChildren(image.id)
|
||||
.then(function(data) {
|
||||
$scope.images = data;
|
||||
//update the thumbnail property
|
||||
_.each($scope.images, function (img) {
|
||||
img.thumbnail = umbImageHelper.getThumbnail({ imageModel: img, scope: $scope });
|
||||
});
|
||||
});
|
||||
} else if (image.contentTypeAlias.toLowerCase() == 'image') {
|
||||
}
|
||||
else if (image.contentTypeAlias.toLowerCase() == 'image') {
|
||||
$scope.select(image);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -37,8 +37,12 @@ angular.module("umbraco")
|
||||
return item.alias == 'umbracoFile';
|
||||
});
|
||||
|
||||
var imageData = $scope.$eval(imageProperty.value);
|
||||
|
||||
var data = {
|
||||
src: imageProperty != null ? imageProperty.value : "nothing.jpg",
|
||||
src: (imageData != null && imageData.length && imageData.length > 0)
|
||||
? imageData[0].file
|
||||
: "nothing.jpg",
|
||||
style: 'width: 100px; height: 100px',
|
||||
id: '__mcenew'
|
||||
};
|
||||
|
||||
@@ -1,5 +1,38 @@
|
||||
/*Contains multiple services for various helper tasks */
|
||||
|
||||
/**
|
||||
* @ngdoc factory
|
||||
* @name umbraco.services:umbImageHelper
|
||||
* @description A helper object used for parsing image paths
|
||||
**/
|
||||
function umbImageHelper() {
|
||||
return {
|
||||
/** formats the display model used to display the content to the model used to save the content */
|
||||
getThumbnail: 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 = options.scope.$eval(imageProp.value);
|
||||
if (imageVal.length && imageVal.length >0 && imageVal[0].isImage) {
|
||||
return this.getThumbnailFromPath(imageVal[0].file);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
},
|
||||
getThumbnailFromPath: function(imagePath) {
|
||||
var ext = imagePath.substr(imagePath.lastIndexOf('.'));
|
||||
return imagePath.substr(0, imagePath.lastIndexOf('.')) + "_thumb" + ext;
|
||||
}
|
||||
};
|
||||
}
|
||||
angular.module('umbraco.services').factory('umbImageHelper', umbImageHelper);
|
||||
|
||||
/**
|
||||
* @ngdoc factory
|
||||
* @name umbraco.services:umbRequestHelper
|
||||
|
||||
@@ -1,20 +1,29 @@
|
||||
//used for the media picker dialog
|
||||
angular.module("umbraco")
|
||||
.controller("Umbraco.Dialogs.MediaPickerController",
|
||||
function($scope, mediaResource) {
|
||||
function ($scope, mediaResource, umbImageHelper) {
|
||||
|
||||
mediaResource.rootMedia()
|
||||
.then(function(data) {
|
||||
$scope.images = data;
|
||||
//update the thumbnail property
|
||||
_.each($scope.images, function(img) {
|
||||
img.thumbnail = umbImageHelper.getThumbnail({ imageModel: img, scope: $scope });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$scope.selectMediaItem = function(image) {
|
||||
if (image.contentTypeAlias.toLowerCase() == 'folder') {
|
||||
mediaResource.getChildren(image.id)
|
||||
.then(function(data) {
|
||||
$scope.images = data;
|
||||
//update the thumbnail property
|
||||
_.each($scope.images, function (img) {
|
||||
img.thumbnail = umbImageHelper.getThumbnail({ imageModel: img, scope: $scope });
|
||||
});
|
||||
});
|
||||
} else if (image.contentTypeAlias.toLowerCase() == 'image') {
|
||||
}
|
||||
else if (image.contentTypeAlias.toLowerCase() == 'image') {
|
||||
$scope.select(image);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -37,11 +37,9 @@
|
||||
ng-click="selectMediaItem(image)"
|
||||
prevent-default>
|
||||
|
||||
<div ng-switch on="image.isImage" >
|
||||
<img ng-src="{{image.thumbnail}}" ng-switch-when="true" alt="{{image.name}}"/>
|
||||
<span ng-switch-default>
|
||||
<i class="icon-folder-close"></i>
|
||||
</span>
|
||||
<div ng-switch on="image.contentTypeAlias" >
|
||||
<img ng-src="{{image.thumbnail}}" ng-switch-when="Image" alt="{{image.name}}"/>
|
||||
<i ng-switch-default class="icon-folder-close"></i>
|
||||
</div>
|
||||
|
||||
{{image.name}}
|
||||
|
||||
@@ -37,8 +37,12 @@ angular.module("umbraco")
|
||||
return item.alias == 'umbracoFile';
|
||||
});
|
||||
|
||||
var imageData = $scope.$eval(imageProperty.value);
|
||||
|
||||
var data = {
|
||||
src: imageProperty != null ? imageProperty.value : "nothing.jpg",
|
||||
src: (imageData != null && imageData.length && imageData.length > 0)
|
||||
? imageData[0].file
|
||||
: "nothing.jpg",
|
||||
style: 'width: 100px; height: 100px',
|
||||
id: '__mcenew'
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@ define(['namespaceMgr'], function () {
|
||||
|
||||
Umbraco.Sys.registerNamespace("MyPackage.PropertyEditors");
|
||||
|
||||
MyPackage.PropertyEditors.FileUploadEditor = function ($scope, $element, $compile) {
|
||||
MyPackage.PropertyEditors.FileUploadEditor = function ($scope, $element, $compile, umbImageHelper) {
|
||||
|
||||
/** Clears the file collections when content is saving (if we need to clear) or after saved */
|
||||
function clearFiles() {
|
||||
@@ -40,8 +40,7 @@ define(['namespaceMgr'], function () {
|
||||
}
|
||||
|
||||
$scope.getThumbnail = function (file) {
|
||||
var ext = file.file.substr(file.file.lastIndexOf('.'));
|
||||
return file.file.substr(0, file.file.lastIndexOf('.')) + "_thumb" + ext;
|
||||
return umbImageHelper.getThumbnailFromPath(file.file);
|
||||
};
|
||||
|
||||
$scope.clearFiles = false;
|
||||
|
||||
@@ -37,11 +37,9 @@
|
||||
ng-click="selectMediaItem(image)"
|
||||
prevent-default>
|
||||
|
||||
<div ng-switch on="image.isImage" >
|
||||
<img ng-src="{{image.thumbnail}}" ng-switch-when="true" alt="{{image.name}}"/>
|
||||
<span ng-switch-default>
|
||||
<i class="icon-folder-close"></i>
|
||||
</span>
|
||||
<div ng-switch on="image.contentTypeAlias" >
|
||||
<img ng-src="{{image.thumbnail}}" ng-switch-when="Image" alt="{{image.name}}"/>
|
||||
<i ng-switch-default class="icon-folder-close"></i>
|
||||
</div>
|
||||
|
||||
{{image.name}}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.ModelBinding;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Editors;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
@@ -125,7 +126,14 @@ namespace Umbraco.Web.Editors
|
||||
var data = new ContentPropertyData(p.Value, d);
|
||||
|
||||
//get the deserialized value from the property editor
|
||||
dboProperty.Value = p.PropertyEditor.ValueEditor.DeserializeValue(data, dboProperty.Value);
|
||||
if (p.PropertyEditor == null)
|
||||
{
|
||||
LogHelper.Warn<ContentController>("No property editor found for property " + p.Alias);
|
||||
}
|
||||
else
|
||||
{
|
||||
dboProperty.Value = p.PropertyEditor.ValueEditor.DeserializeValue(data, dboProperty.Value);
|
||||
}
|
||||
}
|
||||
|
||||
//save the item
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.ModelBinding;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Editors;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
@@ -123,7 +124,14 @@ namespace Umbraco.Web.Editors
|
||||
var data = new ContentPropertyData(p.Value, d);
|
||||
|
||||
//get the deserialized value from the property editor
|
||||
dboProperty.Value = p.PropertyEditor.ValueEditor.DeserializeValue(data, dboProperty.Value);
|
||||
if (p.PropertyEditor == null)
|
||||
{
|
||||
LogHelper.Warn<MediaController>("No property editor found for property " + p.Alias);
|
||||
}
|
||||
else
|
||||
{
|
||||
dboProperty.Value = p.PropertyEditor.ValueEditor.DeserializeValue(data, dboProperty.Value);
|
||||
}
|
||||
}
|
||||
|
||||
//save the item
|
||||
|
||||
Reference in New Issue
Block a user