diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/relationtype.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/relationtype.resource.js index 4035ce0994..f17aae0a6b 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/relationtype.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/relationtype.resource.js @@ -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 + *
+ * relationTypeResource.deleteById(1234).then(function() {
+ * alert('Deleted it!');
+ * });
+ *
+ *
+ * @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
+ );
}
};
diff --git a/src/Umbraco.Web.UI.Client/src/views/relationtypes/delete.controller.js b/src/Umbraco.Web.UI.Client/src/views/relationtypes/delete.controller.js
new file mode 100644
index 0000000000..ead951ae3a
--- /dev/null
+++ b/src/Umbraco.Web.UI.Client/src/views/relationtypes/delete.controller.js
@@ -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);
diff --git a/src/Umbraco.Web.UI.Client/src/views/relationtypes/delete.html b/src/Umbraco.Web.UI.Client/src/views/relationtypes/delete.html
index e69de29bb2..e0fdbc6751 100644
--- a/src/Umbraco.Web.UI.Client/src/views/relationtypes/delete.html
+++ b/src/Umbraco.Web.UI.Client/src/views/relationtypes/delete.html
@@ -0,0 +1,12 @@
+
+