/// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            // HiddenField to store which AttributeMatrix record we are editing
            _hfAttributeMatrixGuid = new HiddenField {
                ID = "_hfAttributeMatrixGuid"
            };
            this.Controls.Add(_hfAttributeMatrixGuid);

            _nbWarning = new NotificationBox {
                ID = "_nbWarning", NotificationBoxType = NotificationBoxType.Warning, Dismissable = true
            };
            this.Controls.Add(_nbWarning);

            // Grid with view of MatrixItems
            _gMatrixItems = new Grid {
                ID = "_gMatrixItems", DisplayType = GridDisplayType.Light
            };
            this.Controls.Add(_gMatrixItems);
            _gMatrixItems.DataKeyNames      = new string[] { "Id" };
            _gMatrixItems.Actions.AddClick += gMatrixItems_AddClick;
            _gMatrixItems.Actions.ShowAdd   = true;
            _gMatrixItems.IsDeleteEnabled   = true;
            _gMatrixItems.GridReorder      += gMatrixItems_GridReorder;
            _gMatrixItems.GridRebind       += _gMatrixItems_GridRebind;

            _hfRowCount = new HiddenFieldWithValidationProperty {
                ID = "_hfRowCount"
            };
            this.Controls.Add(_hfRowCount);

            _requiredRowCountRangeValidator    = new HiddenFieldRangeValidator();
            _requiredRowCountRangeValidator.ID = _hfRowCount.ID + "_rfv";
            _requiredRowCountRangeValidator.ControlToValidate = _hfRowCount.ID;
            _requiredRowCountRangeValidator.Display           = ValidatorDisplay.Dynamic;
            _requiredRowCountRangeValidator.Type     = ValidationDataType.Integer;
            _requiredRowCountRangeValidator.CssClass = "validation-error help-inline";
            _requiredRowCountRangeValidator.Enabled  = false;

            this.Controls.Add(_requiredRowCountRangeValidator);

            _gMatrixItems.Columns.Add(new ReorderField());

            AttributeMatrixItem tempAttributeMatrixItem = null;

            if (this.AttributeMatrixTemplateId.HasValue)
            {
                tempAttributeMatrixItem = new AttributeMatrixItem();
                tempAttributeMatrixItem.AttributeMatrix = new AttributeMatrix {
                    AttributeMatrixTemplateId = this.AttributeMatrixTemplateId.Value
                };
                tempAttributeMatrixItem.LoadAttributes();

                foreach (var attribute in tempAttributeMatrixItem.Attributes.Select(a => a.Value))
                {
                    _gMatrixItems.Columns.Add(new AttributeField {
                        DataField = attribute.Key, HeaderText = attribute.Name
                    });
                }

                AttributeMatrixTemplateService attributeMatrixTemplateService = new AttributeMatrixTemplateService(new RockContext());
                var attributeMatrixTemplateRanges = attributeMatrixTemplateService.GetSelect(this.AttributeMatrixTemplateId.Value, s => new { s.MinimumRows, s.MaximumRows });

                // If a value is required, make sure we have a minumum row count of at least 1.
                var minRowCount = attributeMatrixTemplateRanges.MinimumRows.GetValueOrDefault(0);
                if (this.Required &&
                    minRowCount < 1)
                {
                    minRowCount = 1;
                }
                _requiredRowCountRangeValidator.MinimumValue = minRowCount.ToString();

                _requiredRowCountRangeValidator.Enabled = minRowCount > 0;
                if (minRowCount == 1)
                {
                    _requiredRowCountRangeValidator.ErrorMessage = "At least 1 row is required.";
                }
                else
                {
                    _requiredRowCountRangeValidator.ErrorMessage = $"At least {minRowCount} rows are required";
                }
            }

            DeleteField deleteField = new DeleteField();

            deleteField.Click += gMatrixItems_DeleteClick;
            _gMatrixItems.Columns.Add(deleteField);

            _gMatrixItems.RowSelected += gMatrixItems_RowSelected;

            // Edit Item
            _pnlEditMatrixItem = new Panel {
                ID = "_pnlEditMatrixItem", Visible = false, CssClass = "well js-validation-group validation-group"
            };
            _hfMatrixItemId = new HiddenField {
                ID = "_hfMatrixItemId"
            };
            _pnlEditMatrixItem.Controls.Add(_hfMatrixItemId);

            _phMatrixItemAttributes = new DynamicPlaceholder {
                ID = "_phMatrixItemAttributes"
            };
            _pnlEditMatrixItem.Controls.Add(_phMatrixItemAttributes);

            string validationGroup = GetValidationGroupForAttributeControls();

            if (tempAttributeMatrixItem != null)
            {
                Rock.Attribute.Helper.AddEditControls(tempAttributeMatrixItem, _phMatrixItemAttributes, false, validationGroup);
            }

            _pnlActions = new Panel {
                ID = "_pnlActions", CssClass = "actions"
            };
            _pnlEditMatrixItem.Controls.Add(_pnlActions);

            _btnSaveMatrixItem = new LinkButton {
                ID = "_btnSaveMatrixItem", CssClass = "btn btn-primary btn-sm", Text = "Save", ValidationGroup = validationGroup, CausesValidation = true
            };
            _btnSaveMatrixItem.Click += btnSaveMatrixItem_Click;
            _pnlActions.Controls.Add(_btnSaveMatrixItem);

            _btnCancelMatrixItem = new LinkButton {
                ID = "_btnCancelMatrixItem", CssClass = "btn btn-link", Text = "Cancel", CausesValidation = false
            };
            _btnCancelMatrixItem.Click += btnCancelMatrixItem_Click;
            _pnlActions.Controls.Add(_btnCancelMatrixItem);

            this.Controls.Add(_pnlEditMatrixItem);
        }
