@model IEnumerable<GreenTree.Nachtragsmanagement.Web.Models.Config.ConfigItemDataModel>

@using GreenTree.Nachtragsmanagement.Web.Extensions

@{ 
	var userContext = GreenTree.Nachtragsmanagement.Core.CommonHelper.UserContext();
}

@Html.DevExpress().GridView(s =>
{
	s.Name = "devGridViewConfigItem";
	s.KeyFieldName = "Id";
	s.CallbackRouteValues = new { Controller = "Misc", Action = "PartialConfigItems" };
	s.Width = Unit.Percentage(99);
	s.Settings.ShowFilterRow = true;
	s.Settings.ShowFilterRowMenu = true;
	s.Settings.VerticalScrollBarMode = ScrollBarMode.Auto;
	s.Settings.VerticalScrollableHeight =
		(ViewData["ScrollHeight"] == null || (int)ViewData["ScrollHeight"] == -1)
			? 400
			: (int)ViewData["ScrollHeight"];
	s.SettingsPager.AlwaysShowPager = true;
	s.SettingsPager.PageSizeItemSettings.Visible = true;
	s.SettingsPager.PageSize = 50;

	if (userContext.CurrentUser.HasFunction("Misc-ConfigItems-Edit"))
	{
		s.Columns.Add(column =>
		{
			column.Caption = "#";
			column.SetDataItemTemplateContent(c =>
			{
				ViewContext.Writer.Write(
					"<a href=\"#\" onclick=\"editConfigItem(" + DataBinder.Eval(c.DataItem, "Id") + ")\">Bearbeiten</a>&nbsp;" +
					"<a href=\"#\" onclick=\"confirmDelete(" + DataBinder.Eval(c.DataItem, "Id") + ")\">Löschen</a>"
				);
			});
			column.SetHeaderTemplateContent(c =>
			{
				ViewContext.Writer.Write(
					"<a href=\"#\" onclick=\"editConfigItem(-1)\">Neu</a>&nbsp;");
			});
			column.Settings.AllowDragDrop = DefaultBoolean.False;
			column.Settings.AllowSort = DefaultBoolean.False;
			column.Width = new Unit(150, UnitType.Pixel);
		});
	}
	s.Columns.Add(column =>
	{
		column.Caption = "Name";
		column.FieldName = "Name";
		column.MinWidth = 220;
		column.Width = new Unit(20, UnitType.Percentage);
		column.SetDataItemTemplateContent(c =>
		{
			var name = DataBinder.Eval(c.DataItem, "Name").ToString();

			if (String.IsNullOrEmpty(name))
				ViewContext.Writer.Write(String.Empty);
			else
			{
				if (name.Length > 25)
					ViewContext.Writer.Write(
						"<a href=\"#\" onmouseover='showFullName(\"" + name + "\",this)'>" + name.Substring(0, 25) + " ...</a>");
				else
					ViewContext.Writer.Write(name);
			}
		});
	});
	s.Columns.Add(column =>
	{
		column.Caption = "Datentyp";
		column.FieldName = "TypeDescription";
		column.MinWidth = 100;
		column.Width = new Unit(15, UnitType.Percentage);
	});
	s.Columns.Add(column =>
	{
		column.Caption = "Wert";
		column.FieldName = "Value";
		column.MinWidth = 120;
		column.Width = new Unit(15, UnitType.Percentage);
	});
	s.Columns.Add(column =>
	{
		column.Caption = "Beschreibung";
		column.FieldName = "Description";
		column.MinWidth = 300;
		column.Width = new Unit(40, UnitType.Percentage);
	});

	s.ClientLayout = (sender, e) =>
	{
		if (e.LayoutMode == ClientLayoutMode.Loading)
		{
			if (Session["ConfigItemGridState"] != null)
				e.LayoutData = (string)Session["ConfigItemGridState"];
		}
		else
			Session["ConfigItemGridState"] = e.LayoutData;
	};
	s.ClientSideEvents.BeginCallback = "function (s, e) { e.customArgs['scrollHeight'] = [ gridScrollHeight ]; }";

	s.Styles.AlternatingRow.BackColor = System.Drawing.Color.FromArgb(247, 247, 247);
}).Bind(Model).GetHtml()