protected virtual ITemplate GetFormTemplate() { var context = OrganizationServiceContextFactory.Create() as OrganizationServiceContext; var cellTemplateFactory = CreateCellTemplateFactory(); if (!string.IsNullOrEmpty(TabName)) { var formXml = context.CreateQuery("systemform") .Single(form => form.GetAttributeValue <string>("objecttypecode") == EntityName && form.GetAttributeValue <OptionSetValue>("type").Value == 2) .GetAttributeValue <string>("formxml"); var sections = XDocument.Parse(formXml).XPathSelectElements("form/tabs/tab").Where( tab => tab.XPathSelectElements("labels/label").Any( label => label.Attributes("description").Any(description => description.Value == TabName) ) ).SelectMany(tab => tab.XPathSelectElements("columns/column/sections/section")); cellTemplateFactory.Initialize(this, new FormXmlCellMetadataFactory(), CellBindings, LanguageCode, ValidationGroup, ShowUnsupportedFields); var rowTemplateFactory = new RowTemplateFactory(LanguageCode); var sectionTemplates = sections.Select(s => new SectionTemplate(s, LanguageCode, EntityMetadata, cellTemplateFactory, rowTemplateFactory)); return(new CompositeTemplate(sectionTemplates)); } if (!string.IsNullOrEmpty(SavedQueryName)) { cellTemplateFactory.Initialize(this, new SavedQueryCellMetadataFactory(), CellBindings, LanguageCode, ValidationGroup, ShowUnsupportedFields); var layoutXml = context.CreateQuery("savedquery") .Single(view => view.GetAttributeValue <string>("name") == SavedQueryName) .GetAttributeValue <string>("layoutxml"); var rows = XDocument.Parse(layoutXml).XPathSelectElements("grid/row"); var rowTemplates = rows.Select(r => new SavedQueryRowTemplate(r, LanguageCode, EntityMetadata, cellTemplateFactory)); return(new CompositeTemplate(rowTemplates)); } return(new EmptyTemplate()); }
public override void InstantiateIn(Control container) { var wrapper = new HtmlGenericControl("fieldset"); container.Controls.Add(wrapper); var sectionTable = new HtmlGenericControl("table"); sectionTable.Attributes.Add("role", "presentation"); string sectionName; var sectionLabel = string.Empty; var sectionCssClassName = string.Empty; string visibleProperty; var visible = true; Node.TryGetAttributeValue(".", "visible", out visibleProperty); if (!string.IsNullOrWhiteSpace(visibleProperty)) { bool.TryParse(visibleProperty, out visible); } if (!visible) { return; } if (Node.TryGetAttributeValue(".", "name", out sectionName)) { sectionTable.Attributes.Add("data-name", sectionName); if (_webformMetadata != null) { var sectionWebFormMetadata = _webformMetadata.FirstOrDefault(wfm => wfm.GetAttributeValue <string>("adx_sectionname") == sectionName); if (sectionWebFormMetadata != null) { var label = sectionWebFormMetadata.GetAttributeValue <string>("adx_label"); if (!string.IsNullOrWhiteSpace(label)) { sectionLabel = Localization.GetLocalizedString(label, LanguageCode); } sectionCssClassName = sectionWebFormMetadata.GetAttributeValue <string>("adx_cssclass") ?? string.Empty; } } } sectionTable.Attributes.Add("class", !string.IsNullOrWhiteSpace(sectionCssClassName) ? string.Join(" ", "section", sectionCssClassName) : "section"); if (ShowLabel) { var caption = new HtmlGenericControl("legend") { InnerHtml = string.IsNullOrWhiteSpace(sectionLabel) ? Label : sectionLabel }; var cssClass = "section-title"; if (ShowBar) { cssClass += " show-bar"; } caption.Attributes.Add("class", cssClass); wrapper.Controls.Add(caption); } var colgroup = new HtmlGenericControl("colgroup"); sectionTable.Controls.Add(colgroup); if (PortalSettings.Instance.BingMapsSupported && !string.IsNullOrWhiteSpace(sectionName) && sectionName.EndsWith("section_map")) { var bingmap = new BingMap { ClientIDMode = ClientIDMode.Static, MappingFieldCollection = MappingFieldCollection }; sectionTable.Controls.Add(bingmap); } string columns; if (Node.TryGetAttributeValue(".", "columns", out columns)) { // For every column there is a "1" in the columns attribute... 1=1, 11=2, 111=3, etc.) foreach (var column in columns) { var width = 1 / (double)columns.Length * 100; var col = new SelfClosingHtmlGenericControl("col"); col.Style.Add(HtmlTextWriterStyle.Width, "{0}%".FormatWith(width)); colgroup.Controls.Add(col); } colgroup.Controls.Add(new SelfClosingHtmlGenericControl("col")); } wrapper.Controls.Add(sectionTable); var rowTemplates = Node.XPathSelectElements("rows/row").Select(row => RowTemplateFactory.CreateTemplate(row, EntityMetadata, CellTemplateFactory)); foreach (var template in rowTemplates) { template.InstantiateIn(sectionTable); } }