Пример #1
0
        /// <summary>
        /// Creates the child controls.
        /// </summary>
        /// <returns></returns>
        public override Control[] CreateChildControls( Type entityType, FilterField filterControl, FilterMode filterMode )
        {
            var containerControl = new DynamicControlsPanel();
            containerControl.ID = string.Format( "{0}_containerControl", filterControl.ID );
            containerControl.CssClass = "js-container-control";
            filterControl.Controls.Add( containerControl );

            // Create the field selection dropdown
            var ddlEntityField = new RockDropDownList();
            ddlEntityField.ID = string.Format( "{0}_ddlProperty", filterControl.ID );
            ddlEntityField.ClientIDMode = ClientIDMode.Predictable;
            containerControl.Controls.Add( ddlEntityField );

            // add Empty option first
            ddlEntityField.Items.Add( new ListItem() );
            var rockBlock = filterControl.RockBlock();
            var entityTypeCache = EntityTypeCache.Read( entityType, true );

            this.entityFields = EntityHelper.GetEntityFields( entityType );
            foreach ( var entityField in this.entityFields.OrderBy(a => !a.IsPreviewable).ThenBy(a => a.FieldKind != FieldKind.Property ).ThenBy(a => a.Title) )
            {
                bool isAuthorized = true;
                bool includeField = true;
                if ( entityField.FieldKind == FieldKind.Attribute && entityField.AttributeGuid.HasValue)
                {
                    if ( entityType == typeof( Rock.Model.Workflow ) && !string.IsNullOrWhiteSpace(entityField.AttributeEntityTypeQualifierName) )
                    {
                        // Workflows can contain tons of Qualified Attributes, so let the WorkflowAttributeFilter take care of those
                        includeField = false;
                    }

                    var attribute = AttributeCache.Read( entityField.AttributeGuid.Value );
                    if ( includeField && attribute != null && rockBlock != null )
                    {
                        // only show the Attribute field in the drop down if they have VIEW Auth to it
                        isAuthorized = attribute.IsAuthorized( Rock.Security.Authorization.VIEW, rockBlock.CurrentPerson );
                    }
                }

                if ( isAuthorized && includeField )
                {
                    var listItem = new ListItem( entityField.Title, entityField.Name );

                    if ( entityField.IsPreviewable )
                    {
                        listItem.Attributes["optiongroup"] = "Common";
                    }
                    else if (entityField.FieldKind == FieldKind.Attribute)
                    {
                        listItem.Attributes["optiongroup"] = string.Format( "{0} Attributes", entityType.Name );
                    }
                    else
                    {
                        listItem.Attributes["optiongroup"] = string.Format( "{0} Fields", entityType.Name );
                    }

                    ddlEntityField.Items.Add( listItem  );
                }
            }

            ddlEntityField.AutoPostBack = true;

            // grab the currently selected value off of the request params since we are creating the controls after the Page Init
            var selectedValue = ddlEntityField.Page.Request.Params[ddlEntityField.UniqueID];
            if ( selectedValue != null )
            {
                ddlEntityField.SelectedValue = selectedValue;
                ddlEntityField_SelectedIndexChanged( ddlEntityField, new EventArgs() );
            }

            ddlEntityField.SelectedIndexChanged += ddlEntityField_SelectedIndexChanged;

            return new Control[] { containerControl };
        }
Пример #2
0
 /// <summary>
 /// Registers the javascript include needed for reporting client controls
 /// </summary>
 /// <param name="filterField">The filter field.</param>
 public static void RegisterJavascriptInclude( FilterField filterField )
 {
     ScriptManager.RegisterClientScriptInclude( filterField, filterField.GetType(), "reporting-include", filterField.RockBlock().RockPage.ResolveRockUrl( "~/Scripts/Rock/reportingInclude.js", true ) );
 }