コード例 #1
0
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection(Type entityType, Control[] controls, string selection)
        {
            if (!string.IsNullOrWhiteSpace(selection))
            {
                var values = JsonConvert.DeserializeObject <List <string> >(selection);
                if (controls.Length > 0 && values.Count > 0)
                {
                    var workflowType = new WorkflowTypeService(new RockContext()).Get(values[0].AsGuid());
                    if (workflowType != null)
                    {
                        var containerControl = controls[0] as DynamicControlsPanel;
                        if (containerControl.Controls.Count > 0)
                        {
                            WorkflowTypePicker workflowTypePicker = containerControl.Controls[0] as WorkflowTypePicker;
                            workflowTypePicker.SetValue(workflowType.Id);
                            workflowTypePicker_SelectItem(workflowTypePicker, new EventArgs());
                        }

                        if (containerControl.Controls.Count > 1 && values.Count > 1)
                        {
                            DropDownList ddlProperty  = containerControl.Controls[1] as DropDownList;
                            var          entityFields = GetWorkflowAttributes(workflowType.Id);

                            var panelControls = new List <Control>();
                            panelControls.AddRange(containerControl.Controls.OfType <Control>());
                            SetEntityFieldSelection(entityFields, ddlProperty, values.Skip(1).ToList(), panelControls);
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Sets the selection.
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="controls">The controls.</param>
        /// <param name="selection">The selection.</param>
        public override void SetSelection(Type entityType, Control[] controls, string selection)
        {
            var settings = SelectionConfig.Parse(selection);

            if (controls.Length > 0)
            {
                int?workflowTypeId = settings.WorkflowTypeId;

                var containerControl = controls[0] as DynamicControlsPanel;
                if (containerControl.Controls.Count > 0)
                {
                    WorkflowTypePicker workflowTypePicker = containerControl.Controls[0] as WorkflowTypePicker;
                    workflowTypePicker.SetValue(workflowTypeId);
                    EnsureSelectedWorkflowTypeControls(workflowTypePicker);
                }

                if (containerControl.Controls.Count > 1)
                {
                    DropDownList ddlProperty  = containerControl.Controls[1] as DropDownList;
                    var          entityFields = GetWorkflowAttributes(workflowTypeId);

                    var panelControls = new List <Control>();
                    panelControls.AddRange(containerControl.Controls.OfType <Control>());

                    var parameters = new List <string> {
                        settings.AttributeKey
                    };

                    parameters.AddRange(settings.AttributeFilterSettings);

                    SetEntityFieldSelection(entityFields, ddlProperty, parameters, panelControls);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Creates the child controls.
        /// Implement this version of CreateChildControls if your DataFilterComponent supports different FilterModes
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="filterControl"></param>
        /// <param name="filterMode"></param>
        /// <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);

            WorkflowTypePicker workflowTypePicker = new WorkflowTypePicker();

            workflowTypePicker.ID          = filterControl.ID + "_workflowTypePicker";
            workflowTypePicker.Label       = "Workflow Type";
            workflowTypePicker.SelectItem += workflowTypePicker_SelectItem;
            workflowTypePicker.Visible     = filterMode == FilterMode.AdvancedFilter;
            containerControl.Controls.Add(workflowTypePicker);

            // set the WorkflowTypePicker selected value now so we can create the other controls the depending on know the workflowTypeid
            var hfItem         = workflowTypePicker.ControlsOfTypeRecursive <HiddenFieldWithClass>().Where(a => a.CssClass.Contains("js-item-id-value")).FirstOrDefault();
            int?workflowTypeId = filterControl.Page.Request.Params[hfItem.UniqueID].AsIntegerOrNull();

            workflowTypePicker.SetValue(workflowTypeId);
            workflowTypePicker_SelectItem(workflowTypePicker, new EventArgs());

            return(new Control[] { containerControl });
        }
コード例 #4
0
        /// <summary>
        /// Handles the ValueChanged event of the workflowTypePicker control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        public void workflowTypePicker_ValueChanged(object sender, EventArgs e)
        {
            DynamicControlsPanel containerControl   = (sender as Control).FirstParentControlOfType <DynamicControlsPanel>();
            WorkflowTypePicker   workflowTypePicker = containerControl.ControlsOfTypeRecursive <WorkflowTypePicker>().Where(a => a.CssClass.Contains("js-workflow-type-picker")).FirstOrDefault();

            EnsureSelectedWorkflowTypeControls(workflowTypePicker);
        }
コード例 #5
0
        /// <summary>
        /// Creates the child controls.
        /// Implement this version of CreateChildControls if your DataFilterComponent supports different FilterModes
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="filterControl"></param>
        /// <param name="filterMode"></param>
        /// <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);

            WorkflowTypePicker workflowTypePicker = new WorkflowTypePicker();

            workflowTypePicker.ID    = filterControl.ID + "_workflowTypePicker";
            workflowTypePicker.Label = "Workflow Type";
            workflowTypePicker.AddCssClass("js-workflow-type-picker");
            workflowTypePicker.ValueChanged += workflowTypePicker_ValueChanged;
            if (filterMode == FilterMode.SimpleFilter)
            {
                // we still need to render the control in order to get the selected WorkflowTypeId on PostBack, so just hide it instead
                workflowTypePicker.Style[HtmlTextWriterStyle.Display] = "none";
            }

            containerControl.Controls.Add(workflowTypePicker);

            // set the WorkflowTypePicker selected value now so we can create the other controls the depending on know the workflowTypeId
            if (filterControl.Page.IsPostBack)
            {
                var hiddenField = workflowTypePicker.ControlsOfTypeRecursive <HiddenFieldWithClass>().Where(a => a.CssClass.Contains("js-item-id-value")).FirstOrDefault();

                // since we just created the WorkflowTypePicker, we'll have to sniff the WorkflowTypeId from Request.Params
                int?workflowTypeId = filterControl.Page.Request.Params[hiddenField.UniqueID].AsIntegerOrNull();
                workflowTypePicker.SetValue(workflowTypeId);
                EnsureSelectedWorkflowTypeControls(workflowTypePicker);
            }

            return(new Control[] { containerControl });
        }
コード例 #6
0
        /// <summary>
        /// Handles the SelectedIndexChanged event of the ddlProperty control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void ddlProperty_SelectedIndexChanged(object sender, EventArgs e)
        {
            var                ddlEntityField     = sender as RockDropDownList;
            var                containerControl   = ddlEntityField.FirstParentControlOfType <DynamicControlsPanel>();
            FilterField        filterControl      = ddlEntityField.FirstParentControlOfType <FilterField>();
            WorkflowTypePicker workflowTypePicker = filterControl.ControlsOfTypeRecursive <WorkflowTypePicker>().Where(a => a.HasCssClass("js-workflow-type-picker")).FirstOrDefault();

            var entityFields = GetWorkflowAttributes(workflowTypePicker.SelectedValue.AsIntegerOrNull());

            var entityField = entityFields.FirstOrDefault(a => a.UniqueName == ddlEntityField.SelectedValue);

            if (entityField != null)
            {
                string controlId = string.Format("{0}_{1}", containerControl.ID, entityField.UniqueName);
                if (!containerControl.Controls.OfType <Control>().Any(a => a.ID == controlId))
                {
                    var control = entityField.FieldType.Field.FilterControl(entityField.FieldConfig, controlId, true, filterControl.FilterMode);
                    if (control != null)
                    {
                        // Add the filter controls of the selected field
                        containerControl.Controls.Add(control);
                    }
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Gets the filter value control.
        /// </summary>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="id">The identifier.</param>
        /// <param name="required">if set to <c>true</c> [required].</param>
        /// <param name="filterMode">The filter mode.</param>
        /// <returns></returns>
        public override Control FilterValueControl(Dictionary <string, ConfigurationValue> configurationValues, string id, bool required, FilterMode filterMode)
        {
            var control = base.FilterValueControl(configurationValues, id, required, filterMode);
            WorkflowTypePicker workflowTypePicker = (WorkflowTypePicker)control;

            workflowTypePicker.Required         = required;
            workflowTypePicker.AllowMultiSelect = false;
            return(control);
        }
コード例 #8
0
        /// <summary>
        /// Creates the child controls.
        /// </summary>
        /// <returns></returns>
        public override Control[] CreateChildControls(Type entityType, FilterField filterControl)
        {
            WorkflowTypePicker workflowTypePicker = new WorkflowTypePicker();

            workflowTypePicker.ID       = filterControl.ID + "_workflowTypePicker";
            workflowTypePicker.CssClass = "js-workflow-type-picker";
            workflowTypePicker.Label    = "Workflow Type";
            filterControl.Controls.Add(workflowTypePicker);

            return(new Control[] { workflowTypePicker });
        }
コード例 #9
0
        /// <summary>
        /// Ensures that the controls that are created based on the WorkflowType have been created
        /// </summary>
        /// <param name="workflowTypePicker">The workflow type picker.</param>
        private void EnsureSelectedWorkflowTypeControls(WorkflowTypePicker workflowTypePicker)
        {
            DynamicControlsPanel containerControl = workflowTypePicker.Parent as DynamicControlsPanel;
            FilterField          filterControl    = containerControl.FirstParentControlOfType <FilterField>();

            var entityFields = GetWorkflowAttributes(workflowTypePicker.SelectedValueAsId());

            // Create the field selection dropdown
            string           propertyControlId = string.Format("{0}_ddlProperty", containerControl.ID);
            RockDropDownList ddlProperty       = containerControl.Controls.OfType <RockDropDownList>().FirstOrDefault(a => a.ID == propertyControlId);

            if (ddlProperty == null)
            {
                ddlProperty                       = new RockDropDownList();
                ddlProperty.ID                    = propertyControlId;
                ddlProperty.AutoPostBack          = true;
                ddlProperty.SelectedIndexChanged += ddlProperty_SelectedIndexChanged;
                ddlProperty.AddCssClass("js-property-dropdown");
                ddlProperty.Attributes["EntityTypeId"] = EntityTypeCache.GetId <Rock.Model.Workflow>().ToString();
                containerControl.Controls.Add(ddlProperty);
            }

            // update the list of items just in case the WorkflowType changed
            ddlProperty.Items.Clear();

            // add Empty option first
            ddlProperty.Items.Add(new ListItem());
            foreach (var entityField in entityFields)
            {
                // Add the field to the dropdown of available fields
                ddlProperty.Items.Add(new ListItem(entityField.TitleWithoutQualifier, entityField.UniqueName));
            }

            if (workflowTypePicker.Page.IsPostBack)
            {
                ddlProperty.SetValue(workflowTypePicker.Page.Request.Params[ddlProperty.UniqueID]);
            }

            foreach (var entityField in entityFields)
            {
                string controlId = string.Format("{0}_{1}", containerControl.ID, entityField.UniqueName);
                if (!containerControl.Controls.OfType <Control>().Any(a => a.ID == controlId))
                {
                    var control = entityField.FieldType.Field.FilterControl(entityField.FieldConfig, controlId, true, filterControl.FilterMode);
                    if (control != null)
                    {
                        containerControl.Controls.Add(control);
                    }
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Handles the SelectItem event of the workflowTypePicker control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        public void workflowTypePicker_SelectItem(object sender, EventArgs e)
        {
            WorkflowTypePicker workflowTypePicker = sender as WorkflowTypePicker;

            if (workflowTypePicker == null)
            {
                workflowTypePicker = (sender as Control).FirstParentControlOfType <WorkflowTypePicker>();
            }

            DynamicControlsPanel containerControl = workflowTypePicker.Parent as DynamicControlsPanel;
            FilterField          filterControl    = containerControl.FirstParentControlOfType <FilterField>();

            containerControl.Controls.Clear();
            containerControl.Controls.Add(workflowTypePicker);

            // Create the field selection dropdown
            var ddlProperty = new RockDropDownList();

            ddlProperty.ID = string.Format("{0}_{1}_ddlProperty", containerControl.ID, workflowTypePicker.SelectedValue);
            containerControl.Controls.Add(ddlProperty);

            // add Empty option first
            ddlProperty.Items.Add(new ListItem());

            var entityFields = GetWorkflowAttributes(workflowTypePicker.SelectedValue.AsIntegerOrNull());

            foreach (var entityField in entityFields)
            {
                string controlId = string.Format("{0}_{1}", containerControl.ID, entityField.UniqueName);
                var    control   = entityField.FieldType.Field.FilterControl(entityField.FieldConfig, controlId, true, filterControl.FilterMode);
                if (control != null)
                {
                    // Add the field to the dropdown of available fields
                    ddlProperty.Items.Add(new ListItem(entityField.TitleWithoutQualifier, entityField.UniqueName));
                    containerControl.Controls.Add(control);
                }
            }

            ddlProperty.AutoPostBack = true;

            // grab the currently selected value off of the request params since we are creating the controls after the Page Init
            var selectedValue = ddlProperty.Page.Request.Params[ddlProperty.UniqueID];

            if (selectedValue != null)
            {
                ddlProperty.SelectedValue = selectedValue;
                ddlProperty_SelectedIndexChanged(ddlProperty, new EventArgs());
            }

            ddlProperty.SelectedIndexChanged += ddlProperty_SelectedIndexChanged;
        }
コード例 #11
0
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <param name="filterMode"></param>
        /// <returns></returns>
        public override string GetSelection(Type entityType, Control[] controls, FilterMode filterMode)
        {
            var values = new List <string>();

            if (controls.Length > 0)
            {
                var containerControl = controls[0] as DynamicControlsPanel;
                if (containerControl.Controls.Count >= 1)
                {
                    // note: since this datafilter creates additional controls outside of CreateChildControls(), we'll use our _controlsToRender instead of the controls parameter
                    WorkflowTypePicker workflowTypePicker = containerControl.Controls[0] as WorkflowTypePicker;
                    Guid workflowTypeGuid = Guid.Empty;
                    var  workflowType     = new WorkflowTypeService(new RockContext()).Get(workflowTypePicker.SelectedValue.AsIntegerOrNull() ?? 0);
                    if (workflowType != null)
                    {
                        if (containerControl.Controls.Count == 1 || filterMode == FilterMode.SimpleFilter)
                        {
                            workflowTypePicker_SelectItem(workflowTypePicker, new EventArgs());
                        }

                        if (containerControl.Controls.Count > 1)
                        {
                            DropDownList ddlProperty = containerControl.Controls[1] as DropDownList;

                            var entityFields = GetWorkflowAttributes(workflowType.Id);
                            var entityField  = entityFields.FirstOrDefault(f => f.UniqueName == ddlProperty.SelectedValue);
                            if (entityField != null)
                            {
                                var panelControls = new List <Control>();
                                panelControls.AddRange(containerControl.Controls.OfType <Control>());

                                var control = panelControls.FirstOrDefault(c => c.ID.EndsWith(entityField.UniqueName));
                                if (control != null)
                                {
                                    values.Add(workflowType.Guid.ToString());
                                    values.Add(ddlProperty.SelectedValue);
                                    entityField.FieldType.Field.GetFilterValues(control, entityField.FieldConfig, filterMode).ForEach(v => values.Add(v));
                                }
                            }
                        }
                    }
                }
            }

            return(values.ToJson());
        }
コード例 #12
0
        /// <summary>
        /// Renders the controls.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="filterControl">The filter control.</param>
        /// <param name="writer">The writer.</param>
        /// <param name="controls">The controls.</param>
        /// <param name="filterMode"></param>
        public override void RenderControls(Type entityType, FilterField filterControl, HtmlTextWriter writer, Control[] controls, FilterMode filterMode)
        {
            if (controls.Length > 0)
            {
                var containerControl = controls[0] as DynamicControlsPanel;
                if (containerControl.Controls.Count >= 2)
                {
                    WorkflowTypePicker workflowTypePicker = containerControl.Controls[0] as WorkflowTypePicker;
                    workflowTypePicker.RenderControl(writer);

                    DropDownList ddlEntityField = containerControl.Controls[1] as DropDownList;
                    var          entityFields   = GetWorkflowAttributes(workflowTypePicker.SelectedValue.AsIntegerOrNull());

                    var panelControls = new List <Control>();
                    panelControls.AddRange(containerControl.Controls.OfType <Control>());

                    RenderEntityFieldsControls(entityType, filterControl, writer, entityFields, ddlEntityField, panelControls, containerControl.ID, filterMode);
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// Gets the selection.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="controls">The controls.</param>
        /// <param name="filterMode"></param>
        /// <returns></returns>
        public override string GetSelection(Type entityType, Control[] controls, FilterMode filterMode)
        {
            var settings = new SelectionConfig();

            if (controls.Length > 0)
            {
                var containerControl = controls[0] as DynamicControlsPanel;
                if (containerControl.Controls.Count >= 1)
                {
                    // note: since this datafilter creates additional controls outside of CreateChildControls(), we'll use our _controlsToRender instead of the controls parameter
                    WorkflowTypePicker workflowTypePicker = containerControl.Controls[0] as WorkflowTypePicker;
                    var workflowTypeId = workflowTypePicker.SelectedValueAsId();

                    if (containerControl.Controls.Count > 1)
                    {
                        DropDownList ddlProperty = containerControl.Controls[1] as DropDownList;
                        settings.AttributeKey   = ddlProperty.SelectedValue;
                        settings.WorkflowTypeId = workflowTypeId;
                        var entityFields = GetWorkflowAttributes(workflowTypeId);
                        var entityField  = entityFields.FirstOrDefault(f => f.UniqueName == ddlProperty.SelectedValue);
                        if (entityField != null)
                        {
                            var panelControls = new List <Control>();
                            panelControls.AddRange(containerControl.Controls.OfType <Control>());

                            var control = panelControls.FirstOrDefault(c => c.ID.EndsWith(entityField.UniqueName));
                            if (control != null)
                            {
                                entityField.FieldType.Field.GetFilterValues(control, entityField.FieldConfig, filterMode).ForEach(v => settings.AttributeFilterSettings.Add(v));
                            }
                        }
                    }
                }
            }

            return(settings.ToJson());
        }