コード例 #1
0
ファイル: StepsTakenFilter.cs プロジェクト: waldo2590/Rock
        /// <summary>
        /// Populates the selection lists for Step Type and Step Status.
        /// </summary>
        /// <param name="filterField">The filter field.</param>
        private void PopulateStepProgramRelatedSelectionLists(FilterField filterField)
        {
            var dataContext = new RockContext();

            var programService = new StepProgramService(dataContext);

            StepProgramPicker stepProgramPicker = filterField.ControlsOfTypeRecursive <StepProgramPicker>().FirstOrDefault(c => c.HasCssClass("js-step-program-picker"));
            RockCheckBoxList  cblStepType       = filterField.ControlsOfTypeRecursive <RockCheckBoxList>().FirstOrDefault(c => c.HasCssClass("js-step-type"));
            RockCheckBoxList  _cblStepStatus    = filterField.ControlsOfTypeRecursive <RockCheckBoxList>().FirstOrDefault(c => c.HasCssClass("js-step-status"));

            int?stepProgramId = stepProgramPicker.SelectedValueAsId();

            StepProgram stepProgram = null;

            if (stepProgramId != null)
            {
                stepProgram = programService.Get(stepProgramId.Value);
            }

            if (stepProgram != null)
            {
                // Step Type list
                cblStepType.Items.Clear();

                var stepTypeService = new StepTypeService(dataContext);

                var stepTypes = stepTypeService.Queryable().Where(x => x.StepProgramId == stepProgramId);

                foreach (var item in stepTypes)
                {
                    cblStepType.Items.Add(new ListItem(item.Name, item.Guid.ToString()));
                }

                cblStepType.Visible = cblStepType.Items.Count > 0;

                // Step Status list
                _cblStepStatus.Items.Clear();

                var stepStatusService = new StepStatusService(dataContext);

                var stepStatuses = stepStatusService.Queryable().Where(x => x.StepProgramId == stepProgramId);

                foreach (var item in stepStatuses)
                {
                    _cblStepStatus.Items.Add(new ListItem(item.Name, item.Guid.ToString()));
                }

                _cblStepStatus.Visible = _cblStepStatus.Items.Count > 0;
            }
            else
            {
                cblStepType.Visible    = false;
                _cblStepStatus.Visible = false;
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates the HTML controls required to configure this type of field
        /// </summary>
        /// <returns></returns>
        public override List <Control> ConfigurationControls()
        {
            var stepProgramPicker = new StepProgramPicker
            {
                Label = "Default Step Program",
                Help  = "The default step program selection"
            };

            StepProgramPicker.LoadDropDownItems(stepProgramPicker, true);
            return(new List <Control> {
                stepProgramPicker
            });
        }
コード例 #3
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) || controls.Length <= 0)
            {
                return;
            }

            var values = JsonConvert.DeserializeObject <List <string> >(selection);

            if (values.Count <= 0)
            {
                return;
            }

            var stepType = GetStepType(values[1].AsGuid());

            if (stepType == null)
            {
                return;
            }

            var containerControl = controls[0] as DynamicControlsPanel;

            if (containerControl.Controls.Count > 0)
            {
                StepProgramPicker stepProgramPicker = containerControl.Controls[0] as StepProgramPicker;
                stepProgramPicker.SelectedValue = stepType.StepProgramId.ToString();
            }

            if (containerControl.Controls.Count > 1)
            {
                StepTypePicker stepTypePicker = containerControl.Controls[1] as StepTypePicker;
                stepTypePicker.StepProgramId = stepType.StepProgramId;
                stepTypePicker.SelectedValue = stepType.Id.ToString();

                EnsureSelectedStepTypeControls(stepTypePicker);
            }

            if (containerControl.Controls.Count > 2 && values.Count > 2)
            {
                DropDownList ddlProperty  = containerControl.Controls[2] as DropDownList;
                var          entityFields = GetStepAttributes(stepType.Id);

                var panelControls = new List <Control>();
                panelControls.AddRange(containerControl.Controls.OfType <Control>());
                SetEntityFieldSelection(entityFields, ddlProperty, values.Skip(2).ToList(), panelControls);
            }
        }
コード例 #4
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)
        {
            // Create a container to hold our dynamic controls and add it to the FilterField.
            var containerControl = new DynamicControlsPanel
            {
                ID       = string.Format("{0}_containerControl", filterControl.ID),
                CssClass = "js-container-control"
            };

            filterControl.Controls.Add(containerControl);

            // Create the StepProgramPicker.
            StepProgramPicker stepProgramPicker = new StepProgramPicker
            {
                ID       = filterControl.ID + "_stepProgramPicker",
                Label    = "Step Program",
                Required = true
            };

            stepProgramPicker.SelectedIndexChanged += stepProgramPicker_SelectedIndexChanged;
            stepProgramPicker.AutoPostBack          = true;
            StepProgramPicker.LoadDropDownItems(stepProgramPicker, true);
            containerControl.Controls.Add(stepProgramPicker);

            // Create the StepTypePicker.
            StepTypePicker stepTypePicker = new StepTypePicker
            {
                ID       = filterControl.ID + "_stepTypePicker",
                CssClass = "js-step-type-picker",
                Label    = "Step Type",
                Required = true
            };

            stepTypePicker.SelectedIndexChanged += stepTypePicker_SelectedIndexChanged;
            stepTypePicker.AutoPostBack          = true;
            containerControl.Controls.Add(stepTypePicker);

            if (filterMode == FilterMode.SimpleFilter)
            {
                // we still need to render the control in order to get the selected StepProgramId on postback, so just hide it instead
                stepProgramPicker.Style[HtmlTextWriterStyle.Display] = "none";
                stepTypePicker.Style[HtmlTextWriterStyle.Display]    = "none";
            }

            if (filterControl.Page.IsPostBack)
            {
                // If the Step Program has already been selected, make sure it retains that value, and
                // set the StepProgramId of the StepTypePicker.
                var stepProgramId = filterControl.Page.Request.Params[stepProgramPicker.UniqueID];
                stepProgramPicker.SelectedValue = stepProgramId;
                stepTypePicker.StepProgramId    = stepProgramId.AsIntegerOrNull();

                // If the Step Type has already been selected, make sure it retains that value.
                var stepTypePickerId = filterControl.Page.Request.Params[stepTypePicker.UniqueID];
                stepTypePicker.SelectedValue = stepTypePickerId;

                // Ensure that the attribute filter controls are updated to reflect the current
                // Step Type selection.
                EnsureSelectedStepTypeControls(stepTypePicker);
            }

            return(new Control[] { containerControl });
        }