public static HtmlBuilder Tr( this HtmlBuilder hb, Context context, SiteSettings ss, DataRow dataRow, IEnumerable <Column> columns, bool editRow, bool checkRow, string idColumn, RecordSelector recordSelector = null, FormDataSet formDataSet = null) { var dataId = dataRow.Long(idColumn); var dataVersion = dataRow.Int("Ver"); var isHistory = dataRow.Bool("IsHistory"); var EditColumns = !isHistory ? columns.ToDictionary( column => column.ColumnName, column => EditColumn( context: context, column: column)) : new Dictionary <string, bool>(); BaseItemModel rowModel = null; switch (ss.ReferenceType) { case "Issues": var issueModel = new IssueModel( context: context, ss: ss, dataRow: dataRow, formData: editRow ? formDataSet?.FirstOrDefault(o => o.Id == dataRow.Long("IssueId"))?.Data : null); ss.SetColumnAccessControls( context: context, mine: issueModel.Mine(context: context)); rowModel = issueModel; break; case "Results": var resultModel = new ResultModel( context: context, ss: ss, dataRow: dataRow, formData: editRow ? formDataSet?.FirstOrDefault(o => o.Id == dataRow.Long("ResultId"))?.Data : null); ss.SetColumnAccessControls( context: context, mine: resultModel.Mine(context: context)); rowModel = resultModel; break; } ; var serverScriptRowValues = rowModel?.SetByBeforeOpeningPageServerScript( context: context, ss: ss); var extendedRowCss = serverScriptRowValues?.ExtendedRowCss; extendedRowCss = extendedRowCss.IsNullOrEmpty() ? string.Empty : " " + extendedRowCss; return(hb.Tr( attributes: new HtmlAttributes() .Class("grid-row" + extendedRowCss) .DataId(dataId.ToString()) .DataVer(dataVersion) .DataLatest(1, _using: !isHistory) .Add(name: "data-history", value: "1", _using: isHistory) .Add(name: "data-locked", value: "1", _using: dataRow.Bool("Locked")), action: () => { if (editRow) { hb.Td(action: () => hb .Button( title: Displays.Reload(context: context), controlCss: "button-icon", onClick: $"$p.getData($(this)).Id={dataId};$p.send($(this));", icon: "ui-icon-refresh", action: "ReloadRow", method: "post", _using: !isHistory) .Button( title: Displays.Copy(context: context), controlCss: "button-icon", onClick: $"$p.getData($(this)).OriginalId={dataId};$p.send($(this));", icon: "ui-icon-copy", action: "CopyRow", method: "post", _using: !isHistory && context.CanCreate(ss: ss)) .Hidden( controlId: $"{ss.ReferenceType}_Timestamp_{ss.SiteId}_{dataId}", css: "timestamp", value: dataRow .Field <DateTime>("UpdatedTime") .ToString("yyyy/M/d H:m:s.fff"))); } else if (checkRow) { hb.Td(action: () => hb .CheckBox( controlCss: "grid-check", _checked: recordSelector.Checked(dataId), dataId: dataId.ToString(), _using: !isHistory)); } var depts = new Dictionary <string, DeptModel>(); var groups = new Dictionary <string, GroupModel>(); var registrations = new Dictionary <string, RegistrationModel>(); var users = new Dictionary <string, UserModel>(); var sites = new Dictionary <string, SiteModel>(); var issues = new Dictionary <string, IssueModel>(); var results = new Dictionary <string, ResultModel>(); ServerScriptModelRow serverScriptValues = null; columns.ForEach(column => { var key = column.TableName(); switch (column.SiteSettings?.ReferenceType) { case "Depts": var deptModel = depts.Get(key); if (deptModel == null) { deptModel = new DeptModel( context: context, ss: column.SiteSettings, dataRow: dataRow, tableAlias: column.TableAlias); depts.Add(key, deptModel); ss.SetColumnAccessControls( context: context, mine: deptModel.Mine(context: context)); serverScriptValues = deptModel.SetByBeforeOpeningPageServerScript( context: context, ss: ss); } hb.TdValue( context: context, ss: column.SiteSettings, column: column, deptModel: deptModel); break; case "Groups": var groupModel = groups.Get(key); if (groupModel == null) { groupModel = new GroupModel( context: context, ss: column.SiteSettings, dataRow: dataRow, tableAlias: column.TableAlias); groups.Add(key, groupModel); ss.SetColumnAccessControls( context: context, mine: groupModel.Mine(context: context)); serverScriptValues = groupModel.SetByBeforeOpeningPageServerScript( context: context, ss: ss); } hb.TdValue( context: context, ss: column.SiteSettings, column: column, groupModel: groupModel); break; case "Registrations": var registrationModel = registrations.Get(key); if (registrationModel == null) { registrationModel = new RegistrationModel( context: context, ss: column.SiteSettings, dataRow: dataRow, tableAlias: column.TableAlias); registrations.Add(key, registrationModel); ss.SetColumnAccessControls( context: context, mine: registrationModel.Mine(context: context)); serverScriptValues = registrationModel.SetByBeforeOpeningPageServerScript( context: context, ss: ss); } hb.TdValue( context: context, ss: column.SiteSettings, column: column, registrationModel: registrationModel); break; case "Users": var userModel = users.Get(key); if (userModel == null) { userModel = new UserModel( context: context, ss: column.SiteSettings, dataRow: dataRow, tableAlias: column.TableAlias); users.Add(key, userModel); ss.SetColumnAccessControls( context: context, mine: userModel.Mine(context: context)); serverScriptValues = userModel.SetByBeforeOpeningPageServerScript( context: context, ss: ss); } hb.TdValue( context: context, ss: column.SiteSettings, column: column, userModel: userModel); break; case "Sites": var siteModel = sites.Get(key); if (siteModel == null) { siteModel = new SiteModel( context: context, dataRow: dataRow, formData: editRow ? formDataSet?.FirstOrDefault(o => o.Id == dataRow.Long("SiteId"))?.Data : null, tableAlias: column.TableAlias); sites.Add(key, siteModel); ss.SetColumnAccessControls( context: context, mine: siteModel.Mine(context: context)); serverScriptValues = siteModel.SetByBeforeOpeningPageServerScript( context: context, ss: ss); } hb.TdValue( context: context, ss: column.SiteSettings, column: column, siteModel: siteModel); break; case "Issues": var issueModel = issues.Get(key); if (issueModel == null) { issueModel = new IssueModel( context: context, ss: column.SiteSettings, dataRow: dataRow, formData: editRow ? formDataSet?.FirstOrDefault(o => o.Id == dataRow.Long("IssueId"))?.Data : null, tableAlias: column.TableAlias); issues.Add(key, issueModel); ss.SetColumnAccessControls( context: context, mine: issueModel.Mine(context: context)); serverScriptValues = issueModel.SetByBeforeOpeningPageServerScript( context: context, ss: ss); } if (!issueModel.Locked && EditColumns.Get(column.ColumnName) && column.CanUpdate(baseModel: issueModel)) { hb.Td( css: column.TextAlign == SiteSettings.TextAlignTypes.Right ? " right-align" : string.Empty, action: () => hb.Field( context: context, column: column, issueModel: issueModel, ss: column.SiteSettings, controlOnly: true, idSuffix: issueModel.IdSuffix())); } else { hb.TdValue( context: context, ss: column.SiteSettings, column: column, issueModel: issueModel, serverScriptValues: serverScriptValues ?.Columns ?.Get(column?.ColumnName)); } break; case "Results": var resultModel = results.Get(key); if (resultModel == null) { resultModel = new ResultModel( context: context, ss: column.SiteSettings, dataRow: dataRow, formData: editRow ? formDataSet?.FirstOrDefault(o => o.Id == dataRow.Long("ResultId"))?.Data : null, tableAlias: column.TableAlias); results.Add(key, resultModel); ss.SetColumnAccessControls( context: context, mine: resultModel.Mine(context: context)); serverScriptValues = resultModel.SetByBeforeOpeningPageServerScript( context: context, ss: ss); } if (!resultModel.Locked && EditColumns.Get(column.ColumnName) && column.CanUpdate(baseModel: resultModel)) { hb.Td( css: column.TextAlign == SiteSettings.TextAlignTypes.Right ? " right-align" : string.Empty, action: () => hb.Field( context: context, column: column, resultModel: resultModel, ss: column.SiteSettings, controlOnly: true, idSuffix: resultModel.IdSuffix())); } else { hb.TdValue( context: context, ss: column.SiteSettings, column: column, resultModel: resultModel, serverScriptValues: serverScriptValues ?.Columns ?.Get(column?.ColumnName)); } break; } }); })); }