Stephen2

SF - HierarchicalTaxonField designer -> Control

Oct 23rd, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.24 KB | None | 0 0
  1. *** DESIGNER.ascx ***
  2. <li class="sfFormCtrl">
  3.     <h2>Which video content would you like to display?</h2>
  4.     <sitefinity:HierarchicalTaxonField ID="FilterCategory" runat="server" DisplayMode="Write" Expanded="false" ExpandText="Add Category" ShowDoneSelectingButton="true" AllowMultipleSelection="true" BindOnServer="false" TaxonomyMetafieldName="Category" WebServiceUrl="~/Sitefinity/Services/Taxonomies/HierarchicalTaxon.svc" TaxonomyId="E5CD6D69-1543-427B-AD62-688A99F5E7D4" />
  5.     <div class="sfExample">Select the video category your would like to display.</div>
  6. </li>
  7.  
  8. *** DESIGNER.cs ***
  9. protected virtual HierarchicalTaxonField FilterCategory
  10. {
  11.     get
  12.     {
  13.         return this.Container.GetControl<HierarchicalTaxonField>("FilterCategory", true);
  14.     }
  15. }
  16.  
  17. public override System.Collections.Generic.IEnumerable<System.Web.UI.ScriptDescriptor> GetScriptDescriptors()
  18. {
  19.     var scriptDescriptors = new List<ScriptDescriptor>(base.GetScriptDescriptors());
  20.     var descriptor = (ScriptControlDescriptor)scriptDescriptors.Last();
  21.            
  22.     descriptor.AddComponentProperty("FilterCategory", this.FilterCategory.ClientID);
  23.  
  24.     return scriptDescriptors;
  25. }
  26.  
  27. *** DESIGNER.js ***
  28. // Called when the designer window gets opened and here is place to "bind" your designer to the control properties
  29. refreshUI: function () {
  30.     var controlData = this._propertyEditor.get_control(); // JavaScript clone of your control - all the control properties will be properties of the controlData too
  31.     controlData.CategoryIdsStr && this.get_FilterCategory().set_value(controlData.CategoryIdsStr.split(','));
  32. },
  33. // Called when the "save" button is clicked. Here you can transfer the settings from the designer to the control
  34. applyChanges: function () {
  35.     var controlData = this._propertyEditor.get_control();
  36.     controlData.CategoryIdsStr = this.get_FilterCategory().get_value() ? this.get_FilterCategory().get_value().join() : "";
  37. },
  38.  
  39. *** CONTROL.cs ***
  40. using Telerik.Sitefinity.Data.Linq.Dynamic;
  41.  
  42. public string CategoryIdsStr { get; set; }
  43. private List<Guid> categoryIds
  44. {
  45.     get
  46.     {
  47.         return CategoryIdsStr.IsNullOrWhitespace() ? new List<Guid>() : CategoryIdsStr.Split(',').Where(o => o.IsGuid()).Select(o => o.ToGuid()).ToList();
  48.     }
  49. }
  50. private string categoryIdFilterClause
  51. {
  52.     get
  53.     {
  54.         var clauses = categoryIds.Select(o => string.Format("Category.Contains(({0}))", o));
  55.         return string.Join(" OR ", clauses);
  56.     }
  57. }
  58.  
  59. private void PopulateControl()
  60. {
  61.     //Videos with a valid (length check only) Youtube video code
  62.     var videoCollection = SitefinityFunctions.GetDynamicContentItemsAsQueryable("VideoContent.Video").Where(o => o.GetValue<string>("VideoCode").Length == 11);
  63.  
  64.     if (!categoryIdFilterClause.IsNullOrWhitespace())
  65.     {
  66.         videoCollection = videoCollection.Where(categoryIdFilterClause);
  67.     }
  68.  
  69.     //Sorted please
  70.     var sortedVideoCollection = videoCollection.ToList().OrderBy(o => o.GetValue<decimal>("SortOrder"));
  71.  
  72.     if (videoCollection.Any())
  73.     {
  74.         rptVideoSlider.DataSource = sortedVideoCollection;
  75.         rptVideoSlider.ItemDataBound += rptVideoSlider_ItemDataBound;
  76.         rptVideoSlider.DataBind();
  77.     }
  78.     else
  79.     {
  80.         this.Visible = false;
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment