Пример #1
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="groupMemberId">The group member identifier.</param>
        /// <param name="groupId">The group id.</param>
        public void ShowDetail(int groupMemberId, int?groupId)
        {
            // autoexpand the person picker if this is an add
            var personPickerStartupScript = @"Sys.Application.add_load(function () {

                // if the person picker is empty then open it for quick entry
                var personPicker = $('.js-authorizedperson');
                var currentPerson = personPicker.find('.picker-selectedperson').html();
                if (currentPerson != null && currentPerson.length == 0) {
                    $(personPicker).find('a.picker-label').trigger('click');
                }

            });";

            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "StartupScript", personPickerStartupScript, true);

            var         rockContext = new RockContext();
            GroupMember groupMember = null;

            if (!groupMemberId.Equals(0))
            {
                groupMember = new GroupMemberService(rockContext).Get(groupMemberId);
                pdAuditDetails.SetEntity(groupMember, ResolveRockUrl("~"));
            }
            else
            {
                // only create a new one if parent was specified
                if (groupId.HasValue)
                {
                    groupMember = new GroupMember {
                        Id = 0
                    };
                    groupMember.GroupId           = groupId.Value;
                    groupMember.Group             = new GroupService(rockContext).Get(groupMember.GroupId);
                    groupMember.GroupRoleId       = groupMember.Group.GroupType.DefaultGroupRoleId ?? 0;
                    groupMember.GroupMemberStatus = GroupMemberStatus.Active;
                    groupMember.DateTimeAdded     = RockDateTime.Now;
                    // hide the panel drawer that show created and last modified dates
                    pdAuditDetails.Visible = false;
                }
            }

            if (groupMember == null)
            {
                if (groupMemberId > 0)
                {
                    nbErrorMessage.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Warning;
                    nbErrorMessage.Title = "Warning";
                    nbErrorMessage.Text  = "Group Member not found. Group Member may have been moved to another group or deleted.";
                }
                else
                {
                    nbErrorMessage.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Danger;
                    nbErrorMessage.Title = "Invalid Request";
                    nbErrorMessage.Text  = "An incorrect querystring parameter was used.  A valid GroupMemberId or GroupId parameter is required.";
                }

                pnlEditDetails.Visible = false;
                return;
            }

            pnlEditDetails.Visible = true;

            hfGroupId.Value       = groupMember.GroupId.ToString();
            hfGroupMemberId.Value = groupMember.Id.ToString();

            if (IsUserAuthorized(Authorization.ADMINISTRATE))
            {
                cbIsNotified.Checked = groupMember.IsNotified;
                cbIsNotified.Visible = true;
                cbIsNotified.Help    = "If this box is unchecked and a <a href=\"http://www.rockrms.com/Rock/BookContent/7/#servicejobsrelatingtogroups\">group leader notification job</a> is enabled then a notification will be sent to the group's leaders when this group member is saved.";
            }
            else
            {
                cbIsNotified.Visible = false;
            }

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            var group = groupMember.Group;

            if (!string.IsNullOrWhiteSpace(group.GroupType.IconCssClass))
            {
                lGroupIconHtml.Text = string.Format("<i class='{0}' ></i>", group.GroupType.IconCssClass);
            }
            else
            {
                lGroupIconHtml.Text = "<i class='fa fa-user' ></i>";
            }

            if (groupMember.Id.Equals(0))
            {
                lReadOnlyTitle.Text    = ActionTitle.Add(groupMember.Group.GroupType.GroupTerm + " " + groupMember.Group.GroupType.GroupMemberTerm).FormatAsHtmlTitle();
                btnSaveThenAdd.Visible = true;
            }
            else
            {
                lReadOnlyTitle.Text    = groupMember.Person.FullName.FormatAsHtmlTitle();
                btnSaveThenAdd.Visible = false;
            }

            if (groupMember.DateTimeAdded.HasValue)
            {
                hfDateAdded.Text    = string.Format("Added: {0}", groupMember.DateTimeAdded.Value.ToShortDateString());
                hfDateAdded.Visible = true;
            }
            else
            {
                hfDateAdded.Text    = string.Empty;
                hfDateAdded.Visible = false;
            }

            // user has to have EDIT Auth to the Block OR the group
            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized(Authorization.EDIT) && !group.IsAuthorized(Authorization.EDIT, this.CurrentPerson))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(Group.FriendlyTypeName);
            }

            if (groupMember.IsSystem)
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem(Group.FriendlyTypeName);
            }

            btnSave.Visible = !readOnly;

            if (readOnly || groupMember.Id == 0)
            {
                // hide the ShowMoveDialog if this is readOnly or if this is a new group member (can't move a group member that doesn't exist yet)
                btnShowMoveDialog.Visible = false;
            }

            LoadDropDowns();

            ShowRequiredDocumentStatus(rockContext, groupMember, group);

            ppGroupMemberPerson.SetValue(groupMember.Person);
            ppGroupMemberPerson.Enabled = !readOnly;

            if (groupMember.Id != 0)
            {
                // once a group member record is saved, don't let them change the person
                ppGroupMemberPerson.Enabled = false;
            }

            ddlGroupRole.SetValue(groupMember.GroupRoleId);
            ddlGroupRole.Enabled = !readOnly;

            tbNote.Text     = groupMember.Note;
            tbNote.ReadOnly = readOnly;

            rblStatus.SetValue((int)groupMember.GroupMemberStatus);
            rblStatus.Enabled = !readOnly;
            rblStatus.Label   = string.Format("{0} Status", group.GroupType.GroupMemberTerm);

            var registrations = new RegistrationRegistrantService(rockContext)
                                .Queryable().AsNoTracking()
                                .Where(r =>
                                       r.Registration != null &&
                                       r.Registration.RegistrationInstance != null &&
                                       r.GroupMemberId.HasValue &&
                                       r.GroupMemberId.Value == groupMember.Id)
                                .Select(r => new
            {
                Id   = r.Registration.Id,
                Name = r.Registration.RegistrationInstance.Name
            })
                                .ToList();

            if (registrations.Any())
            {
                rcwLinkedRegistrations.Visible    = true;
                rptLinkedRegistrations.DataSource = registrations;
                rptLinkedRegistrations.DataBind();
            }
            else
            {
                rcwLinkedRegistrations.Visible = false;
            }

            if (groupMember.Group.RequiredSignatureDocumentTemplate != null)
            {
                fuSignedDocument.Label = groupMember.Group.RequiredSignatureDocumentTemplate.Name;
                if (groupMember.Group.RequiredSignatureDocumentTemplate.BinaryFileType != null)
                {
                    fuSignedDocument.BinaryFileTypeGuid = groupMember.Group.RequiredSignatureDocumentTemplate.BinaryFileType.Guid;
                }

                var signatureDocument = new SignatureDocumentService(rockContext)
                                        .Queryable().AsNoTracking()
                                        .Where(d =>
                                               d.SignatureDocumentTemplateId == groupMember.Group.RequiredSignatureDocumentTemplateId.Value &&
                                               d.AppliesToPersonAlias != null &&
                                               d.AppliesToPersonAlias.PersonId == groupMember.PersonId &&
                                               d.LastStatusDate.HasValue &&
                                               d.Status == SignatureDocumentStatus.Signed &&
                                               d.BinaryFile != null)
                                        .OrderByDescending(d => d.LastStatusDate.Value)
                                        .FirstOrDefault();

                if (signatureDocument != null)
                {
                    hfSignedDocumentId.Value      = signatureDocument.Id.ToString();
                    fuSignedDocument.BinaryFileId = signatureDocument.BinaryFileId;
                }

                fuSignedDocument.Visible = true;
            }
            else
            {
                fuSignedDocument.Visible = false;
            }

            groupMember.LoadAttributes();
            phAttributes.Controls.Clear();

            Rock.Attribute.Helper.AddEditControls(groupMember, phAttributes, true, string.Empty);
            if (readOnly)
            {
                Rock.Attribute.Helper.AddDisplayControls(groupMember, phAttributesReadOnly);
                phAttributesReadOnly.Visible = true;
                phAttributes.Visible         = false;
            }
            else
            {
                phAttributesReadOnly.Visible = false;
                phAttributes.Visible         = true;
            }

            var groupHasRequirements = group.GroupRequirements.Any();

            pnlRequirements.Visible        = groupHasRequirements;
            btnReCheckRequirements.Visible = groupHasRequirements;

            ShowGroupRequirementsStatuses();
        }
