コード例 #1
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="pageId">The page identifier.</param>
        /// <param name="parentPageId">The parent page identifier.</param>
        public void ShowDetail(int pageId, int?parentPageId)
        {
            var rockContext = new RockContext();

            LoadSites(rockContext);

            PageService pageService = new PageService(rockContext);

            Rock.Model.Page page = pageService.Queryable("Layout,PageRoutes")
                                   .Where(p => p.Id == pageId)
                                   .FirstOrDefault();

            if (page == null)
            {
                page = new Rock.Model.Page {
                    Id = 0, IsSystem = false, ParentPageId = parentPageId
                };

                // fetch the ParentCategory (if there is one) so that security can check it
                page.ParentPage = pageService.Get(parentPageId ?? 0);
            }

            hfPageId.Value = page.Id.ToString();

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

            nbEditModeMessage.Text = string.Empty;

            // if the person is Authorized to EDIT the page, or has EDIT for the block
            var canEdit = page.IsAuthorized(Authorization.EDIT, CurrentPerson) || this.IsUserAuthorized(Authorization.EDIT);

            if (!canEdit)
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(Rock.Model.Page.FriendlyTypeName);
            }

            btnSecurity.Visible  = page.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson);
            btnSecurity.Title    = page.InternalName;
            btnSecurity.EntityId = page.Id;

            aChildPages.HRef = string.Format("javascript: Rock.controls.modal.show($(this), '/pages/{0}?t=Child Pages&amp;pb=&amp;sb=Done')", page.Id);

            // this will be true when used in the Page Builder page, and false when used in the System Dialog
            var enableFullEditMode = this.GetAttributeValue("EnableFullEditMode").AsBooleanOrNull() ?? false;

            pnlEditModeActions.Visible     = enableFullEditMode;
            pnlReadOnlyModeActions.Visible = enableFullEditMode;
            pnlHeading.Visible             = enableFullEditMode;
            pnlDetails.CssClass            = enableFullEditMode ? "panel panel-block" : string.Empty;
            pnlBody.CssClass = enableFullEditMode ? "panel-body" : string.Empty;

            if (readOnly)
            {
                btnEdit.Visible   = false;
                btnDelete.Visible = false;
                ShowReadonlyDetails(page);
            }
            else
            {
                btnEdit.Visible = true;
                string errorMessage = string.Empty;
                btnDelete.Visible = true;
                btnDelete.Enabled = pageService.CanDelete(page, out errorMessage);
                btnDelete.ToolTip = btnDelete.Enabled ? string.Empty : errorMessage;

                if (page.Id > 0 && enableFullEditMode)
                {
                    ShowReadonlyDetails(page);
                }
                else
                {
                    ShowEditDetails(page);
                }
            }

            if (btnDelete.Visible && btnDelete.Enabled)
            {
                btnDelete.Attributes["onclick"] = string.Format("javascript: return Rock.dialogs.confirmDelete(event, '{0}');", Rock.Model.Page.FriendlyTypeName.ToLower());
            }
        }
コード例 #2
0
        /// <summary>
        /// Handles the Click event of the lbSave 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 lbSave_Click( object sender, EventArgs e )
        {
            if ( Page.IsValid )
            {
                Rock.Model.Page page;

                var rockContext = new RockContext();
                var pageService = new PageService( rockContext );

                int pageId = hfPageId.Value.AsInteger();
                if ( pageId == 0 )
                {
                    page = new Rock.Model.Page();

                    if ( _page != null )
                    {
                        page.ParentPageId = _page.Id;
                        page.LayoutId = _page.LayoutId;
                    }
                    else
                    {
                        page.ParentPageId = null;
                        page.LayoutId = PageCache.Read( RockPage.PageId ).LayoutId;
                    }

                    page.PageTitle = dtbPageName.Text;
                    page.BrowserTitle = page.PageTitle;
                    page.EnableViewState = true;
                    page.IncludeAdminFooter = true;
                    page.MenuDisplayChildPages = true;

                    Rock.Model.Page lastPage = pageService.GetByParentPageId( _page.Id ).OrderByDescending( b => b.Order ).FirstOrDefault();

                    if ( lastPage != null )
                    {
                        page.Order = lastPage.Order + 1;
                    }
                    else
                    {
                        page.Order = 0;
                    }

                    pageService.Add( page );
                }
                else
                {
                    page = pageService.Get( pageId );
                }

                page.LayoutId = ddlLayout.SelectedValueAsInt().Value;
                page.InternalName = dtbPageName.Text;

                if ( page.IsValid )
                {
                    rockContext.SaveChanges();

                    PageCache.Flush( page.Id );
                    if ( _page != null )
                    {
                        Rock.Security.Authorization.CopyAuthorization( _page, page );
                        _page.FlushChildPages();
                    }

                    BindGrid();
                }

                rGrid.Visible = true;
                pnlDetails.Visible = false;
            }
        }
