/// <summary> /// Raises 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) { EnsureChildControls(); _ddlFieldType.DataSource = FieldTypeCache.All(); _ddlFieldType.DataBind(); base.OnInit(e); }
/// <summary> /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { base.CreateChildControls(); this.Items.Clear(); this.Items.Add(new ListItem()); foreach (var item in FieldTypeCache.All()) { this.Items.Add(new ListItem(item.Name, item.Id.ToString())); } }
/// <summary> /// Gets all the field types that can be used while building the form. /// This represents the list of field types that can be dragged from /// the left panel onto the main form sections. /// </summary> /// <returns>The list of field type view models.</returns> private static List <FormFieldTypeViewModel> GetAvailableFieldTypes() { return(FieldTypeCache.All() .Where(f => f.Platform.HasFlag(Rock.Utility.RockPlatform.Obsidian) && (f.Usage.HasFlag(Field.FieldTypeUsage.Common) || f.Usage.HasFlag(Field.FieldTypeUsage.Advanced))) .Select(f => new FormFieldTypeViewModel { Guid = f.Guid, Text = f.Name, Svg = f.IconSvg, IsCommon = f.Usage.HasFlag(Field.FieldTypeUsage.Common) }) .ToList()); }
public IHttpActionResult GetAvailableFieldTypes() { var fieldTypes = FieldTypeCache.All() .Where(f => f.Platform.HasFlag(Rock.Utility.RockPlatform.Obsidian)) .ToList(); var fieldTypeItems = fieldTypes .Select(f => new ListItemViewModel { Text = f.Name, Value = f.Guid.ToString() }) .ToList(); return(Ok(fieldTypeItems)); }
public void GetSupportedRegistrationConditionalFields() { var notSupportedBuilder = new StringBuilder(); var supportedBuilder = new StringBuilder(); foreach (var fieldType in FieldTypeCache.All()) { try { if (fieldType.Field.HasFilterControl()) { //var qualifiers = attribute.AttributeQualifiers.ToDictionary( k => k.Key, v => new ConfigurationValue( v.Value ) ); // get the editControl to see if the FieldType supports a ChangeHandler for it (but don't actually use the control) var editControl = fieldType.Field.EditControl(new System.Collections.Generic.Dictionary <string, ConfigurationValue>(), $"temp_editcontrol_attribute_TEST"); if (fieldType.Field.HasChangeHandler(editControl)) { supportedBuilder.AppendLine($"'{fieldType.Name}"); continue; } } else { } notSupportedBuilder.AppendLine($"{fieldType.Name}"); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } Debug.WriteLine("Supported Field Types:"); Debug.WriteLine(supportedBuilder.ToString()); Debug.WriteLine("Unsupported Field Types:"); Debug.WriteLine(notSupportedBuilder.ToString()); }
/// <summary> /// Loads the cache objects. /// </summary> private static void LoadCacheObjects(RockContext rockContext) { // Cache all the entity types foreach (var entityType in new Rock.Model.EntityTypeService(rockContext).Queryable().AsNoTracking()) { EntityTypeCache.Get(entityType); } // Cache all the Field Types foreach (var fieldType in new Rock.Model.FieldTypeService(rockContext).Queryable().AsNoTracking()) { // improve performance of loading FieldTypeCache by doing LoadAttributes using an existing rockContext before doing FieldTypeCache.Get to avoid calling LoadAttributes with new context per FieldTypeCache fieldType.LoadAttributes(rockContext); FieldTypeCache.Get(fieldType); } var all = FieldTypeCache.All(); // Read all the qualifiers first so that EF doesn't perform a query for each attribute when it's cached var qualifiers = new Dictionary <int, Dictionary <string, string> >(); foreach (var attributeQualifier in new Rock.Model.AttributeQualifierService(rockContext).Queryable().AsNoTracking()) { try { if (!qualifiers.ContainsKey(attributeQualifier.AttributeId)) { qualifiers.Add(attributeQualifier.AttributeId, new Dictionary <string, string>()); } qualifiers[attributeQualifier.AttributeId].Add(attributeQualifier.Key, attributeQualifier.Value); } catch (Exception ex) { var startupException = new RockStartupException("Error loading cache objects", ex); LogError(startupException, null); } } // Cache all the attributes, except for user preferences var attributeQuery = new Rock.Model.AttributeService(rockContext).Queryable("Categories"); int?personUserValueEntityTypeId = EntityTypeCache.GetId(Person.USER_VALUE_ENTITY); if (personUserValueEntityTypeId.HasValue) { attributeQuery = attributeQuery.Where(a => !a.EntityTypeId.HasValue || a.EntityTypeId.Value != personUserValueEntityTypeId); } foreach (var attribute in attributeQuery.AsNoTracking().ToList()) { // improve performance of loading AttributeCache by doing LoadAttributes using an existing rockContext before doing AttributeCache.Get to avoid calling LoadAttributes with new context per AttributeCache attribute.LoadAttributes(rockContext); if (qualifiers.ContainsKey(attribute.Id)) { Rock.Web.Cache.AttributeCache.Get(attribute, qualifiers[attribute.Id]); } else { Rock.Web.Cache.AttributeCache.Get(attribute, new Dictionary <string, string>()); } } // Force authorizations to be cached Rock.Security.Authorization.Get(); }
/// <summary> /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { if (!_controlsLoaded) { Controls.Clear(); _hfExistingKeyNames = new HtmlInputHidden(); _hfExistingKeyNames.AddCssClass("js-existing-key-names"); _hfExistingKeyNames.ID = this.ID + "_hfExistingKeyNames"; Controls.Add(_hfExistingKeyNames); _lAttributeActionTitle = new Literal(); _lAttributeActionTitle.ID = "lAttributeActionTitle"; Controls.Add(_lAttributeActionTitle); _validationSummary = new ValidationSummary(); _validationSummary.ID = "valiationSummary"; _validationSummary.CssClass = "alert alert-danger"; _validationSummary.HeaderText = "Please Correct the Following"; Controls.Add(_validationSummary); _tbName = new RockTextBox(); _tbName.ID = "tbName"; _tbName.Label = "Name"; _tbName.Required = true; Controls.Add(_tbName); _tbDescription = new RockTextBox(); _tbDescription.Label = "Description"; _tbDescription.ID = "tbDescription"; _tbDescription.TextMode = TextBoxMode.MultiLine; _tbDescription.Rows = 3; Controls.Add(_tbDescription); _cpCategories = new CategoryPicker(); _cpCategories.ID = "cpCategories_" + this.ID.ToString(); _cpCategories.Label = "Categories"; _cpCategories.AllowMultiSelect = true; _cpCategories.EntityTypeId = EntityTypeCache.Read(typeof(Rock.Model.Attribute)).Id; _cpCategories.EntityTypeQualifierColumn = "EntityTypeId"; Controls.Add(_cpCategories); _tbKey = new RockTextBox(); _tbKey.ID = "tbKey"; _tbKey.Label = "Key"; _tbKey.Required = true; Controls.Add(_tbKey); _cvKey = new CustomValidator(); _cvKey.ID = "cvKey"; _cvKey.ControlToValidate = _tbKey.ID; _cvKey.ClientValidationFunction = "validateKey"; _cvKey.ServerValidate += cvKey_ServerValidate; _cvKey.Display = ValidatorDisplay.Dynamic; _cvKey.CssClass = "validation-error help-inline"; _cvKey.ErrorMessage = "There is already an existing property with the key value you entered. Please select a different key value."; Controls.Add(_cvKey); _tbIconCssClass = new RockTextBox(); _tbIconCssClass.ID = "_tbIconCssClass"; _tbIconCssClass.Label = "Icon CSS Class"; Controls.Add(_tbIconCssClass); _cbRequired = new RockCheckBox(); _cbRequired.ID = "cbRequired"; _cbRequired.Label = "Required"; _cbRequired.Text = "Require a value"; Controls.Add(_cbRequired); _cbShowInGrid = new RockCheckBox(); _cbShowInGrid.ID = "cbShowInGrid"; _cbShowInGrid.Label = "Show in Grid"; _cbShowInGrid.Text = "Yes"; _cbShowInGrid.Help = "If selected, this attribute will be included in a grid."; Controls.Add(_cbShowInGrid); _ddlFieldType = new RockDropDownList(); _ddlFieldType.ID = "ddlFieldType"; _ddlFieldType.Label = "Field Type"; _ddlFieldType.AutoPostBack = true; _ddlFieldType.SelectedIndexChanged += _ddlFieldType_SelectedIndexChanged; Controls.Add(_ddlFieldType); if (!Page.IsPostBack) { _ddlFieldType.DataValueField = "Id"; _ddlFieldType.DataTextField = "Name"; _ddlFieldType.DataSource = FieldTypeCache.All(); _ddlFieldType.DataBind(); } _phQualifiers = new PlaceHolder(); _phQualifiers.ID = "phQualifiers"; _phQualifiers.EnableViewState = false; Controls.Add(_phQualifiers); _phDefaultValue = new PlaceHolder(); _phDefaultValue.ID = "phDefaultValue"; _phDefaultValue.EnableViewState = false; Controls.Add(_phDefaultValue); _btnSave = new LinkButton(); _btnSave.ID = "btnSave"; _btnSave.Text = "OK"; _btnSave.CssClass = "btn btn-primary"; _btnSave.Click += btnSave_Click; Controls.Add(_btnSave); _btnCancel = new LinkButton(); _btnCancel.ID = "btnCancel"; _btnCancel.Text = "Cancel"; _btnCancel.CssClass = "btn btn-link"; _btnCancel.CausesValidation = false; _btnCancel.Click += btnCancel_Click; Controls.Add(_btnCancel); _tbName.Attributes["onblur"] = string.Format("populateAttributeKey('{0}','{1}')", _tbName.ClientID, _tbKey.ClientID); _controlsLoaded = true; } }