Getting Revision History to work in the Products Module samp

Posted by Community Admin on 05-Aug-2018 23:56

Getting Revision History to work in the Products Module sample

All Replies

Posted by Community Admin on 01-Feb-2011 00:00

When editing a product, nothing happens when I click on "Revision History" in the right column. How can I get this to work like the News Module?

Posted by Community Admin on 08-Feb-2011 00:00

Hi bemara57,

We are really sorry for the late answer. Unfortunately "Revision History" feature was not implemented in the Products Module for the official release, but it will be added in the next service pack. We will also extend the documentation for the sample module.

Best wishes,
Ivan Pelovski
the Telerik team


Check out Telerik Trainer, the state of the art learning tool for Telerik products.

Posted by Community Admin on 09-Feb-2011 00:00

Hello bemara57,

There was a problem in Sitefinity that did not allow to store versions of types outside of Telerik.Sitefinity and Telerik.Sitefinity.Model assemblies. The fix for this issue will be added to the next Sitefinity internal build (probably this week). Also check the Sitefinity SDK release where the code of Products module will be updated. Here are the changes that will enable version history and comparison in the Products module:

Add the following properties to ProductsResources class

/// <summary>
/// word: Tags
/// </summary>
[ResourceEntry("Tags",
    Value = "Tags",
    Description = "word: Tags",
    LastModified = "2011/02/09")]
public string Tags
    get
    
        return this["Tags"];
    
 
/// <summary>
/// Word: Category
/// </summary>
[ResourceEntry("Category",
    Value = "Category",
    Description = "word",
    LastModified = "2011/02/09")]
public string Category
    get
    
        return this["Category"];
    
 
/// <summary>
/// Version comparison screeen Title
/// </summary>
[ResourceEntry("VersionComparison",
    Value = "version comparison",
    Description = "word: News",
    LastModified = "2011/02/09")]
public string VersionComparison
    get return this["VersionComparison"];

Change the Initialize() method of the ProductsModule class by registering the assembly of the Products module to the TypeResolutionService

using Telerik.Sitefinity.Utilities.TypeConverters;
 
[SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "This method is obsolete")]
[SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "This method is obsolete")]
public override void Initialize(ModuleSettings settings)
    base.Initialize(settings);           
 
    Config.RegisterSection<ProductsConfig>();
    Res.RegisterResource<ProductsResources>();
    ObjectFactory.RegisterWebService(typeof(ProductsBackendService), "Sitefinity/Services/Content/Products.svc");
 
    //register templatable controls
    ControlTemplates.RegisterTemplatableControl(typeof(MasterListView), typeof(ProductItem));
    ControlTemplates.RegisterTemplatableControl(typeof(ProductDetailsView), typeof(ProductItem));
 
    //register the assembly with the TypeResolutionService
    TypeResolutionService.RegisterAssembly(typeof(ProductsModule).Assembly.GetName());

To the ProductsDefinitions add the following code:
- in DefineProductsBackendContentView() method you will need to register three more dialogs (declared in the Dialogs definition region) and to define two new views (declared in Preview History Form and Versioning Comparison Screen regions)

#region Dialogs definition
 
string versioningParams = string.Concat(
    "?ControlDefinitionName=",
    ProductsDefinitions.BackendDefinitionName,
    "&moduleName=", ProductsDefinitions.ModuleName,
    "&typeName=", typeof(ProductItem).AssemblyQualifiedName,
    "&title=", Res.Get<ProductsResources>().PermissionsForProducts,
    "&backLabelText=", Res.Get<ProductsResources>().BackToItems,
    "&" + ProductsDefinitions.ComparisonViewHistoryScreenQueryParameter + "=" + ProductsDefinitions.BackendVersionComapreViewName);
 
DialogElement versioningDialogElement = DefinitionsHelper.CreateDialogElement(
    productsGridView.DialogsConfig,
    DefinitionsHelper.HistoryCommandName,
    "VersionHistoryDialog",
    versioningParams);
productsGridView.DialogsConfig.Add(versioningDialogElement);
 
string versioningGridParams = string.Concat(
   "?ControlDefinitionName=",
   ProductsDefinitions.BackendDefinitionName,
   "&moduleName=", ProductsDefinitions.ModuleName,
   "&typeName=", typeof(ProductItem).AssemblyQualifiedName,
   "&title=", Res.Get<ProductsResources>().PermissionsForProducts,
   "&backLabelText=", Res.Get<ProductsResources>().BackToItems,
   "&" + ProductsDefinitions.ComparisonViewHistoryScreenQueryParameter + "=" + ProductsDefinitions.BackendVersionComapreViewName);
 
DialogElement versioningGridDialogElement = DefinitionsHelper.CreateDialogElement(
    productsGridView.DialogsConfig,
    ProductsDefinitions.HistoryGridCommandName,
    "VersionHistoryDialog",
    versioningGridParams);
productsGridView.DialogsConfig.Add(versioningGridDialogElement);
 
parameters = string.Concat(
   "?ControlDefinitionName=",
   ProductsDefinitions.BackendDefinitionName,
   "&ViewName=",
   ProductsDefinitions.BackendVersionPreviewViewName, "&backLabelText=", Res.Get<Labels>().BackToRevisionHistory, "&SuppressBackToButtonLabelModify=true");
DialogElement previewVersionDialogElement = DefinitionsHelper.CreateDialogElement(
    productsGridView.DialogsConfig,
    DefinitionsHelper.VersionPreviewCommandName,
    "ContentViewEditDialog",
    parameters);
