/// <summary> /// Handles the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); this.DataValueField = "Id"; this.DataTextField = UseAbbreviation ? "Id" : "Value"; _rebindRequired = false; var definedType = DefinedTypeCache.Read(new Guid(SystemGuid.DefinedType.LOCATION_ADDRESS_STATE)); this.DataSource = definedType.DefinedValues.OrderBy(v => v.Order).Select(v => new { Id = v.Name, Value = v.Description }); this.DataBind(); if (!this.Page.IsPostBack) { string orgLocGuid = GlobalAttributesCache.Read().GetValue("OrganizationAddress"); if (!string.IsNullOrWhiteSpace(orgLocGuid)) { Guid locGuid = Guid.Empty; if (Guid.TryParse(orgLocGuid, out locGuid)) { var location = new Rock.Model.LocationService().Get(locGuid); if (location != null) { var li = this.Items.FindByValue(location.State); if (li != null) { li.Selected = true; } } } } } }
/// <summary> /// Handles the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit( EventArgs e ) { base.OnInit( e ); this.DataValueField = "Id"; this.DataTextField = UseAbbreviation ? "Id" : "Value"; _rebindRequired = false; var definedType = DefinedTypeCache.Read( new Guid( SystemGuid.DefinedType.LOCATION_ADDRESS_STATE ) ); this.DataSource = definedType.DefinedValues.OrderBy( v => v.Order ).Select( v => new { Id = v.Name, Value = v.Description } ); this.DataBind(); if ( !this.Page.IsPostBack ) { string orgLocGuid = GlobalAttributesCache.Read().GetValue( "OrganizationAddress" ); if ( !string.IsNullOrWhiteSpace( orgLocGuid ) ) { Guid locGuid = Guid.Empty; if ( Guid.TryParse( orgLocGuid, out locGuid ) ) { var location = new Rock.Model.LocationService().Get( locGuid ); if ( location != null ) { var li = this.Items.FindByValue( location.State ); if ( li != null ) { li.Selected = true; } } } } } }
/// <summary> /// Registers the java script. /// </summary> protected virtual void RegisterJavaScript() { string mapStyle = "null"; string markerColor = ""; try { DefinedValueCache dvcMapStyle = DefinedValueCache.Get(this.MapStyleValueGuid); if (dvcMapStyle != null) { mapStyle = dvcMapStyle.GetAttributeValue("DynamicMapStyle"); var colors = dvcMapStyle.GetAttributeValue("Colors").Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (colors.Any()) { markerColor = colors.First().Replace("#", ""); } } } catch { } // oh well... string options = string.Format("controlId: '{0}', drawingMode: '{1}', strokeColor: '{2}', fillColor: '{2}', mapStyle: {3}", this.ClientID, this.DrawingMode, markerColor, mapStyle); DbGeography centerPoint = CenterPoint; if (centerPoint != null && centerPoint.Latitude != null && centerPoint.Longitude != null) { options += string.Format(", centerLatitude: '{0}', centerLongitude: '{1}'", centerPoint.Latitude, centerPoint.Longitude); } else { // If no centerpoint was defined, try to get it from organization address var globalAttributes = GlobalAttributesCache.Get(); Guid guid = globalAttributes.GetValue("OrganizationAddress").AsGuid(); if (!guid.Equals(Guid.Empty)) { var location = new Rock.Model.LocationService(new Rock.Data.RockContext()).Get(guid); if (location != null && location.GeoPoint != null && location.GeoPoint.Latitude != null && location.GeoPoint.Longitude != null) { CenterPoint = location.GeoPoint; options += string.Format(", centerLatitude: '{0}', centerLongitude: '{1}'", location.GeoPoint.Latitude, location.GeoPoint.Longitude); } } } string script = string.Format(@" // if the geoPicker was rendered, initialize it if ($('#{1}').length > 0) {{ Rock.controls.geoPicker.initialize({{ {0} }}); }} ", options, this.ClientID); ScriptManager.RegisterStartupScript(this, this.GetType(), "geo_picker-" + this.ClientID, script, true); }
/// <summary> /// Registers the java script. /// </summary> protected virtual void RegisterJavaScript() { string mapStyle = "null"; string markerColor = ""; try { DefinedValueCache dvcMapStyle = DefinedValueCache.Read( this.MapStyleValueGuid ); if ( dvcMapStyle != null ) { mapStyle = dvcMapStyle.GetAttributeValue( "DynamicMapStyle" ); var colors = dvcMapStyle.GetAttributeValue( "Colors" ).Split( new char[] {'|'}, StringSplitOptions.RemoveEmptyEntries).ToList(); if ( colors.Any() ) { markerColor = colors.First().Replace( "#", "" ); } } } catch { } // oh well... string options = string.Format( "controlId: '{0}', drawingMode: '{1}', strokeColor: '{2}', fillColor: '{2}', mapStyle: {3}", this.ClientID, this.DrawingMode, markerColor, mapStyle ); DbGeography centerPoint = CenterPoint; if ( centerPoint != null && centerPoint.Latitude != null && centerPoint.Longitude != null ) { options += string.Format( ", centerLatitude: '{0}', centerLongitude: '{1}'", centerPoint.Latitude, centerPoint.Longitude ); } else { // If no centerpoint was defined, try to get it from organization address var globalAttributes = Rock.Web.Cache.GlobalAttributesCache.Read(); Guid guid = globalAttributes.GetValue( "OrganizationAddress" ).AsGuid(); if ( !guid.Equals( Guid.Empty ) ) { var location = new Rock.Model.LocationService( new Rock.Data.RockContext() ).Get( guid ); if (location != null && location.GeoPoint != null && location.GeoPoint.Latitude != null && location.GeoPoint.Latitude != null ) { CenterPoint = location.GeoPoint; options += string.Format( ", centerLatitude: '{0}', centerLongitude: '{1}'", location.GeoPoint.Latitude, location.GeoPoint.Longitude ); } } } string script = string.Format( @" // if the geoPicker was rendered, initialize it if ($('#{1}').length > 0) {{ Rock.controls.geoPicker.initialize({{ {0} }}); }} ", options, this.ClientID ); ScriptManager.RegisterStartupScript( this, this.GetType(), "geo_picker-" + this.ClientID, script, true ); }