Hierchical selector for custom field
Hi,
For the custom type of my custom module, I define a field of type Guid to rapresent the association with an album (library images). I need to realize an album selector and for that i follow this example but the ContentSelector used in this example does not have a hierarchical rappresentation.
Can you suggest me how to do it?
Thank you.
I replace ContentSelector with FolderField that is used also by Sitefinity designer controls. It shows image libraries but not sub libraries.
I m using Sitefinity 6.
I dont know why, there is any docs about SDK. Could someone help me please?
.ascx
<%@ Control Language="C#" AutoEventWireup="true" %><%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %><%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Modules.Libraries.Web.UI.Fields" TagPrefix="sfLib" %><asp:Label ID="titleLabel" runat="server" CssClass="sfTxtLbl" /><ol class="sfRadioList"> <li><asp:RadioButton ID="noParent" runat="server" GroupName="ParentLibrary" Text="None" /></li> <li> <asp:RadioButton ID="selectParent" runat="server" GroupName="ParentLibrary" Text="Selected album:" /> <sfLib:FolderField runat="server" ID="parentLibrarySelector" DisplayMode="Write" WrapperTag="div" /> </li></ol><sf:SitefinityLabel id="descriptionLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfDescription" /><sf:SitefinityLabel id="exampleLabel" runat="server" WrapperTagName="div" HideIfNoText="true" CssClass="sfExample" />using System;using System.Collections.Generic;using System.Linq;using System.Web.UI;using System.Web.UI.WebControls;using Telerik.Sitefinity.Web.UI;using Telerik.Sitefinity.Web.UI.Fields;using Telerik.Sitefinity.Modules.Libraries.Web.UI.Fields;namespace Telerik.Sitefinity.Samples.FieldControls /// <summary> /// A simple field control used to select a thumbnail from a Sitefinity library. /// </summary> [FieldDefinitionElement(typeof(ImgLibraryElement))] public class ImgLibraryField : FieldControl #region Properties /// <summary> /// Gets the name of the layout template. /// </summary> /// <value>The name of the layout template.</value> protected override string LayoutTemplateName get return String.Empty; /// <summary> /// Gets or sets the layout template path. /// </summary> /// <value>The layout template path.</value> public override string LayoutTemplatePath get return layoutTemplatePath; set base.LayoutTemplatePath = value; /// <summary> /// Gets the title label. /// </summary> /// <value>The title label.</value> protected internal Label TitleLabel get return this.Container.GetControl<SitefinityLabel>("titleLabel", true); /// <summary> /// Gets the description label. /// </summary> /// <value>The description label.</value> protected internal Label DescriptionLabel get return this.Container.GetControl<SitefinityLabel>("descriptionLabel", true); /// <summary> /// Gets the example label. /// </summary> /// <value>The example label.</value> protected internal Label ExampleLabel get return this.Container.GetControl<SitefinityLabel>("exampleLabel", true); protected internal RadioButton NoParent get return base.Container.GetControl<RadioButton>("noParent", true); protected internal FolderField ParentLibrarySelector get return base.Container.GetControl<FolderField>("parentLibrarySelector", true); protected internal RadioButton SelectParent get return base.Container.GetControl<RadioButton>("selectParent", true); public string ProviderName get; set; #endregion #region Overridden Methods /// <summary> /// Gets the script references. /// </summary> /// <returns></returns> public override IEnumerable<ScriptReference> GetScriptReferences() var baseReferences = new List<ScriptReference>(base.GetScriptReferences()); var componentRef = new ScriptReference(imageLibraryFieldScript, this.GetType().Assembly.FullName); baseReferences.Add(componentRef); return baseReferences; /// <summary> /// Gets the script descriptors. /// </summary> /// <returns></returns> public override IEnumerable<ScriptDescriptor> GetScriptDescriptors() ScriptControlDescriptor scriptControlDescriptor = (ScriptControlDescriptor)base.GetScriptDescriptors().Last<ScriptDescriptor>(); scriptControlDescriptor.AddComponentProperty("parentLibrarySelector", this.ParentLibrarySelector.ClientID); scriptControlDescriptor.AddElementProperty("noParent", this.NoParent.ClientID); scriptControlDescriptor.AddElementProperty("selectParent", this.SelectParent.ClientID); ScriptControlDescriptor[] scriptControlDescriptorArray = new ScriptControlDescriptor[1]; scriptControlDescriptorArray[0] = scriptControlDescriptor; return scriptControlDescriptorArray; protected override void InitializeControls(GenericContainer container) this.ParentLibrarySelector.WebServiceUrl = webServiceUrl; this.ParentLibrarySelector.ItemName = "Album"; this.ParentLibrarySelector.LibraryTypeName = "Telerik.Sitefinity.Libraries.Model.Album"; #endregion #region Private Fields private const string webServiceUrl = "~/Sitefinity/Services/Content/AlbumService.svc/"; private const string imageLibraryFieldScript = "Telerik.Sitefinity.Samples.Resources.Scripts.ImgLibraryField.js"; private const string layoutTemplatePath = "~/SfSamples/Telerik.Sitefinity.Samples.Resources.Views.ImgLibraryField.ascx"; #endregion Type.registerNamespace("Telerik.Sitefinity.Samples.FieldControls");Telerik.Sitefinity.Samples.FieldControls.ImgLibraryField = function (element) Telerik.Sitefinity.Samples.FieldControls.ImgLibraryField.initializeBase(this, [element]); this._element = element; this._noParent = null; this._selectParent = null; this._parentLibrarySelector = null; this._radioButtonsClickDelegate = null; this._providerName = null;Telerik.Sitefinity.Samples.FieldControls.ImgLibraryField.prototype = initialize: function () Telerik.Sitefinity.Samples.FieldControls.ImgLibraryField.callBaseMethod(this, "initialize"); this._radioButtonsClickDelegate = Function.createDelegate(this, this._radioButtonsClick); $addHandler(this.get_noParent(), "click", this._radioButtonsClickDelegate); $addHandler(this.get_selectParent(), "click", this._radioButtonsClickDelegate); , dispose: function () if (!this._radioButtonsClickDelegate) if (this.get_noParent()) $removeHandler(this.get_noParent(), "click", this._radioButtonsClickDelegate); if (this.get_selectParent()) $removeHandler(this.get_selectParent(), "click", this._radioButtonsClickDelegate); delete this._radioButtonsClickDelegate; Telerik.Sitefinity.Samples.FieldControls.ImgLibraryField.callBaseMethod(this, "dispose"); , /* -------------------- public methods ----------- */ reset: function () this.set_value(null); this.get_parentLibrarySelector().reset(); Telerik.Sitefinity.Samples.FieldControls.ImgLibraryField.callBaseMethod(this, "reset"); , add_hasParentChanged: function (delegate) this.get_events().addHandler('hasParentChanged', delegate); , remove_hasParentChanged: function (delegate) this.get_events().removeHandler('hasParentChanged', delegate); , /* -------------------- event handlers ------------ */ /* -------------------- private methods ----------- */ _radioButtonsClick: function () this._updateVisibility(); this._raiseHasParentChanged(this.get_selectParent().checked); , _updateVisibility: function () jQuery(this.get_parentLibrarySelector().get_element()).toggle(this.get_selectParent().checked); , _raiseHasParentChanged: function (hasParent) var handler = this.get_events().getHandler("hasParentChanged"); var eventArgs = get_hasParent: function () return hasParent; ; if (handler) handler(this, eventArgs); return eventArgs; , /* -------------------- properties ---------------- */ get_noParent: function () return this._noParent; , set_noParent: function (value) this._noParent = value; , get_selectParent: function () return this._selectParent; , set_selectParent: function (value) this._selectParent = value; , get_parentLibrarySelector: function () return this._parentLibrarySelector; , set_parentLibrarySelector: function (value) this._parentLibrarySelector = value; , get_value: function () if ((this.get_selectParent()).checked) return this.get_parentLibrarySelector().get_value(); else return "00000000-0000-0000-0000-000000000000"; , set_value: function (value) if (this.get_parentLibrarySelector()) this.get_parentLibrarySelector().set_value(value); if (value == null || value == "" || value == "00000000-0000-0000-0000-000000000000") this.get_noParent().checked = true; else this.get_selectParent().checked = true; this._updateVisibility(); this._raiseHasParentChanged(this.get_selectParent().checked); this._value = value; , // Passes the provider to the control set_providerName: function (value) this._providerName = value; if (this.get_parentLibrarySelector()) this.get_parentLibrarySelector().rebind(value); , // Gets the provider from the control get_providerName: function () return this._providerName; ;Telerik.Sitefinity.Samples.FieldControls.ImgLibraryField.registerClass("Telerik.Sitefinity.Samples.FieldControls.ImgLibraryField", Telerik.Sitefinity.Web.UI.Fields.FieldControl);Hi Stefano,
The FolderField needs some additional parameters set in order to work correctly. I think the problem in your case is that you need to set the WebserviceUrl. Please take a look at the following forum thread on detailed info about making it work (more specifically the answer by Marin Atanasov):
http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/need-help-with-libraryselector-in-control-designer#pLY99tT1zE6VlPO64Qp5Bw
Hi Slavo,
I'm setting WebService url here:
protected override void InitializeControls(GenericContainer container) this.ParentLibrarySelector.WebServiceUrl = webServiceUrl;private const string webServiceUrl = "~/Sitefinity/Services/Content/AlbumService.svc/";Ok, I solved!
I read carefully the post of Marin Atanasov and I see what is different on WebServiceUrl used by him.
My url: ~/Sitefinity/Services/Content/AlbumService.svc/
Marin Atanasov url: ~/Sitefinity/Services/Content/AlbumService.svc/folders/
So I reflected changes on my code and get it working as I espect.
Thank you. Hope this can be useful.
Regards,
Stefano