private WebControl GetIcon() { var icon = new WebControl(HtmlTextWriterTag.I); icon.Attributes.Add("aria-hidden", "true"); icon.AddCssClass("cms-icon-50"); icon.AddCssClass("icon-circle"); icnState.Controls.AddAt(0, icon); return(icon); }
private void ApplyCssClassAndStyles(WebControl control) { if (!String.IsNullOrEmpty(CssClass)) { control.AddCssClass(CssClass); CssClass = null; } if (!String.IsNullOrEmpty(ControlStyle)) { control.Attributes.Add("style", ControlStyle); ControlStyle = null; } }
/// <summary> /// Configures a control to display and toggle following for the specified entity /// </summary> /// <param name="followEntity">The follow entity. NOTE: Make sure to use PersonAlias instead of Person when following a Person</param> /// <param name="followControl">The follow control.</param> /// <param name="follower">The follower.</param> public static void SetFollowing(IEntity followEntity, WebControl followControl, Person follower) { if (followEntity == null) { return; } var followingEntityType = EntityTypeCache.Get(followEntity.GetType()); if (follower != null && follower.PrimaryAliasId.HasValue) { using (var rockContext = new RockContext()) { var personAliasService = new PersonAliasService(rockContext); var followingService = new FollowingService(rockContext); var followingQry = followingService.Queryable() .Where(f => f.EntityTypeId == followingEntityType.Id && f.PersonAlias.PersonId == follower.Id); followingQry = followingQry.Where(f => f.EntityId == followEntity.Id); if (followingQry.Any()) { followControl.AddCssClass("following"); } else { followControl.RemoveCssClass("following"); } } int entityId = followEntity.Id; // only show the following control if the entity has been saved to the database followControl.Visible = entityId > 0; string script = string.Format( @"Rock.controls.followingsToggler.initialize($('#{0}'), {1}, {2}, {3}, {4});", followControl.ClientID, followingEntityType.Id, entityId, follower.Id, follower.PrimaryAliasId); ScriptManager.RegisterStartupScript(followControl, followControl.GetType(), followControl.ClientID + "_following", script, true); } }
/// <summary> /// Configures a control to display and toggle following for the specified entity /// </summary> /// <param name="entityTypeId">The entity type identifier.</param> /// <param name="entityId">The entity identifier.</param> /// <param name="followControl">The follow control.</param> /// <param name="follower">The follower.</param> /// <param name="callbackScript">The callback script.</param> /// <param name="purposeKey">A purpose that defines how this following will be used.</param> public static void SetFollowing(int entityTypeId, int entityId, WebControl followControl, Person follower, string callbackScript = "", string purposeKey = "") { if (follower != null && follower.PrimaryAliasId.HasValue) { using (var rockContext = new RockContext()) { var personAliasService = new PersonAliasService(rockContext); var followingService = new FollowingService(rockContext); // If PurposeKey is null then the provided purposeKey must be // empty. // If PurposeKey is not null then it must match the provided // purposeKey. var followingQry = followingService.Queryable() .Where(f => f.EntityTypeId == entityTypeId && f.EntityId == entityId && f.PersonAlias.PersonId == follower.Id && ((f.PurposeKey == null && purposeKey == "") || f.PurposeKey == purposeKey)); if (followingQry.Any()) { followControl.AddCssClass("following"); } else { followControl.RemoveCssClass("following"); } } // only show the following control if the entity has been saved to the database followControl.Visible = entityId > 0; string script = string.Format( @"Rock.controls.followingsToggler.initialize($('#{0}'), {1}, {2}, '{3}', {4}, {5}, {6});", followControl.ClientID, entityTypeId, entityId, purposeKey.Replace("'", "\\'"), follower.Id, follower.PrimaryAliasId, callbackScript.IsNullOrWhiteSpace() ? "null" : callbackScript); ScriptManager.RegisterStartupScript(followControl, followControl.GetType(), followControl.ClientID + "_following", script, true); } }
/// <summary> /// Disable a <see cref="WebControl"/> in server-side and change appearance in client-side. /// </summary> /// <param name="control">Current <see cref="WebControl"/></param> /// <param name="cssClass">CSS class that define disabled state in client view. By default is "disabled" class.</param> /// <returns>The Same <see cref="WebControl"/></returns> public static WebControl Disable(this WebControl control, string cssClass = "disabled") { control.AddCssClass(cssClass); control.Enabled = false; return(control); }