Пример #2
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="groupMemberId">The group member identifier.</param>
        /// <param name="groupId">The group id.</param>
        public void ShowDetail( int groupMemberId, int? groupId )
        {
            // autoexpand the person picker if this is an add
            var personPickerStartupScript = @"Sys.Application.add_load(function () {

                // if the person picker is empty then open it for quick entry
                var personPicker = $('.js-authorizedperson');
                var currentPerson = personPicker.find('.picker-selectedperson').html();
                if (currentPerson != null && currentPerson.length == 0) {
                    $(personPicker).find('a.picker-label').trigger('click');
                }

            });";

            this.Page.ClientScript.RegisterStartupScript( this.GetType(), "StartupScript", personPickerStartupScript, true );

            var rockContext = new RockContext();
            GroupMember groupMember = null;

            if ( !groupMemberId.Equals( 0 ) )
            {
                groupMember = new GroupMemberService( rockContext ).Get( groupMemberId );
                pdAuditDetails.SetEntity( groupMember, ResolveRockUrl( "~" ) );
            }
            else
            {
                // only create a new one if parent was specified
                if ( groupId.HasValue )
                {
                    groupMember = new GroupMember { Id = 0 };
                    groupMember.GroupId = groupId.Value;
                    groupMember.Group = new GroupService( rockContext ).Get( groupMember.GroupId );
                    groupMember.GroupRoleId = groupMember.Group.GroupType.DefaultGroupRoleId ?? 0;
                    groupMember.GroupMemberStatus = GroupMemberStatus.Active;
                    groupMember.DateTimeAdded = RockDateTime.Now;
                    // hide the panel drawer that show created and last modified dates
                    pdAuditDetails.Visible = false;
                }
            }

            if ( groupMember == null )
            {
                if ( groupMemberId > 0 )
                {
                    nbErrorMessage.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Warning;
                    nbErrorMessage.Title = "Warning";
                    nbErrorMessage.Text = "Group Member not found. Group Member may have been moved to another group or deleted.";
                }
                else
                {
                    nbErrorMessage.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Danger;
                    nbErrorMessage.Title = "Invalid Request";
                    nbErrorMessage.Text = "An incorrect querystring parameter was used.  A valid GroupMemberId or GroupId parameter is required.";
                }

                pnlEditDetails.Visible = false;
                return;
            }

            pnlEditDetails.Visible = true;

            hfGroupId.Value = groupMember.GroupId.ToString();
            hfGroupMemberId.Value = groupMember.Id.ToString();

            if ( IsUserAuthorized( Authorization.ADMINISTRATE ) )
            {
                cbIsNotified.Checked = groupMember.IsNotified;
                cbIsNotified.Visible = true;
                cbIsNotified.Help = "If this box is unchecked and a <a href=\"http://www.rockrms.com/Rock/BookContent/7/#servicejobsrelatingtogroups\">group leader notification job</a> is enabled then a notification will be sent to the group's leaders when this group member is saved.";
            }
            else
            {
                cbIsNotified.Visible = false;
            }

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            var group = groupMember.Group;
            if ( !string.IsNullOrWhiteSpace( group.GroupType.IconCssClass ) )
            {
                lGroupIconHtml.Text = string.Format( "<i class='{0}' ></i>", group.GroupType.IconCssClass );
            }
            else
            {
                lGroupIconHtml.Text = "<i class='fa fa-user' ></i>";
            }

            if ( groupMember.Id.Equals( 0 ) )
            {
                lReadOnlyTitle.Text = ActionTitle.Add( groupMember.Group.GroupType.GroupTerm + " " + groupMember.Group.GroupType.GroupMemberTerm ).FormatAsHtmlTitle();
                btnSaveThenAdd.Visible = true;
            }
            else
            {
                lReadOnlyTitle.Text = groupMember.Person.FullName.FormatAsHtmlTitle();
                btnSaveThenAdd.Visible = false;
            }

            if ( groupMember.DateTimeAdded.HasValue )
            {
                hfDateAdded.Text = string.Format( "Added: {0}", groupMember.DateTimeAdded.Value.ToShortDateString() );
                hfDateAdded.Visible = true;
            }
            else
            {
                hfDateAdded.Text = string.Empty;
                hfDateAdded.Visible = false;
            }

            // user has to have EDIT Auth to the Block OR the group
            nbEditModeMessage.Text = string.Empty;
            if ( !IsUserAuthorized( Authorization.EDIT ) && !group.IsAuthorized( Authorization.EDIT, this.CurrentPerson ) )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( Group.FriendlyTypeName );
            }

            if ( groupMember.IsSystem )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( Group.FriendlyTypeName );
            }

            btnSave.Visible = !readOnly;

            if ( readOnly || groupMember.Id == 0)
            {
                // hide the ShowMoveDialog if this is readOnly or if this is a new group member (can't move a group member that doesn't exist yet)
                btnShowMoveDialog.Visible = false;
            }

            LoadDropDowns();

            ShowRequiredDocumentStatus( rockContext, groupMember, group );

            ppGroupMemberPerson.SetValue( groupMember.Person );
            ppGroupMemberPerson.Enabled = !readOnly;

            if ( groupMember.Id != 0 )
            {
                // once a group member record is saved, don't let them change the person
                ppGroupMemberPerson.Enabled = false;
            }

            ddlGroupRole.SetValue( groupMember.GroupRoleId );
            ddlGroupRole.Enabled = !readOnly;

            tbNote.Text = groupMember.Note;
            tbNote.ReadOnly = readOnly;

            rblStatus.SetValue( (int)groupMember.GroupMemberStatus );
            rblStatus.Enabled = !readOnly;
            rblStatus.Label = string.Format( "{0} Status", group.GroupType.GroupMemberTerm );

            var registrations = new RegistrationRegistrantService( rockContext )
                .Queryable().AsNoTracking()
                .Where( r =>
                    r.Registration != null &&
                    r.Registration.RegistrationInstance != null &&
                    r.GroupMemberId.HasValue &&
                    r.GroupMemberId.Value == groupMember.Id )
                .Select( r => new
                {
                    Id = r.Registration.Id,
                    Name = r.Registration.RegistrationInstance.Name
                } )
                .ToList();
            if ( registrations.Any() )
            {
                rcwLinkedRegistrations.Visible = true;
                rptLinkedRegistrations.DataSource = registrations;
                rptLinkedRegistrations.DataBind();
            }
            else
            {
                rcwLinkedRegistrations.Visible = false;
            }

            if ( groupMember.Group.RequiredSignatureDocumentTemplate != null )
            {
                fuSignedDocument.Label = groupMember.Group.RequiredSignatureDocumentTemplate.Name;
                if ( groupMember.Group.RequiredSignatureDocumentTemplate.BinaryFileType != null )
                {
                    fuSignedDocument.BinaryFileTypeGuid = groupMember.Group.RequiredSignatureDocumentTemplate.BinaryFileType.Guid;
                }

                var signatureDocument = new SignatureDocumentService( rockContext )
                    .Queryable().AsNoTracking()
                    .Where( d =>
                        d.SignatureDocumentTemplateId == groupMember.Group.RequiredSignatureDocumentTemplateId.Value &&
                        d.AppliesToPersonAlias != null &&
                        d.AppliesToPersonAlias.PersonId == groupMember.PersonId &&
                        d.LastStatusDate.HasValue &&
                        d.Status == SignatureDocumentStatus.Signed &&
                        d.BinaryFile != null )
                    .OrderByDescending( d => d.LastStatusDate.Value )
                    .FirstOrDefault();

                if ( signatureDocument != null )
                {
                    hfSignedDocumentId.Value = signatureDocument.Id.ToString();
                    fuSignedDocument.BinaryFileId = signatureDocument.BinaryFileId;
                }

                fuSignedDocument.Visible = true;
            }
            else
            {
                fuSignedDocument.Visible = false;
            }

            groupMember.LoadAttributes();
            phAttributes.Controls.Clear();

            Rock.Attribute.Helper.AddEditControls( groupMember, phAttributes, true, string.Empty, true );
            if ( readOnly )
            {
                Rock.Attribute.Helper.AddDisplayControls( groupMember, phAttributesReadOnly );
                phAttributesReadOnly.Visible = true;
                phAttributes.Visible = false;
            }
            else
            {
                phAttributesReadOnly.Visible = false;
                phAttributes.Visible = true;
            }

            var groupHasRequirements = group.GroupRequirements.Any();
            pnlRequirements.Visible = groupHasRequirements;
            btnReCheckRequirements.Visible = groupHasRequirements;

            ShowGroupRequirementsStatuses();
        }