@*   Xafari Framework version : 17.2.3011.1336   *@

@using System.Web.UI.WebControls
@using DevExpress.ExpressApp.Utils
@using DevExpress.Persistent.Base.General
@using Xafari.Mvc.MVCx.Controls
@using Xafari.Mvc.MVCx.Editors

@model Xafari.BC.Mvc.Editors.MvcExplorerListEditor

@{
	const string customizeSettingsEventHandlerKey = "CustomizeSettingsEventHandler for MvcExplorerListEditor";
	var customizeSettingsEventHandler = new EventHandler<CustomizeSettingsEventArgs>(delegate(object sender, CustomizeSettingsEventArgs args)
	{
		var settings = args.Settings;

		//Folder column
		var folderColumn = new MVCxGridViewColumn
		{
			Name = "Open",
			Caption = @" ",
			ToolTip = CaptionHelper.GetLocalizedText("Texts", "OpenFolderActionCaption", "Open folder"),
		};
		folderColumn.Settings.AllowAutoFilter = DefaultBoolean.False;
		folderColumn.Settings.AllowAutoFilterTextInputTimer = DefaultBoolean.False;
		folderColumn.Settings.AllowHeaderFilter = DefaultBoolean.False;
		folderColumn.Settings.AllowSort = DefaultBoolean.False;
		folderColumn.Settings.AllowDragDrop = DefaultBoolean.False;
		folderColumn.Settings.AllowGroup = DefaultBoolean.False;
		folderColumn.Settings.ShowInFilterControl = DefaultBoolean.False;
		folderColumn.CellStyle.HorizontalAlign = HorizontalAlign.Center;
		folderColumn.Width = Unit.Pixel(32);
		folderColumn.FixedStyle = GridViewColumnFixedStyle.Left;
		folderColumn.Index = 0;
		folderColumn.VisibleIndex = 0;
		folderColumn.SetDataItemTemplateContent(a =>
		{
			var viewContext = a.ViewContext() ?? Html.ViewContext;
			Html.Xafari().RenderRelativePartial(viewContext.Writer, "_DataItemTemplateContentFolderColumn", this.Model, new ViewDataDictionary { { "Container", a }, { "GridName", settings.Name } });
		});

		settings.Columns.Insert(0, folderColumn);

		//Image column
		if (typeof (ITreeNodeImageProvider).IsAssignableFrom(this.Model.ObjectsType))
		{
			var imageColumn = new MVCxGridViewColumn
			{
				Name = "TreeNodeImage",
				Caption = @" ",
			};
			imageColumn.Settings.AllowAutoFilter = DefaultBoolean.False;
			imageColumn.Settings.AllowAutoFilterTextInputTimer = DefaultBoolean.False;
			imageColumn.Settings.AllowHeaderFilter = DefaultBoolean.False;
			imageColumn.Settings.AllowSort = DefaultBoolean.False;
			imageColumn.Settings.AllowDragDrop = DefaultBoolean.False;
			imageColumn.Settings.AllowGroup = DefaultBoolean.False;
			imageColumn.Settings.ShowInFilterControl = DefaultBoolean.False;
			imageColumn.CellStyle.HorizontalAlign = HorizontalAlign.Center;
			imageColumn.Width = Unit.Pixel(32);
			imageColumn.FixedStyle = GridViewColumnFixedStyle.Left;
			imageColumn.Index = 1;
			imageColumn.VisibleIndex = 1;
			imageColumn.SetDataItemTemplateContent(a =>
			{
				var viewContext = a.ViewContext() ?? Html.ViewContext;
				Html.Xafari().RenderRelativePartial(viewContext.Writer, "_DataItemTemplateContentImageColumn", null, new ViewDataDictionary { { "Container", a } });
			});

			settings.Columns.Insert(1, imageColumn);
		}
		//TODO: Проработать более детально вариант с отпиской
		this.Model.CustomizeSettings -= (EventHandler<CustomizeSettingsEventArgs>) this.ViewData[customizeSettingsEventHandlerKey];
		this.ViewData.Remove(customizeSettingsEventHandlerKey);

	});

	this.ViewData[customizeSettingsEventHandlerKey] = customizeSettingsEventHandler;
	this.Model.CustomizeSettings += customizeSettingsEventHandler;
}

@Html.Xafari().Partial("Editors/Xafari.Mvc.MVCx.Editors/MVCxGridListEditor/_PartialCallback")