Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DESIGNER.ascx:
- --------------
- <sitefinity:HierarchicalTaxonField ID="FilterCategory" runat="server" DisplayMode="Write" Expanded="false" ExpandText="Add Category" ShowDoneSelectingButton="true" AllowMultipleSelection="false" BindOnServer="false" TaxonomyMetafieldName="Category" WebServiceUrl="~/Sitefinity/Services/Taxonomies/HierarchicalTaxon.svc" TaxonomyId="E5CD6D69-1543-427B-AD62-688A99F5E7D4" />
- DESIGNER.cs:
- ------------
- descriptor.AddComponentProperty("FilterCategory", this.FilterCategory.ClientID);
- 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:
- -----------
- 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);
- }
- }
- protected override void InitializeControls(GenericContainer container) {
- //NB: uses dynamic LINQ expression as "Intersect" is not implemented on database...
- //This way all filtering is done on DB for performance
- var staffMembers = SitefinityFunctions.GetDynamicContentItems("StaffMembers.Staff");
- if (!categoryIdFilterClause.IsNullOrWhitespace()) {
- staffMembers = staffMembers.Where(categoryIdFilterClause);
- }
- }
- HELPERS.cs:
- -----------
- public static IQueryable<DynamicContent> GetDynamicContentItems(string type) {
- var itemType = TypeResolutionService.ResolveType(string.Concat("Telerik.Sitefinity.DynamicTypes.Model.", type));
- return DynamicModuleManager.GetManager().GetDataItems(itemType).Where(o => o.Visible && o.Status == ContentLifecycleStatus.Live);
- }
- public static Guid ToGuid(this string str) {
- var g = Guid.Empty;
- Guid.TryParse(str, out g);
- return g;
- }
Advertisement
Add Comment
Please, Sign In to add comment