示例#1
0
        /// <summary>
        /// Creates the dynamic family controls.
        /// </summary>
        /// <param name="editFamilyState">State of the edit family.</param>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        private void CreateDynamicFamilyControls(FamilyRegistrationState editFamilyState)
        {
            var fakeFamily = new Group()
            {
                GroupTypeId = GroupTypeCache.GetFamilyGroupType().Id
            };
            var attributeList = editFamilyState.FamilyAttributeValuesState.Select(a => AttributeCache.Get(a.Value.AttributeId)).ToList();

            fakeFamily.Attributes      = attributeList.ToDictionary(a => a.Key, v => v);
            fakeFamily.AttributeValues = editFamilyState.FamilyAttributeValuesState;
            var familyAttributeKeysToEdit = this.RequiredAttributesForFamilies.OrderBy(a => a.Order).ToList();

            familyAttributeKeysToEdit.AddRange(this.OptionalAttributesForFamilies.OrderBy(a => a.Order).ToList());

            avcFamilyAttributes.IncludedAttributes = familyAttributeKeysToEdit.ToArray();
            avcFamilyAttributes.ValidationGroup    = btnSaveFamily.ValidationGroup;
            avcFamilyAttributes.NumberOfColumns    = 2;
            avcFamilyAttributes.ShowCategoryLabel  = false;
            avcFamilyAttributes.AddEditControls(fakeFamily);

            // override the attribute's IsRequired and set Required based on whether the attribute is part of the Required or Optional set of attributes for the Registration
            foreach (Control attributeControl in avcFamilyAttributes.ControlsOfTypeRecursive <Control>().OfType <Control>())
            {
                if (attributeControl is IHasRequired && attributeControl.ID.IsNotNullOrWhiteSpace())
                {
                    int?attributeControlAttributeId = attributeControl.ID.Replace("attribute_field_", string.Empty).AsIntegerOrNull();
                    if (attributeControlAttributeId.HasValue)
                    {
                        (attributeControl as IHasRequired).Required = this.RequiredAttributesForFamilies.Any(a => a.Id == attributeControlAttributeId.Value);
                    }
                }
            }
        }
        /// <summary>
        /// Restores the view-state information from a previous user control request that was saved by the <see cref="M:System.Web.UI.UserControl.SaveViewState" /> method.
        /// </summary>
        /// <param name="savedState">An <see cref="T:System.Object" /> that represents the user control state to be restored.</param>
        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);

            if (CurrentCheckInState == null)
            {
                return;
            }

            EditFamilyState = (this.ViewState["EditFamilyState"] as string).FromJsonOrNull <FamilyRegistrationState>();

            CreateDynamicFamilyControls(FamilyRegistrationState.FromGroup(new Group()
            {
                GroupTypeId = GroupTypeCache.GetFamilyGroupType().Id
            }), false);

            CreateDynamicPersonControls(FamilyRegistrationState.FamilyPersonState.FromTemporaryPerson(), false);
        }
        /// <summary>
        /// Creates the dynamic family controls.
        /// </summary>
        /// <param name="editFamilyState">State of the edit family.</param>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        private void CreateDynamicFamilyControls(FamilyRegistrationState editFamilyState, bool setValues)
        {
            phFamilyAttributes.Controls.Clear();

            var fakeFamily = new Group()
            {
                GroupTypeId = GroupTypeCache.GetFamilyGroupType().Id
            };
            var attributeList = editFamilyState.FamilyAttributeValuesState.Select(a => AttributeCache.Get(a.Value.AttributeId)).ToList();

            fakeFamily.Attributes      = attributeList.ToDictionary(a => a.Key, v => v);
            fakeFamily.AttributeValues = editFamilyState.FamilyAttributeValuesState;
            var familyAttributeKeysToEdit = this.RequiredAttributesForFamilies.OrderBy(a => a.Order).Select(a => a.Key).ToList();

            familyAttributeKeysToEdit.AddRange(this.OptionalAttributesForFamilies.OrderBy(a => a.Order).Select(a => a.Key).ToList());

            Rock.Attribute.Helper.AddEditControls(
                string.Empty,
                familyAttributeKeysToEdit,
                fakeFamily,
                phFamilyAttributes,
                btnSaveFamily.ValidationGroup,
                setValues,
                new List <string>(),
                2);

            // override the attribute's IsRequired and set Required based on whether the attribute is part of the Required or Optional set of attributes for the Registration
            foreach (Control attributeControl in phFamilyAttributes.ControlsOfTypeRecursive <Control>().OfType <Control>())
            {
                if (attributeControl is IHasRequired && attributeControl.ID.IsNotNullOrWhiteSpace())
                {
                    int?attributeControlAttributeId = attributeControl.ID.Replace("attribute_field_", string.Empty).AsIntegerOrNull();
                    if (attributeControlAttributeId.HasValue)
                    {
                        (attributeControl as IHasRequired).Required = this.RequiredAttributesForFamilies.Any(a => a.Id == attributeControlAttributeId.Value);
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// Creates the dynamic family controls.
        /// </summary>
        /// <param name="editFamilyState">State of the edit family.</param>
        private void CreateDynamicFamilyControls(FamilyRegistrationState editFamilyState)
        {
            var fakeFamily = new Group()
            {
                GroupTypeId = GroupTypeCache.GetFamilyGroupType().Id
            };
            var attributeList = editFamilyState.FamilyAttributeValuesState.Select(a => AttributeCache.Get(a.Value.AttributeId)).ToList();

            fakeFamily.Attributes      = attributeList.ToDictionary(a => a.Key, v => v);
            fakeFamily.AttributeValues = editFamilyState.FamilyAttributeValuesState;
            var familyAttributeKeysToEdit = this.RequiredAttributesForFamilies.OrderBy(a => a.Order).ToList();

            familyAttributeKeysToEdit.AddRange(this.OptionalAttributesForFamilies.OrderBy(a => a.Order).ToList());

            avcFamilyAttributes.IncludedAttributes = familyAttributeKeysToEdit.ToArray();

            // override the attribute's IsRequired and set Required based on whether the attribute is part of the Required or Optional set of attributes for the Registration
            avcFamilyAttributes.RequiredAttributes = this.RequiredAttributesForFamilies.ToArray();

            avcFamilyAttributes.ValidationGroup   = btnSaveFamily.ValidationGroup;
            avcFamilyAttributes.NumberOfColumns   = 2;
            avcFamilyAttributes.ShowCategoryLabel = false;
            avcFamilyAttributes.AddEditControls(fakeFamily);
        }
示例#5
0
        /// <summary>
        /// Shows edit UI fo the family (or null adding a new family)
        /// </summary>
        /// <param name="checkInFamily">The check in family.</param>
        private void ShowFamilyDetail(CheckInFamily checkInFamily)
        {
            if (checkInFamily != null && checkInFamily.Group != null)
            {
                this.EditFamilyState = FamilyRegistrationState.FromGroup(checkInFamily.Group);
                hfGroupId.Value      = checkInFamily.Group.Id.ToString();
                mdEditFamily.Title   = checkInFamily.Group.Name;

                int groupId            = hfGroupId.Value.AsInteger();
                var rockContext        = new RockContext();
                var groupMemberService = new GroupMemberService(rockContext);
                var groupMembersQuery  = groupMemberService.Queryable(false)
                                         .Include(a => a.Person)
                                         .Where(a => a.GroupId == groupId)
                                         .OrderBy(m => m.GroupRole.Order)
                                         .ThenBy(m => m.Person.BirthYear)
                                         .ThenBy(m => m.Person.BirthMonth)
                                         .ThenBy(m => m.Person.BirthDay)
                                         .ThenBy(m => m.Person.Gender);

                var groupMemberList = groupMembersQuery.ToList();

                foreach (var groupMember in groupMemberList)
                {
                    var familyPersonState = FamilyRegistrationState.FamilyPersonState.FromPerson(groupMember.Person, 0, true);
                    familyPersonState.GroupMemberGuid = groupMember.Guid;
                    familyPersonState.GroupId         = groupMember.GroupId;
                    familyPersonState.IsAdult         = groupMember.GroupRoleId == _groupTypeRoleAdultId;
                    this.EditFamilyState.FamilyPersonListState.Add(familyPersonState);
                }

                var adultIds = this.EditFamilyState.FamilyPersonListState.Where(a => a.IsAdult && a.PersonId.HasValue).Select(a => a.PersonId.Value).ToList();
                var roleIds  = CurrentCheckInState.CheckInType.Registration.KnownRelationships.Where(a => a.Key != 0).Select(a => a.Key).ToList();
                IEnumerable <GroupMember> personRelationships = new PersonService(rockContext).GetRelatedPeople(adultIds, roleIds);
                foreach (GroupMember personRelationship in personRelationships)
                {
                    if (!this.EditFamilyState.FamilyPersonListState.Any(a => a.PersonId == personRelationship.Person.Id))
                    {
                        var familyPersonState = FamilyRegistrationState.FamilyPersonState.FromPerson(personRelationship.Person, personRelationship.GroupRoleId, false);
                        familyPersonState.GroupMemberGuid = Guid.NewGuid();
                        var relatedFamily = personRelationship.Person.GetFamily();
                        if (relatedFamily != null)
                        {
                            familyPersonState.GroupId = relatedFamily.Id;
                        }

                        familyPersonState.IsAdult = false;
                        familyPersonState.ChildRelationshipToAdult = personRelationship.GroupRoleId;
                        familyPersonState.CanCheckIn = CurrentCheckInState.CheckInType.Registration.KnownRelationshipsCanCheckin.Any(k => k.Key == familyPersonState.ChildRelationshipToAdult);
                        this.EditFamilyState.FamilyPersonListState.Add(familyPersonState);
                    }
                }

                BindFamilyMembersGrid();
                CreateDynamicFamilyControls(EditFamilyState);

                ShowFamilyView();
            }
            else
            {
                this.EditFamilyState = FamilyRegistrationState.FromGroup(new Group()
                {
                    GroupTypeId = GroupTypeCache.GetFamilyGroupType().Id
                });
                CreateDynamicFamilyControls(EditFamilyState);
                hfGroupId.Value    = "0";
                mdEditFamily.Title = "Add Family";
                EditGroupMember(null);
            }

            _initialEditFamilyStateHash = this.EditFamilyState.GetStateHash();

            // disable any idle redirect blocks that are on the page when the mdEditFamily modal is open
            DisableIdleRedirectBlocks(true);

            upContent.Update();
            mdEditFamily.Show();
        }