コード例 #3
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            CompetencyPersonProject competencyPersonProject;
            ResidencyService <CompetencyPersonProject> competencyPersonProjectService = new ResidencyService <CompetencyPersonProject>();

            CompetencyPersonProjectAssessment competencyPersonProjectAssessment;
            ResidencyService <CompetencyPersonProjectAssessment> competencyPersonProjectAssessmentService = new ResidencyService <CompetencyPersonProjectAssessment>();

            ResidencyService <CompetencyPersonProjectAssessmentPointOfAssessment> competencyPersonProjectAssessmentPointOfAssessmentService = new ResidencyService <CompetencyPersonProjectAssessmentPointOfAssessment>();

            int competencyPersonProjectId = hfCompetencyPersonProjectId.ValueAsInt();

            if (competencyPersonProjectId == 0)
            {
                competencyPersonProject = new CompetencyPersonProject();
                competencyPersonProjectService.Add(competencyPersonProject, CurrentPersonId);
            }
            else
            {
                competencyPersonProject = competencyPersonProjectService.Get(competencyPersonProjectId);
            }

            int competencyPersonProjectAssessmentId = hfCompetencyPersonProjectAssessmentId.ValueAsInt();

            if (competencyPersonProjectAssessmentId == 0)
            {
                competencyPersonProjectAssessment = new CompetencyPersonProjectAssessment();
                competencyPersonProjectAssessmentService.Add(competencyPersonProjectAssessment, CurrentPersonId);
            }
            else
            {
                competencyPersonProjectAssessment = competencyPersonProjectAssessmentService.Get(competencyPersonProjectAssessmentId);
                competencyPersonProjectAssessment.CompetencyPersonProjectAssessmentPointOfAssessments = new List <CompetencyPersonProjectAssessmentPointOfAssessment>();
            }

            // set competencyPersonProjectAssessment.CompetencyPersonProjectId after saving competencyPersonProject in case it is new
            competencyPersonProjectAssessment.AssessmentDateTime = DateTime.Now;
            competencyPersonProjectAssessment.RatingNotes        = tbRatingNotesOverall.Text;
            competencyPersonProjectAssessment.AssessorPersonId   = hfAssessorPersonId.ValueAsInt();

            if (!competencyPersonProjectAssessment.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            List <CompetencyPersonProjectAssessmentPointOfAssessment> competencyPersonProjectAssessmentPointOfAssessmentList = new List <CompetencyPersonProjectAssessmentPointOfAssessment>();

            foreach (RepeaterItem item in rptPointOfAssessment.Items.OfType <RepeaterItem>())
            {
                HiddenField hfProjectPointOfAssessmentId = item.FindControl("hfProjectPointOfAssessmentId") as HiddenField;
                int         projectPointOfAssessmentId   = hfProjectPointOfAssessmentId.ValueAsInt();

                CompetencyPersonProjectAssessmentPointOfAssessment competencyPersonProjectAssessmentPointOfAssessment = competencyPersonProjectAssessmentPointOfAssessmentService.Queryable()
                                                                                                                        .Where(a => a.ProjectPointOfAssessmentId == projectPointOfAssessmentId)
                                                                                                                        .Where(a => a.CompetencyPersonProjectAssessmentId == competencyPersonProjectAssessmentId).FirstOrDefault();

                if (competencyPersonProjectAssessmentPointOfAssessment == null)
                {
                    competencyPersonProjectAssessmentPointOfAssessment = new CompetencyPersonProjectAssessmentPointOfAssessment();
                    //// set competencyPersonProjectAssessmentPointOfAssessment.CompetencyPersonProjectAssessmentId = competencyPersonProjectAssessment.Id in save in case it's new
                    competencyPersonProjectAssessmentPointOfAssessment.ProjectPointOfAssessmentId = projectPointOfAssessmentId;
                }

                LabeledDropDownList ddlPointOfAssessmentRating = item.FindControl("ddlPointOfAssessmentRating") as LabeledDropDownList;
                TextBox             tbRatingNotesPOA           = item.FindControl("tbRatingNotesPOA") as TextBox;

                competencyPersonProjectAssessmentPointOfAssessment.Rating      = ddlPointOfAssessmentRating.SelectedValueAsInt();
                competencyPersonProjectAssessmentPointOfAssessment.RatingNotes = tbRatingNotesPOA.Text;

                competencyPersonProjectAssessmentPointOfAssessmentList.Add(competencyPersonProjectAssessmentPointOfAssessment);
            }

            RockTransactionScope.WrapTransaction(() =>
            {
                competencyPersonProjectService.Save(competencyPersonProject, CurrentPersonId);
                competencyPersonProjectAssessment.CompetencyPersonProjectId = competencyPersonProject.Id;

                // set Overall Rating based on average of POA ratings
                competencyPersonProjectAssessment.OverallRating = (decimal?)competencyPersonProjectAssessmentPointOfAssessmentList.Average(a => a.Rating);
                competencyPersonProjectAssessmentService.Save(competencyPersonProjectAssessment, CurrentPersonId);

                foreach (var competencyPersonProjectAssessmentPointOfAssessment in competencyPersonProjectAssessmentPointOfAssessmentList)
                {
                    competencyPersonProjectAssessmentPointOfAssessment.CompetencyPersonProjectAssessmentId = competencyPersonProjectAssessment.Id;

                    if (competencyPersonProjectAssessmentPointOfAssessment.Id == 0)
                    {
                        competencyPersonProjectAssessmentPointOfAssessmentService.Add(competencyPersonProjectAssessmentPointOfAssessment, CurrentPersonId);
                    }

                    competencyPersonProjectAssessmentPointOfAssessmentService.Save(competencyPersonProjectAssessmentPointOfAssessment, CurrentPersonId);
                }
            });

            Rock.Model.Page page = null;
            string          personProjectDetailPageGuid = this.GetAttributeValue("PersonProjectDetailPage");

            if (!string.IsNullOrWhiteSpace(personProjectDetailPageGuid))
            {
                page = new PageService().Get(new Guid(personProjectDetailPageGuid));
            }

            if (page != null)
            {
                Dictionary <string, string> qryString = new Dictionary <string, string>();
                qryString["competencyPersonProjectId"] = hfCompetencyPersonProjectId.Value;
                NavigateToPage(page.Guid, qryString);
            }
            else
            {
                throw new Exception("PersonProjectDetailPage not configured correctly");
            }
        }