Esempio n. 2
0
        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            // HiddenField to store which AttributeMatrix record we are editing
            _hfAttributeMatrixGuid = new HiddenField {
                ID = "_hfAttributeMatrixGuid"
            };
            this.Controls.Add(_hfAttributeMatrixGuid);

            _nbWarning = new NotificationBox {
                ID = "_nbWarning", NotificationBoxType = NotificationBoxType.Warning, Dismissable = true
            };
            this.Controls.Add(_nbWarning);

            // Grid with view of MatrixItems
            _gMatrixItems = new Grid {
                ID = "_gMatrixItems", DisplayType = GridDisplayType.Light
            };
            this.Controls.Add(_gMatrixItems);
            _gMatrixItems.DataKeyNames      = new string[] { "Id" };
            _gMatrixItems.Actions.AddClick += gMatrixItems_AddClick;
            _gMatrixItems.Actions.ShowAdd   = true;
            _gMatrixItems.IsDeleteEnabled   = true;
            _gMatrixItems.GridReorder      += gMatrixItems_GridReorder;
            _gMatrixItems.GridRebind       += _gMatrixItems_GridRebind;

            _gMatrixItems.Columns.Add(new ReorderField());

            AttributeMatrixItem tempAttributeMatrixItem = null;

            if (this.AttributeMatrixTemplateId.HasValue)
            {
                tempAttributeMatrixItem = new AttributeMatrixItem();
                tempAttributeMatrixItem.AttributeMatrix = new AttributeMatrix {
                    AttributeMatrixTemplateId = this.AttributeMatrixTemplateId.Value
                };
                tempAttributeMatrixItem.LoadAttributes();

                foreach (var attribute in tempAttributeMatrixItem.Attributes.Select(a => a.Value))
                {
                    _gMatrixItems.Columns.Add(new AttributeField {
                        DataField = attribute.Key, HeaderText = attribute.Name
                    });
                }
            }

            DeleteField deleteField = new DeleteField();

            deleteField.Click += gMatrixItems_DeleteClick;
            _gMatrixItems.Columns.Add(deleteField);

            _gMatrixItems.RowSelected += gMatrixItems_RowSelected;

            // Edit Item
            _pnlEditMatrixItem = new Panel {
                ID = "_pnlEditMatrixItem", Visible = false, CssClass = "well js-validation-group"
            };
            _hfMatrixItemId = new HiddenField {
                ID = "_hfMatrixItemId"
            };
            _pnlEditMatrixItem.Controls.Add(_hfMatrixItemId);

            _phMatrixItemAttributes = new DynamicPlaceholder {
                ID = "_phMatrixItemAttributes"
            };
            _pnlEditMatrixItem.Controls.Add(_phMatrixItemAttributes);

            string validationGroup = GetValidationGroupForAttributeControls();

            if (tempAttributeMatrixItem != null)
            {
                Rock.Attribute.Helper.AddEditControls(tempAttributeMatrixItem, _phMatrixItemAttributes, false, validationGroup);
            }

            _pnlActions = new Panel {
                ID = "_pnlActions", CssClass = "actions"
            };
            _pnlEditMatrixItem.Controls.Add(_pnlActions);

            _btnSaveMatrixItem = new LinkButton {
                ID = "_btnSaveMatrixItem", CssClass = "btn btn-primary btn-sm", Text = "Save", ValidationGroup = validationGroup, CausesValidation = true
            };
            _btnSaveMatrixItem.Click += btnSaveMatrixItem_Click;
            _pnlActions.Controls.Add(_btnSaveMatrixItem);

            _btnCancelMatrixItem = new LinkButton {
                ID = "_btnCancelMatrixItem", CssClass = "btn btn-link", Text = "Cancel", CausesValidation = false
            };
            _btnCancelMatrixItem.Click += btnCancelMatrixItem_Click;
            _pnlActions.Controls.Add(_btnCancelMatrixItem);

            this.Controls.Add(_pnlEditMatrixItem);
        }
