2013-08-12 15:06:12 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Net.Http.Formatting;
|
2013-10-28 13:45:38 +11:00
|
|
|
|
using System.Web.Http.Routing;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
using Umbraco.Core.Logging;
|
|
|
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
|
using Umbraco.Core.Services;
|
2013-10-08 12:38:27 +11:00
|
|
|
|
using Umbraco.Web.Models.Trees;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
using Umbraco.Web.Mvc;
|
|
|
|
|
|
using Umbraco.Web.WebApi;
|
|
|
|
|
|
using Umbraco.Web.WebApi.Filters;
|
2013-10-28 13:45:38 +11:00
|
|
|
|
using umbraco.cms.presentation.Trees;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Trees
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This is used to output JSON from legacy trees
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[PluginController("UmbracoTrees")]
|
2014-11-27 17:57:33 +11:00
|
|
|
|
[LegacyTreeAuthorizeAttribute]
|
2013-10-28 13:45:38 +11:00
|
|
|
|
public class LegacyTreeController : TreeControllerBase
|
2013-08-12 15:06:12 +02:00
|
|
|
|
{
|
2013-10-28 13:45:38 +11:00
|
|
|
|
private readonly XmlTreeNode _xmlTreeNode;
|
|
|
|
|
|
private readonly string _treeAlias;
|
|
|
|
|
|
private readonly string _currentSection;
|
|
|
|
|
|
private readonly string _rootDisplay;
|
|
|
|
|
|
|
|
|
|
|
|
public LegacyTreeController()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public LegacyTreeController(XmlTreeNode xmlTreeNode, string treeAlias, string currentSection, UrlHelper urlHelper)
|
|
|
|
|
|
{
|
|
|
|
|
|
_xmlTreeNode = xmlTreeNode;
|
|
|
|
|
|
_treeAlias = treeAlias;
|
|
|
|
|
|
_currentSection = currentSection;
|
|
|
|
|
|
_rootDisplay = xmlTreeNode.Text;
|
|
|
|
|
|
Url = urlHelper;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override TreeNode CreateRootNode(FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
return LegacyTreeDataConverter.ConvertFromLegacy(
|
|
|
|
|
|
_xmlTreeNode.NodeID,
|
|
|
|
|
|
_xmlTreeNode,
|
|
|
|
|
|
Url,
|
|
|
|
|
|
_currentSection,
|
|
|
|
|
|
queryStrings,
|
|
|
|
|
|
isRoot: true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
|
2013-08-12 15:06:12 +02:00
|
|
|
|
{
|
|
|
|
|
|
var tree = GetTree(queryStrings);
|
|
|
|
|
|
var attempt = tree.TryLoadFromLegacyTree(id, queryStrings, Url, tree.ApplicationAlias);
|
|
|
|
|
|
if (attempt.Success == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
var msg = "Could not render tree " + queryStrings.GetRequiredString("treeType") + " for node id " + id;
|
2013-09-12 12:54:34 +02:00
|
|
|
|
LogHelper.Error<LegacyTreeController>(msg, attempt.Exception);
|
2013-08-12 15:06:12 +02:00
|
|
|
|
throw new ApplicationException(msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return attempt.Result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-28 13:45:38 +11:00
|
|
|
|
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
2013-08-12 15:06:12 +02:00
|
|
|
|
//get the parent id from the query strings
|
|
|
|
|
|
var parentId = queryStrings.GetRequiredString("parentId");
|
|
|
|
|
|
var tree = GetTree(queryStrings);
|
|
|
|
|
|
|
|
|
|
|
|
var rootIds = new[]
|
|
|
|
|
|
{
|
|
|
|
|
|
Core.Constants.System.Root.ToString(CultureInfo.InvariantCulture),
|
|
|
|
|
|
Core.Constants.System.RecycleBinContent.ToString(CultureInfo.InvariantCulture),
|
|
|
|
|
|
Core.Constants.System.RecycleBinMedia.ToString(CultureInfo.InvariantCulture)
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//if the id and the parentId are both -1 then we need to get the menu for the root node
|
|
|
|
|
|
if (rootIds.Contains(id) && parentId == "-1")
|
|
|
|
|
|
{
|
|
|
|
|
|
var attempt = tree.TryGetMenuFromLegacyTreeRootNode(queryStrings, Url);
|
|
|
|
|
|
if (attempt.Success == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
var msg = "Could not render menu for root node for treeType " + queryStrings.GetRequiredString("treeType");
|
2013-09-12 12:54:34 +02:00
|
|
|
|
LogHelper.Error<LegacyTreeController>(msg, attempt.Exception);
|
2013-08-12 15:06:12 +02:00
|
|
|
|
throw new ApplicationException(msg);
|
|
|
|
|
|
}
|
2013-10-01 12:32:27 +02:00
|
|
|
|
|
2013-10-03 15:05:48 +10:00
|
|
|
|
foreach (var menuItem in attempt.Result.Items)
|
2013-10-01 12:32:27 +02:00
|
|
|
|
{
|
|
|
|
|
|
menuItem.Name = global::umbraco.ui.Text("actions", menuItem.Alias);
|
|
|
|
|
|
}
|
2013-08-12 15:06:12 +02:00
|
|
|
|
return attempt.Result;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var attempt = tree.TryGetMenuFromLegacyTreeNode(parentId, id, queryStrings, Url);
|
|
|
|
|
|
if (attempt.Success == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
var msg = "Could not render menu for treeType " + queryStrings.GetRequiredString("treeType") + " for node id " + parentId;
|
2013-09-12 12:54:34 +02:00
|
|
|
|
LogHelper.Error<LegacyTreeController>(msg, attempt.Exception);
|
2013-08-12 15:06:12 +02:00
|
|
|
|
throw new ApplicationException(msg);
|
|
|
|
|
|
}
|
2013-10-03 15:05:48 +10:00
|
|
|
|
foreach (var menuItem in attempt.Result.Items)
|
2013-10-01 12:32:27 +02:00
|
|
|
|
{
|
|
|
|
|
|
menuItem.Name = global::umbraco.ui.Text("actions", menuItem.Alias);
|
|
|
|
|
|
}
|
2013-08-12 15:06:12 +02:00
|
|
|
|
return attempt.Result;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-28 13:45:38 +11:00
|
|
|
|
public override string RootNodeDisplayName
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _rootDisplay; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string TreeAlias
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _treeAlias; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
private ApplicationTree GetTree(FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
//need to ensure we have a tree type
|
|
|
|
|
|
var treeType = queryStrings.GetRequiredString("treeType");
|
|
|
|
|
|
//now we'll look up that tree
|
|
|
|
|
|
var tree = Services.ApplicationTreeService.GetByAlias(treeType);
|
|
|
|
|
|
if (tree == null)
|
|
|
|
|
|
throw new InvalidOperationException("No tree found with alias " + treeType);
|
|
|
|
|
|
return tree;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2013-05-31 17:20:56 -10:00
|
|
|
|
}
|