Completed delete action

This commit is contained in:
James Coxhead
2018-12-02 18:10:03 +00:00
parent a6ab471505
commit 2dfcb8ed4e
3 changed files with 68 additions and 8 deletions

View File

@@ -27,13 +27,7 @@ function relationTypeResource($q, $http, umbRequestHelper, umbDataFormatter) {
*/
getById: function (id) {
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"relationTypeApiBaseUrl",
"GetById",
[{ id: id }]
)
),
$http.get(umbRequestHelper.getApiUrl("relationTypeApiBaseUrl", "GetById", [{ id: id }])),
"Failed to get item " + id
);
},
@@ -97,8 +91,29 @@ function relationTypeResource($q, $http, umbRequestHelper, umbDataFormatter) {
);
},
/**
* @ngdoc method
* @name umbraco.resources.relationTypeResource#deleteById
* @methodof umbraco.resources.relationTypeResource
*
* @description
* Deletes a relation type with a given ID.
*
* * ## Usage
* <pre>
* relationTypeResource.deleteById(1234).then(function() {
* alert('Deleted it!');
* });
* </pre>
*
* @param {Int} id The ID of the relation type to delete.
* @returns {Promose} resourcePromise object.
*/
deleteById: function (id) {
return umbRequestHelper.resourcePromise(
$http.post(umbRequestHelper.getApiUrl("relationTypeApiBaseUrl", "DeleteById", [{ id: id }])),
"Failed to delete item " + id
);
}
};

View File

@@ -0,0 +1,33 @@
function RelationTypeDeleteController($scope, $location, relationTypeResource, treeService, navigationService, appState) {
var vm = this;
vm.cancel = cancel;
vm.performDelete = performDelete;
function cancel() {
navigationService.hideDialog();
}
function performDelete() {
// stop from firing again on double-click
if ($scope.busy) { return false; }
//mark it for deletion (used in the UI)
$scope.currentNode.loading = true;
$scope.busy = true;
relationTypeResource.deleteById($scope.currentNode.id).then(function () {
$scope.currentNode.loading = false;
treeService.removeNode($scope.currentNode);
navigationService.hideMenu();
var currentSection = appState.getSectionState("currentSection");
$location.path("/" + currentSection + "/");
});
}
}
angular.module("umbraco").controller("Umbraco.Editors.RelationTypes.DeleteController", RelationTypeDeleteController);

View File

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