@*   Xafari Framework version : 17.2.3011.1336   *@

@using System.Web.UI.WebControls
@using Xafari.BC.Settings
@using Xafari.BC.Settings.Mvc
@using Xafari.Mvc.Templates
@using Xafari.Utils

@model MvcSettingsPropertyEditor
@{
	var postUrl = Url.Action("SelectSettingsSlice", "MVCxSettingsPropertyEditor");
	
	var settingsKeyCallbackPanelName = this.Model.Frame.ControlId(this.Model.FormName() + "SettingsKeyCallbackPanel");
	
	var settings = new TreeViewSettings { Name = this.ViewData.Frame().ControlId(this.Model.FormName() + "SettingsSlices_TreeView"), AllowSelectNode = true };
	settings.ControlStyle.Border.BorderStyle = BorderStyle.None;
	settings.ControlStyle.CssClass = "xafNavigationBarActionContainer";
	settings.SaveStateToCookies = true;
	settings.SaveStateToCookiesID = this.Model.Id + "SettingsSlices_TreeView";
	settings.EnableClientSideAPI = true;
	settings.Width = Unit.Percentage(100);

	var rootSlice = SettingsAccessor.Instance.RootSlice; 

	rootSlice.Recursive(settings.Nodes,
	(parentNode, slice) => slice.ChildrenSlices,
	(parentNode, slice) =>
	{
		var node = parentNode.Add();
		node.Text = slice.ToString();
		node.Name = slice.SliceKey != null ? slice.SliceKeyString : MvcSettingsPropertyEditor.RootPath;
		var imageName = slice.SliceObjectType == null ? "OpenRootFolder" : this.Model.GetSliceImageName(slice);
		node.Image.SpriteProperties.SetImageProperties(imageName);
		node.DataItem = slice;
		return node.Nodes;
	});
	settings.PreRender += (sender, args) =>
	{
		var treeView = (ASPxTreeView)sender;
		if (this.Model.SettingsCurrentSlicePath == null)
		{
			var firstNode = treeView.Nodes[0];
			if (firstNode != null)
			{
				treeView.SelectedNode = firstNode;
				firstNode.Expanded = true;
			}
		}
		else
		{
			treeView.SelectedNode = treeView.Nodes.FindRecursive(node => node.Name == this.Model.SettingsCurrentSlicePath);
			treeView.ExpandToNode(treeView.SelectedNode);
		}
	};
	string nodeClickScript = string.Format(@"function(s, e) {{
if(window.xafari.settings.sliceSelectTimeoutId)
	window.clearTimeout(window.xafari.settings.sliceSelectTimeoutId);
var nodeName = e.node.name;
window.xafari.settings.sliceSelectTimeoutId = window.setTimeout(function() {{ 
	window.xafari.settings.sliceSelectTimeoutId = null;
	window.top.setTimeout('window.top.xafari.startProgress()', 1);
	$.post('{0}', {{ currentSettingsSlice: nodeName, windowId: '{1}', frameId: '{2}' }}).
			success(function() {{ if ({3}) {3}.PerformCallback(); }});
}}, 500);
}}", postUrl, this.ViewData.Window().FrameId(), this.ViewData.Frame().FrameId(), settingsKeyCallbackPanelName);
	settings.ClientSideEvents.NodeClick = nodeClickScript;
}
@Html.DevExpress().TreeView(settings).GetHtml()


   