Esempio n. 3
0
        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            _phControls = new DynamicPlaceholder {
                ID = "phControls"
            };
            this.Controls.Add(_phControls);

            _pnlRow = new DynamicControlsPanel {
                ID = "pnlRow", CssClass = "row"
            };
            _pnlCol1 = new DynamicControlsPanel {
                ID = "pnlCol1", CssClass = "col-sm-4"
            };
            _pnlCol2 = new DynamicControlsPanel {
                ID = "pnlCol2", CssClass = "col-sm-4"
            };
            _pnlCol3 = new DynamicControlsPanel {
                ID = "pnlCol3", CssClass = "col-sm-4"
            };
            _phControls.Controls.Add(_pnlRow);
            _pnlRow.Controls.Add(_pnlCol1);
            _pnlRow.Controls.Add(_pnlCol2);
            _pnlRow.Controls.Add(_pnlCol3);


            _hfPersonId = new HiddenField
            {
                ID = "_hfPersonId"
            };

            _phControls.Controls.Add(_hfPersonId);

            _dvpPersonTitle = new DefinedValuePicker
            {
                ID              = "_dvpPersonTitle",
                DefinedTypeId   = DefinedTypeCache.GetId(Rock.SystemGuid.DefinedType.PERSON_TITLE.AsGuid()),
                Label           = "Title",
                CssClass        = "input-width-md",
                ValidationGroup = ValidationGroup
            };

            _tbPersonFirstName = new RockTextBox
            {
                ID               = "tbPersonFirstName",
                Label            = "First Name",
                Required         = true,
                AutoCompleteType = AutoCompleteType.None,
                ValidationGroup  = ValidationGroup
            };

            _tbPersonLastName = new RockTextBox
            {
                ID               = "tbPersonLastName",
                Label            = "Last Name",
                Required         = true,
                AutoCompleteType = AutoCompleteType.None,
                ValidationGroup  = ValidationGroup
            };

            _dvpPersonSuffix = new DefinedValuePicker
            {
                ID              = "dvpPersonSuffix",
                DefinedTypeId   = DefinedTypeCache.GetId(Rock.SystemGuid.DefinedType.PERSON_SUFFIX.AsGuid()),
                Label           = "Suffix",
                CssClass        = "input-width-md",
                ValidationGroup = ValidationGroup
            };

            // Have Email and PhoneNumber hidden by default
            _ebPersonEmail = new EmailBox
            {
                ID              = "ebPersonEmail",
                Label           = "Email",
                ValidationGroup = ValidationGroup,
                Visible         = false
            };

            _pnbMobilePhoneNumber = new PhoneNumberBox
            {
                Label   = "Mobile Phone",
                ID      = "pnbMobilePhoneNumber",
                Visible = false
            };

            _dvpPersonConnectionStatus = new DefinedValuePicker
            {
                ID              = "dvpPersonConnectionStatus",
                DefinedTypeId   = DefinedTypeCache.GetId(Rock.SystemGuid.DefinedType.PERSON_CONNECTION_STATUS.AsGuid()),
                Label           = "Connection Status",
                Required        = true,
                ValidationGroup = ValidationGroup
            };

            _rblPersonRole = new RockRadioButtonList
            {
                ID              = "rblPersonRole",
                Label           = "Role",
                RepeatDirection = RepeatDirection.Horizontal,
                DataTextField   = "Name",
                DataValueField  = "Id",
                Required        = true,
                ValidationGroup = ValidationGroup
            };

            _rblPersonGender = new RockRadioButtonList
            {
                ID              = "rblPersonGender",
                Label           = "Gender",
                RepeatDirection = RepeatDirection.Horizontal,
                Required        = this.RequireGender,
                ValidationGroup = this.RequireGender == true ? ValidationGroup : string.Empty,
                ShowNoneOption  = false
            };

            _bdpPersonBirthDate = new BirthdayPicker
            {
                ID              = "bdpPersonBirthDate",
                Label           = "Birthdate",
                ValidationGroup = ValidationGroup
            };

            _ddlGradePicker = new GradePicker
            {
                ID                    = "ddlGradePicker",
                Label                 = "Grade",
                UseAbbreviation       = true,
                UseGradeOffsetAsValue = true,
                ValidationGroup       = ValidationGroup
            };

            _dvpPersonMaritalStatus = new DefinedValuePicker
            {
                ID              = "dvpPersonMaritalStatus",
                Label           = "Marital Status",
                DefinedTypeId   = DefinedTypeCache.GetId(Rock.SystemGuid.DefinedType.PERSON_MARITAL_STATUS.AsGuid()),
                ValidationGroup = ValidationGroup
            };

            var groupType = GroupTypeCache.GetFamilyGroupType();

            _rblPersonRole.DataSource = groupType.Roles.OrderBy(r => r.Order).ToList();
            _rblPersonRole.DataBind();

            _rblPersonGender.Items.Clear();
            _rblPersonGender.Items.Add(new ListItem(Gender.Male.ConvertToString(), Gender.Male.ConvertToInt().ToString()));
            _rblPersonGender.Items.Add(new ListItem(Gender.Female.ConvertToString(), Gender.Female.ConvertToInt().ToString()));

            ArrangePersonControls(this.ShowInColumns);
            UpdatePersonControlLabels();
        }