The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.]
In the previous article we have touched on the benefits of deriving our Control Panel class from the base Telerik.Cms.Web.UI.Backend.ControlPanel class. The first built-in feature we are going to examine is the automatic command generation.
It is a common scenario in module development that children views of the root View (Control Panel) should have corresponding commands always present in the module. The first level Views generally represent different tasks that can be accomplished with the module and therefore user should be able to navigate among them regardless of the currently displayed View.
Let us take a look how this approach works in practice, by examining the Generic Content module.
As we can see from the figure above, we have four commands available and they will stay available regardless if we are creating new content item or setting permissions for the new role.
It was this common pattern that has encouraged us to provide a simple and effortless way to automatically generate automatic commands for the first level children of the module.
By default, Control Panel will generate commands automatically for you. An overloaded constructor is available, however, which allows you to turn this feature off when instantiating control panel. In the following example, the ficticious ContactsControlPanel class is disabling automatic command generation by passing the false as an argument to its base constructor.
using Telerik.Cms.Web.UI.Backend; |
using ViewSamples; |
/// <summary> |
/// ContactsControlPanel - root view of the Contacts module |
/// </summary> |
public class ContactsControlPanel : ControlPanel<ContactsControlPanel> |
{ |
public ContactsControlPanel() |
: base(false) |
{ |
} |
/// <summary> |
/// We add the views to the control panel. The two views we are adding are so called "container" views, since |
/// they do not have user interface and display their default child view. |
/// </summary> |
protected override void CreateViews() |
{ |
AddView<ContactsView>("Contacts", "Contacts", "From here you can manage all the contacts.", "all", null); |
AddView<DepartmentsView>("Departments", "Departments", "From here you can manage all the departments", "all", null); |
AddView<MyProjectView<ContactsControlPanel>>("MyView", "My View", "My View description", "all", null); |
} |
} |
public ContactsControlPanel() |
: base(true) |
{ |
} |
Or even better, we take advantage of the ControlPanel’s default behavior:
public ContactsControlPanel() |
{ |
} |
/// <summary> |
/// We add the views to the control panel. The two views we are adding are so called "container" views, since |
/// they do not have user interface and display their default child view. |
/// </summary> |
protected override void CreateViews() |
{ |
AddView<ContactsView>("Contacts", "Contacts", "From here you can manage all the contacts.", "all", null); |
AddView<DepartmentsView>( "Departments", "Departments", "From here you can manage all the departments", "all", null); |
AddView<MyProjectView<ContactsControlPanel>>("MyView", "My View", "My View description", "all", null); |
} |
You can take a look at the following screenshot to see how would Sitefinity automatically generate commands based on these Views.
If we take a look at the actual signature of the AddView method that we were calling, the principle becomes crystal clear.
public void AddView<TView>( string viewName, string title, string description, string viewCommandCssClass, ResourceManager resources) where TView : Control, new(); |
By comparing the previous sample and resulting screenshot, we can see following:
*** NOTE ***
Sitefinity will also automatically set CssClass of the command representing current mode to “sfSel”, which is styled in the current theme, but of course, you are free to modify its declaration as you see fit.
*** END NOTE ***
We have seen in our previous sample that title and description arguments were taken literally and displayed as typed. The reason for this lays in the fact that we have provided null for the last argument, namely ResourcesManager. If you provide an actual ResourceManager object for this argument, Sitefinity will this recognize as your desire to have localized commands and therefore will:
Treat title and description arguments as resource file keys and not literal text to be displayed.
Let us take a closer look at this approach that comes from our built-in News module:
protected override void CreateViews() |
{ |
AddView<NewsItemsView>( null, "CommandPanel_NewsItems_Title", "CommandPanel_NewsItems_Desc", "all", Messages.ResourceManager); |
AddView<NewsCategoriesView>(null, "Categories", "CommandPanel_Categories_Desc", "cat", Messages.ResourceManager); |
AddView<NewsTagsView>(null, "Tags", "CommandPanel_Tags_Desc", "tags", Messages.ResourceManager); |
if(this.Manager.Provider.AllowComments) |
AddView<NewsCommentsView>(null, "Comments", "CommentsDescription", "comments", Messages.ResourceManager); |
AddView<NewsPermissionsView>(null, "Permissions", "CommandPanel_Permissions_Desc", "globalPerm", Messages.ResourceManager); |
} |
News module is using automatic command generation, yet obviously the HyperLinks in the command panel do not state “CommandPanel_NewsItems_Title” or similar nonsense. These strings are in this sample treated as keys of the localization resource file, since we have provided the instance of ResourceManager as the last argument in each of the calls to the AddView<T> method.
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.