Datatype delete dialog

This commit is contained in:
perploug
2013-10-22 09:46:22 +02:00
parent 547361a185
commit d4a069451f
4 changed files with 96 additions and 3 deletions

View File

@@ -53,10 +53,37 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) {
umbRequestHelper.getApiUrl(
"dataTypeApiBaseUrl",
"GetEmpty")),
'Failed to retreive data for empty media item type ' + alias);
'Failed to retreive data for empty datatype ' + alias);
},
/**
* @ngdoc method
* @name umbraco.resources.dataTypeResource#deleteById
* @methodOf umbraco.resources.dataTypeResource
*
* @description
* Deletes a content item with a given id
*
* ##usage
* <pre>
* dataTypeResource.deleteById(1234)
* .then(function() {
* alert('its gone!');
* });
* </pre>
*
* @param {Int} id id of content item to delete
* @returns {Promise} resourcePromise object.
*
*/
deleteById: function(id) {
return umbRequestHelper.resourcePromise(
$http.delete(
umbRequestHelper.getApiUrl(
"dataTypeApiBaseUrl",
"DeleteById",
[{ id: id }])),
'Failed to delete item ' + id);
},
/** saves or updates a data type object */
save: function (dataType, preValues, isNew) {

View File

@@ -0,0 +1,33 @@
/**
* @ngdoc controller
* @name Umbraco.Editors.ContentDeleteController
* @function
*
* @description
* The controller for deleting content
*/
function DataTypeDeleteController($scope, dataTypeResource, treeService, navigationService) {
$scope.performDelete = function() {
//mark it for deletion (used in the UI)
$scope.currentNode.loading = true;
dataTypeResource.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);
navigationService.hideMenu();
});
};
$scope.cancel = function() {
navigationService.hideDialog();
};
}
angular.module("umbraco").controller("Umbraco.Editors.DataType.DeleteController", DataTypeDeleteController);

View File

@@ -0,0 +1,12 @@
<div class="umb-dialog umb-pane" ng-controller="Umbraco.Editors.DataType.DeleteController">
<div class="umb-dialog-body">
<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

@@ -15,6 +15,7 @@ using Umbraco.Web.WebApi.Binders;
using Umbraco.Web.WebApi.Filters;
using umbraco;
using Constants = Umbraco.Core.Constants;
using System.Net.Http;
namespace Umbraco.Web.Editors
{
@@ -48,6 +49,26 @@ namespace Umbraco.Web.Editors
return Mapper.Map<IDataTypeDefinition, DataTypeDisplay>(dataType);
}
/// <summary>
/// Deletes a data type wth a given ID
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete]
public HttpResponseMessage DeleteById(int id)
{
var foundType = Services.DataTypeService.GetDataTypeDefinitionById(id);
if (foundType == null)
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
Services.DataTypeService.Delete(foundType, UmbracoUser.Id);
return Request.CreateResponse(HttpStatusCode.OK);
}
public DataTypeDisplay GetEmpty()
{
var dt = new DataTypeDefinition(-1, "");