Fixes deleting a template - uses the correct way to delete stuff with angular and not relying on legacy code

This commit is contained in:
Shannon
2017-09-08 15:45:10 +10:00
parent 38c961209e
commit 75ace2b162
4 changed files with 65 additions and 6 deletions

View File

@@ -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);

View File

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

View File

@@ -94,10 +94,7 @@ namespace Umbraco.Web.Trees
if (template.IsMasterTemplate == false)
{
//add delete option if it doesn't have children
menu.Items.Add<ActionDelete>(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<string>("application"));
menu.Items.Add<ActionDelete>(ui.Text("actions", ActionDelete.Instance.Alias), true);
}
//add refresh

View File

@@ -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<string, object> 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;