/// <summary> /// Binds the group members grid. /// </summary> protected void BindLayoutBlocksGrid() { pnlBlocks.Visible = false; int layoutId = PageParameter( "layoutId" ).AsInteger(); if ( layoutId == 0 ) { pnlContent.Visible = false; return; } var rockContext = new RockContext(); var layout = LayoutCache.Read( layoutId, rockContext ); if (layout == null) { pnlContent.Visible = false; return; } hfLayoutId.SetValue( layoutId ); pnlBlocks.Visible = true; BlockService blockService = new BlockService( new RockContext() ); gLayoutBlocks.DataSource = blockService.GetByLayout( layoutId ).ToList(); gLayoutBlocks.DataBind(); }
/// <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) { int blockId = Convert.ToInt32(PageParameter("BlockId")); if (Page.IsValid) { var rockContext = new RockContext(); var blockService = new Rock.Model.BlockService(rockContext); var block = blockService.Get(blockId); block.LoadAttributes(); block.Name = tbBlockName.Text; block.CssClass = tbCssClass.Text; block.PreHtml = cePreHtml.Text; block.PostHtml = cePostHtml.Text; block.OutputCacheDuration = 0; //Int32.Parse( tbCacheDuration.Text ); rockContext.SaveChanges(); Rock.Attribute.Helper.GetEditValues(phAttributes, block); if (phAdvancedAttributes.Controls.Count > 0) { Rock.Attribute.Helper.GetEditValues(phAdvancedAttributes, block); } block.SaveAttributeValues(rockContext); Rock.Web.Cache.BlockCache.Flush(block.Id); string script = string.Format("window.parent.Rock.controls.modal.close('BLOCK_UPDATED:{0}');", blockId); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "close-modal", script, true); } }
/// <summary> /// Binds the group members grid. /// </summary> protected void BindLayoutBlocksGrid() { pnlBlocks.Visible = false; int layoutId = PageParameter( "layoutId" ).AsInteger() ?? 0; if ( layoutId == 0 ) { return; } hfLayoutId.SetValue( layoutId ); pnlBlocks.Visible = true; BlockService blockService = new BlockService( new RockContext() ); gLayoutBlocks.DataSource = blockService.GetByLayout( layoutId ).ToList(); gLayoutBlocks.DataBind(); }
public void Move( int id, Block block ) { var user = CurrentUser(); if ( user != null ) { var service = new BlockService(); block.Id = id; Block model; if ( !service.TryGet( id, out model ) ) throw new HttpResponseException( HttpStatusCode.NotFound ); if ( !model.IsAuthorized( "Edit", user.Person ) ) throw new HttpResponseException( HttpStatusCode.Unauthorized ); if ( model.LayoutId.HasValue && model.LayoutId != block.LayoutId ) Rock.Web.Cache.PageCache.FlushLayoutBlocks( model.LayoutId.Value ); if ( block.LayoutId.HasValue ) Rock.Web.Cache.PageCache.FlushLayoutBlocks( block.LayoutId.Value ); else { var page = Rock.Web.Cache.PageCache.Read( block.PageId.Value ); page.FlushBlocks(); } model.Zone = block.Zone; model.PageId = block.PageId; model.LayoutId = block.LayoutId; if ( model.IsValid ) { model.Order = service.GetMaxOrder( model ); service.Save( model, user.PersonId ); } else throw new HttpResponseException( HttpStatusCode.BadRequest ); } else throw new HttpResponseException( HttpStatusCode.Unauthorized ); }
/// <summary> /// Handles the GridReorder event of the gPageBlocks control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="GridReorderEventArgs"/> instance containing the event data.</param> protected void gPageBlocks_GridReorder( object sender, GridReorderEventArgs e ) { int pageId = PageParameter( "EditPage" ).AsInteger(); Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read( pageId ); string zoneName = this.PageParameter( "ZoneName" ); var rockContext = new RockContext(); BlockService blockService = new BlockService( rockContext ); var blocks = blockService.GetByPageAndZone( page.Id, zoneName ).ToList(); blockService.Reorder( blocks, e.OldIndex, e.NewIndex ); rockContext.SaveChanges(); page.FlushBlocks(); BindGrids(); }
/// <summary> /// Binds the page grid. /// </summary> private void BindPageGrid() { BlockService blockService = new BlockService( new RockContext() ); int pageId = PageParameter( "EditPage" ).AsInteger(); Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read( pageId ); string zoneName = this.PageParameter( "ZoneName" ); gPageBlocks.DataSource = blockService.GetByPageAndZone( page.Id, zoneName ).ToList(); gPageBlocks.DataBind(); }
/// <summary> /// Handles the GridReorder event of the gPageBlocks control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="GridReorderEventArgs"/> instance containing the event data.</param> protected void gPageBlocks_GridReorder( object sender, GridReorderEventArgs e ) { BlockService blockService = new BlockService(); int pageId = PageParameter( "EditPage" ).AsInteger() ?? 0; Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read( pageId ); string zoneName = this.PageParameter( "ZoneName" ); blockService.Reorder( blockService.GetByPageAndZone( page.Id, zoneName ).ToList(), e.OldIndex, e.NewIndex, CurrentPersonId ); BindGrids(); }
/// <summary> /// Handles the Delete event of the gPageBlocks 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 gPageBlocks_Delete( object sender, RowEventArgs e ) { int pageId = PageParameter( "EditPage" ).AsInteger(); Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read( pageId ); string zoneName = this.PageParameter( "ZoneName" ); var rockContext = new RockContext(); BlockService blockService = new BlockService( rockContext ); Rock.Model.Block block = blockService.Get( e.RowKeyId ); if ( block != null ) { blockService.Delete( block ); rockContext.SaveChanges(); page.FlushBlocks(); } BindGrids(); }
/// <summary> /// Copies any auths for the original pages and blocks over to the copied pages and blocks. /// </summary> /// <param name="pageGuidDictionary">The dictionary containing the original page guids and the corresponding copied page guids.</param> /// <param name="blockGuidDictionary">The dictionary containing the original block guids and the corresponding copied block guids.</param> /// <param name="rockContext">The rock context.</param> /// <param name="currentPersonAliasId">The current person alias identifier.</param> private void GeneratePageBlockAuths( Dictionary<Guid, Guid> pageGuidDictionary, Dictionary<Guid, Guid> blockGuidDictionary, RockContext rockContext, int? currentPersonAliasId = null ) { var authService = new AuthService( rockContext ); var pageService = new PageService( rockContext ); var blockService = new BlockService( rockContext ); var pageGuid = Rock.SystemGuid.EntityType.PAGE.AsGuid(); var blockGuid = Rock.SystemGuid.EntityType.BLOCK.AsGuid(); Dictionary<Guid, int> pageIntDictionary = pageService.Queryable() .Where( p => pageGuidDictionary.Keys.Contains( p.Guid ) || pageGuidDictionary.Values.Contains( p.Guid ) ) .ToDictionary( p => p.Guid, p => p.Id ); Dictionary<Guid, int> blockIntDictionary = blockService.Queryable() .Where( p => blockGuidDictionary.Keys.Contains( p.Guid ) || blockGuidDictionary.Values.Contains( p.Guid ) ) .ToDictionary( p => p.Guid, p => p.Id ); var pageAuths = authService.Queryable().Where( a => a.EntityType.Guid == pageGuid && pageIntDictionary.Values.Contains( a.EntityId.Value ) ) .ToList(); var blockAuths = authService.Queryable().Where( a => a.EntityType.Guid == blockGuid && blockIntDictionary.Values.Contains( a.EntityId.Value ) ) .ToList(); foreach ( var pageAuth in pageAuths ) { var newPageAuth = pageAuth.Clone( false ); newPageAuth.CreatedByPersonAlias = null; newPageAuth.CreatedByPersonAliasId = currentPersonAliasId; newPageAuth.CreatedDateTime = RockDateTime.Now; newPageAuth.ModifiedByPersonAlias = null; newPageAuth.ModifiedByPersonAliasId = currentPersonAliasId; newPageAuth.ModifiedDateTime = RockDateTime.Now; newPageAuth.Id = 0; newPageAuth.Guid = Guid.NewGuid(); newPageAuth.EntityId = pageIntDictionary[pageGuidDictionary[pageIntDictionary.Where( d => d.Value == pageAuth.EntityId.Value ).FirstOrDefault().Key]]; authService.Add( newPageAuth ); } foreach ( var blockAuth in blockAuths ) { var newBlockAuth = blockAuth.Clone( false ); newBlockAuth.CreatedByPersonAlias = null; newBlockAuth.CreatedByPersonAliasId = currentPersonAliasId; newBlockAuth.CreatedDateTime = RockDateTime.Now; newBlockAuth.ModifiedByPersonAlias = null; newBlockAuth.ModifiedByPersonAliasId = currentPersonAliasId; newBlockAuth.ModifiedDateTime = RockDateTime.Now; newBlockAuth.Id = 0; newBlockAuth.Guid = Guid.NewGuid(); newBlockAuth.EntityId = blockIntDictionary[blockGuidDictionary[blockIntDictionary.Where( d => d.Value == blockAuth.EntityId.Value ).FirstOrDefault().Key]]; authService.Add( newBlockAuth ); } rockContext.SaveChanges(); }
/// <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 ) { int blockId = Convert.ToInt32( PageParameter( "BlockId" ) ); if ( Page.IsValid ) { var rockContext = new RockContext(); var blockService = new Rock.Model.BlockService( rockContext ); var block = blockService.Get( blockId ); block.LoadAttributes(); block.Name = tbBlockName.Text; block.CssClass = tbCssClass.Text; block.PreHtml = cePreHtml.Text; block.PostHtml = cePostHtml.Text; block.OutputCacheDuration = Int32.Parse( tbCacheDuration.Text ); rockContext.SaveChanges(); Rock.Attribute.Helper.GetEditValues( phAttributes, block ); if ( phAdvancedAttributes.Controls.Count > 0 ) { Rock.Attribute.Helper.GetEditValues( phAdvancedAttributes, block ); } block.SaveAttributeValues( rockContext ); Rock.Web.Cache.BlockCache.Flush( block.Id ); string script = string.Format( "window.parent.Rock.controls.modal.close('BLOCK_UPDATED:{0}');", blockId ); ScriptManager.RegisterStartupScript( this.Page, this.GetType(), "close-modal", script, true ); } }
/// <summary> /// Handles the Delete event of the gPageBlocks 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 gPageBlocks_Delete( object sender, RowEventArgs e ) { BlockService blockService = new BlockService(); int pageId = PageParameter( "EditPage" ).AsInteger() ?? 0; Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read( pageId ); string zoneName = this.PageParameter( "ZoneName" ); Rock.Model.Block block = blockService.Get( e.RowKeyId ); if ( block != null ) { blockService.Delete( block, CurrentPersonId ); blockService.Save( block, CurrentPersonId ); page.FlushBlocks(); } BindGrids(); }
/// <summary> /// Copies any HtmlContent in the original page tree over to the corresponding blocks on the copied page tree. /// </summary> /// <param name="blockGuidDictionary">The dictionary containing the original block guids and the corresponding copied block guids.</param> /// <param name="rockContext">The rock context.</param> /// <param name="currentPersonAliasId">The current person alias identifier.</param> private void CloneHtmlContent( Dictionary<Guid, Guid> blockGuidDictionary, RockContext rockContext, int? currentPersonAliasId = null ) { var htmlContentService = new HtmlContentService( rockContext ); var blockService = new BlockService( rockContext ); Dictionary<Guid, int> blockIntDictionary = blockService.Queryable() .Where( p => blockGuidDictionary.Keys.Contains( p.Guid ) || blockGuidDictionary.Values.Contains( p.Guid ) ) .ToDictionary( p => p.Guid, p => p.Id ); var htmlContents = htmlContentService.Queryable().Where( a => blockIntDictionary.Values.Contains( a.BlockId ) ) .ToList(); foreach ( var htmlContent in htmlContents ) { var newHtmlContent = htmlContent.Clone( false ); newHtmlContent.CreatedByPersonAlias = null; newHtmlContent.CreatedByPersonAliasId = currentPersonAliasId; newHtmlContent.CreatedDateTime = RockDateTime.Now; newHtmlContent.ModifiedByPersonAlias = null; newHtmlContent.ModifiedByPersonAliasId = currentPersonAliasId; newHtmlContent.ModifiedDateTime = RockDateTime.Now; newHtmlContent.Id = 0; newHtmlContent.Guid = Guid.NewGuid(); newHtmlContent.BlockId = blockIntDictionary[blockGuidDictionary[blockIntDictionary.Where( d => d.Value == htmlContent.BlockId ).FirstOrDefault().Key]]; htmlContentService.Add( newHtmlContent ); } rockContext.SaveChanges(); }
public string GetHtmlForBlock( int blockId, int? entityTypeId = null, int? entityId = null ) { RockContext rockContext = this.Service.Context as RockContext ?? new RockContext(); Block block = new BlockService( rockContext ).Get( blockId ); if ( block != null ) { block.LoadAttributes(); string liquidTemplate = block.GetAttributeValue( "LiquidTemplate" ); var metricCategoryPairList = Rock.Attribute.MetricCategoriesFieldAttribute.GetValueAsGuidPairs( block.GetAttributeValue( "MetricCategories" ) ); var metricGuids = metricCategoryPairList.Select( a => a.MetricGuid ).ToList(); bool roundYValues = block.GetAttributeValue( "RoundValues" ).AsBooleanOrNull() ?? true; MetricService metricService = new MetricService( rockContext ); var metrics = metricService.GetByGuids( metricGuids ); List<object> metricsData = new List<object>(); if ( metrics.Count() == 0 ) { return @"<div class='alert alert-warning'> Please select a metric in the block settings. </div>"; } MetricValueService metricValueService = new MetricValueService( rockContext ); DateTime firstDayOfYear = new DateTime( RockDateTime.Now.Year, 1, 1 ); DateTime currentDateTime = RockDateTime.Now; DateTime firstDayOfNextYear = new DateTime( RockDateTime.Now.Year + 1, 1, 1 ); foreach ( var metric in metrics ) { var metricYTDData = JsonConvert.DeserializeObject( metric.ToJson(), typeof( MetricYTDData ) ) as MetricYTDData; var qryMeasureValues = metricValueService.Queryable() .Where( a => a.MetricId == metricYTDData.Id ) .Where( a => a.MetricValueDateTime >= firstDayOfYear && a.MetricValueDateTime < currentDateTime ) .Where( a => a.MetricValueType == MetricValueType.Measure ); //// if an entityTypeId/EntityId filter was specified, and the entityTypeId is the same as the metrics.EntityTypeId, filter the values to the specified entityId //// Note: if a Metric or it's Metric Value doesn't have a context, include it regardless of Context setting if ( entityTypeId.HasValue && ( metric.EntityTypeId == entityTypeId || metric.EntityTypeId == null ) ) { if ( entityId.HasValue ) { qryMeasureValues = qryMeasureValues.Where( a => a.EntityId == entityId || a.EntityId == null ); } } var lastMetricValue = qryMeasureValues.OrderByDescending( a => a.MetricValueDateTime ).FirstOrDefault(); if ( lastMetricValue != null ) { metricYTDData.LastValue = lastMetricValue.YValue.HasValue ? Math.Round( lastMetricValue.YValue.Value, roundYValues ? 0 : 2 ) : (decimal?)null; metricYTDData.LastValueDate = lastMetricValue.MetricValueDateTime.HasValue ? lastMetricValue.MetricValueDateTime.Value.Date : DateTime.MinValue; } decimal? sum = qryMeasureValues.Sum( a => a.YValue ); metricYTDData.CumulativeValue = sum.HasValue ? Math.Round( sum.Value, roundYValues ? 0 : 2 ) : (decimal?)null; // figure out goal as of current date time by figuring out the slope of the goal var qryGoalValuesCurrentYear = metricValueService.Queryable() .Where( a => a.MetricId == metricYTDData.Id ) .Where( a => a.MetricValueDateTime >= firstDayOfYear && a.MetricValueDateTime < firstDayOfNextYear ) .Where( a => a.MetricValueType == MetricValueType.Goal ); // if an entityTypeId/EntityId filter was specified, and the entityTypeId is the same as the metrics.EntityTypeId, filter the values to the specified entityId if ( entityTypeId.HasValue && metric.EntityTypeId == entityTypeId ) { if ( entityId.HasValue ) { qryGoalValuesCurrentYear = qryGoalValuesCurrentYear.Where( a => a.EntityId == entityId ); } } MetricValue goalLineStartPoint = qryGoalValuesCurrentYear.Where( a => a.MetricValueDateTime <= currentDateTime ).OrderByDescending( a => a.MetricValueDateTime ).FirstOrDefault(); MetricValue goalLineEndPoint = qryGoalValuesCurrentYear.Where( a => a.MetricValueDateTime >= currentDateTime ).FirstOrDefault(); if ( goalLineStartPoint != null && goalLineEndPoint != null ) { var changeInX = goalLineEndPoint.DateTimeStamp - goalLineStartPoint.DateTimeStamp; var changeInY = goalLineEndPoint.YValue - goalLineStartPoint.YValue; if ( changeInX != 0 ) { decimal? slope = changeInY / changeInX; decimal goalValue = ( ( slope * ( currentDateTime.ToJavascriptMilliseconds() - goalLineStartPoint.DateTimeStamp ) ) + goalLineStartPoint.YValue ).Value; metricYTDData.GoalValue = Math.Round( goalValue, roundYValues ? 0 : 2 ); } } else { // if there isn't a both a start goal and end goal within the date range, there wouldn't be a goal line shown in a line chart, so don't display a goal in liquid either metricYTDData.GoalValue = null; } metricsData.Add( metricYTDData.ToLiquid() ); } Dictionary<string, object> mergeValues = new Dictionary<string, object>(); mergeValues.Add( "Metrics", metricsData ); string resultHtml = liquidTemplate.ResolveMergeFields( mergeValues ); // show liquid help for debug if ( block.GetAttributeValue( "EnableDebug" ).AsBoolean() ) { resultHtml += mergeValues.lavaDebugInfo(); } return resultHtml; } return string.Format( @"<div class='alert alert-danger'> unable to find block_id: {1} </div>", blockId ); }
/// <summary> /// Binds the layout grid. /// </summary> private void BindLayoutGrid() { BlockService blockService = new BlockService(); int pageId = PageParameter( "EditPage" ).AsInteger() ?? 0; Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read( pageId ); string zoneName = this.PageParameter( "ZoneName" ); gLayoutBlocks.DataSource = blockService.GetByLayoutAndZone( page.LayoutId, zoneName ).ToList(); gLayoutBlocks.DataBind(); }
/// <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) { bool reloadPage = false; int blockId = Convert.ToInt32(PageParameter("BlockId")); if (!Page.IsValid) { return; } var rockContext = new RockContext(); rockContext.WrapTransaction(() => { var blockService = new Rock.Model.BlockService(rockContext); var block = blockService.Get(blockId); block.LoadAttributes(); block.Name = tbBlockName.Text; block.CssClass = tbCssClass.Text; block.PreHtml = cePreHtml.Text; block.PostHtml = cePostHtml.Text; block.OutputCacheDuration = 0; //Int32.Parse( tbCacheDuration.Text ); avcAttributes.GetEditValues(block); avcMobileAttributes.GetEditValues(block); avcAdvancedAttributes.GetEditValues(block); foreach (var kvp in CustomSettingsProviders) { kvp.Key.WriteSettingsToEntity(block, kvp.Value, rockContext); } SaveCustomColumnsConfigToViewState(); if (this.CustomGridColumnsConfigState != null && this.CustomGridColumnsConfigState.ColumnsConfig.Any()) { if (!block.Attributes.Any(a => a.Key == CustomGridColumnsConfig.AttributeKey)) { block.Attributes.Add(CustomGridColumnsConfig.AttributeKey, null); } var customGridColumnsJSON = this.CustomGridColumnsConfigState.ToJson(); if (block.GetAttributeValue(CustomGridColumnsConfig.AttributeKey) != customGridColumnsJSON) { block.SetAttributeValue(CustomGridColumnsConfig.AttributeKey, customGridColumnsJSON); // if the CustomColumns changed, reload the whole page so that we can avoid issues with columns changing between postbacks reloadPage = true; } } else { if (block.Attributes.Any(a => a.Key == CustomGridColumnsConfig.AttributeKey)) { if (block.GetAttributeValue(CustomGridColumnsConfig.AttributeKey) != null) { // if the CustomColumns were removed, reload the whole page so that we can avoid issues with columns changing between postbacks reloadPage = true; } block.SetAttributeValue(CustomGridColumnsConfig.AttributeKey, null); } } // Save the custom action configs SaveCustomActionsConfigToViewState(); if (CustomActionsConfigState != null && CustomActionsConfigState.Any()) { if (!block.Attributes.Any(a => a.Key == CustomGridOptionsConfig.CustomActionsConfigsAttributeKey)) { block.Attributes.Add(CustomGridOptionsConfig.CustomActionsConfigsAttributeKey, null); } var json = CustomActionsConfigState.ToJson(); if (block.GetAttributeValue(CustomGridOptionsConfig.CustomActionsConfigsAttributeKey) != json) { block.SetAttributeValue(CustomGridOptionsConfig.CustomActionsConfigsAttributeKey, json); // if the actions changed, reload the whole page so that we can avoid issues with launchers changing between postbacks reloadPage = true; } } else { if (block.Attributes.Any(a => a.Key == CustomGridOptionsConfig.CustomActionsConfigsAttributeKey)) { if (block.GetAttributeValue(CustomGridOptionsConfig.CustomActionsConfigsAttributeKey) != null) { // if the actions were removed, reload the whole page so that we can avoid issues with launchers changing between postbacks reloadPage = true; } block.SetAttributeValue(CustomGridOptionsConfig.CustomActionsConfigsAttributeKey, null); } } if (tglEnableStickyHeader.Checked) { if (!block.Attributes.Any(a => a.Key == CustomGridOptionsConfig.EnableStickyHeadersAttributeKey)) { block.Attributes.Add(CustomGridOptionsConfig.EnableStickyHeadersAttributeKey, null); } } if (block.GetAttributeValue(CustomGridOptionsConfig.EnableStickyHeadersAttributeKey).AsBoolean() != tglEnableStickyHeader.Checked) { block.SetAttributeValue(CustomGridOptionsConfig.EnableStickyHeadersAttributeKey, tglEnableStickyHeader.Checked.ToTrueFalse()); // if EnableStickyHeaders changed, reload the page reloadPage = true; } // Save the default launcher enabled setting var isDefaultLauncherEnabled = tglEnableDefaultWorkflowLauncher.Checked; if (isDefaultLauncherEnabled && !block.Attributes.Any(a => a.Key == CustomGridOptionsConfig.EnableDefaultWorkflowLauncherAttributeKey)) { block.Attributes.Add(CustomGridOptionsConfig.EnableDefaultWorkflowLauncherAttributeKey, null); } if (block.GetAttributeValue(CustomGridOptionsConfig.EnableDefaultWorkflowLauncherAttributeKey).AsBoolean() != isDefaultLauncherEnabled) { block.SetAttributeValue(CustomGridOptionsConfig.EnableDefaultWorkflowLauncherAttributeKey, isDefaultLauncherEnabled.ToTrueFalse()); // since the setting changed, reload the page reloadPage = true; } rockContext.SaveChanges(); block.SaveAttributeValues(rockContext); // If this is a PageMenu block then we need to also flush the lava template cache for the block here. // Changes to the PageMenu block configuration will handle this in the PageMenu_BlockUpdated event handler, // but here we address the situation where child pages are modified using the "CMS Configuration | Pages" menu option. if (block.BlockType.Guid == Rock.SystemGuid.BlockType.PAGE_MENU.AsGuid()) { var cacheKey = string.Format("Rock:PageMenu:{0}", block.Id); if (LavaService.RockLiquidIsEnabled) { #pragma warning disable CS0618 // Type or member is obsolete LavaTemplateCache.Remove(cacheKey); #pragma warning restore CS0618 // Type or member is obsolete } LavaService.RemoveTemplateCacheEntry(cacheKey); } StringBuilder scriptBuilder = new StringBuilder(); if (reloadPage) { scriptBuilder.AppendLine("window.parent.location.reload();"); } else { scriptBuilder.AppendLine(string.Format("window.parent.Rock.controls.modal.close('BLOCK_UPDATED:{0}');", blockId)); } ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "close-modal", scriptBuilder.ToString(), true); }); }
/// <summary> /// Handles the Click event of the _btnSelectCurrentPage control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> public void _btnSelectCurrentPage_Click( object sender, EventArgs e ) { int? pageId = null; var rockBlock = this.RockBlock(); if ( rockBlock.PageCache.Guid == Rock.SystemGuid.Page.BLOCK_PROPERTIES.AsGuid() ) { // if the BlockProperties block is the current block, we'll treat the page that this block properties is for as the current page int blockId = rockBlock.PageParameter( "BlockId" ).AsInteger(); var block = new BlockService( new RockContext() ).Get( blockId ); if ( block != null ) { pageId = block.PageId; } } else { pageId = rockBlock.PageCache.Id; } if ( pageId.HasValue ) { var currentPage = new PageService( new RockContext() ).Get( pageId.Value ); this.SetValue( currentPage ); } ShowDropDown = true; }
/// <summary> /// Raises the <see cref="E:Init" /> event. /// </summary> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected override void OnInit( EventArgs e ) { Rock.Web.UI.DialogPage dialogPage = this.Page as Rock.Web.UI.DialogPage; if ( dialogPage != null ) { dialogPage.OnSave += new EventHandler<EventArgs>( masterPage_OnSave ); } try { int blockId = Convert.ToInt32( PageParameter( "BlockId" ) ); Block _block = new BlockService( new RockContext() ).Get( blockId ); if ( _block.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson ) ) { phAttributes.Controls.Clear(); phAdvancedAttributes.Controls.Clear(); _block.LoadAttributes(); if ( _block.Attributes != null ) { foreach ( var attributeCategory in Rock.Attribute.Helper.GetAttributeCategories( _block ) ) { if (attributeCategory.Category != null && attributeCategory.Category.Name.Equals("advanced", StringComparison.OrdinalIgnoreCase)) { Rock.Attribute.Helper.AddEditControls( string.Empty, attributeCategory.Attributes.Select( a => a.Key ).ToList(), _block, phAdvancedAttributes, string.Empty, !Page.IsPostBack, new List<string>()); } else { Rock.Attribute.Helper.AddEditControls( attributeCategory.Category != null ? attributeCategory.Category.Name : string.Empty, attributeCategory.Attributes.Select( a => a.Key ).ToList(), _block, phAttributes, string.Empty, !Page.IsPostBack, new List<string>() ); } } } } else { DisplayError( "You are not authorized to edit this block", null ); } } catch ( SystemException ex ) { DisplayError( ex.Message, "<pre>" + ex.StackTrace + "</pre>" ); } base.OnInit( e ); }
/// <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 ) { int pageId = PageParameter( "EditPage" ).AsInteger(); Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read( pageId ); string zoneName = this.PageParameter( "ZoneName" ); Rock.Model.Block block; var rockContext = new RockContext(); BlockService blockService = new BlockService( rockContext ); int blockId = hfBlockId.ValueAsInt(); if ( blockId == 0 ) { block = new Rock.Model.Block(); BlockLocation location = hfBlockLocation.Value.ConvertToEnum<BlockLocation>(); if ( location == BlockLocation.Layout ) { block.LayoutId = page.LayoutId; block.PageId = null; } else { block.LayoutId = null; block.PageId = page.Id; } block.Zone = zoneName; Rock.Model.Block lastBlock = blockService.GetByPageAndZone( page.Id, zoneName ).OrderByDescending( b => b.Order ).FirstOrDefault(); if ( lastBlock != null ) { block.Order = lastBlock.Order + 1; } else { block.Order = 0; } blockService.Add( block ); } else { block = blockService.Get( blockId ); } block.Name = tbBlockName.Text; block.BlockTypeId = Convert.ToInt32( ddlBlockType.SelectedValue ); rockContext.SaveChanges(); Rock.Security.Authorization.CopyAuthorization( page, block ); if ( block.Layout != null ) { Rock.Web.Cache.PageCache.FlushLayoutBlocks( page.LayoutId ); } else { page.FlushBlocks(); } BindGrids(); pnlDetails.Visible = false; pnlLists.Visible = true; }
/// <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 ) { bool newBlock = false; Rock.Model.Block block = null; using ( var rockContext = new RockContext() ) { BlockService blockService = new BlockService( rockContext ); int blockId = hfBlockId.ValueAsInt(); if ( blockId != 0 ) { block = blockService.Get( blockId ); } if ( block == null ) { newBlock = true; block = new Rock.Model.Block(); blockService.Add( block ); BlockLocation location = hfBlockLocation.Value.ConvertToEnum<BlockLocation>(); if ( location == BlockLocation.Layout ) { block.LayoutId = _Page.LayoutId; block.PageId = null; } else { block.LayoutId = null; block.PageId = _Page.Id; } block.Zone = _ZoneName; Rock.Model.Block lastBlock = blockService.GetByPageAndZone( _Page.Id, _ZoneName ).OrderByDescending( b => b.Order ).FirstOrDefault(); if ( lastBlock != null ) { block.Order = lastBlock.Order + 1; } else { block.Order = 0; } } block.Name = tbBlockName.Text; block.BlockTypeId = Convert.ToInt32( ddlBlockType.SelectedValue ); rockContext.SaveChanges(); if ( newBlock ) { Rock.Security.Authorization.CopyAuthorization( _Page, block, rockContext ); } if ( block.Layout != null ) { Rock.Web.Cache.PageCache.FlushLayoutBlocks( _Page.LayoutId ); } else { _Page.FlushBlocks(); } } PageUpdated = true; BindGrids(); pnlDetails.Visible = false; pnlLists.Visible = true; }
/// <summary> /// Recursively saves Pages and associated Blocks, PageRoutes and PageContexts. /// </summary> /// <param name="page">The current Page to save</param> /// <param name="newBlockTypes">List of BlockTypes not currently installed</param> /// <param name="personId">Id of the Person performing the "Import" operation</param> /// <param name="parentPageId">Id of the the current Page's parent</param> /// <param name="siteId">Id of the site the current Page is being imported into</param> private void SavePages( Page page, IEnumerable<BlockType> newBlockTypes, int personId, int parentPageId, int siteId ) { // find layout var layoutService = new LayoutService(); var layout = layoutService.GetBySiteId(siteId).Where( l => l.Name == page.Layout.Name && l.FileName == page.Layout.FileName ).FirstOrDefault(); if ( layout == null ) { layout = new Layout(); layout.FileName = page.Layout.FileName; layout.Name = page.Layout.Name; layout.SiteId = siteId; layoutService.Add( layout, null ); layoutService.Save( layout, null ); } int layoutId = layout.Id; // Force shallow copies on entities so save operations are more atomic and don't get hosed // by nested object references. var pg = page.Clone(deepCopy: false); var blockTypes = newBlockTypes.ToList(); pg.ParentPageId = parentPageId; pg.LayoutId = layoutId; var pageService = new PageService(); pageService.Add( pg, personId ); pageService.Save( pg, personId ); var blockService = new BlockService(); foreach ( var block in page.Blocks ?? new List<Block>() ) { var blockType = blockTypes.FirstOrDefault( bt => block.BlockType.Path == bt.Path ); var b = block.Clone( deepCopy: false ); b.PageId = pg.Id; if ( blockType != null ) { b.BlockTypeId = blockType.Id; } blockService.Add( b, personId ); blockService.Save( b, personId ); } var pageRouteService = new PageRouteService(); foreach ( var pageRoute in page.PageRoutes ?? new List<PageRoute>() ) { var pr = pageRoute.Clone(deepCopy: false); pr.PageId = pg.Id; pageRouteService.Add( pr, personId ); pageRouteService.Save( pr, personId ); } var pageContextService = new PageContextService(); foreach ( var pageContext in page.PageContexts ?? new List<PageContext>() ) { var pc = pageContext.Clone(deepCopy: false); pc.PageId = pg.Id; pageContextService.Add( pc, personId ); pageContextService.Save( pc, personId ); } foreach ( var p in page.Pages ?? new List<Page>() ) { SavePages( p, blockTypes, personId, pg.Id, siteId ); } }
/// <summary> /// Handles the GridReorder event of the gPageBlocks control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="GridReorderEventArgs"/> instance containing the event data.</param> protected void gPageBlocks_GridReorder( object sender, GridReorderEventArgs e ) { using ( var rockContext = new RockContext() ) { BlockService blockService = new BlockService( rockContext ); var blocks = blockService.GetByPageAndZone( _Page.Id, _ZoneName ).ToList(); blockService.Reorder( blocks, e.OldIndex, e.NewIndex ); rockContext.SaveChanges(); } _Page.FlushBlocks(); PageUpdated = true; BindGrids(); }
/// <summary> /// This method takes the attribute values of the original blocks, and creates copies of them that point to the copied blocks. /// In addition, any block attribute value pointing to a page in the original page tree is now updated to point to the /// corresponding page in the copied page tree. /// </summary> /// <param name="pageGuidDictionary">The dictionary containing the original page guids and the corresponding copied page guids.</param> /// <param name="blockGuidDictionary">The dictionary containing the original block guids and the corresponding copied block guids.</param> /// <param name="rockContext">The rock context.</param> /// <param name="currentPersonAliasId">The current person alias identifier.</param> private void GenerateBlockAttributeValues( Dictionary<Guid, Guid> pageGuidDictionary, Dictionary<Guid, Guid> blockGuidDictionary, RockContext rockContext, int? currentPersonAliasId = null ) { var attributeValueService = new AttributeValueService( rockContext ); var pageService = new PageService( rockContext ); var blockService = new BlockService( rockContext ); var pageGuid = Rock.SystemGuid.EntityType.PAGE.AsGuid(); var blockGuid = Rock.SystemGuid.EntityType.BLOCK.AsGuid(); Dictionary<Guid, int> blockIntDictionary = blockService.Queryable() .Where( p => blockGuidDictionary.Keys.Contains( p.Guid ) || blockGuidDictionary.Values.Contains( p.Guid ) ) .ToDictionary( p => p.Guid, p => p.Id ); var attributeValues = attributeValueService.Queryable().Where( a => a.Attribute.EntityType.Guid == blockGuid && blockIntDictionary.Values.Contains( a.EntityId.Value ) ) .ToList(); foreach ( var attributeValue in attributeValues ) { var newAttributeValue = attributeValue.Clone( false ); newAttributeValue.CreatedByPersonAlias = null; newAttributeValue.CreatedByPersonAliasId = currentPersonAliasId; newAttributeValue.CreatedDateTime = RockDateTime.Now; newAttributeValue.ModifiedByPersonAlias = null; newAttributeValue.ModifiedByPersonAliasId = currentPersonAliasId; newAttributeValue.ModifiedDateTime = RockDateTime.Now; newAttributeValue.Id = 0; newAttributeValue.Guid = Guid.NewGuid(); newAttributeValue.EntityId = blockIntDictionary[blockGuidDictionary[blockIntDictionary.Where( d => d.Value == attributeValue.EntityId.Value ).FirstOrDefault().Key]]; if ( attributeValue.Attribute.FieldType.Guid == Rock.SystemGuid.FieldType.PAGE_REFERENCE.AsGuid() ) { if ( pageGuidDictionary.ContainsKey( attributeValue.Value.AsGuid() ) ) { newAttributeValue.Value = pageGuidDictionary[attributeValue.Value.AsGuid()].ToString(); } } attributeValueService.Add( newAttributeValue ); } rockContext.SaveChanges(); }
/// <summary> /// Binds the grids. /// </summary> private void BindGrids() { using ( var rockContext = new RockContext() ) { BlockService blockService = new BlockService( rockContext ); gLayoutBlocks.DataSource = blockService.GetByLayoutAndZone( _Page.LayoutId, _ZoneName ) .Select( b => new { b.Id, b.Name, BlockTypeName = b.BlockType.Name, BlockTypePath = b.BlockType.Path } ) .ToList(); gLayoutBlocks.DataBind(); gPageBlocks.DataSource = blockService.GetByPageAndZone( _Page.Id, _ZoneName ) .Select( b => new { b.Id, b.Name, BlockTypeName = b.BlockType.Name, BlockTypePath = b.BlockType.Path } ) .ToList(); gPageBlocks.DataBind(); } }
/// <summary> /// Handles the Delete click event for the grid. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs" /> instance containing the event data.</param> protected void DeleteBlock_Click( object sender, Rock.Web.UI.Controls.RowEventArgs e ) { var rockContext = new RockContext(); BlockService blockService = new BlockService( rockContext ); Block block = blockService.Get( e.RowKeyId ); if ( block != null ) { string errorMessage; if ( !blockService.CanDelete( block, out errorMessage ) ) { mdGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } blockService.Delete( block ); rockContext.SaveChanges(); BlockCache.Flush( e.RowKeyId ); } BindLayoutBlocksGrid(); }
/// <summary> /// Gets the group placement registrants. /// </summary> /// <param name="options">The options.</param> /// <param name="currentPerson">The current person.</param> /// <returns></returns> public List <GroupPlacementRegistrant> GetGroupPlacementRegistrants(GetGroupPlacementRegistrantsParameters options, Person currentPerson) { var rockContext = this.Context as RockContext; var registrationRegistrantService = new RegistrationRegistrantService(rockContext); var registrationRegistrantQuery = registrationRegistrantService.Queryable(); registrationRegistrantQuery = registrationRegistrantQuery .Where(a => a.Registration.RegistrationInstance.RegistrationTemplateId == options.RegistrationTemplateId); if (options.RegistrationInstanceId.HasValue) { registrationRegistrantQuery = registrationRegistrantQuery.Where(a => a.Registration.RegistrationInstanceId == options.RegistrationInstanceId.Value); } else if (options.RegistrationTemplateInstanceIds?.Any() == true) { registrationRegistrantQuery = registrationRegistrantQuery.Where(a => options.RegistrationTemplateInstanceIds.Contains(a.Registration.RegistrationInstanceId)); } if (options.RegistrantPersonDataViewFilterId.HasValue) { var dataFilter = new DataViewFilterService(rockContext).Get(options.RegistrantPersonDataViewFilterId.Value); List <string> errorMessages = new List <string>(); var personService = new PersonService(rockContext); var paramExpression = personService.ParameterExpression; var personWhereExpression = dataFilter?.GetExpression(typeof(Person), personService, paramExpression, errorMessages); if (personWhereExpression != null) { var personIdQry = personService.Queryable().Where(paramExpression, personWhereExpression, null).Select(x => x.Id); registrationRegistrantQuery = registrationRegistrantQuery.Where(a => personIdQry.Contains(a.PersonAlias.PersonId)); } } if (options.RegistrantId.HasValue) { registrationRegistrantQuery = registrationRegistrantQuery.Where(a => a.Id == options.RegistrantId.Value); } Block registrationInstanceGroupPlacementBlock = new BlockService(rockContext).Get(options.BlockId); if (registrationInstanceGroupPlacementBlock != null && currentPerson != null) { const string RegistrantAttributeFilter_RegistrationInstanceId = "RegistrantAttributeFilter_RegistrationInstanceId_{0}"; const string RegistrantAttributeFilter_RegistrationTemplateId = "RegistrantAttributeFilter_RegistrationTemplateId_{0}"; string userPreferenceKey; if (options.RegistrationInstanceId.HasValue) { userPreferenceKey = PersonService.GetBlockUserPreferenceKeyPrefix(options.BlockId) + string.Format(RegistrantAttributeFilter_RegistrationInstanceId, options.RegistrationInstanceId); } else { userPreferenceKey = PersonService.GetBlockUserPreferenceKeyPrefix(options.BlockId) + string.Format(RegistrantAttributeFilter_RegistrationTemplateId, options.RegistrationTemplateId); } var attributeFilters = PersonService.GetUserPreference(currentPerson, userPreferenceKey).FromJsonOrNull <Dictionary <int, string> >() ?? new Dictionary <int, string>(); var parameterExpression = registrationRegistrantService.ParameterExpression; Expression registrantWhereExpression = null; foreach (var attributeFilter in attributeFilters) { var attribute = AttributeCache.Get(attributeFilter.Key); var attributeFilterValues = attributeFilter.Value.FromJsonOrNull <List <string> >(); var entityField = EntityHelper.GetEntityFieldForAttribute(attribute); if (entityField != null && attributeFilterValues != null) { var attributeWhereExpression = ExpressionHelper.GetAttributeExpression(registrationRegistrantService, parameterExpression, entityField, attributeFilterValues); if (registrantWhereExpression == null) { registrantWhereExpression = attributeWhereExpression; } else { registrantWhereExpression = Expression.AndAlso(registrantWhereExpression, attributeWhereExpression); } } } if (registrantWhereExpression != null) { registrationRegistrantQuery = registrationRegistrantQuery.Where(parameterExpression, registrantWhereExpression); } } var registrationTemplatePlacement = new RegistrationTemplatePlacementService(rockContext).Get(options.RegistrationTemplatePlacementId); if (options.FilterFeeId.HasValue) { registrationRegistrantQuery = registrationRegistrantQuery.Where(a => a.Fees.Any(f => f.RegistrationTemplateFeeId == options.FilterFeeId.Value)); } if (options.FilterFeeOptionIds?.Any() == true) { registrationRegistrantQuery = registrationRegistrantQuery.Where(a => a.Fees.Any(f => f.RegistrationTemplateFeeItemId.HasValue && options.FilterFeeOptionIds.Contains(f.RegistrationTemplateFeeItemId.Value))); } // don't include registrants that are on the waiting list registrationRegistrantQuery = registrationRegistrantQuery.Where(a => a.OnWaitList == false); registrationRegistrantQuery = registrationRegistrantQuery.OrderBy(a => a.PersonAlias.Person.LastName).ThenBy(a => a.PersonAlias.Person.NickName); var registrationTemplatePlacementService = new RegistrationTemplatePlacementService(rockContext); var registrationInstanceService = new RegistrationInstanceService(rockContext); // get a queryable of PersonIds for the registration template shared groups so we can determine if the registrant has been placed var registrationTemplatePlacementGroupsPersonIdQuery = registrationTemplatePlacementService.GetRegistrationTemplatePlacementPlacementGroups(registrationTemplatePlacement).SelectMany(a => a.Members).Select(a => a.PersonId); // and also get a queryable of PersonIds for the registration instance placement groups so we can determine if the registrant has been placed IQueryable <InstancePlacementGroupPersonId> allInstancesPlacementGroupInfoQuery = null; if (!options.RegistrationInstanceId.HasValue && (options.RegistrationTemplateInstanceIds == null || !options.RegistrationTemplateInstanceIds.Any())) { // if neither RegistrationInstanceId or RegistrationTemplateInstanceIds was specified, use all of the RegistrationTemplates instances options.RegistrationTemplateInstanceIds = new RegistrationTemplateService(rockContext).GetSelect(options.RegistrationTemplateId, s => s.Instances.Select(i => i.Id)).ToArray(); } if (options.RegistrationInstanceId.HasValue) { allInstancesPlacementGroupInfoQuery = registrationInstanceService.GetRegistrationInstancePlacementGroups(registrationInstanceService.Get(options.RegistrationInstanceId.Value)) .Where(a => a.GroupTypeId == registrationTemplatePlacement.GroupTypeId) .SelectMany(a => a.Members).Select(a => a.PersonId) .Select(s => new InstancePlacementGroupPersonId { PersonId = s, RegistrationInstanceId = options.RegistrationInstanceId.Value }); } else if (options.RegistrationTemplateInstanceIds?.Any() == true) { foreach (var registrationInstanceId in options.RegistrationTemplateInstanceIds) { var instancePlacementGroupInfoQuery = registrationInstanceService.GetRegistrationInstancePlacementGroups(registrationInstanceService.Get(registrationInstanceId)) .Where(a => a.GroupTypeId == registrationTemplatePlacement.GroupTypeId) .SelectMany(a => a.Members).Select(a => a.PersonId) .Select(s => new InstancePlacementGroupPersonId { PersonId = s, RegistrationInstanceId = registrationInstanceId }); if (allInstancesPlacementGroupInfoQuery == null) { allInstancesPlacementGroupInfoQuery = instancePlacementGroupInfoQuery; } else { allInstancesPlacementGroupInfoQuery = allInstancesPlacementGroupInfoQuery.Union(instancePlacementGroupInfoQuery); } } } if (allInstancesPlacementGroupInfoQuery == null) { throw new ArgumentNullException("Registration Instance(s) must be specified"); } // select in a way to avoid lazy loading var registrationRegistrantPlacementQuery = registrationRegistrantQuery.Select(r => new { Registrant = r, r.PersonAlias.Person, r.Registration.RegistrationInstance, // marked as AlreadyPlacedInGroup if the Registrant is a member of any of the registrant template placement group or the registration instance placement groups AlreadyPlacedInGroup = registrationTemplatePlacementGroupsPersonIdQuery.Contains(r.PersonAlias.PersonId) || allInstancesPlacementGroupInfoQuery.Any(x => x.RegistrationInstanceId == r.Registration.RegistrationInstanceId && x.PersonId == r.PersonAlias.PersonId) }); var registrationRegistrantPlacementList = registrationRegistrantPlacementQuery.AsNoTracking().ToList(); var groupPlacementRegistrantList = registrationRegistrantPlacementList .Select(x => new GroupPlacementRegistrant(x.Registrant, x.Person, x.AlreadyPlacedInGroup, x.RegistrationInstance, options)) .ToList(); return(groupPlacementRegistrantList.ToList()); }
/// <summary> /// Handles the Delete event of the gPageBlocks 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 gPageBlocks_Delete( object sender, RowEventArgs e ) { using ( var rockContext = new RockContext() ) { BlockService blockService = new BlockService( rockContext ); Rock.Model.Block block = blockService.Get( e.RowKeyId ); if ( block != null ) { blockService.Delete( block ); rockContext.SaveChanges(); _Page.FlushBlocks(); PageUpdated = true; } } BindGrids(); }
/// <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) { bool reloadPage = false; int blockId = Convert.ToInt32(PageParameter("BlockId")); if (!Page.IsValid) { return; } var rockContext = new RockContext(); rockContext.WrapTransaction(() => { var blockService = new Rock.Model.BlockService(rockContext); var block = blockService.Get(blockId); block.LoadAttributes(); block.Name = tbBlockName.Text; block.CssClass = tbCssClass.Text; block.PreHtml = cePreHtml.Text; block.PostHtml = cePostHtml.Text; block.OutputCacheDuration = 0; //Int32.Parse( tbCacheDuration.Text ); avcAttributes.GetEditValues(block); avcMobileAttributes.GetEditValues(block); avcAdvancedAttributes.GetEditValues(block); foreach (var kvp in CustomSettingsProviders) { kvp.Key.WriteSettingsToEntity(block, kvp.Value, rockContext); } SaveCustomColumnsConfigToViewState(); if (this.CustomGridColumnsConfigState != null && this.CustomGridColumnsConfigState.ColumnsConfig.Any()) { if (!block.Attributes.Any(a => a.Key == CustomGridColumnsConfig.AttributeKey)) { block.Attributes.Add(CustomGridColumnsConfig.AttributeKey, null); } var customGridColumnsJSON = this.CustomGridColumnsConfigState.ToJson(); if (block.GetAttributeValue(CustomGridColumnsConfig.AttributeKey) != customGridColumnsJSON) { block.SetAttributeValue(CustomGridColumnsConfig.AttributeKey, customGridColumnsJSON); // if the CustomColumns changed, reload the whole page so that we can avoid issues with columns changing between postbacks reloadPage = true; } } else { if (block.Attributes.Any(a => a.Key == CustomGridColumnsConfig.AttributeKey)) { if (block.GetAttributeValue(CustomGridColumnsConfig.AttributeKey) != null) { // if the CustomColumns were removed, reload the whole page so that we can avoid issues with columns changing between postbacks reloadPage = true; } block.SetAttributeValue(CustomGridColumnsConfig.AttributeKey, null); } } if (tglEnableStickyHeader.Checked) { if (!block.Attributes.Any(a => a.Key == CustomGridOptionsConfig.EnableStickyHeadersAttributeKey)) { block.Attributes.Add(CustomGridOptionsConfig.EnableStickyHeadersAttributeKey, null); } } if (block.GetAttributeValue(CustomGridOptionsConfig.EnableStickyHeadersAttributeKey).AsBoolean() != tglEnableStickyHeader.Checked) { block.SetAttributeValue(CustomGridOptionsConfig.EnableStickyHeadersAttributeKey, tglEnableStickyHeader.Checked.ToTrueFalse()); // if EnableStickyHeaders changed, reload the page reloadPage = true; } rockContext.SaveChanges(); block.SaveAttributeValues(rockContext); // If this is a page menu block then we need to also flush the LavaTemplateCache for the block ID if (block.BlockType.Guid == Rock.SystemGuid.BlockType.PAGE_MENU.AsGuid()) { var cacheKey = string.Format("Rock:PageMenu:{0}", block.Id); LavaTemplateCache.Remove(cacheKey); } StringBuilder scriptBuilder = new StringBuilder(); if (reloadPage) { scriptBuilder.AppendLine("window.parent.location.reload();"); } else { scriptBuilder.AppendLine(string.Format("window.parent.Rock.controls.modal.close('BLOCK_UPDATED:{0}');", blockId)); } ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "close-modal", scriptBuilder.ToString(), true); }); }
/// <summary> /// Shows the edit. /// </summary> /// <param name="location">The location.</param> /// <param name="blockId">The block id.</param> protected void ShowEdit( BlockLocation location, int blockId ) { using ( var rockContext = new RockContext() ) { BlockService blockService = new BlockService( rockContext ); Rock.Model.Block block = blockService.Get( blockId ); hfBlockLocation.Value = location.ConvertToString(); if ( block != null ) { lAction.Text = "Edit "; hfBlockId.Value = block.Id.ToString(); ddlBlockType.SelectedValue = block.BlockType.Id.ToString(); tbBlockName.Text = block.Name; } else { lAction.Text = "Add "; hfBlockId.Value = "0"; // Select HTML Content block by default var blockType = new Rock.Model.BlockTypeService( rockContext ) .GetByGuid( new Guid( Rock.SystemGuid.BlockType.HTML_CONTENT ) ); if ( blockType != null ) { ddlBlockType.SelectedValue = blockType.Id.ToString(); } else { ddlBlockType.SelectedIndex = -1; } tbBlockName.Text = string.Empty; } } lAction.Text += hfBlockLocation.Value; pnlLists.Visible = false; pnlDetails.Visible = true; }
/// <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) { bool reloadPage = false; int blockId = Convert.ToInt32(PageParameter("BlockId")); if (Page.IsValid) { var rockContext = new RockContext(); var blockService = new Rock.Model.BlockService(rockContext); var block = blockService.Get(blockId); block.LoadAttributes(); block.Name = tbBlockName.Text; block.CssClass = tbCssClass.Text; block.PreHtml = cePreHtml.Text; block.PostHtml = cePostHtml.Text; block.OutputCacheDuration = 0; //Int32.Parse( tbCacheDuration.Text ); rockContext.SaveChanges(); Rock.Attribute.Helper.GetEditValues(phAttributes, block); if (phAdvancedAttributes.Controls.Count > 0) { Rock.Attribute.Helper.GetEditValues(phAdvancedAttributes, block); } SaveCustomColumnsConfigToViewState(); if (this.CustomGridColumnsConfigState != null && this.CustomGridColumnsConfigState.ColumnsConfig.Any()) { if (!block.Attributes.Any(a => a.Key == CustomGridColumnsConfig.AttributeKey)) { block.Attributes.Add(CustomGridColumnsConfig.AttributeKey, null); } var customGridColumnsJSON = this.CustomGridColumnsConfigState.ToJson(); if (block.GetAttributeValue(CustomGridColumnsConfig.AttributeKey) != customGridColumnsJSON) { block.SetAttributeValue(CustomGridColumnsConfig.AttributeKey, customGridColumnsJSON); // if the CustomColumns changed, reload the whole page so that we can avoid issues with columns changing between postbacks reloadPage = true; } } else { if (block.Attributes.Any(a => a.Key == CustomGridColumnsConfig.AttributeKey)) { if (block.GetAttributeValue(CustomGridColumnsConfig.AttributeKey) != null) { // if the CustomColumns were removed, reload the whole page so that we can avoid issues with columns changing between postbacks reloadPage = true; } block.SetAttributeValue(CustomGridColumnsConfig.AttributeKey, null); } } block.SaveAttributeValues(rockContext); Rock.Web.Cache.BlockCache.Flush(block.Id); StringBuilder scriptBuilder = new StringBuilder(); if (reloadPage) { scriptBuilder.AppendLine("window.parent.location.reload();"); } else { scriptBuilder.AppendLine(string.Format("window.parent.Rock.controls.modal.close('BLOCK_UPDATED:{0}');", blockId)); } ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "close-modal", scriptBuilder.ToString(), true); } }
/// <summary> /// Handles the Delete event of the gLayoutBlocks 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 gLayoutBlocks_Delete( object sender, RowEventArgs e ) { int pageId = PageParameter( "EditPage" ).AsInteger(); Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read( pageId ); var rockContext = new RockContext(); BlockService blockService = new BlockService( rockContext ); Rock.Model.Block block = blockService.Get( (int)gLayoutBlocks.DataKeys[e.RowIndex]["id"] ); if ( block != null ) { blockService.Delete( block ); rockContext.SaveChanges(); Rock.Web.Cache.PageCache.FlushLayoutBlocks( page.LayoutId ); } BindGrids(); }
/// <summary> /// Handles the Delete event of the gLayoutBlocks 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 gLayoutBlocks_Delete( object sender, RowEventArgs e ) { BlockService blockService = new BlockService(); int pageId = PageParameter( "EditPage" ).AsInteger() ?? 0; Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read( pageId ); Rock.Model.Block block = blockService.Get( (int)gLayoutBlocks.DataKeys[e.RowIndex]["id"] ); if ( block != null ) { blockService.Delete( block, CurrentPersonId ); blockService.Save( block, CurrentPersonId ); Rock.Web.Cache.PageCache.FlushLayoutBlocks( page.LayoutId ); } BindGrids(); }