productsGridView.DialogsConfig.Add(previewVersionDialogElement);
 
#endregion
 
#region Versioning Comparison Screen
 
var versionComparisonView = new ComparisonViewElement(backendContentView.ViewsConfig)
    Title = "VersionComparison",
    ViewName = ProductsDefinitions.BackendVersionComapreViewName,
    ViewType = typeof(VersionComparisonView),
    DisplayMode = FieldDisplayMode.Read,
    ResourceClassId = typeof(ProductsResources).Name,
    UseWorkflow = false
;
 
backendContentView.ViewsConfig.Add(versionComparisonView);
 
versionComparisonView.Fields.Add(new ComparisonFieldElement(versionComparisonView.Fields) FieldName = "Title", Title = "lTitle", ResourceClassId = typeof(ProductsResources).Name );
versionComparisonView.Fields.Add(new ComparisonFieldElement(versionComparisonView.Fields) FieldName = "Content", Title = "Content", ResourceClassId = typeof(ProductsResources).Name );
versionComparisonView.Fields.Add(new ComparisonFieldElement(versionComparisonView.Fields) FieldName = "WhatIsInTheBox", Title = "WhatIsInTheBox", ResourceClassId = typeof(ProductsResources).Name );
versionComparisonView.Fields.Add(new ComparisonFieldElement(versionComparisonView.Fields) FieldName = "Price", Title = "Price", ResourceClassId = typeof(ProductsResources).Name );
versionComparisonView.Fields.Add(new ComparisonFieldElement(versionComparisonView.Fields) FieldName = "QuantityInStock", Title = "QuantityInStock", ResourceClassId = typeof(ProductsResources).Name );
 
versionComparisonView.Fields.Add(new ComparisonFieldElement(versionComparisonView.Fields) FieldName = "Category", Title = "Category", ResourceClassId = typeof(ProductsResources).Name );
versionComparisonView.Fields.Add(new ComparisonFieldElement(versionComparisonView.Fields) FieldName = "Tags", Title = "Tags", ResourceClassId = typeof(ProductsResources).Name );
 
versionComparisonView.Fields.Add(new ComparisonFieldElement(versionComparisonView.Fields) FieldName = "UrlName", Title = "UrlName", ResourceClassId = typeof(ProductsResources).Name );
 
#endregion
 
 
#region Preview History Form
 
var previewLocalization = new Dictionary<string, string>()
     "ItemVersionOfClientTemplate", Res.Get<VersionResources>().ItemVersionOfClientTemplate ,
     "PreviouslyPublished", Res.Get<VersionResources>().PreviouslyPublishedBrackets ,
     "CannotDeleteLastPublishedVersion", Res.Get<VersionResources>().CannotDeleteLastPublishedVersion
;
var previewExternalScripts = DefinitionsHelper.GetExtenalClientScripts(
    "Telerik.Sitefinity.Versioning.Web.UI.Scripts.VersionHistoryExtender.js, Telerik.Sitefinity",
    "OnDetailViewLoaded");
 
var productsHistoryPreviewDetailView = new DetailFormViewElement(backendContentView.ViewsConfig)
    Title = "EditItem",
    ViewName = ProductsDefinitions.BackendVersionPreviewViewName,
    ViewType = typeof(DetailFormView),
    ShowSections = true,
    DisplayMode = FieldDisplayMode.Read,
    ShowTopToolbar = false,
    ResourceClassId = typeof(ProductsResources).Name,
    ExternalClientScripts = previewExternalScripts,
    WebServiceBaseUrl = "~/Sitefinity/Services/Content/Products.svc/",
    ShowNavigation = true,
    Localization = previewLocalization,
    UseWorkflow = false
;
 
backendContentView.ViewsConfig.Add(productsHistoryPreviewDetailView);
 
ProductsDefinitions.CreateBackendSections(productsHistoryPreviewDetailView, FieldDisplayMode.Read);
 
#endregion


- change the FillActionMenuItems() method by adding a new command in the Actions menu

public static void FillActionMenuItems(ConfigElementList<WidgetElement> menuItems, ConfigElement parent, string resourceClassId)
    menuItems.Add(
        CreateActionMenuCommand(menuItems, "View", HtmlTextWriterTag.Li, PreviewCommandName, "View", resourceClassId));
    menuItems.Add(
        CreateActionMenuCommand(menuItems, "Delete", HtmlTextWriterTag.Li, DeleteCommandName, "Delete", resourceClassId, "sfDeleteItm"));
    menuItems.Add(
        CreateActionMenuSeparator(menuItems, "Separator", HtmlTextWriterTag.Li, "sfSeparator", "Edit", resourceClassId));
    menuItems.Add(
        CreateActionMenuCommand(menuItems, "Content", HtmlTextWriterTag.Li, EditCommandName, "Content", resourceClassId));
    menuItems.Add(
        CreateActionMenuCommand(menuItems, "Permissions", HtmlTextWriterTag.Li, PermissionsCommandName, "Permissions", resourceClassId));
    menuItems.Add(
        CreateActionMenuCommand(menuItems, "History", HtmlTextWriterTag.Li, HistoryGridCommandName, "HistoryMenuItemTitle", "VersionResources"));

- add this constant string used in the code above

/// <summary>
/// Common name used for a command that displays the history of an item.
/// </summary>
public const string HistoryGridCommandName = "historygrid";


Once again I'll mention that you will need the fix from the next internal release in order these changes to work.

All the best,
Ivan Pelovski
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.

This thread is closed