using System.Runtime.Serialization; using Newtonsoft.Json; using Umbraco.Core.IO; using System; using System.Collections; using System.Collections.Generic; using Umbraco.Core; namespace Umbraco.Web.Trees { /// /// Represents a model in the tree /// /// /// TreeNode is sealed to prevent developers from adding additional json data to the response /// [DataContract(Name = "node", Namespace = "")] public class TreeNode { /// /// Internal constructor, to create a tree node use the CreateTreeNode methods of the TreeApiController. /// /// /// /// internal TreeNode(string nodeId, string getChildNodesUrl, string menuUrl) { //_menuItems = menuItems; //Style = new NodeStyle(); NodeId = nodeId; AdditionalData = new Dictionary(); ChildNodesUrl = getChildNodesUrl; MenuUrl = menuUrl; //default Icon = "icon-folder-close"; } /// /// The unique identifier for the node /// [DataMember(Name = "id")] public string NodeId { get; private set; } /// /// A flag to set whether or not this node has children /// [DataMember(Name = "hasChildren")] public bool HasChildren { get; set; } /// /// The text title of the node that is displayed in the tree /// [DataMember(Name = "name")] public string Title { get; set; } /// /// Gets or sets the node path. /// [DataMember(Name = "nodePath")] public string NodePath { get; set; } /// /// The icon to use for the node, this can be either a path to an image or a Css class. /// If a '/' is found in the string then it will be considered a path to an image. /// [DataMember(Name = "icon")] public string Icon { get; set; } /// /// The tree nodetype which refers to the type of node rendered in the tree /// [DataMember(Name = "nodetype")] public string NodeType { get; set; } /// /// Returns true if the icon represents a CSS class instead of a file path /// [DataMember(Name = "iconIsClass")] public bool IconIsClass { get { if (Icon.IsNullOrWhiteSpace()) { return true; } //if it starts with a '.' or doesn't contain a '.' at all then it is a class return Icon.StartsWith(".") || Icon.Contains(".") == false; } } /// /// Returns the icon file path if the icon is not a class, otherwise returns an empty string /// [DataMember(Name = "iconFilePath")] public string IconFilePath { get { return IconIsClass ? string.Empty : IOHelper.ResolveUrl("~/umbraco/images/umbraco/" + Icon); } } /// /// Optional: The Route path for the editor for this node /// /// /// If this is not set, then the route path will be automatically determined by: {section}/edit/{id} /// [DataMember(Name = "routePath")] public string RoutePath { get; set; } /// /// The JSON url to load the nodes children /// [DataMember(Name = "childNodesUrl")] public string ChildNodesUrl { get; set; } /// /// The JSON url to load the menu from /// [DataMember(Name = "menuUrl")] public string MenuUrl { get; set; } /// /// A dictionary to support any additional meta data that should be rendered for the node which is /// useful for custom action commands such as 'create', 'copy', etc... /// [DataMember(Name = "metaData")] public Dictionary AdditionalData { get; private set; } ///// ///// The UI style to give the model ///// //public NodeStyle Style { get; private set; } } }