@model IEnumerable<GreenTree.Nachtragsmanagement.Web.Models.Admin.Plugins.PluginDataModel>

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

@Html.DevExpress().GridView(s =>
{
	s.Name = "devGridViewPlugin";
	s.KeyFieldName = "Id";
	s.CallbackRouteValues = new { Controller = "Admin", Action = "PartialPlugins" };
	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;

	if (userContext.CurrentUser.HasFunction("Administration-Plugins-Edit"))
	{
		s.Columns.Add(column =>
		{
			column.Caption = "#";
			column.SetDataItemTemplateContent(c =>
			{
				var isInstalled = Convert.ToBoolean(DataBinder.Eval(c.DataItem, "IsInstalled"));
				var systemName = DataBinder.Eval(c.DataItem, "SystemName").ToString();

				if (isInstalled)
					ViewContext.Writer.Write(
						"<a href=\"#\" onclick=\'toggleInstallation(\"" + systemName + "\",\"uninstall\")'>Deinstallieren</a>");
				else
					ViewContext.Writer.Write(
						"<a href=\"#\" onclick=\'toggleInstallation(\"" + systemName + "\",\"install\")'>Installieren</a>");
			});
			column.Settings.AllowDragDrop = DefaultBoolean.False;
			column.Settings.AllowSort = DefaultBoolean.False;
			column.Width = 60;
		});
	}
	s.Columns.Add(column =>
	{
		column.Caption = "Logo";
		column.FieldName = "LogoUrl";
		column.SetDataItemTemplateContent(c =>
		{
			var logoPath = DataBinder.Eval(c.DataItem, "LogoUrl").ToString();

			ViewContext.Writer.Write("<img src=\"" + Url.Content(logoPath) + "\" />");
		});
		column.MinWidth = 80;
		column.Width = new Unit(80, UnitType.Pixel);
		column.CellStyle.HorizontalAlign = HorizontalAlign.Center;
	});
	s.Columns.Add(column =>
	{
		column.Caption = "Gruppe";
		column.FieldName = "Group";
		column.MinWidth = 110;
		column.Width = new Unit(130, UnitType.Pixel);
	});
	s.Columns.Add(column =>
	{
		column.Caption = "Name";
		column.FieldName = "FriendlyName";
		column.MinWidth = 120;
		column.Width = new Unit(150, UnitType.Pixel);
	});
	s.Columns.Add(column =>
	{
		column.Caption = "Systemname";
		column.FieldName = "SystemName";
		column.MinWidth = 150;
		column.Width = new Unit(180, UnitType.Pixel);
	});
	s.Columns.Add(column =>
	{
		column.Caption = "Version";
		column.FieldName = "Version";
		column.MinWidth = 70;
		column.Width = new Unit(90, UnitType.Pixel);
	});
	s.Columns.Add(column =>
	{
		column.Caption = "Autor";
		column.FieldName = "Author";
		column.MinWidth = 110;
		column.Width = new Unit(150, UnitType.Pixel);
	});

	s.ClientLayout = (sender, e) =>
	{
		if (e.LayoutMode == ClientLayoutMode.Loading)
		{
			if (Session["PluginGridState"] != null)
				e.LayoutData = (string)Session["PluginGridState"];
		}
		else
			Session["PluginGridState"] = 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()