From 75ace2b162c50fb96be3d957717ed10a109ace33 Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 8 Sep 2017 15:45:10 +1000 Subject: [PATCH] Fixes deleting a template - uses the correct way to delete stuff with angular and not relying on legacy code --- .../src/views/templates/delete.controller.js | 33 +++++++++++++++++++ .../src/views/templates/delete.html | 12 +++++++ .../Trees/TemplatesTreeController.cs | 5 +-- src/Umbraco.Web/UI/LegacyDialogHandler.cs | 21 ++++++++++-- 4 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/views/templates/delete.controller.js create mode 100644 src/Umbraco.Web.UI.Client/src/views/templates/delete.html diff --git a/src/Umbraco.Web.UI.Client/src/views/templates/delete.controller.js b/src/Umbraco.Web.UI.Client/src/views/templates/delete.controller.js new file mode 100644 index 0000000000..8995cb1a31 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/templates/delete.controller.js @@ -0,0 +1,33 @@ +/** + * @ngdoc controller + * @name Umbraco.Editors.Templates.DeleteController + * @function + * + * @description + * The controller for the template delete dialog + */ +function TemplatesDeleteController($scope, templateResource , treeService, navigationService) { + + $scope.performDelete = function() { + + //mark it for deletion (used in the UI) + $scope.currentNode.loading = true; + templateResource.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.Templates.DeleteController", TemplatesDeleteController); diff --git a/src/Umbraco.Web.UI.Client/src/views/templates/delete.html b/src/Umbraco.Web.UI.Client/src/views/templates/delete.html new file mode 100644 index 0000000000..34648aa43e --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/templates/delete.html @@ -0,0 +1,12 @@ +
+
+ +

+ Are you sure you want to delete {{currentNode.name}} ? +

+ + + + +
+
diff --git a/src/Umbraco.Web/Trees/TemplatesTreeController.cs b/src/Umbraco.Web/Trees/TemplatesTreeController.cs index c5c3c3dc70..33ce91cf6d 100644 --- a/src/Umbraco.Web/Trees/TemplatesTreeController.cs +++ b/src/Umbraco.Web/Trees/TemplatesTreeController.cs @@ -94,10 +94,7 @@ namespace Umbraco.Web.Trees if (template.IsMasterTemplate == false) { //add delete option if it doesn't have children - menu.Items.Add(ui.Text("actions", ActionDelete.Instance.Alias), true) - //Since we haven't implemented anything for languages in angular, this needs to be converted to - //use the legacy format - .ConvertLegacyMenuItem(entity, "templates", queryStrings.GetValue("application")); + menu.Items.Add(ui.Text("actions", ActionDelete.Instance.Alias), true); } //add refresh diff --git a/src/Umbraco.Web/UI/LegacyDialogHandler.cs b/src/Umbraco.Web/UI/LegacyDialogHandler.cs index dfa7fbc153..c51a8bb08b 100644 --- a/src/Umbraco.Web/UI/LegacyDialogHandler.cs +++ b/src/Umbraco.Web/UI/LegacyDialogHandler.cs @@ -125,6 +125,10 @@ namespace Umbraco.Web.UI internal static bool UserHasCreateAccess(HttpContextBase httpContext, User umbracoUser, string nodeType) { var task = GetTaskForOperation(httpContext, umbracoUser, Operation.Create, nodeType); + if (task == null) + throw new InvalidOperationException( + string.Format("Could not task for operation {0} for node type {1}", Operation.Create, nodeType)); + var dialogTask = task as LegacyDialogTask; if (dialogTask != null) { @@ -149,6 +153,10 @@ namespace Umbraco.Web.UI internal static bool UserHasDeleteAccess(HttpContextBase httpContext, User umbracoUser, string nodeType) { var task = GetTaskForOperation(httpContext, umbracoUser, Operation.Delete, nodeType); + if (task == null) + throw new InvalidOperationException( + string.Format("Could not task for operation {0} for node type {1}", Operation.Delete, nodeType)); + var dialogTask = task as LegacyDialogTask; if (dialogTask != null) { @@ -160,7 +168,10 @@ namespace Umbraco.Web.UI public static void Delete(HttpContextBase httpContext, User umbracoUser, string nodeType, int nodeId, string text) { var typeInstance = GetTaskForOperation(httpContext, umbracoUser, Operation.Delete, nodeType); - + if (typeInstance == null) + throw new InvalidOperationException( + string.Format("Could not task for operation {0} for node type {1}", Operation.Delete, nodeType)); + typeInstance.ParentID = nodeId; typeInstance.Alias = text; @@ -170,7 +181,10 @@ namespace Umbraco.Web.UI public static string Create(HttpContextBase httpContext, User umbracoUser, string nodeType, int nodeId, string text, int typeId = 0) { var typeInstance = GetTaskForOperation(httpContext, umbracoUser, Operation.Create, nodeType); - + if (typeInstance == null) + throw new InvalidOperationException( + string.Format("Could not task for operation {0} for node type {1}", Operation.Create, nodeType)); + typeInstance.TypeID = typeId; typeInstance.ParentID = nodeId; typeInstance.Alias = text; @@ -187,6 +201,9 @@ namespace Umbraco.Web.UI internal static string Create(HttpContextBase httpContext, User umbracoUser, string nodeType, int nodeId, string text, IDictionary additionalValues, int typeId = 0) { var typeInstance = GetTaskForOperation(httpContext, umbracoUser, Operation.Create, nodeType); + if (typeInstance == null) + throw new InvalidOperationException( + string.Format("Could not task for operation {0} for node type {1}", Operation.Create, nodeType)); typeInstance.TypeID = typeId; typeInstance.ParentID = nodeId;