using System.Linq;
using System.Xml.Linq;
using System.Xml.XPath;
using umbraco.cms.presentation.Trees;
namespace umbraco.editorControls.MultiNodeTreePicker
{
///
/// XmlTreeNode extensions for the MultiNodeTreePicker.
///
public static class XmlTreeNodeExtensions
{
//public static void DetermineSelected(this XmlTreeNode node)
//{
//}
///
/// Determines if the node should be clickable based on the xpath given
///
/// The node.
/// The xpath.
/// The type.
/// The XML.
public static void DetermineClickable(this XmlTreeNode node, string xpath, XPathFilterType type, XElement xml)
{
if (!string.IsNullOrEmpty(xpath))
{
try
{
var matched = xml.XPathSelectElements(xpath);
if (matched.Count() > 0)
{
if (type == XPathFilterType.Disable)
{
//add the non-clickable color to the node
node.Style.AddCustom("uc-treenode-noclick");
}
else
{
//add the non-clickable color to the node
node.Style.AddCustom("uc-treenode-click");
}
}
else
{
if (type == XPathFilterType.Disable)
{
//ensure the individual node is the correct color
node.Style.AddCustom("uc-treenode-click");
}
else
{
//ensure the individual node is the correct color
node.Style.AddCustom("uc-treenode-noclick");
}
}
}
catch (XPathException)
{
node.Text = "umbraco.editorControls: MNTP: XPath Error!";
}
}
else
{
if (type == XPathFilterType.Disable)
{
//ensure the individual node is the correct color
node.Style.AddCustom("uc-treenode-click");
}
else
{
//ensure the individual node is the correct color
node.Style.AddCustom("uc-treenode-noclick");
}
}
}
}
}