private static void CreateBackendSections(DetailFormViewElement detailView, FieldDisplayMode displayMode) { #region Toolbar section if (detailView.ViewName == ProductsDefinitions.BackendEditViewName) { var toolbarSection = new ContentViewSectionElement(detailView.Sections) { Name = DefinitionsHelper.ToolbarSectionName }; var languageListFieldElement = new LanguageListFieldElement(toolbarSection.Fields) { ID = "languageListField", FieldType = typeof(LanguageListField), ResourceClassId = typeof(LocalizationResources).Name, Title = "OtherTranslationsColon", DisplayMode = displayMode, FieldName = "languageListField", DataFieldName = "AvailableLanguages" }; toolbarSection.Fields.Add(languageListFieldElement); detailView.Sections.Add(toolbarSection); } #endregion #region Main section var mainSection = new ContentViewSectionElement(detailView.Sections) { Name = "MainSection", CssClass = "sfFirstForm" }; var titleField = new TextFieldDefinitionElement(mainSection.Fields) { ID = "titleFieldControl", DataFieldName = (displayMode == FieldDisplayMode.Write) ? "Title.PersistedValue" : "Title", DisplayMode = displayMode, Title = "lTitle", CssClass = "sfTitleField", ResourceClassId = typeof(ProductsResources).Name, WrapperTag = HtmlTextWriterTag.Li, }; titleField.ValidatorConfig = new ValidatorDefinitionElement(titleField) { Required = true, MessageCssClass = "sfError", RequiredViolationMessage = "TitleCannotBeEmpty", ResourceClassId = typeof(ProductsResources).Name }; mainSection.Fields.Add(titleField); if (detailView.ViewName == ProductsDefinitions.BackendEditViewName || detailView.ViewName == ProductsDefinitions.BackendInsertViewName) { var languageChoiceField = new ChoiceFieldElement(mainSection.Fields) { ID = "languageChoiceField", FieldType = typeof(LanguageChoiceField), ResourceClassId = typeof(ProductsResources).Name, Title = "Language", DisplayMode = displayMode, FieldName = "languageField", RenderChoiceAs = RenderChoicesAs.DropDown, MutuallyExclusive = true, DataFieldName = "AvailableLanguages" }; mainSection.Fields.Add(languageChoiceField); } var dropDownTaxonomyField = new TaxonFieldDefinitionElement(mainSection.Fields) { ID = "testTaxonomyField", Title = "Colors", DataFieldName = "Colors", TaxonomyId = ProductsModule.ColorsTaxonomyId, FieldType = typeof(TaxonomyDropDownField), DisplayMode = displayMode, }; mainSection.Fields.Add(dropDownTaxonomyField); var contentField = new HtmlFieldElement(mainSection.Fields) { ID = "contentFieldControl", DataFieldName = (displayMode == FieldDisplayMode.Write) ? "Content.PersistedValue" : "Content", DisplayMode = displayMode, CssClass = "sfFormSeparator sfContentField", ResourceClassId = typeof(ProductsResources).Name, WrapperTag = HtmlTextWriterTag.Li, EditorContentFilters = Telerik.Web.UI.EditorFilters.DefaultFilters, EditorStripFormattingOptions = (Telerik.Web.UI.EditorStripFormattingOptions?)(Telerik.Web.UI.EditorStripFormattingOptions.MSWord | Telerik.Web.UI.EditorStripFormattingOptions.Css | Telerik.Web.UI.EditorStripFormattingOptions.Font | Telerik.Web.UI.EditorStripFormattingOptions.Span | Telerik.Web.UI.EditorStripFormattingOptions.ConvertWordLists) }; mainSection.Fields.Add(contentField); //Product Image var productImageField = new ImageFieldElement(mainSection.Fields) { ID = "avatarField", DataFieldName = "ProductImage", DisplayMode = displayMode, UploadMode = ImageFieldUploadMode.Dialog, Title = "ProductImageFieldTitle", WrapperTag = HtmlTextWriterTag.Li, CssClass = "sfUserAvatar", ResourceClassId = typeof(ProductsResources).Name, DataFieldType = typeof(ContentLink), DefaultSrc = "~/SFRes/images/ProductCatalogSample/Images.NoProductImage.png", // put your default image location example: SizeInPx = 100 }; mainSection.Fields.Add(productImageField); var summaryField = new TextFieldDefinitionElement(mainSection.Fields) { ID = "whatsInTheBoxFieldControl", DataFieldName = (displayMode == FieldDisplayMode.Write) ? "WhatIsInTheBox.PersistedValue" : "WhatIsInTheBox", DisplayMode = displayMode, Title = "WhatIsInTheBox", CssClass = "sfFormSeparator", WrapperTag = HtmlTextWriterTag.Li, ResourceClassId = typeof(ProductsResources).Name, Rows = 5 }; summaryField.ExpandableDefinitionConfig = new ExpandableControlElement(summaryField) { Expanded = false, ExpandText = "ClickToAddSummary", ResourceClassId = typeof(ProductsResources).Name }; summaryField.ValidatorConfig.Required = false; mainSection.Fields.Add(summaryField); var quantityField = new TextFieldDefinitionElement(mainSection.Fields) { ID = "quantityFieldControl", DataFieldName = "QuantityInStock", DisplayMode = displayMode, Title = "QuantityInStock", CssClass = "sfTitleField", ResourceClassId = typeof(ProductsResources).Name, WrapperTag = HtmlTextWriterTag.Li }; quantityField.ValidatorConfig = new ValidatorDefinitionElement(quantityField) { Required = true, MessageCssClass = "sfError", RequiredViolationMessage = "TitleCannotBeEmpty", ResourceClassId = typeof(ProductsResources).Name, RegularExpression = "^[0-9]+[.]*[0-9]*$", RegularExpressionViolationMessage = "TheQuantityMustBeAPositiveNumber" }; mainSection.Fields.Add(quantityField); var priceField = new TextFieldDefinitionElement(mainSection.Fields) { ID = "priceFieldControl", DataFieldName = "Price", DisplayMode = displayMode, Title = "Price", CssClass = "sfTitleField", ResourceClassId = typeof(ProductsResources).Name, WrapperTag = HtmlTextWriterTag.Li, }; priceField.ValidatorConfig = new ValidatorDefinitionElement(priceField) { Required = true, MessageCssClass = "sfError", RequiredViolationMessage = "TitleCannotBeEmpty", ResourceClassId = typeof(ProductsResources).Name, RegularExpression = "^[0-9]+[.]*[0-9]*$", RegularExpressionViolationMessage = "ThePriceMustBeAPositiveNumber" }; mainSection.Fields.Add(priceField); detailView.Sections.Add(mainSection); #endregion #region Categories and Tags var taxonSection = new ContentViewSectionElement(detailView.Sections) { Name = "TaxonSection", Title = "CategoriesAndTags", ResourceClassId = typeof(ProductsResources).Name, CssClass = "sfExpandableForm", ExpandableDefinitionConfig = { Expanded = false } }; var categories = DefinitionTemplates.CategoriesFieldWriteMode(taxonSection.Fields); categories.DisplayMode = displayMode; taxonSection.Fields.Add(categories); var tags = DefinitionTemplates.TagsFieldWriteMode(taxonSection.Fields); tags.DisplayMode = displayMode; tags.CssClass = "sfFormSeparator"; tags.ExpandableDefinition.Expanded = true; tags.Description = "TagsFieldInstructions"; taxonSection.Fields.Add(tags); detailView.Sections.Add(taxonSection); #endregion #region More options section var moreOptionsSection = new ContentViewSectionElement(detailView.Sections) { Name = "MoreOptionsSection", Title = "MoreOptionsURL", ResourceClassId = typeof(ProductsResources).Name, CssClass = "sfExpandableForm", ExpandableDefinitionConfig = { Expanded = false } }; if (displayMode == FieldDisplayMode.Write) { var urlName = new MirrorTextFieldElement(moreOptionsSection.Fields) { Title = "UrlName", ResourceClassId = typeof(ProductsResources).Name, ID = "urlName", MirroredControlId = titleField.ID, DataFieldName = (displayMode == FieldDisplayMode.Write) ? "UrlName.PersistedValue" : "UrlName", DisplayMode = displayMode, RegularExpressionFilter = DefinitionsHelper.UrlRegularExpressionFilter, WrapperTag = HtmlTextWriterTag.Li, ReplaceWith = "-" }; var validationDef = new ValidatorDefinitionElement(urlName) { Required = true, MessageCssClass = "sfError", RequiredViolationMessage = Res.Get<ProductsResources>().UrlNameCannotBeEmpty, RegularExpression = DefinitionsHelper.UrlRegularExpressionFilterForValidator, RegularExpressionViolationMessage = Res.Get<PageResources>().UrlNameInvalidSymbols }; urlName.ValidatorConfig = validationDef; moreOptionsSection.Fields.Add(urlName); } var allowCommentsFieldElement = new ChoiceFieldElement(moreOptionsSection.Fields) { ID = "allowCommentsField", Title = (displayMode == FieldDisplayMode.Read) ? "AllowComments" : string.Empty, DataFieldName = "AllowComments", DisplayMode = displayMode, RenderChoiceAs = RenderChoicesAs.SingleCheckBox, CssClass = "sfCheckBox sfFormSeparator", WrapperTag = HtmlTextWriterTag.Li, ResourceClassId = typeof(ProductsResources).Name }; allowCommentsFieldElement.ChoicesConfig.Add( new ChoiceElement(allowCommentsFieldElement.ChoicesConfig) { Text = "AllowComments", ResourceClassId = typeof(ProductsResources).Name }); moreOptionsSection.Fields.Add(allowCommentsFieldElement); detailView.Sections.Add(moreOptionsSection); #endregion #region Sidebar if (displayMode == FieldDisplayMode.Write) { var sidebar = new ContentViewSectionElement(detailView.Sections) { Name = DefinitionsHelper.SidebarSectionName, CssClass = "sfItemReadOnlyInfo" }; sidebar.Fields.Add(new ContentWorkflowStatusInfoFieldElement(sidebar.Fields) { DisplayMode = displayMode, FieldName = "NewsWorkflowStatusInfoField", ResourceClassId = typeof(ProductsResources).Name, WrapperTag = HtmlTextWriterTag.Li, FieldType = typeof(ContentWorkflowStatusInfoField) }); detailView.Sections.Add(sidebar); } #endregion }
private static void CreateBackendSections(DetailFormViewElement detailView, FieldDisplayMode displayMode) { #region Toolbar section if (detailView.ViewName == AgentsDefinitions.BackendEditViewName) { var toolbarSection = new ContentViewSectionElement(detailView.Sections) { Name = DefinitionsHelper.ToolbarSectionName }; var languageListFieldElement = new LanguageListFieldElement(toolbarSection.Fields) { ID = "languageListField", FieldType = typeof(LanguageListField), ResourceClassId = typeof(LocalizationResources).Name, Title = "OtherTranslationsColon", DisplayMode = displayMode, FieldName = "languageListField", DataFieldName = "AvailableLanguages" }; toolbarSection.Fields.Add(languageListFieldElement); detailView.Sections.Add(toolbarSection); } #endregion #region Main section var mainSection = new ContentViewSectionElement(detailView.Sections) { Name = "MainSection", CssClass = "sfFirstForm" }; var titleField = new TextFieldDefinitionElement(mainSection.Fields) { ID = "titleFieldControl", DataFieldName = (displayMode == FieldDisplayMode.Write) ? "Title.PersistedValue" : "Title", DisplayMode = displayMode, Title = "lTitle", CssClass = "sfTitleField", ResourceClassId = typeof(AgentsResources).Name, WrapperTag = HtmlTextWriterTag.Li, }; titleField.ValidatorConfig = new ValidatorDefinitionElement(titleField) { Required = true, MessageCssClass = "sfError", RequiredViolationMessage = "TitleCannotBeEmpty", ResourceClassId = typeof(AgentsResources).Name }; mainSection.Fields.Add(titleField); if (detailView.ViewName == AgentsDefinitions.BackendEditViewName || detailView.ViewName == AgentsDefinitions.BackendInsertViewName) { var languageChoiceField = new ChoiceFieldElement(mainSection.Fields) { ID = "languageChoiceField", FieldType = typeof(LanguageChoiceField), ResourceClassId = typeof(AgentsResources).Name, Title = "Language", DisplayMode = displayMode, FieldName = "languageField", RenderChoiceAs = RenderChoicesAs.DropDown, MutuallyExclusive = true, DataFieldName = "AvailableLanguages" }; mainSection.Fields.Add(languageChoiceField); } var emailField = new TextFieldDefinitionElement(mainSection.Fields) { ID = "emailFieldControl", DataFieldName = "Email", DisplayMode = displayMode, Title = "Email", CssClass = "sfTitleField", ResourceClassId = typeof(AgentsResources).Name, WrapperTag = HtmlTextWriterTag.Li }; emailField.ValidatorConfig = new ValidatorDefinitionElement(emailField) { Required = true, MessageCssClass = "sfError", RequiredViolationMessage = "EmailCannotBeEmpty", RegularExpression = @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$", RegularExpressionViolationMessage = "EmailMustBeValid", ResourceClassId = typeof(AgentsResources).Name }; mainSection.Fields.Add(emailField); var phoneNumberField = new TextFieldDefinitionElement(mainSection.Fields) { ID = "phoneNumberFieldControl", DataFieldName = "PhoneNumber", DisplayMode = displayMode, Title = "PhoneNumber", CssClass = "sfTitleField", ResourceClassId = typeof(AgentsResources).Name, WrapperTag = HtmlTextWriterTag.Li }; mainSection.Fields.Add(phoneNumberField); var addressField = new TextFieldDefinitionElement(mainSection.Fields) { ID = "addressFieldControl", DataFieldName = "Address", DisplayMode = displayMode, Title = "Address", CssClass = "sfTitleField", ResourceClassId = typeof(AgentsResources).Name, WrapperTag = HtmlTextWriterTag.Li }; mainSection.Fields.Add(addressField); var postalCodeField = new TextFieldDefinitionElement(mainSection.Fields) { ID = "postalCodeFieldControl", DataFieldName = "PostalCode", DisplayMode = displayMode, Title = "PostalCode", CssClass = "sfTitleField", ResourceClassId = typeof(AgentsResources).Name, WrapperTag = HtmlTextWriterTag.Li }; mainSection.Fields.Add(postalCodeField); detailView.Sections.Add(mainSection); #endregion #region Categories and Tags var taxonSection = new ContentViewSectionElement(detailView.Sections) { Name = "TaxonSection", Title = "CategoriesAndTags", ResourceClassId = typeof(AgentsResources).Name, CssClass = "sfExpandableForm", ExpandableDefinitionConfig = { Expanded = false } }; var categories = DefinitionTemplates.CategoriesFieldWriteMode(taxonSection.Fields); categories.DisplayMode = displayMode; taxonSection.Fields.Add(categories); var tags = DefinitionTemplates.TagsFieldWriteMode(taxonSection.Fields); tags.DisplayMode = displayMode; tags.CssClass = "sfFormSeparator"; tags.ExpandableDefinition.Expanded = true; tags.Description = "TagsFieldInstructions"; taxonSection.Fields.Add(tags); detailView.Sections.Add(taxonSection); #endregion #region More options section var moreOptionsSection = new ContentViewSectionElement(detailView.Sections) { Name = "MoreOptionsSection", Title = "MoreOptionsURL", ResourceClassId = typeof(AgentsResources).Name, CssClass = "sfExpandableForm", ExpandableDefinitionConfig = { Expanded = false } }; if (displayMode == FieldDisplayMode.Write) { var urlName = new MirrorTextFieldElement(moreOptionsSection.Fields) { Title = "UrlName", ID = "urlName", MirroredControlId = titleField.ID, DataFieldName = "UrlName.PersistedValue", DisplayMode = displayMode, RegularExpressionFilter = DefinitionsHelper.UrlRegularExpressionFilter, WrapperTag = HtmlTextWriterTag.Li, ReplaceWith = "-", ResourceClassId = typeof(AgentsResources).Name }; var validationDef = new ValidatorDefinitionElement(urlName) { Required = true, MessageCssClass = "sfError", RequiredViolationMessage = "UrlNameCannotBeEmpty", RegularExpression = DefinitionsHelper.UrlRegularExpressionFilterForValidator, RegularExpressionViolationMessage = "UrlNameInvalid", ResourceClassId = typeof(AgentsResources).Name }; urlName.ValidatorConfig = validationDef; moreOptionsSection.Fields.Add(urlName); } detailView.Sections.Add(moreOptionsSection); #endregion #region Sidebar if (displayMode == FieldDisplayMode.Write) { var sidebar = new ContentViewSectionElement(detailView.Sections) { Name = DefinitionsHelper.SidebarSectionName, CssClass = "sfItemReadOnlyInfo" }; sidebar.Fields.Add(new ContentWorkflowStatusInfoFieldElement(sidebar.Fields) { DisplayMode = displayMode, FieldName = "NewsWorkflowStatusInfoField", ResourceClassId = typeof(AgentsResources).Name, WrapperTag = HtmlTextWriterTag.Li, FieldType = typeof(ContentWorkflowStatusInfoField) }); detailView.Sections.Add(sidebar); } #endregion }