@model IEnumerable<GreenTree.Nachtragsmanagement.Web.Models.Site.SiteDataModel>

@using GreenTree.Nachtragsmanagement.Web.Extensions

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

@Html.DevExpress().GridView(Html.SiteGridViewSettings()).Bind(Model).GetHtml()

@*@Html.DevExpress().GridView(s =>
{
	s.Name = "devGridViewSite";
	s.KeyFieldName = "Id";
	s.CallbackRouteValues = new { Controller = "Site", Action = "PartialSites" };
	s.Width = Unit.Percentage(100);
	s.Settings.ShowFilterRow = true;
	s.Settings.ShowFilterRowMenu = true;
	s.Settings.ShowFooter = true;
	s.Settings.ShowGroupPanel = true;
	s.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
	s.Settings.VerticalScrollBarMode = ScrollBarMode.Auto;
	s.Settings.VerticalScrollableHeight = (ViewData["ScrollHeight"] == null || (int)ViewData["ScrollHeight"] == -1) ? 400 : (int)ViewData["ScrollHeight"];
	s.Toolbars.Add(t =>
	{
		var refreshItem = t.Items.Add(GridViewToolbarCommand.Refresh);
		refreshItem.Text = "Aktualisieren";
		var expandItem = t.Items.Add(GridViewToolbarCommand.FullExpand);
		expandItem.Text = "Alle aufklappen";
		var collapseItem = t.Items.Add(GridViewToolbarCommand.FullCollapse);
		collapseItem.Text = "Alle einklappen";
		var filterItem = t.Items.Add(GridViewToolbarCommand.ClearFilter);
		filterItem.Text = "Filter entfernen";
		t.Items.Add(i =>
		{
			i.Text = "Exportieren nach";
			i.Image.IconID = IconID.ActionsDownload16x16office2013;
			i.BeginGroup = true;
			i.Items.Add(exportitem =>
			{
				exportitem.Name = "Pdf";
				exportitem.Text = "PDF";
				exportitem.Image.IconID = IconID.ExportExporttopdf16x16office2013;
			});
			i.Items.Add(exportitem =>
			{
				exportitem.Name = "Xlsx";
				exportitem.Text = "XLSX";
				exportitem.Image.IconID = IconID.ExportExporttoxlsx16x16office2013;
			});
			i.Items.Add(exportitem =>
			{
				exportitem.Name = "Xls";
				exportitem.Text = "XLS";
				exportitem.Image.IconID = IconID.ExportExporttoxls16x16office2013;
			});
		});
	});

	if (userContext.CurrentUser.HasFunction("Site-Sites-Edit"))
	{
		s.Columns.Add(column =>
		{
			column.Caption = "#";
			column.SetDataItemTemplateContent(c =>
			{
				ViewContext.Writer.Write(
					"<a href=\"#\" onclick=\"editSite(" + 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=\"editSite(-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 = "Kostenstelle";
		column.FieldName = "CustomNumber";
		column.MinWidth = 100;
		column.Width = new Unit(10, UnitType.Percentage);
	});
	s.Columns.Add(column =>
	{
		column.Caption = "Bauvorhaben";
		column.FieldName = "Description";
		column.Width = new Unit(13, UnitType.Percentage);
	});
	s.Columns.Add(column =>
	{
		column.Caption = "Start";
		column.FieldName = "Start";
		column.PropertiesEdit.DisplayFormatString = "dd.MM.yyyy";
		column.MinWidth = 110;
		column.Width = new Unit(8, UnitType.Percentage);
	});
	s.Columns.Add(column =>
	{
		column.Caption = "Ende";
		column.FieldName = "End";
		column.PropertiesEdit.DisplayFormatString = "dd.MM.yyyy";
		column.MinWidth = 110;
		column.Width = new Unit(8, UnitType.Percentage);
	});
	s.Columns.Add(column =>
	{
		column.Caption = "VA";
		column.FieldName = "DeviationDescription";
		column.MinWidth = 150;
		column.Width = new Unit(12, UnitType.Percentage);
	});
	s.Columns.Add(column =>
	{
		column.Caption = "VA-Summe";
		column.FieldName = "DeviationValue";
		column.PropertiesEdit.DisplayFormatString = "c2";
		column.MinWidth = 120;
		column.Width = new Unit(10, UnitType.Percentage);
	});
	s.Columns.Add(column =>
	{
		column.Caption = "Nachträge";
		column.FieldName = "AppendixDescription";
		column.Width = new Unit(10, UnitType.Percentage);
	});
	s.Columns.Add(column =>
	{
		column.Caption = "Mitarbeiter";
		column.FieldName = "UserDescription";
		column.MinWidth = 150;
		column.Width = new Unit(20, UnitType.Percentage);
	});

	s.TotalSummary.Add(DevExpress.Data.SummaryItemType.Sum, "DeviationValue");
	s.GroupSummary.Add(DevExpress.Data.SummaryItemType.Sum, "DeviationValue");

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

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