diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbfoldergrid.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbfoldergrid.directive.js
index 812038b51a..37c38fe105 100644
--- a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbfoldergrid.directive.js
+++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbfoldergrid.directive.js
@@ -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();
}
};
diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbmediagrid.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbmediagrid.directive.js
index e9e7395761..4960a11f19 100644
--- a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbmediagrid.directive.js
+++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbmediagrid.directive.js
@@ -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();
}
};
diff --git a/src/Umbraco.Web.UI.Client/src/common/services/mediatypehelper.service.js b/src/Umbraco.Web.UI.Client/src/common/services/mediatypehelper.service.js
index b06a5ca8e3..87804c8473 100644
--- a/src/Umbraco.Web.UI.Client/src/common/services/mediatypehelper.service.js
+++ b/src/Umbraco.Web.UI.Client/src/common/services/mediatypehelper.service.js
@@ -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){
diff --git a/src/Umbraco.Web.UI.Client/src/views/common/overlays/mediaPicker/mediapicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/overlays/mediaPicker/mediapicker.controller.js
index f6ae9a8d6b..99d9fee8dd 100644
--- a/src/Umbraco.Web.UI.Client/src/views/common/overlays/mediaPicker/mediapicker.controller.js
+++ b/src/Umbraco.Web.UI.Client/src/views/common/overlays/mediaPicker/mediapicker.controller.js
@@ -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;
}
diff --git a/src/Umbraco.Web/Editors/MediaController.cs b/src/Umbraco.Web/Editors/MediaController.cs
index 64c619ee6f..8b9a5ef781 100644
--- a/src/Umbraco.Web/Editors/MediaController.cs
+++ b/src/Umbraco.Web/Editors/MediaController.cs
@@ -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
}
///
- /// Gets the content json for the content id
+ /// Gets the media item by id
///
///
///
@@ -141,6 +142,43 @@ namespace Umbraco.Web.Editors
return Mapper.Map(foundContent);
}
+ ///
+ /// Gets the media item by id
+ ///
+ ///
+ ///
+ [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(foundContent);
+ }
+
+ ///
+ /// Gets the media item by id
+ ///
+ ///
+ ///
+ [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);
+ }
+
///
/// Return media for the specified ids
///
diff --git a/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForMediaAttribute.cs b/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForMediaAttribute.cs
index cb0f07f796..e126d42c21 100644
--- a/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForMediaAttribute.cs
+++ b/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForMediaAttribute.cs
@@ -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();
- // }
- //}
-
+
}