/// <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(); Controls.Clear(); RockControlHelper.CreateChildControls(this, Controls); _mfpMergeFields = new MergeFieldPicker(); _mfpMergeFields.ID = string.Format("mfpMergeFields_{0}", this.ID); _mfpMergeFields.SelectItem += MergeFields_SelectItem; Controls.Add(_mfpMergeFields); }
/// <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(); Controls.Clear(); RockControlHelper.CreateChildControls( this, Controls ); _mfpMergeFields = new MergeFieldPicker(); _mfpMergeFields.ID = string.Format( "mfpMergeFields_{0}", this.ID ); _mfpMergeFields.SelectItem += MergeFields_SelectItem; Controls.Add( _mfpMergeFields ); }
/// <summary> /// Formats the selected value (node path) into a liquid merge field. /// </summary> /// <param name="selectedValue">The selected value.</param> /// <returns></returns> public static string FormatSelectedValue(string selectedValue) { var idParts = selectedValue.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (idParts.Count > 0) { if (idParts.Count == 2 && idParts[0] == "GlobalAttribute") { return(string.Format("{{{{ 'Global' | Attribute:'{0}' }}}}", idParts[1])); } if (idParts.Count == 1 && idParts[0].StartsWith("AdditionalMergeField")) { string mFields = idParts[0].Replace("AdditionalMergeField_", "").Replace("AdditionalMergeFields_", ""); if (mFields.IsNotNullOrWhiteSpace()) { string beginFor = "{% for field in AdditionalFields %}"; string endFor = "{% endfor %}"; var mergeFields = String.Join("", mFields.Split(new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries) .Select(f => "{{ field." + f + "}}")); return($"{beginFor}{mergeFields}{endFor}"); } } if (idParts.Count == 1) { if (idParts[0] == "Campuses") { return(@" {% for campus in Campuses %} <p> Name: {{ campus.Name }}<br/> Description: {{ campus.Description }}<br/> Is Active: {{ campus.IsActive }}<br/> Short Code: {{ campus.ShortCode }}<br/> Url: {{ campus.Url }}<br/> Phone Number: {{ campus.PhoneNumber }}<br/> Service Times: {% for serviceTime in campus.ServiceTimes %} {{ serviceTime.Day }} {{ serviceTime.Time }}, {% endfor %} <br/> {% endfor %} "); } if (idParts[0] == "Date") { return("{{ 'Now' | Date:'MM/dd/yyyy' }}"); } if (idParts[0] == "Time") { return("{{ 'Now' | Date:'hh:mm:ss tt' }}"); } if (idParts[0] == "DayOfWeek") { return("{{ 'Now' | Date:'dddd' }}"); } if (idParts[0] == "PageParameter") { return("{{ PageParameter.[Enter Page Parameter Name Here] }}"); } } var workingParts = new List <string>(); // Get the root type int pathPointer = 0; EntityTypeCache entityType = null; while (entityType == null && pathPointer < idParts.Count()) { string item = idParts[pathPointer]; string[] itemParts = item.Split(new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries); string itemName = itemParts.Length > 1 ? itemParts[0] : string.Empty; string mergeFieldId = itemParts.Length > 1 ? itemParts[1] : item; var entityTypeInfo = MergeFieldPicker.GetEntityTypeInfoFromMergeFieldId(mergeFieldId); entityType = entityTypeInfo?.EntityType; workingParts.Add(entityType != null ? (itemName != string.Empty ? itemName : entityType.FriendlyName.Replace(" ", string.Empty)) : idParts[pathPointer]); pathPointer++; } if (entityType != null) { Type type = entityType.GetEntityType(); var formatString = "{0}"; // Traverse the Property path bool itemIsCollection = false; bool lastItemIsProperty = true; while (idParts.Count > pathPointer) { string propertyName = idParts[pathPointer]; workingParts.Add(propertyName); var childProperty = type.GetProperty(propertyName); if (childProperty != null) { lastItemIsProperty = true; type = childProperty.PropertyType; if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ICollection <>) && type.GetGenericArguments().Length == 1) { string propertyNameSingularized = propertyName.Singularize(); string forString = string.Format("<% for {0} in {1} %> {{0}} <% endfor %>", propertyNameSingularized, workingParts.AsDelimited(".")); workingParts.Clear(); workingParts.Add(propertyNameSingularized); formatString = string.Format(formatString, forString); type = type.GetGenericArguments()[0]; itemIsCollection = true; } else { itemIsCollection = false; } } else { lastItemIsProperty = false; } pathPointer++; } string itemString = string.Empty; if (!itemIsCollection) { if (lastItemIsProperty) { itemString = string.Format("<< {0} >>", workingParts.AsDelimited(".")); } else { string partPath = workingParts.Take(workingParts.Count - 1).ToList().AsDelimited("."); var partItem = workingParts.Last(); if (type == typeof(Rock.Model.Person) && partItem == "Campus") { itemString = string.Format("{{{{ {0} | Campus | Property:'Name' }}}}", partPath); } else { itemString = string.Format("{{{{ {0} | Attribute:'{1}' }}}}", partPath, partItem); } } } return(string.Format(formatString, itemString).Replace("<", "{").Replace(">", "}")); } return(string.Format("{{{{ {0} }}}}", idParts.AsDelimited("."))); } return(string.Empty); }
/// <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(); Controls.Clear(); tbFrom = new RockTextBox(); tbFrom.ID = string.Format("tbFrom_{0}", this.ID); tbFrom.MaxLength = 11; tbFrom.Label = "From"; tbFrom.Help = "The name the recipient will see as the message originating from."; Controls.Add(tbFrom); lFrom = new RockLiteral(); lFrom.ID = string.Format("lFrom_{0}", this.ID); lFrom.Label = "From"; Controls.Add(lFrom); rcwMessage = new RockControlWrapper(); rcwMessage.ID = string.Format("rcwMessage_{0}", this.ID); rcwMessage.Label = "Message"; rcwMessage.Help = "<span class='tip tip-lava'></span>"; Controls.Add(rcwMessage); mfpMessage = new MergeFieldPicker(); mfpMessage.ID = string.Format("mfpMergeFields_{0}", this.ID); mfpMessage.MergeFields.Clear(); mfpMessage.MergeFields.Add("GlobalAttribute"); mfpMessage.MergeFields.Add("Rock.Model.Person"); mfpMessage.CssClass += " pull-right margin-b-sm"; mfpMessage.SelectItem += mfpMergeFields_SelectItem; rcwMessage.Controls.Add(mfpMessage); tbMessage = new RockTextBox(); tbMessage.ID = string.Format("tbTextMessage_{0}", this.ID); tbMessage.TextMode = TextBoxMode.MultiLine; tbMessage.Rows = 3; rcwMessage.Controls.Add(tbMessage); cbAppendUserInfo = new RockCheckBox(); cbAppendUserInfo.ID = string.Format("cbAppendUserInfo_{0}", this.ID); cbAppendUserInfo.Label = "Add organisation footer to message?"; cbAppendUserInfo.Help = "Append your message with your organisation's custom mesage or just the name of your organisation?"; cbAppendUserInfo.Checked = true; Controls.Add(cbAppendUserInfo); hfSenderGuid = new HiddenField(); hfSenderGuid.ID = string.Format( "hfSenderGuid_{0}", this.ID ); Controls.Add( hfSenderGuid ); }