U4-8658 RTE Editor: Edit an existing image by clicking 'media picker' in toolbar, show a blank picker
This commit is contained in:
@@ -87,7 +87,8 @@ Use this directive to generate a list of folders presented as a flexbox grid.
|
||||
|
||||
scope.clickFolder = function(folder, $event, $index) {
|
||||
if(scope.onClick) {
|
||||
scope.onClick(folder, $event, $index);
|
||||
scope.onClick(folder, $event, $index);
|
||||
$event.stopPropagation();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -247,6 +247,7 @@ Use this directive to generate a thumbnail grid of media items.
|
||||
scope.clickItem = function(item, $event, $index) {
|
||||
if (scope.onClick) {
|
||||
scope.onClick(item, $event, $index);
|
||||
$event.stopPropagation();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -21,7 +21,9 @@ function mediaTypeHelper(mediaTypeResource, $q) {
|
||||
},
|
||||
|
||||
getAllowedImagetypes: function (mediaId){
|
||||
|
||||
|
||||
//TODO: This is horribly inneficient - why make one request per type!?
|
||||
|
||||
// Get All allowedTypes
|
||||
return mediaTypeResource.getAllowedTypes(mediaId)
|
||||
.then(function(types){
|
||||
|
||||
@@ -119,7 +119,7 @@ angular.module("umbraco")
|
||||
localStorageService.set("umbLastOpenedMediaNodeId", folder.id);
|
||||
};
|
||||
|
||||
$scope.clickHandler = function(image, event, index) {
|
||||
$scope.clickHandler = function (image, event, index) {
|
||||
if (image.isFolder) {
|
||||
if ($scope.disableFolderSelect) {
|
||||
$scope.gotoFolder(image);
|
||||
@@ -179,27 +179,49 @@ angular.module("umbraco")
|
||||
$scope.activeDrag = false;
|
||||
};
|
||||
|
||||
function ensureWithinStartNode(node) {
|
||||
// make sure that last opened node is on the same path as start node
|
||||
var nodePath = node.path.split(",");
|
||||
|
||||
if (nodePath.indexOf($scope.startNodeId.toString()) !== -1) {
|
||||
$scope.gotoFolder({ id: $scope.lastOpenedNode, name: "Media", icon: "icon-folder" });
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
$scope.gotoFolder({ id: $scope.startNodeId, name: "Media", icon: "icon-folder" });
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function gotoStartNode(err) {
|
||||
$scope.gotoFolder({ id: $scope.startNodeId, name: "Media", icon: "icon-folder" });
|
||||
}
|
||||
|
||||
//default root item
|
||||
if (!$scope.target) {
|
||||
if ($scope.lastOpenedNode && $scope.lastOpenedNode !== -1) {
|
||||
entityResource.getById($scope.lastOpenedNode, "media")
|
||||
.then(function(node) {
|
||||
// make sure that las opened node is on the same path as start node
|
||||
var nodePath = node.path.split(",");
|
||||
|
||||
if (nodePath.indexOf($scope.startNodeId.toString()) !== -1) {
|
||||
$scope
|
||||
.gotoFolder({ id: $scope.lastOpenedNode, name: "Media", icon: "icon-folder" });
|
||||
} else {
|
||||
$scope.gotoFolder({ id: $scope.startNodeId, name: "Media", icon: "icon-folder" });
|
||||
}
|
||||
},
|
||||
function(err) {
|
||||
$scope.gotoFolder({ id: $scope.startNodeId, name: "Media", icon: "icon-folder" });
|
||||
});
|
||||
} else {
|
||||
$scope.gotoFolder({ id: $scope.startNodeId, name: "Media", icon: "icon-folder" });
|
||||
.then(ensureWithinStartNode, gotoStartNode);
|
||||
}
|
||||
else {
|
||||
gotoStartNode();
|
||||
}
|
||||
}
|
||||
else {
|
||||
//if a target is specified, go look it up - generally this target will just contain ids not the actual full
|
||||
//media object so we need to look it up
|
||||
var id = $scope.target.udi ? $scope.target.udi : $scope.target.id
|
||||
var altText = $scope.target.altText;
|
||||
mediaResource.getById(id)
|
||||
.then(function (node) {
|
||||
$scope.target = node;
|
||||
if (ensureWithinStartNode(node)) {
|
||||
selectImage(node);
|
||||
$scope.target.url = mediaHelper.resolveFile(node);
|
||||
$scope.target.altText = altText;
|
||||
$scope.openDetailsDialog();
|
||||
}
|
||||
}, gotoStartNode);
|
||||
}
|
||||
|
||||
$scope.openDetailsDialog = function() {
|
||||
@@ -308,15 +330,19 @@ angular.module("umbraco")
|
||||
var folderImage = $scope.images[folderImageIndex];
|
||||
var imageIsSelected = false;
|
||||
|
||||
for (var selectedImageIndex = 0;
|
||||
selectedImageIndex < $scope.model.selectedImages.length;
|
||||
selectedImageIndex++) {
|
||||
var selectedImage = $scope.model.selectedImages[selectedImageIndex];
|
||||
if ($scope.model && angular.isArray($scope.model.selectedImages)) {
|
||||
for (var selectedImageIndex = 0;
|
||||
selectedImageIndex < $scope.model.selectedImages.length;
|
||||
selectedImageIndex++) {
|
||||
var selectedImage = $scope.model.selectedImages[selectedImageIndex];
|
||||
|
||||
if (folderImage.key === selectedImage.key) {
|
||||
imageIsSelected = true;
|
||||
if (folderImage.key === selectedImage.key) {
|
||||
imageIsSelected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (imageIsSelected) {
|
||||
folderImage.selected = true;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ namespace Umbraco.Web.Editors
|
||||
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
|
||||
{
|
||||
controllerSettings.Services.Replace(typeof(IHttpActionSelector), new ParameterSwapControllerActionSelector(
|
||||
new ParameterSwapControllerActionSelector.ParameterSwapInfo("GetById", "id", typeof(int), typeof(Guid), typeof(Udi)),
|
||||
new ParameterSwapControllerActionSelector.ParameterSwapInfo("GetChildren", "id", typeof(int), typeof(Guid), typeof(Udi), typeof(string))));
|
||||
}
|
||||
}
|
||||
@@ -122,7 +123,7 @@ namespace Umbraco.Web.Editors
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content json for the content id
|
||||
/// Gets the media item by id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
@@ -141,6 +142,43 @@ namespace Umbraco.Web.Editors
|
||||
return Mapper.Map<IMedia, MediaItemDisplay>(foundContent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the media item by id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[OutgoingEditorModelEvent]
|
||||
[EnsureUserPermissionForMedia("id")]
|
||||
public MediaItemDisplay GetById(Guid id)
|
||||
{
|
||||
var foundContent = GetObjectFromRequest(() => Services.MediaService.GetById(id));
|
||||
|
||||
if (foundContent == null)
|
||||
{
|
||||
HandleContentNotFound(id);
|
||||
//HandleContentNotFound will throw an exception
|
||||
return null;
|
||||
}
|
||||
return Mapper.Map<IMedia, MediaItemDisplay>(foundContent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the media item by id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[OutgoingEditorModelEvent]
|
||||
[EnsureUserPermissionForMedia("id")]
|
||||
public MediaItemDisplay GetById(Udi id)
|
||||
{
|
||||
var guidUdi = id as GuidUdi;
|
||||
if (guidUdi != null)
|
||||
{
|
||||
return GetById(guidUdi.Guid);
|
||||
}
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return media for the specified ids
|
||||
/// </summary>
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace Umbraco.Web.WebApi.Filters
|
||||
{
|
||||
private readonly int? _nodeId;
|
||||
private readonly string _paramName;
|
||||
private DictionarySource _source;
|
||||
|
||||
public enum DictionarySource
|
||||
{
|
||||
@@ -43,14 +42,12 @@ namespace Umbraco.Web.WebApi.Filters
|
||||
{
|
||||
Mandate.ParameterNotNullOrEmpty(paramName, "paramName");
|
||||
_paramName = paramName;
|
||||
_source = DictionarySource.ActionArguments;
|
||||
}
|
||||
|
||||
public EnsureUserPermissionForMediaAttribute(string paramName, DictionarySource source)
|
||||
{
|
||||
Mandate.ParameterNotNullOrEmpty(paramName, "paramName");
|
||||
_paramName = paramName;
|
||||
_source = source;
|
||||
}
|
||||
|
||||
public override bool AllowMultiple
|
||||
@@ -58,6 +55,33 @@ namespace Umbraco.Web.WebApi.Filters
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
private int GetNodeIdFromParameter(object parameterValue)
|
||||
{
|
||||
if (parameterValue is int)
|
||||
{
|
||||
return (int) parameterValue;
|
||||
}
|
||||
|
||||
var guidId = Guid.Empty;
|
||||
if (parameterValue is Guid)
|
||||
{
|
||||
guidId = (Guid)parameterValue;
|
||||
}
|
||||
else if (parameterValue is GuidUdi)
|
||||
{
|
||||
guidId = ((GuidUdi) parameterValue).Guid;
|
||||
}
|
||||
|
||||
if (guidId != Guid.Empty)
|
||||
{
|
||||
var found = ApplicationContext.Current.Services.EntityService.GetIdForKey(guidId, UmbracoObjectTypes.Media);
|
||||
if (found)
|
||||
return found.Result;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("The id type: " + parameterValue.GetType() + " is not a supported id");
|
||||
}
|
||||
|
||||
public override void OnActionExecuting(HttpActionContext actionContext)
|
||||
{
|
||||
if (UmbracoContext.Current.Security.CurrentUser == null)
|
||||
@@ -68,7 +92,7 @@ namespace Umbraco.Web.WebApi.Filters
|
||||
int nodeId;
|
||||
if (_nodeId.HasValue == false)
|
||||
{
|
||||
var parts = _paramName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var parts = _paramName.Split(new [] { '.' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (actionContext.ActionArguments[parts[0]] == null)
|
||||
{
|
||||
@@ -77,7 +101,7 @@ namespace Umbraco.Web.WebApi.Filters
|
||||
|
||||
if (parts.Length == 1)
|
||||
{
|
||||
nodeId = (int)actionContext.ActionArguments[parts[0]];
|
||||
nodeId = GetNodeIdFromParameter(actionContext.ActionArguments[parts[0]]);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -88,7 +112,7 @@ namespace Umbraco.Web.WebApi.Filters
|
||||
{
|
||||
throw new InvalidOperationException("No argument found for the current action with the name: " + _paramName);
|
||||
}
|
||||
nodeId = (int)prop.GetValue(actionContext.ActionArguments[parts[0]]);
|
||||
nodeId = GetNodeIdFromParameter(prop.GetValue(actionContext.ActionArguments[parts[0]]));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -109,22 +133,7 @@ namespace Umbraco.Web.WebApi.Filters
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//private object GetValueFromSource(HttpActionContext actionContext, string key)
|
||||
//{
|
||||
// switch (_source)
|
||||
// {
|
||||
// case DictionarySource.ActionArguments:
|
||||
// return actionContext.ActionArguments[key];
|
||||
// case DictionarySource.RequestForm:
|
||||
// return actionContext.Request.Properties
|
||||
// case DictionarySource.RequestQueryString:
|
||||
// break;
|
||||
// default:
|
||||
// throw new ArgumentOutOfRangeException();
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user