+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Custom Video Selector

Custom Video Selector

4 posts, 0 answered
  1. Richa
    Richa avatar
    69 posts
    Registered:
    04 Jun 2009
    18 Nov 2010
    Link to this post
    hello, am trying to create a usercontrol which will let user select the list of video libraries from which to show videos on the page:
    the user control has a public property:
    01.private List<Guid> listIds;
    02. 
    03./// <summary>
    04./// Gets or sets the list of selected video libraries ids
    05./// </summary>
    06.[DisplayName("Video Libraries")]
    07.[ReadOnly(true)]
    08.[Category("List settings")]
    09.[WebEditor("Modules.Video.VideoLibraryIdsListItemEditor")]
    10.public List<Guid> ListVideoLibraryIds
    11.{
    12.    get
    13.    {
    14.        // if listIds dictionary is null, we'll create an empty dictionary
    15.        // to avoid dealing with null reference in code
    16.        if (listIds == null)
    17.            listIds = new List<Guid>();
    18.        return listIds;
    19.    }
    20.    set
    21.    {
    22.        listIds = value;
    23.    }
    24.}

    the VideoLibraryIdsListItemEditor class:
    001.using System;
    002.using System.Web.UI;
    003.using System.Collections.Generic;
    004.using Telerik.Cms.Web.UI;
    005.using Telerik.Framework.Web;
    006.using Telerik.Libraries.WebControls.Design.Selectors;
    007. 
    008. 
    009.namespace Modules.Video
    010.{
    011.    
    012.   /// <summary>
    013.   /// WebEditor control used for editing the items (ListVideoLibraryIds property)
    014.   /// of the links list in user friendly manner
    015.   /// </summary>
    016.   public class VideoLibraryIdsListItemEditor : WebUITypeEditor<List<Guid>>, IControlPropertyEditor
    017.   {
    018.       #region Properties
    019.       /// <summary>
    020.       /// Gets or sets the Value property - Value property represents the property which TypeEditor
    021.       /// will edit of the parent control which fired the type editor. In our sample, Value property
    022.       /// represents ListVideoLibraryIds property of the LinksList6.ascx user control
    023.       /// </summary>
    024.       public override List<Guid> Value
    025.       {
    026.           get
    027.           {
    028.               return listLinks;
    029.           }
    030.           set
    031.           {
    032.               listLinks = value;
    033.           }
    034.       }
    035.       /// <summary>
    036.       /// Gets or sets the path of the Dialog template
    037.       /// </summary>
    038.       public string DialogTemplatePath
    039.       {
    040.           get
    041.           {
    042.               string value = (string)ViewState["DialogTemplatePath"];
    043.               return String.IsNullOrEmpty(value) ? "~/Sitefinity/Admin/ControlTemplates/Libraries/SampleVideoControlDesigner.ascx" : value;
    044.           }
    045.           set
    046.           {
    047.               ViewState["DialogTemplatePath"] = value;
    048.           }
    049.       }
    050.       /// <summary>
    051.       /// Gets or sets the Dialog template
    052.       /// </summary>
    053.       public ITemplate DialogTemplate
    054.       {
    055.           get
    056.           {
    057.               dialogTemplate = ControlUtils.GetTemplate<DefaultDialogTemplate>(DialogTemplatePath);
    058.               return dialogTemplate;
    059.           }
    060.           set
    061.           {
    062.               dialogTemplate = value;
    063.           }
    064.       }
    065.       #endregion
    066.       #region Methods
    067.       /// <summary>
    068.       /// Overriden. Cancels the rendering of a beginning HTML tag for the control.
    069.       /// </summary>
    070.       /// <param name="writer">The HtmlTextWriter object used to render the markup.</param>
    071.       public override void RenderBeginTag(HtmlTextWriter writer)
    072.       {
    073.           // Do not render begin tag
    074.       }
    075.       /// <summary>
    076.       /// Overriden. Cancels the rendering of an ending HTML tag for the control.
    077.       /// </summary>
    078.       /// <param name="writer">The HtmlTextWriter object used to render the markup.</param>
    079.       public override void RenderEndTag(HtmlTextWriter writer)
    080.       {
    081.           // Do not render end tag
    082.       }
    083.       /// <summary>
    084.       /// Overrides the base method and registers ControlDesignerBase control as one whose control state
    085.       /// must be persisted.
    086.       /// </summary>
    087.       /// <param name="e"></param>
    088.       protected override void OnInit(EventArgs e)
    089.       {
    090.           base.OnInit(e);
    091.           if (Page != null)
    092.               Page.RegisterRequiresControlState(this);
    093.       }
    094.       /// <summary>
    095.       /// Restores control state information from a previous page request that was saved by the SaveControlState
    096.       /// method.
    097.       /// </summary>
    098.       /// <param name="savedState">Represents the control state to be restored.</param>
    099.       protected override void LoadControlState(object savedState)
    100.       {
    101.           if (savedState != null)
    102.           {
    103.               listLinks = (List<Guid>)savedState;
    104.           }
    105.       }
    106.       /// <summary>
    107.       /// Saves server control state changes.
    108.       /// </summary>
    109.       /// <returns></returns>
    110.       protected override object SaveControlState()
    111.       {
    112.           return listLinks;
    113.       }
    114. 
    115.       /// <summary>
    116.       /// Overriden. Called to populate the child control hierarchy. This is the main
    117.       /// method to render the control's markup, since it is a CompositeControl and contains
    118.       /// child controls.
    119.       /// </summary>
    120.       protected override void CreateChildControls()
    121.       {
    122.           // initialize the container and template
    123.           dialogContainer = new Container();
    124.           DialogTemplate.InstantiateIn(dialogContainer);
    125.           dialogContainer.VideoSelector.WebServicePath = "~/Sitefinity/Admin/Services/LibrariesService.asmx";
    126.           dialogContainer.VideoSelector.SelectorTarget = "Video";
    127.           listLinks = dialogContainer.VideoSelector.SelectedValues;
    128. 
    129.           Controls.Add(dialogContainer);
    130.       }
    131.       #endregion
    132.       #region Private methods
    133. 
    134.       #endregion
    135.        
    136.       #region Event handlers
    137. 
    138.       #endregion
    139.        
    140.       #region Private Propeties
    141. 
    142.       private List<Guid> listLinks;
    143.       private ITemplate dialogTemplate;
    144.       private Container dialogContainer;
    145.        
    146.       #endregion
    147. 
    148.       #region Default Templates
    149.       /// <summary>
    150.       /// Class which defines the template for this control, in case template has not been
    151.       /// defined through an external file or through inline declaration
    152.       /// </summary>
    153.       private class DefaultDialogTemplate : ITemplate
    154.       {
    155.           public void InstantiateIn(Control container)
    156.           {
    157.               throw new Exception("Default template for VideoLibraryIdsListItemEditor has not been implemented.");
    158.           }
    159.       }
    160.       #endregion
    161. 
    162.       #region Containers
    163.       /// <summary>
    164.       /// Class which provides easy, strongly-typed access to the child controls defined in a template
    165.       /// regardless of their position in the child control hierarchy
    166.       /// </summary>
    167.       private class Container : GenericContainer
    168.       {
    169.           public VideoSelector VideoSelector
    170.           {
    171.               get
    172.               {
    173.                   if (videoSelector == null)
    174.                       videoSelector = GetControl<VideoSelector>("GuidSelector", true);
    175. 
    176.                   return videoSelector;
    177.               }
    178.           }
    179.           private VideoSelector videoSelector;
    180.       }
    181.       #endregion
    182. 
    183.       public IDictionary<string, object> DependentProperties
    184.       {
    185.           get { return new Dictionary<string, object>(); }
    186.       }
    187.   }
    188.}

    SampleVideoControlDesigner.ascx:
    01.<%@ Control Language="C#" %>
    02.<%@ Register Namespace="Telerik.Libraries.WebControls.Design.Selectors" Assembly="Telerik.Libraries"
    03.    TagPrefix="sfLibrarySelectors" %>
    04.<%@ Register Namespace="Telerik.Cms.Engine.WebControls.Design" Assembly="Telerik.Cms.Engine"
    05.    TagPrefix="sfDesign" %>
    06.<%@ Register Namespace="Telerik.Cms.Engine.WebControls.Design.Settings" Assembly="Telerik.Cms.Engine"
    07.    TagPrefix="sfDesignSettings" %>
    08. 
    09.<div class="ctrlProps">
    10.    <div class="ctrlContent slidingWizard">
    11.        <div id="slidingWizardSteps">
    12.            <!-- Wizard panel 1 -->
    13.            <div id="Panel1">
    14.                <h3>
    15.                    <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:WhichVideosToDisplay %>"></asp:Literal></h3>
    16.                <div>
    17.                    <sfLibrarySelectors:VideoSelector ID="GuidSelector" runat="server" SelectAllItemsText="Display all videos"
    18.                        SelectSpecificItemsText="Display videos from selected libraries" />
    19.                </div>
    20.                <div class="extLinks">
    21.                </div>
    22.            </div>
    23.            <!-- end wizard panel 1 -->
    24.        </div>
    25.    </div>
    26.</div>
    27.<asp:HiddenField ID="designerIsDirty" runat="server" />
    28.<asp:HiddenField ID="selectedModeIdField" runat="server" />
    29.<asp:HiddenField ID="selectedModeClientIdField" runat="server" />
    30. 
    31.<script type="text/javascript">
    32. 
    33.</script>

    my question is line 127 in VideoLibraryIdsListItemEditor does not get me the selected libraries, which event do i need to register to get the selected values? and how to persist that state?

    Thanks in advance
    Richa
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 Nov 2010
    Link to this post
    Hello Richa,

    In CreatechildControls you need to get a list of all items and compare the item name with the selected Value - name or Id

    The Value property should be a view state property

    below is a sample implementation

    public override string Value
        {
            get
            {
                string obj = (string)ViewState["selectedItem"];
                Guid itemID = Guid.Empty;
                if (ButtonList.SelectedItem != null)
                    itemID = new Guid(ButtonList.SelectedValue);
                if (itemID != Guid.Empty)
                    obj = (manager.GetLibrary(itemID)).Name;
                if (!String.IsNullOrEmpty(obj))
                    return obj;
                return String.Empty;
            }
            set
            {
                this.ViewState["selectedItem"] = value;
                   
            }
        }
       
         
        public string Templte
        {
            get
            {
                object o = this.ViewState["Template"];
                if (o == null)
                    return ("~/CustomControls/GallerySelectorTemplate.ascx");
                return (string)o;
            }
            set
            {
                this.ViewState["Template"] = value;
            }
        }
      
      
      
      
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            this.manager = new LibraryManager("Libraries");
            this.template = ControlUtils.GetTemplate<SelectorTemplate>(this.Templte);
            this.template.InstantiateIn(this);
            if (ButtonList != null)
            {
                IList allLibs = manager.GetAllLibraries();
                if (allLibs.Count > 0)
                {
                    foreach (ILibrary library in allLibs)
                    {
                        ListItem item = new ListItem(library.Name, library.ID.ToString());
                        ButtonList.Items.Add(item);
                        if (library.Name == Value)
                        {
                            item.Selected = true;
                        }
      
                    }
                }
      
            }
        }
        


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Richa
    Richa avatar
    69 posts
    Registered:
    04 Jun 2009
    18 Nov 2010
    Link to this post
    Thanks a bunch for your time, Ivan.
    2 questions:
    1. why is Value - string? shoudnt it be List<string> or List<Guid> because the user can select more than one video libraries.
    2. what type is ButtonList? is this a control that should be on GallerySelectorTemplate.ascx?

    -Richa
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 Nov 2010
    Link to this post
    Hello Richa,

    Because this is just a sample that shows how to achieve your goal. In your code you have to use the proper types.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
4 posts, 0 answered