コード例 #4
0
        /// <summary>
        /// Handles the Click event of the lbSave 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 lbSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Rock.Model.Page page;

                var rockContext = new RockContext();
                var pageService = new PageService(rockContext);

                int pageId = hfPageId.Value.AsInteger();
                if (pageId == 0)
                {
                    page = new Rock.Model.Page();

                    if (_page != null)
                    {
                        page.ParentPageId  = _page.Id;
                        page.LayoutId      = _page.LayoutId;
                        page.AllowIndexing = _page.AllowIndexing;
                    }
                    else
                    {
                        page.ParentPageId = null;
                        page.LayoutId     = PageCache.Read(RockPage.PageId).LayoutId;
                    }

                    page.PageTitle             = dtbPageName.Text;
                    page.BrowserTitle          = page.PageTitle;
                    page.EnableViewState       = true;
                    page.IncludeAdminFooter    = true;
                    page.MenuDisplayChildPages = true;

                    Rock.Model.Page lastPage = pageService.GetByParentPageId(_page.Id).OrderByDescending(b => b.Order).FirstOrDefault();

                    if (lastPage != null)
                    {
                        page.Order = lastPage.Order + 1;
                    }
                    else
                    {
                        page.Order = 0;
                    }

                    pageService.Add(page);
                }
                else
                {
                    page = pageService.Get(pageId);
                }

                page.LayoutId     = ddlLayout.SelectedValueAsInt().Value;
                page.InternalName = dtbPageName.Text;

                if (page.IsValid)
                {
                    rockContext.SaveChanges();

                    PageCache.Flush(page.Id);
                    if (_page != null)
                    {
                        Rock.Security.Authorization.CopyAuthorization(_page, page, rockContext);
                        _page.FlushChildPages();
                    }

                    BindGrid();
                }

                rGrid.Visible      = true;
                pnlDetails.Visible = false;
            }
        }
コード例 #5
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="pageRoute">The page route.</param>
        public void SetValue(Rock.Model.PageRoute pageRoute)
        {
            if (pageRoute != null)
            {
                Rock.Model.Page page = pageRoute.Page;
                PageRouteId = pageRoute.Id;
                ItemId      = page.Id.ToString();

                var parentPageIds = new List <string>();
                var parentPage    = page.ParentPage;
                while (parentPage != null)
                {
                    if (!parentPageIds.Contains(parentPage.Id.ToString()))
                    {
                        parentPageIds.Insert(0, parentPage.Id.ToString());
                    }
                    else
                    {
                        // infinite recursion
                        break;
                    }

                    parentPage = parentPage.ParentPage;
                }

                InitialItemParentIds = parentPageIds.AsDelimited(",");
                if (pageRoute.Id != 0)
                {
                    // PageRoute is selected, so show the Page and its PageRoute and don't show the PageRoute picker
                    ItemName = page.InternalName + " (" + pageRoute.Route + ")";

                    _rblSelectPageRoute.Visible = false;
                    _btnShowPageRoutePicker.Style[HtmlTextWriterStyle.Display] = "none";
                }
                else
                {
                    // Only a Page is selected, so show PageRoutePicker button if it has page routes
                    ItemName    = page.InternalName;
                    PageRouteId = null;

                    // Update PageRoutePicker control values
                    _rblSelectPageRoute.Items.Clear();
                    _rblSelectPageRoute.Visible = page.PageRoutes.Any();

                    if (page.PageRoutes.Count > 0)
                    {
                        foreach (var item in page.PageRoutes)
                        {
                            _rblSelectPageRoute.Items.Add(new ListItem(item.Route, item.Id.ToString()));
                        }
                    }

                    if (_rblSelectPageRoute.Items.Count > 0)
                    {
                        _btnShowPageRoutePicker.Style[HtmlTextWriterStyle.Display] = "";
                    }
                    else
                    {
                        _btnShowPageRoutePicker.Style[HtmlTextWriterStyle.Display] = "none";
                    }

                    if (_rblSelectPageRoute.Items.Count == 1)
                    {
                        _btnShowPageRoutePicker.Text = "( 1 route exists )";
                    }
                    else
                    {
                        _btnShowPageRoutePicker.Text = "(" + _rblSelectPageRoute.Items.Count + " routes exist )";
                    }
                }
            }
            else
            {
                ItemId      = Rock.Constants.None.IdValue;
                ItemName    = Rock.Constants.None.TextHtml;
                PageRouteId = null;
                _rblSelectPageRoute.Visible = false;
                _btnShowPageRoutePicker.Style[HtmlTextWriterStyle.Display] = "none";
            }
        }
コード例 #6
0
        /// <summary>
        /// Handles the Click event of the lbSave 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 lbSave_Click(object sender, EventArgs e)
        {
            var rockContext  = new RockContext();
            var pageService  = new PageService(rockContext);
            int parentPageId = SiteCache.Get(PageParameter("SiteId").AsInteger()).DefaultPageId.Value;

            var page = pageService.Get(PageParameter("Page").AsInteger());

            if (page == null)
            {
                page = new Rock.Model.Page();
                pageService.Add(page);

                var order = pageService.GetByParentPageId(parentPageId)
                            .OrderByDescending(p => p.Order)
                            .Select(p => p.Order)
                            .FirstOrDefault();
                page.Order        = order + 1;
                page.ParentPageId = parentPageId;
            }

            var additionalSettings = page.AdditionalSettings.FromJsonOrNull <Rock.Mobile.AdditionalPageSettings>() ?? new Rock.Mobile.AdditionalPageSettings();

            additionalSettings.LavaEventHandler = ceEventHandler.Text;

            page.InternalName       = tbInternalName.Text;
            page.BrowserTitle       = tbName.Text;
            page.PageTitle          = tbName.Text;
            page.Description        = tbDescription.Text;
            page.LayoutId           = ddlLayout.SelectedValueAsId().Value;
            page.DisplayInNavWhen   = cbDisplayInNavigation.Checked ? DisplayInNavWhen.WhenAllowed : DisplayInNavWhen.Never;
            page.AdditionalSettings = additionalSettings.ToJson();
            int?oldIconId = null;

            if (page.IconBinaryFileId != imgPageIcon.BinaryFileId)
            {
                oldIconId             = page.IconBinaryFileId;
                page.IconBinaryFileId = imgPageIcon.BinaryFileId;
            }

            rockContext.WrapTransaction(() =>
            {
                rockContext.SaveChanges();

                if (oldIconId.HasValue || page.IconBinaryFileId.HasValue)
                {
                    BinaryFileService binaryFileService = new BinaryFileService(rockContext);
                    if (oldIconId.HasValue)
                    {
                        var binaryFile = binaryFileService.Get(oldIconId.Value);
                        if (binaryFile != null)
                        {
                            // marked the old images as IsTemporary so they will get cleaned up later
                            binaryFile.IsTemporary = true;
                            rockContext.SaveChanges();
                        }
                    }

                    if (page.IconBinaryFileId.HasValue)
                    {
                        var binaryFile = binaryFileService.Get(page.IconBinaryFileId.Value);
                        if (binaryFile != null)
                        {
                            // marked the old images as IsTemporary so they will get cleaned up later
                            binaryFile.IsTemporary = false;
                            rockContext.SaveChanges();
                        }
                    }
                }
            });

            NavigateToCurrentPage(new Dictionary <string, string>
            {
                { "SiteId", PageParameter("SiteId") },
                { "Page", page.Id.ToString() }
            });
        }
コード例 #7
0
        /// <summary>
        /// Shows the page edit.
        /// </summary>
        /// <param name="pageId">The page identifier.</param>
        private void ShowPageEdit(int pageId)
        {
            var page = new PageService(new RockContext()).Get(pageId);

            //
            // Ensure the page is valid.
            //
            if (pageId != 0)
            {
                var pageCache = PageCache.Get(pageId);

                if (!CheckIsValidMobilePage(pageCache))
                {
                    return;
                }
            }

            if (page == null)
            {
                page = new Rock.Model.Page
                {
                    DisplayInNavWhen = DisplayInNavWhen.WhenAllowed
                };
            }

            //
            // Ensure user has access to edit this page.
            //
            if (!page.IsAuthorized(Authorization.EDIT, CurrentPerson))
            {
                nbError.Text = Rock.Constants.EditModeMessage.NotAuthorizedToEdit(typeof(Rock.Model.Page).GetFriendlyTypeName());

                pnlEditPage.Visible = false;

                return;
            }

            var additionalSettings = page.AdditionalSettings.FromJsonOrNull <Rock.Mobile.AdditionalPageSettings>() ?? new Rock.Mobile.AdditionalPageSettings();

            //
            // Set the basic fields of the page.
            //
            tbName.Text                   = page.PageTitle;
            tbInternalName.Text           = page.InternalName;
            tbDescription.Text            = page.Description;
            cbDisplayInNavigation.Checked = page.DisplayInNavWhen == DisplayInNavWhen.WhenAllowed;
            ceEventHandler.Text           = additionalSettings.LavaEventHandler;
            imgPageIcon.BinaryFileId      = page.IconBinaryFileId;

            //
            // Configure the layout options.
            //
            var siteId = PageParameter("SiteId").AsInteger();

            ddlLayout.Items.Add(new ListItem());
            foreach (var layout in LayoutCache.All().Where(l => l.SiteId == siteId))
            {
                ddlLayout.Items.Add(new ListItem(layout.Name, layout.Id.ToString()));
            }

            ddlLayout.SetValue(page.LayoutId);

            pnlEditPage.Visible = true;
            pnlDetails.Visible  = false;
            pnlBlocks.Visible   = false;
        }