More in this section

Forums / Developing with Sitefinity / Generic content base module issue

Generic content base module issue

6 posts, 0 answered
  1. Armen
    Armen avatar
    9 posts
    Registered:
    26 Oct 2011
    09 Dec 2008
    Link to this post
    Hi,

    I have successfully built my generic content based module with workflow, based on your products sample and now need to have section in command panel of the same module which is dealing with other data but is related with my generic content based module. 

    Let's say I have an other Linkbutton in CommandPanel which is firing button_Command event with "Sample" CommandName. For all generic command items there is Mode enumeration that I am able to set and refresh the control panel to bring appropriate template. 
            protected virtual void button_Command(object sender, CommandEventArgs e) 
            { 
                // based on the command name, set the Mode of ControlPanel 
                ControlPanel ctrlPnl = ((ControlPanel) base.ControlPanel); 
                switch (e.CommandName) 
                { 
                    case "ContentView": 
                        ctrlPnl.Mode = Telerik.Cms.Engine.WebControls.Admin.ControlPanel.Modes.List; 
                        ctrlPnl.Refresh(); 
                        break; 
                    case "CategoriesView": 
                        ctrlPnl.Mode = Telerik.Cms.Engine.WebControls.Admin.ControlPanel.Modes.Categories; 
                        ctrlPnl.Refresh(); 
                        break; 
                    case "TagsView": 
                        ctrlPnl.Mode = Telerik.Cms.Engine.WebControls.Admin.ControlPanel.Modes.Tags; 
                        ctrlPnl.Refresh(); 
                        break; 
                    case "CommentsView": 
                        ctrlPnl.Mode = Telerik.Cms.Engine.WebControls.Admin.ControlPanel.Modes.CommentsView; 
                        ctrlPnl.Refresh(); 
                        break; 
                    case "PermissionView": 
                        ctrlPnl.Mode = Telerik.Cms.Engine.WebControls.Admin.ControlPanel.Modes.Permissions; 
                        ctrlPnl.Refresh(); 
                        break; 
                    case "Sample": 
                        ctrlPnl.Mode = ???????; 
                        ctrlPnl.Refresh(); 
                        break; 
                } 
     
                // loop through all the buttons, and make the button that sent the command 
                // have "sel" css class 
                foreach (Control ctrl in container.Controls[0].Controls) 
                { 
                    if (ctrl is LinkButton) 
                    { 
                        LinkButton button = (LinkButton) ctrl; 
     
                        buttonbutton.CssClass = button.ID == ((LinkButton) sender).ID ? "sel" : ""; 
                    } 
                } 
            } 
     
     



    Can you please let me know how I should load my template when case "Sample" command is arriving from button_command from command panel?


    Thanks.
    Armen
  2. valio b
    valio b avatar
    33 posts
    Registered:
    24 Sep 2012
    11 Dec 2008
    Link to this post
    Hi Armen,
    The generic content Modes enum is defined like that:
    public enum Modes { List, Insert, View, Edit, History, Permissions, CommentsView, CommentsEdit, Tags, Categories } 

    so when you get to your case of "Sample" you will have to provide your own logic something like:

    case "Sample":  
                        DoSample(); 
                        ctrlPnl.Mode = ChooseWhateverModeFromTheGenericContentModesYouLike; 
                        ctrlPnl.Refresh(); 
                        break;  

    If you want to load any of the existing templates, specify one of the existing enum values to the ctrlPnl.Mode property.

    Another solution would be to override the GenericContent CreateChildControls() as well as the Modes enumerator and provide for your own template to be loaded.

    Best wishes,
    valio b
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Armen
    Armen avatar
    9 posts
    Registered:
    26 Oct 2011
    12 Dec 2008
    Link to this post
    Hi Valio,

    Thank you for reply. 
    Can you please let me know how to override Modes. I am trying  to do it like
            public new enum Modes { List=0, Insert, View, Edit, History, Permissions, CommentsView, CommentsEdit, Tags, Categories, myView, myInsert, myEdit } 
     
            public override ControlPanel.Modes Mode 
            { 
                get 
                { 
                    if (this.ViewState["Mode"] == null
                        return Modes.List; 
                    return (ControlPanel.Modes)this.ViewState["Mode"]; 
                } 
                set 
                { 
                    ViewState.Add("Mode", value); 
                } 
            } 
     
     

    I am getting the error from compiler, telling

    Error 1 'DCPA.Shows.WebControls.Admin.ControlPanel.Mode': type must be 'Telerik.Cms.Engine.WebControls.Admin.ControlPanel.Modes' to match overridden member 'Telerik.Cms.Engine.WebControls.Admin.ControlPanel.Mode' D:\Projects\DCPA\Modules\DCPA.Shows\WebControls\Admin\ControlPanel.cs 114 38 DCPA.Shows

    Can you please give me some sample on how to create my own modes so that I can load my templates under overrided CreateChildControls() function based on the mode arrived?

    Thanks,
    Armen
  4. valio b
    valio b avatar
    33 posts
    Registered:
    24 Sep 2012
    15 Dec 2008
    Link to this post
    Hello Armen,
    The idea is that you can declare your own enumerator and based on its current value take some action.
    So in the CommandPanel you can have something like:
    public CommandPanelExtend(ControlPanel ctrlPnl) 
                : base(ctrlPnl) 
            { 
                PopulateEnum(); 
            } 
     
            private void PopulateEnum() 
            { 
                MyModes List = (MyModes) Telerik.Cms.Engine.WebControls.Admin.ControlPanel.Modes.List; 
                MyModes Insert = (MyModes) Telerik.Cms.Engine.WebControls.Admin.ControlPanel.Modes.Insert; 
                //... 
               //MyModes.Insert == ControlPanel.Modes.Insert 
            } 
             
            public enum MyModes {List, Insert, View, Edit, History, Permissions, CommentsView, CommentsEdit, Tags, Categories, myView, myInsert, myEdit } 
     
            protected override void button_Command(object sender, CommandEventArgs e) 
            { 
                ControlPanel ctrlPnl = ((ControlPanel) base.ControlPanel); 
                switch (e.CommandName) 
                { 
                    case "ContentView": 
                        ctrlPnl.Mode = Admin.ControlPanel.Modes.List; 
                        break; 
                    case "MyView": 
                        this.ControlPanelExtended.M 
                        ctrlPnl.Mode = MyModes.myView; 
                        break; 
     
                } 
            } 
     
            protected override void CreateChildControls() 
            { 
                //base.CreateChildControls(); 
                ControlPanel ctrlPnl = ((ControlPanel)base.ControlPanel); 
     
     
                ctrlPnl.Mode = (Admin.ControlPanel.Modes) MyModes.List; 
                //get the correct base container  
                //Instantiate your custom template in the proper container 
                //then 
                if (this.displayMode == MyModes.myView) 
                { 
                    //do something here 
                } 
            } 

    Basically your enum will have all the existing values in Modes, and based on which one is selected take some action. So in your property which gets or sets the Mode you will have to account for the different type of enum which is expected. In case you would like to call base.CreateChildControls(), make sure enum of type ControlPanel.Mode is set, otherwise enum of type MyModes.

    The good news is that in version 3.6 it will be much easier to set your custom enum values.

    Hopefully that would get you going!

    Greetings,
    valio b
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Armen
    Armen avatar
    9 posts
    Registered:
    26 Oct 2011
    18 Dec 2008
    Link to this post
    Hi Valio,

    Thanks a lot for your reply. It was very helpfull. In fact I have left the base modes untouched and just added myModes with all the values plus my Modes and in Command panel I am setting 2 modes for each command item. In ControlPanel I have overrided the CreateChildControls where I am checking if it is my mode or not and if not my mode calling base.CreateChildControls(), while in myModes case loading my own control container and it works fine now. But will try to change it in your suggested way just after getting some more free time, as it looks more correct way. 

    I am glad to know that this functionality wil be enhanced in next release as well, seems I'll become a Sitefinity evangelist soon!

    Thanks,
    Armen
  6. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    18 Dec 2008
    Link to this post
    Hello Armen,

    It is great to hear that you have it working, and you like Sitefinity!

    Greetings,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
6 posts, 0 answered