Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *** DESIGNER.ascx ***
- <li class="sfFormCtrl">
- <h2>Which video content would you like to display?</h2>
- <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" />
- <div class="sfExample">Select the video category your would like to display.</div>
- </li>
- *** DESIGNER.cs ***
- protected virtual HierarchicalTaxonField FilterCategory
- {
- get
- {
- return this.Container.GetControl<HierarchicalTaxonField>("FilterCategory", true);
- }
- }
- public override System.Collections.Generic.IEnumerable<System.Web.UI.ScriptDescriptor> GetScriptDescriptors()
- {
- var scriptDescriptors = new List<ScriptDescriptor>(base.GetScriptDescriptors());
- var descriptor = (ScriptControlDescriptor)scriptDescriptors.Last();
- descriptor.AddComponentProperty("FilterCategory", this.FilterCategory.ClientID);
- return scriptDescriptors;
- }
- *** DESIGNER.js ***
- // Called when the designer window gets opened and here is place to "bind" your designer to the control properties
- refreshUI: function () {
- var controlData = this._propertyEditor.get_control(); // JavaScript clone of your control - all the control properties will be properties of the controlData too
- controlData.CategoryIdsStr && this.get_FilterCategory().set_value(controlData.CategoryIdsStr.split(','));
- },
- // Called when the "save" button is clicked. Here you can transfer the settings from the designer to the control
- applyChanges: function () {
- var controlData = this._propertyEditor.get_control();
- controlData.CategoryIdsStr = this.get_FilterCategory().get_value() ? this.get_FilterCategory().get_value().join() : "";
- },
- *** CONTROL.cs ***
- using Telerik.Sitefinity.Data.Linq.Dynamic;
- public string CategoryIdsStr { get; set; }
- private List<Guid> categoryIds
- {
- get
- {
- return CategoryIdsStr.IsNullOrWhitespace() ? new List<Guid>() : CategoryIdsStr.Split(',').Where(o => o.IsGuid()).Select(o => o.ToGuid()).ToList();
- }
- }
- private string categoryIdFilterClause
- {
- get
- {
- var clauses = categoryIds.Select(o => string.Format("Category.Contains(({0}))", o));
- return string.Join(" OR ", clauses);
- }
- }
- private void PopulateControl()
- {
- //Videos with a valid (length check only) Youtube video code
- var videoCollection = SitefinityFunctions.GetDynamicContentItemsAsQueryable("VideoContent.Video").Where(o => o.GetValue<string>("VideoCode").Length == 11);
- if (!categoryIdFilterClause.IsNullOrWhitespace())
- {
- videoCollection = videoCollection.Where(categoryIdFilterClause);
- }
- //Sorted please
- var sortedVideoCollection = videoCollection.ToList().OrderBy(o => o.GetValue<decimal>("SortOrder"));
- if (videoCollection.Any())
- {
- rptVideoSlider.DataSource = sortedVideoCollection;
- rptVideoSlider.ItemDataBound += rptVideoSlider_ItemDataBound;
- rptVideoSlider.DataBind();
- }
- else
- {
- this.Visible = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment