/// <summary> /// Copies the page. /// </summary> /// <param name="pageId">The page identifier.</param> /// <param name="currentPersonAliasId">The current person alias identifier.</param> public Guid? CopyPage( int pageId, int? currentPersonAliasId = null ) { var rockContext = new RockContext(); var pageService = new PageService( rockContext ); Guid? newPageGuid = null; var page = pageService.Get( pageId ); if ( page != null ) { Dictionary<Guid, Guid> pageGuidDictionary = new Dictionary<Guid, Guid>(); Dictionary<Guid, Guid> blockGuidDictionary = new Dictionary<Guid, Guid>(); var newPage = GeneratePageCopy( page, pageGuidDictionary, blockGuidDictionary, currentPersonAliasId ); pageService.Add( newPage ); rockContext.SaveChanges(); if ( newPage.ParentPageId.HasValue ) { PageCache.Flush( newPage.ParentPageId.Value ); } newPageGuid= newPage.Guid; GenerateBlockAttributeValues( pageGuidDictionary, blockGuidDictionary, rockContext, currentPersonAliasId ); GeneratePageBlockAuths( pageGuidDictionary, blockGuidDictionary, rockContext, currentPersonAliasId ); CloneHtmlContent( blockGuidDictionary, rockContext, currentPersonAliasId ); } return newPageGuid; }
/// <summary> /// Returns the field's current value(s) /// </summary> /// <param name="parentControl">The parent control.</param> /// <param name="value">Information about the value</param> /// <param name="configurationValues">The configuration values.</param> /// <param name="condensed">Flag indicating if the value should be condensed (i.e. for use in a grid column)</param> /// <returns></returns> public override string FormatValue( System.Web.UI.Control parentControl, string value, Dictionary<string, ConfigurationValue> configurationValues, bool condensed ) { string formattedValue = string.Empty; if ( !string.IsNullOrWhiteSpace( value ) ) { var service = new PageService(); var page = service.Get( new Guid( value ) ); if ( page != null ) { formattedValue = page.InternalName; } } return base.FormatValue( parentControl, formattedValue, null, condensed ); }
/// <summary> /// Handles the OnSave event of the masterPage 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 masterPage_OnSave( object sender, EventArgs e ) { Page.Validate( BlockValidationGroup ); if ( Page.IsValid && _pageId.HasValue ) { var rockContext = new RockContext(); var pageService = new PageService( rockContext ); var routeService = new PageRouteService( rockContext ); var contextService = new PageContextService( rockContext ); var page = pageService.Get( _pageId.Value ); // validate/check for removed routes var editorRoutes = tbPageRoute.Text.SplitDelimitedValues().Distinct(); var databasePageRoutes = page.PageRoutes.ToList(); var deletedRouteIds = new List<int>(); var addedRoutes = new List<string>(); if ( editorRoutes.Any() ) { // validate for any duplicate routes var duplicateRoutes = routeService.Queryable() .Where( r => editorRoutes.Contains( r.Route ) && r.PageId != _pageId ) .Select( r => r.Route ) .Distinct() .ToList(); if ( duplicateRoutes.Any() ) { // Duplicate routes nbPageRouteWarning.Title = "Duplicate Route(s)"; nbPageRouteWarning.Text = string.Format( "<p>The page route <strong>{0}</strong>, already exists for another page. Please choose a different route name.</p>", duplicateRoutes.AsDelimited( "</strong> and <strong>" ) ); nbPageRouteWarning.Dismissable = true; nbPageRouteWarning.Visible = true; CurrentTab = "Advanced Settings"; rptProperties.DataSource = _tabs; rptProperties.DataBind(); ShowSelectedPane(); return; } } // validate if removed routes can be deleted foreach ( var pageRoute in databasePageRoutes ) { if ( !editorRoutes.Contains( pageRoute.Route ) ) { // make sure the route can be deleted string errorMessage; if ( !routeService.CanDelete( pageRoute, out errorMessage ) ) { nbPageRouteWarning.Text = string.Format( "The page route <strong>{0}</strong>, cannot be removed. {1}", pageRoute.Route, errorMessage ); nbPageRouteWarning.NotificationBoxType = NotificationBoxType.Warning; nbPageRouteWarning.Dismissable = true; nbPageRouteWarning.Visible = true; CurrentTab = "Advanced Settings"; rptProperties.DataSource = _tabs; rptProperties.DataBind(); ShowSelectedPane(); return; } } } // take care of deleted routes foreach ( var pageRoute in databasePageRoutes ) { if ( !editorRoutes.Contains( pageRoute.Route ) ) { // if they removed the Route, remove it from the database page.PageRoutes.Remove( pageRoute ); routeService.Delete( pageRoute ); deletedRouteIds.Add( pageRoute.Id ); } } // take care of added routes foreach ( string route in editorRoutes ) { // if they added the Route, add it to the database if ( !databasePageRoutes.Any( a => a.Route == route ) ) { var pageRoute = new PageRoute(); pageRoute.Route = route.TrimStart( new char[] { '/' } ); pageRoute.Guid = Guid.NewGuid(); page.PageRoutes.Add( pageRoute ); addedRoutes.Add( route ); } } int parentPageId = ppParentPage.SelectedValueAsInt() ?? 0; if ( page.ParentPageId != parentPageId ) { if ( page.ParentPageId.HasValue ) { PageCache.Flush( page.ParentPageId.Value ); } if ( parentPageId != 0 ) { PageCache.Flush( parentPageId ); } } page.InternalName = tbPageName.Text; page.PageTitle = tbPageTitle.Text; page.BrowserTitle = tbBrowserTitle.Text; if ( parentPageId != 0 ) { page.ParentPageId = parentPageId; } else { page.ParentPageId = null; } page.LayoutId = ddlLayout.SelectedValueAsInt().Value; int? orphanedIconFileId = null; page.IconCssClass = tbIconCssClass.Text; page.PageDisplayTitle = cbPageTitle.Checked; page.PageDisplayBreadCrumb = cbPageBreadCrumb.Checked; page.PageDisplayIcon = cbPageIcon.Checked; page.PageDisplayDescription = cbPageDescription.Checked; page.DisplayInNavWhen = ddlMenuWhen.SelectedValue.ConvertToEnumOrNull<DisplayInNavWhen>() ?? DisplayInNavWhen.WhenAllowed; page.MenuDisplayDescription = cbMenuDescription.Checked; page.MenuDisplayIcon = cbMenuIcon.Checked; page.MenuDisplayChildPages = cbMenuChildPages.Checked; page.BreadCrumbDisplayName = cbBreadCrumbName.Checked; page.BreadCrumbDisplayIcon = cbBreadCrumbIcon.Checked; page.RequiresEncryption = cbRequiresEncryption.Checked; page.EnableViewState = cbEnableViewState.Checked; page.IncludeAdminFooter = cbIncludeAdminFooter.Checked; page.OutputCacheDuration = tbCacheDuration.Text.AsIntegerOrNull() ?? 0; page.Description = tbDescription.Text; page.HeaderContent = ceHeaderContent.Text; // update PageContexts foreach ( var pageContext in page.PageContexts.ToList() ) { contextService.Delete( pageContext ); } page.PageContexts.Clear(); foreach ( var control in phContext.Controls ) { if ( control is RockTextBox ) { var tbContext = control as RockTextBox; if ( !string.IsNullOrWhiteSpace( tbContext.Text ) ) { var pageContext = new PageContext(); pageContext.Entity = tbContext.ID.Substring( 8 ).Replace( '_', '.' ); pageContext.IdParameter = tbContext.Text; page.PageContexts.Add( pageContext ); } } } // save page and it's routes if ( page.IsValid ) { rockContext.SaveChanges(); // remove any routes that were deleted foreach (var deletedRouteId in deletedRouteIds ) { var existingRoute = RouteTable.Routes.OfType<Route>().FirstOrDefault( a => a.RouteId() == deletedRouteId ); if ( existingRoute != null ) { RouteTable.Routes.Remove( existingRoute ); } } // ensure that there aren't any other extra routes for this page in the RouteTable foreach (var routeTableRoute in RouteTable.Routes.OfType<Route>().Where(a => a.PageId() == page.Id)) { if ( !editorRoutes.Any( a => a == routeTableRoute.Url ) ) { RouteTable.Routes.Remove( routeTableRoute ); } } // Add any routes that were added foreach ( var pageRoute in new PageRouteService( rockContext ).GetByPageId( page.Id ) ) { if ( addedRoutes.Contains( pageRoute.Route ) ) { RouteTable.Routes.AddPageRoute( pageRoute ); } } if ( orphanedIconFileId.HasValue ) { BinaryFileService binaryFileService = new BinaryFileService( rockContext ); var binaryFile = binaryFileService.Get( orphanedIconFileId.Value ); if ( binaryFile != null ) { // marked the old images as IsTemporary so they will get cleaned up later binaryFile.IsTemporary = true; rockContext.SaveChanges(); } } Rock.Web.Cache.PageCache.Flush( page.Id ); string script = "if (typeof window.parent.Rock.controls.modal.close === 'function') window.parent.Rock.controls.modal.close('PAGE_UPDATED');"; ScriptManager.RegisterStartupScript( this.Page, this.GetType(), "close-modal", script, true ); } } }
/// <summary> /// Handles the Click event of the lbExport 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 lbExport_Click( object sender, EventArgs e ) { if ( _pageId.HasValue ) { var pageService = new PageService( new RockContext() ); var page = pageService.Get( _pageId.Value ); var packageService = new PackageService(); var pageName = page.InternalName.Replace( " ", "_" ) + ( cbExportChildren.Checked ? "_wChildPages" : string.Empty ); using ( var stream = packageService.ExportPage( page, cbExportChildren.Checked ) ) { EnableViewState = false; Response.Clear(); Response.ContentType = "application/octet-stream"; Response.AddHeader( "content-disposition", "attachment; filename=" + pageName + ".nupkg" ); Response.Charset = string.Empty; Response.BinaryWrite( stream.ToArray() ); Response.Flush(); Response.End(); } } }
/// <summary> /// Handles the Delete event of the gPages control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gPages_Delete( object sender, RowEventArgs e ) { var rockContext = new RockContext(); PageService pageService = new PageService( rockContext ); var pageViewService = new PageViewService(rockContext); var siteService = new SiteService(rockContext); Rock.Model.Page page = pageService.Get( new Guid( e.RowKeyValue.ToString() ) ); if ( page != null ) { string errorMessage; if ( !pageService.CanDelete( page, out errorMessage, includeSecondLvl: true ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Alert ); return; } foreach (var site in siteService.Queryable()) { if (site.DefaultPageId == page.Id) { site.DefaultPageId = null; site.DefaultPageRouteId = null; } if (site.LoginPageId == page.Id) { site.LoginPageId = null; site.LoginPageRouteId = null; } if (site.RegistrationPageId == page.Id) { site.RegistrationPageId = null; site.RegistrationPageRouteId = null; } } foreach (var pageView in pageViewService.GetByPageId(page.Id)) { pageView.Page = null; pageView.PageId = null; } pageService.Delete( page ); rockContext.SaveChanges(); PageCache.Flush( page.Id ); } BindPagesGrid(); }
protected void lbSave_Click( object sender, EventArgs e ) { if ( updatePage ) { var pageCache = PageCache.Read( RockPage.PageId ); if ( pageCache != null && ( pageCache.PageTitle != tbName.Text || pageCache.Description != tbDesc.Text ) ) { var rockContext = new RockContext(); var service = new PageService( rockContext ); var page = service.Get( pageCache.Id ); page.InternalName = tbName.Text; page.PageTitle = tbName.Text; page.BrowserTitle = tbName.Text; page.Description = tbDesc.Text; rockContext.SaveChanges(); Rock.Web.Cache.PageCache.Flush( page.Id ); pageCache = PageCache.Read( RockPage.PageId ); var breadCrumb = RockPage.BreadCrumbs.Where( c => c.Url == RockPage.PageReference.BuildUrl() ).FirstOrDefault(); if ( breadCrumb != null ) { breadCrumb.Name = pageCache.BreadCrumbText; } } } SetAttributeValue( "Query", ceQuery.Text ); SetAttributeValue( "QueryParams", tbParams.Text ); SetAttributeValue( "UrlMask", tbUrlMask.Text ); SetAttributeValue( "Columns", tbColumns.Text ); SetAttributeValue( "ShowColumns", ddlHideShow.SelectedValue ); SetAttributeValue( "FormattedOutput", ceFormattedOutput.Text ); SetAttributeValue( "PersonReport", cbPersonReport.Checked.ToString() ); SetAttributeValue( "MergeFields", tbMergeFields.Text ); SaveAttributeValues(); ShowView(); }
protected void rGrid_Delete( object sender, RowEventArgs e ) { var rockContext = new RockContext(); var pageService = new PageService( rockContext ); var pageViewService = new PageViewService( rockContext ); var siteService = new SiteService( rockContext ); var page = pageService.Get( (int)rGrid.DataKeys[e.RowIndex]["id"] ); if ( page != null ) { string errorMessage = string.Empty; if ( !pageService.CanDelete( page, out errorMessage ) ) { //errorMessage = "The page is the parent page of another page."; mdDeleteWarning.Show( errorMessage, ModalAlertType.Alert ); return; } foreach ( var site in siteService.Queryable() ) { if ( site.DefaultPageId == page.Id ) { site.DefaultPageId = null; site.DefaultPageRouteId = null; } if ( site.LoginPageId == page.Id ) { site.LoginPageId = null; site.LoginPageRouteId = null; } if ( site.RegistrationPageId == page.Id ) { site.RegistrationPageId = null; site.RegistrationPageRouteId = null; } } // TODO: Could be thousands of page views. Can we set this up as cascade? foreach( var pageView in pageViewService.GetByPageId(page.Id)) { pageViewService.Delete( pageView ); } pageService.Delete( page ); rockContext.SaveChanges(); Rock.Web.Cache.PageCache.Flush( page.Id ); if ( _page != null ) { _page.FlushChildPages(); } } BindGrid(); }
/// <summary> /// Binds the exception list filter. /// </summary> private void BindExceptionListFilter() { BindSitesFilter(); int siteId; var rockContext = new RockContext(); if ( int.TryParse( fExceptionList.GetUserPreference( "Site" ), out siteId ) && ddlSite.Items.FindByValue( siteId.ToString() ) != null ) { ddlSite.SelectedValue = siteId.ToString(); } int pageId; if ( int.TryParse( fExceptionList.GetUserPreference( "Page" ), out pageId ) ) { PageService pageService = new PageService( rockContext ); ppPage.SetValue( pageService.Get( pageId ) ); } else { ppPage.SetValue( None.Id ); } int userPersonId; if ( int.TryParse( fExceptionList.GetUserPreference( "User" ), out userPersonId ) ) { PersonService personService = new PersonService( rockContext ); ppUser.SetValue( personService.Get( userPersonId ) ); } if ( !String.IsNullOrEmpty( fExceptionList.GetUserPreference( "Status Code" ) ) ) { txtStatusCode.Text = fExceptionList.GetUserPreference( "Status Code" ); } DateTime startDate; if ( DateTime.TryParse( fExceptionList.GetUserPreference( "Start Date" ), out startDate ) ) { dpStartDate.Text = startDate.ToShortDateString(); } DateTime endDate; if ( DateTime.TryParse( fExceptionList.GetUserPreference( "End Date" ), out endDate ) ) { dpEndDate.Text = endDate.ToShortDateString(); } }
/// <summary> /// Handles the Delete event of the rGrid control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param> protected void rGrid_Delete( object sender, RowEventArgs e ) { var rockContext = new RockContext(); var pageService = new PageService( rockContext ); var pageViewService = new PageViewService( rockContext ); var siteService = new SiteService( rockContext ); var page = pageService.Get( e.RowKeyId ); if ( page != null ) { string errorMessage = string.Empty; if ( !pageService.CanDelete( page, out errorMessage ) ) { mdDeleteWarning.Show( errorMessage, ModalAlertType.Alert ); return; } foreach ( var site in siteService.Queryable() ) { if ( site.DefaultPageId == page.Id ) { site.DefaultPageId = null; site.DefaultPageRouteId = null; } if ( site.LoginPageId == page.Id ) { site.LoginPageId = null; site.LoginPageRouteId = null; } if ( site.RegistrationPageId == page.Id ) { site.RegistrationPageId = null; site.RegistrationPageRouteId = null; } } foreach ( var pageView in pageViewService.GetByPageId( page.Id ) ) { pageView.Page = null; pageView.PageId = null; } pageService.Delete( page ); rockContext.SaveChanges(); Rock.Web.Cache.PageCache.Flush( page.Id ); if ( _page != null ) { _page.FlushChildPages(); } } BindGrid(); }
/// <summary> /// Returns a list of matching people /// </summary> /// <param name="searchterm"></param> /// <returns></returns> public override IQueryable<string> Search( string searchterm ) { var rootPageGuid = GetAttributeValue( "RootPage" ).AsGuid(); var terms = searchterm.Split( ' ' ); var pageServ = new PageService( new RockContext() ); IEnumerable<Page> pages; var rootPage = pageServ.Get( rootPageGuid ); if ( rootPage != null ) { pages = pageServ.GetAllDescendents( rootPage.Id ); } else { pages = pageServ.Queryable(); } return pages.ToList().Where( p => Regex.IsMatch( p.PageTitle, String.Join( "\\w* ", terms.Select( t => Regex.Escape( t ) ) ), RegexOptions.IgnoreCase ) ).Select( p => p.PageTitle ).AsQueryable(); }
/// <summary> /// Handles the Delete event of the gPages control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gPages_Delete( object sender, RowEventArgs e ) { bool canDelete = false; var rockContext = new RockContext(); PageService pageService = new PageService( rockContext ); Rock.Model.Page page = pageService.Get( new Guid( e.RowKeyValue.ToString() ) ); if ( page != null ) { string errorMessage; canDelete = pageService.CanDelete( page, out errorMessage, includeSecondLvl: true ); if ( !canDelete ) { mdGridWarning.Show( errorMessage, ModalAlertType.Alert ); return; } pageService.Delete( page ); rockContext.SaveChanges(); PageCache.Flush( page.Id ); } BindPagesGrid(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var rockContext = new RockContext(); var htmlContentService = new HtmlContentService( rockContext ); var htmlContent = htmlContentService.Queryable(); string pageName = ""; string siteName = ""; var htmlList = new List<HtmlApproval>(); foreach ( var content in htmlContent ) { content.Block.LoadAttributes(); var blah = content.Block.GetAttributeValue( "RequireApproval" ); if ( !string.IsNullOrEmpty( blah ) && blah.ToLower() == "true" ) { var pageService = new PageService( rockContext ); if ( content.Block.PageId != null ) { var page = pageService.Get( (int)content.Block.PageId ); if ( page != null ) { pageName = page.InternalName; while ( page.ParentPageId != null ) { page = pageService.Get( (int)page.ParentPageId ); } var siteService = new SiteService( rockContext ); siteName = siteService.GetByDefaultPageId( page.Id ).Select( s => s.Name ).FirstOrDefault(); } } var htmlApprovalClass = new HtmlApproval(); htmlApprovalClass.SiteName = siteName; htmlApprovalClass.PageName = pageName; htmlApprovalClass.Block = content.Block; htmlApprovalClass.BlockId = content.BlockId; htmlApprovalClass.Content = content.Content; htmlApprovalClass.Id = content.Id; htmlApprovalClass.IsApproved = content.IsApproved; htmlApprovalClass.ApprovedByPerson = content.ApprovedByPerson; htmlApprovalClass.ApprovedByPersonId = content.ApprovedByPersonId; htmlApprovalClass.ApprovedDateTime = content.ApprovedDateTime; htmlList.Add( htmlApprovalClass ); } } // Filter by Site if ( ddlSiteFilter.SelectedIndex > 0 ) { if ( ddlSiteFilter.SelectedValue.ToLower() != "all" ) { htmlList = htmlList.Where( h => h.SiteName == ddlSiteFilter.SelectedValue ).ToList(); } } // Filter by approved/unapproved if ( ddlApprovedFilter.SelectedIndex > -1 ) { if ( ddlApprovedFilter.SelectedValue.ToLower() == "unapproved" ) { htmlList = htmlList.Where( a => a.IsApproved == false ).ToList(); } else if ( ddlApprovedFilter.SelectedValue.ToLower() == "approved" ) { htmlList = htmlList.Where( a => a.IsApproved == true ).ToList(); } } // Filter by the person that approved the content if ( _canApprove ) { int personId = 0; if ( int.TryParse( gContentListFilter.GetUserPreference( "Approved By" ), out personId ) && personId != 0 ) { htmlList = htmlList.Where( a => a.ApprovedByPersonId.HasValue && a.ApprovedByPersonId.Value == personId ).ToList(); } } SortProperty sortProperty = gContentList.SortProperty; if ( sortProperty != null ) { gContentList.DataSource = htmlList.AsQueryable().Sort( sortProperty ).ToList(); } else { gContentList.DataSource = htmlList.OrderBy( h => h.Id ).ToList(); } gContentList.DataBind(); }
/// <summary> /// Build filter values/summary with user friendly data from filters /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> protected void fExceptionList_DisplayFilterValue( object sender, GridFilter.DisplayFilterValueArgs e ) { switch ( e.Key ) { case "Site": int siteId; if ( int.TryParse( e.Value, out siteId ) ) { SiteService siteService = new SiteService(); var site = siteService.Get( siteId ); if ( site != null ) { e.Value = site.Name; } } break; case "Page": int pageId; if ( int.TryParse( e.Value, out pageId ) ) { PageService pageService = new PageService(); var page = pageService.Get( pageId ); if ( page != null ) { e.Value = page.InternalName; } } break; case "User": int userPersonId; if ( int.TryParse( e.Value, out userPersonId ) ) { PersonService personService = new PersonService(); var user = personService.Get( userPersonId ); if ( user != null ) { e.Value = user.FullName; } } break; } }
protected void rGrid_Delete( object sender, RowEventArgs e ) { using ( new UnitOfWorkScope() ) { var pageService = new PageService(); var siteService = new SiteService(); var page = pageService.Get( (int)rGrid.DataKeys[e.RowIndex]["id"] ); if ( page != null ) { RockTransactionScope.WrapTransaction( () => { foreach ( var site in siteService.Queryable() ) { bool updateSite = false; if (site.DefaultPageId == page.Id) { site.DefaultPageId = null; site.DefaultPageRouteId = null; updateSite = true; } if (site.LoginPageId == page.Id) { site.LoginPageId = null; site.LoginPageRouteId = null; updateSite = true; } if (site.RegistrationPageId == page.Id) { site.RegistrationPageId = null; site.RegistrationPageRouteId = null; updateSite = true; } if (updateSite) { siteService.Save( site, CurrentPersonId ); } } pageService.Delete( page, CurrentPersonId ); pageService.Save( page, CurrentPersonId ); Rock.Web.Cache.PageCache.Flush( page.Id ); if ( _page != null ) _page.FlushChildPages(); } ); } } BindGrid(); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad( EventArgs e ) { if ( !Page.IsPostBack && _pageId.HasValue ) { var rockContext = new RockContext(); LoadSites( rockContext ); PageService pageService = new PageService( rockContext ); Rock.Model.Page page = pageService.Queryable( "Layout,PageRoutes" ) .Where( p => p.Id == _pageId.Value ) .FirstOrDefault(); if ( page.Layout != null ) { ddlSite.SelectedValue = page.Layout.SiteId.ToString(); LoadLayouts( rockContext, SiteCache.Read( page.Layout.SiteId ) ); ddlLayout.SelectedValue = page.Layout.Id.ToString(); } rptProperties.DataSource = _tabs; rptProperties.DataBind(); tbPageName.Text = page.InternalName; tbPageTitle.Text = page.PageTitle; tbBrowserTitle.Text = page.BrowserTitle; ppParentPage.SetValue( pageService.Get( page.ParentPageId ?? 0 ) ); tbIconCssClass.Text = page.IconCssClass; cbPageTitle.Checked = page.PageDisplayTitle; cbPageBreadCrumb.Checked = page.PageDisplayBreadCrumb; cbPageIcon.Checked = page.PageDisplayIcon; cbPageDescription.Checked = page.PageDisplayDescription; ddlMenuWhen.SelectedValue = ( (int)page.DisplayInNavWhen ).ToString(); cbMenuDescription.Checked = page.MenuDisplayDescription; cbMenuIcon.Checked = page.MenuDisplayIcon; cbMenuChildPages.Checked = page.MenuDisplayChildPages; cbBreadCrumbIcon.Checked = page.BreadCrumbDisplayIcon; cbBreadCrumbName.Checked = page.BreadCrumbDisplayName; cbRequiresEncryption.Checked = page.RequiresEncryption; cbEnableViewState.Checked = page.EnableViewState; cbIncludeAdminFooter.Checked = page.IncludeAdminFooter; tbCacheDuration.Text = page.OutputCacheDuration.ToString(); tbDescription.Text = page.Description; ceHeaderContent.Text = page.HeaderContent; tbPageRoute.Text = string.Join( ",", page.PageRoutes.Select( route => route.Route ).ToArray() ); // Add enctype attribute to page's <form> tag to allow file upload control to function Page.Form.Attributes.Add( "enctype", "multipart/form-data" ); } base.OnLoad( e ); }
/// <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 ( _updatePage ) { var pageCache = PageCache.Read( RockPage.PageId ); if ( pageCache != null && ( pageCache.PageTitle != tbName.Text || pageCache.Description != tbDesc.Text ) ) { var rockContext = new RockContext(); var service = new PageService( rockContext ); var page = service.Get( pageCache.Id ); page.InternalName = tbName.Text; page.PageTitle = tbName.Text; page.BrowserTitle = tbName.Text; page.Description = tbDesc.Text; rockContext.SaveChanges(); Rock.Web.Cache.PageCache.Flush( page.Id ); pageCache = PageCache.Read( RockPage.PageId ); var breadCrumb = RockPage.BreadCrumbs.Where( c => c.Url == RockPage.PageReference.BuildUrl() ).FirstOrDefault(); if ( breadCrumb != null ) { breadCrumb.Name = pageCache.BreadCrumbText; } } } SetAttributeValue( "Query", ceQuery.Text ); SetAttributeValue( "Timeout", nbTimeout.Text ); SetAttributeValue( "StoredProcedure", cbStoredProcedure.Checked.ToString() ); SetAttributeValue( "QueryParams", tbParams.Text ); SetAttributeValue( "UrlMask", tbUrlMask.Text ); SetAttributeValue( "Columns", tbColumns.Text ); SetAttributeValue( "ShowColumns", ddlHideShow.SelectedValue ); SetAttributeValue( "FormattedOutput", ceFormattedOutput.Text ); SetAttributeValue( "PageTitleLava", cePageTitleLava.Text ); SetAttributeValue( "PersonReport", cbPersonReport.Checked.ToString() ); SetAttributeValue( "ShowCommunicate", ( cbPersonReport.Checked && cbShowCommunicate.Checked ).ToString() ); SetAttributeValue( "ShowMergePerson", ( cbPersonReport.Checked && cbShowMergePerson.Checked ).ToString() ); SetAttributeValue( "ShowBulkUpdate", ( cbPersonReport.Checked && cbShowBulkUpdate.Checked ).ToString() ); SetAttributeValue( "ShowExcelExport", cbShowExcelExport.Checked.ToString() ); SetAttributeValue( "ShowMergeTemplate", cbShowMergeTemplate.Checked.ToString() ); SetAttributeValue( "ShowGridFilter", cbShowGridFilter.Checked.ToString() ); SetAttributeValue( "MergeFields", tbMergeFields.Text ); SaveAttributeValues(); mdEdit.Hide(); pnlEditModel.Visible = false; upnlContent.Update(); BuildControls( true ); }
/// <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; } }
/// <summary> /// Handles the OnSave event of the masterPage 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 masterPage_OnSave( object sender, EventArgs e ) { Page.Validate( BlockValidationGroup ); if ( Page.IsValid && _pageId.HasValue ) { var rockContext = new RockContext(); var pageService = new PageService( rockContext ); var routeService = new PageRouteService( rockContext ); var contextService = new PageContextService( rockContext ); var page = pageService.Get( _pageId.Value ); int parentPageId = ppParentPage.SelectedValueAsInt() ?? 0; if ( page.ParentPageId != parentPageId ) { if ( page.ParentPageId.HasValue ) { PageCache.Flush( page.ParentPageId.Value ); } if ( parentPageId != 0 ) { PageCache.Flush( parentPageId ); } } page.InternalName = tbPageName.Text; page.PageTitle = tbPageTitle.Text; page.BrowserTitle = tbBrowserTitle.Text; if ( parentPageId != 0 ) { page.ParentPageId = parentPageId; } else { page.ParentPageId = null; } page.LayoutId = ddlLayout.SelectedValueAsInt().Value; int? orphanedIconFileId = null; page.IconCssClass = tbIconCssClass.Text; page.PageDisplayTitle = cbPageTitle.Checked; page.PageDisplayBreadCrumb = cbPageBreadCrumb.Checked; page.PageDisplayIcon = cbPageIcon.Checked; page.PageDisplayDescription = cbPageDescription.Checked; page.DisplayInNavWhen = (DisplayInNavWhen)Enum.Parse( typeof( DisplayInNavWhen ), ddlMenuWhen.SelectedValue ); page.MenuDisplayDescription = cbMenuDescription.Checked; page.MenuDisplayIcon = cbMenuIcon.Checked; page.MenuDisplayChildPages = cbMenuChildPages.Checked; page.BreadCrumbDisplayName = cbBreadCrumbName.Checked; page.BreadCrumbDisplayIcon = cbBreadCrumbIcon.Checked; page.RequiresEncryption = cbRequiresEncryption.Checked; page.EnableViewState = cbEnableViewState.Checked; page.IncludeAdminFooter = cbIncludeAdminFooter.Checked; page.OutputCacheDuration = int.Parse( tbCacheDuration.Text ); page.Description = tbDescription.Text; page.HeaderContent = ceHeaderContent.Text; // new or updated route foreach ( var pageRoute in page.PageRoutes.ToList() ) { var existingRoute = RouteTable.Routes.OfType<Route>().FirstOrDefault( a => a.RouteId() == pageRoute.Id ); if ( existingRoute != null ) { RouteTable.Routes.Remove( existingRoute ); } routeService.Delete( pageRoute ); } page.PageRoutes.Clear(); foreach ( string route in tbPageRoute.Text.SplitDelimitedValues() ) { var pageRoute = new PageRoute(); pageRoute.Route = route.TrimStart( new char[] { '/' } ); pageRoute.Guid = Guid.NewGuid(); page.PageRoutes.Add( pageRoute ); } foreach ( var pageContext in page.PageContexts.ToList() ) { contextService.Delete( pageContext ); } page.PageContexts.Clear(); foreach ( var control in phContext.Controls ) { if ( control is RockTextBox ) { var tbContext = control as RockTextBox; if ( !string.IsNullOrWhiteSpace( tbContext.Text ) ) { var pageContext = new PageContext(); pageContext.Entity = tbContext.ID.Substring( 8 ).Replace( '_', '.' ); pageContext.IdParameter = tbContext.Text; page.PageContexts.Add( pageContext ); } } } if ( page.IsValid ) { rockContext.SaveChanges(); foreach ( var pageRoute in new PageRouteService( rockContext ).GetByPageId( page.Id ) ) { RouteTable.Routes.AddPageRoute( pageRoute ); } if ( orphanedIconFileId.HasValue ) { BinaryFileService binaryFileService = new BinaryFileService( rockContext ); var binaryFile = binaryFileService.Get( orphanedIconFileId.Value ); if ( binaryFile != null ) { // marked the old images as IsTemporary so they will get cleaned up later binaryFile.IsTemporary = true; rockContext.SaveChanges(); } } Rock.Web.Cache.PageCache.Flush( page.Id ); string script = "if (typeof window.parent.Rock.controls.modal.close === 'function') window.parent.Rock.controls.modal.close('PAGE_UPDATED');"; ScriptManager.RegisterStartupScript( this.Page, this.GetType(), "close-modal", script, true ); } } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad( EventArgs e ) { if ( _page == null ) { int pageId = Convert.ToInt32( PageParameter( "Page" ) ); _page = Rock.Web.Cache.PageCache.Read( pageId ); } if ( !Page.IsPostBack && _page.IsAuthorized( "Administrate", CurrentPerson ) ) { PageService pageService = new PageService(); Rock.Model.Page page = pageService.Get( _page.Id ); LoadSites(); if ( _page.Layout != null ) { ddlSite.SelectedValue = _page.Layout.SiteId.ToString(); LoadLayouts( _page.Layout.Site ); ddlLayout.SelectedValue = _page.Layout.Id.ToString(); } rptProperties.DataSource = _tabs; rptProperties.DataBind(); tbPageName.Text = _page.InternalName; tbPageTitle.Text = _page.PageTitle; tbBrowserTitle.Text = _page.BrowserTitle; ppParentPage.SetValue( pageService.Get( page.ParentPageId ?? 0 ) ); tbIconCssClass.Text = _page.IconCssClass; cbPageTitle.Checked = _page.PageDisplayTitle; cbPageBreadCrumb.Checked = _page.PageDisplayBreadCrumb; cbPageIcon.Checked = _page.PageDisplayIcon; cbPageDescription.Checked = _page.PageDisplayDescription; ddlMenuWhen.SelectedValue = ( (int)_page.DisplayInNavWhen ).ToString(); cbMenuDescription.Checked = _page.MenuDisplayDescription; cbMenuIcon.Checked = _page.MenuDisplayIcon; cbMenuChildPages.Checked = _page.MenuDisplayChildPages; cbBreadCrumbIcon.Checked = _page.BreadCrumbDisplayIcon; cbBreadCrumbName.Checked = _page.BreadCrumbDisplayName; cbRequiresEncryption.Checked = _page.RequiresEncryption; cbEnableViewState.Checked = _page.EnableViewState; cbIncludeAdminFooter.Checked = _page.IncludeAdminFooter; tbCacheDuration.Text = _page.OutputCacheDuration.ToString(); tbDescription.Text = _page.Description; ceHeaderContent.Text = _page.HeaderContent; tbPageRoute.Text = string.Join( ",", page.PageRoutes.Select( route => route.Route ).ToArray() ); // Add enctype attribute to page's <form> tag to allow file upload control to function Page.Form.Attributes.Add( "enctype", "multipart/form-data" ); } base.OnLoad( e ); }