Media delete dialog, missing D attr validation

This commit is contained in:
perploug
2013-09-24 16:02:58 +02:00
parent e9f69e39ab
commit 5c8d027383
6 changed files with 125 additions and 10 deletions

View File

@@ -88,6 +88,37 @@ function mediaResource($q, $http, umbDataFormatter, umbRequestHelper) {
[{ id: id }])),
'Failed to retreive data for media id ' + id);
},
/**
* @ngdoc method
* @name umbraco.resources.mediaResource#deleteById
* @methodOf umbraco.resources.mediaResource
*
* @description
* Deletes a media item with a given id
*
* ##usage
* <pre>
* mediaResource.deleteById(1234)
* .then(function() {
* alert('its gone!');
* });
* </pre>
*
* @param {Int} id id of media item to delete
* @returns {Promise} resourcePromise object.
*
*/
deleteById: function(id) {
return umbRequestHelper.resourcePromise(
$http.delete(
umbRequestHelper.getApiUrl(
"mediaApiBaseUrl",
"DeleteById",
[{ id: id }])),
'Failed to delete item ' + id);
},
/**
* @ngdoc method
* @name umbraco.resources.mediaResource#getByIds

View File

@@ -1,6 +1,10 @@
<div class="umb-dialog umb-pane" ng-controller="Umbraco.Editors.Content.DeleteController">
<div class="umb-dialog-body" auto-scale="90">
<p class="umb-abstract">
Are you sure you want to delete <strong>{{currentNode.name}}</strong> ?
</p>
<umb-confirm on-confirm="performDelete" on-cancel="cancel">
</umb-confirm>

View File

@@ -1,13 +1,6 @@
<div>
<p ng-hide="!caption" class="umb-abstract">{{caption}}</p>
<ul class="nav nav-pills">
<li class="active">
<a href="" ng-click="onConfirm()">Ok</a>
</li>
<li>
<a href="" ng-click="onCancel()">Cancel</a>
</li>
</ul>
<a href class="btn btn-link" ng-click="onCancel()">Cancel</a>
<a href class="btn btn-primary" ng-click="onConfirm()">Ok</a>
</div>

View File

@@ -0,0 +1,10 @@
<div class="umb-dialog umb-pane" ng-controller="Umbraco.Editors.Media.DeleteController">
<div class="umb-dialog-body" auto-scale="90">
<p class="umb-abstract">
Are you sure you want to delete <strong>{{currentNode.name}}</strong> ?
</p>
<umb-confirm on-confirm="performDelete" on-cancel="cancel"></umb-confirm>
</div>
</div>

View File

@@ -0,0 +1,43 @@
/**
* @ngdoc controller
* @name Umbraco.Editors.ContentDeleteController
* @function
*
* @description
* The controller for deleting content
*/
function MediaDeleteController($scope, mediaResource, treeService, navigationService) {
$scope.performDelete = function() {
//mark it for deletion (used in the UI)
$scope.currentNode.loading = true;
mediaResource.deleteById($scope.currentNode.id).then(function () {
$scope.currentNode.loading = false;
//get the root node before we remove it
var rootNode = treeService.getTreeRoot($scope.currentNode);
//TODO: Need to sync tree, etc...
treeService.removeNode($scope.currentNode);
//ensure the recycle bin has child nodes now
var recycleBin = treeService.getDescendantNode(rootNode, -21);
if(recycleBin){
recycleBin.hasChildren = true;
}
navigationService.hideMenu();
},function() {
$scope.currentNode.loading = false;
});
};
$scope.cancel = function() {
navigationService.hideDialog();
};
}
angular.module("umbraco").controller("Umbraco.Editors.Media.DeleteController", MediaDeleteController);

View File

@@ -126,6 +126,40 @@ namespace Umbraco.Web.Editors
.Select(Mapper.Map<IMedia, ContentItemBasic<ContentPropertyBasic, IMedia>>);
}
/// <summary>
/// Moves an item to the recycle bin, if it is already there then it will permanently delete it
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <remarks>
/// The CanAccessContentAuthorize attribute will deny access to this method if the current user
/// does not have Delete access to this node.
/// </remarks>
[EnsureUserPermissionForMedia("id")]
public HttpResponseMessage DeleteById(int id)
{
//TODO: We need to check if the user is allowed to do this!
var foundMedia = Services.MediaService.GetById(id);
if (foundMedia == null)
{
return HandleContentNotFound(id, false);
}
//if the current item is in the recycle bin
if (foundMedia.IsInRecycleBin() == false)
{
Services.MediaService.MoveToRecycleBin(foundMedia, UmbracoUser.Id);
}
else
{
Services.MediaService.Delete(foundMedia, UmbracoUser.Id);
}
return Request.CreateResponse(HttpStatusCode.OK);
}
/// <summary>
/// Saves content
/// </summary>