In this method, you must create the actual form for managing the items in your module. Use the following code for the method:
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
}