public static PropertyAppearance GetAppearance(this PluginContainer pluginContainer, string propertyName) { object appearanceValue = pluginContainer.GetPropertyDefinition <object>(propertyName, "Appearance"); if (appearanceValue == null) { return(null); } if (appearanceValue is PropertyAppearance) { PropertyAppearance propertyAppearance = (PropertyAppearance)appearanceValue; propertyAppearance.Width = verifyWidth(propertyAppearance.Width); propertyAppearance.Height = verifyHeight(propertyAppearance.Height); return(propertyAppearance); } IDictionary <string, object> values = new RouteValueDictionary(appearanceValue); object widthValue = values.ContainsKey("Width") ? values["Width"] : null; object heightValue = values.ContainsKey("Height") ? values["Height"] : null; if (widthValue != null || heightValue != null) { return new PropertyAppearance() { Width = verifyWidth(widthValue), Height = verifyHeight(heightValue) } } ; return(null); }
public static string PluginPropertyFieldsets(this HtmlHelper htmlHelper, Plugin plugin, PluginEditInput pluginEditInput, Func <string, string, string> localize) { StringBuilder outputBuilder = new StringBuilder(); IEnumerable <ExtendedProperty> editInputProperties = pluginEditInput.GetExtendedProperties(plugin.ExtendedProperties); IEnumerable <IGrouping <KeyValuePair <string, int>, ExtendedProperty> > extendedPropertyGroupings = plugin.ExtendedProperties.GroupBy( ps => plugin.GetGroup(ps.Name) != null ? new KeyValuePair <string, int>(plugin.GetGroup(ps.Name).Name, plugin.GetGroup(ps.Name).Order) : new KeyValuePair <string, int>(localize("Plugin.OtherPropertyGroup", "Other"), int.MaxValue)); foreach (var extendedPropertyGrouping in extendedPropertyGroupings.OrderBy(psg => psg.Key.Value)) { if (extendedPropertyGroupings.Count(epg => epg.Key.Key != "Other") > 0) { outputBuilder.AppendFormat("<h4>{0}</h4>", extendedPropertyGrouping.Key.Key.CleanText()); } foreach (var extendedProperty in extendedPropertyGrouping.OrderBy(ps => plugin.GetOrder(ps.Name))) { string extendedPropertyName = extendedProperty.Name; ExtendedProperty editInputProperty = editInputProperties.FirstOrDefault(ep => ep.Name == extendedPropertyName); object extendedPropertyValue = editInputProperty != null ? editInputProperty.Value : extendedProperty.Value; bool labelFirst = true; string fieldName = string.Format("ps_{0}", extendedPropertyName.CleanAttribute()); Func <string> fieldRenderField = () => extendedPropertyName.EndsWith("Password") && extendedProperty.Type == typeof(string) ? htmlHelper.Password(fieldName, extendedPropertyValue, new { id = fieldName }) : htmlHelper.TextBox(fieldName, extendedPropertyValue, new { id = fieldName }); var fieldset = new TagBuilder("fieldset"); string extendedPropertyValidationKey = string.Format("PluginPropertiesInput.{0}", extendedProperty.Name); if (htmlHelper.ViewData.ModelState.ContainsKey(extendedPropertyValidationKey) && htmlHelper.ViewData.ModelState[extendedPropertyValidationKey].Errors.Count > 0) { fieldset.AddCssClass("error"); } fieldset.Attributes["id"] = string.Format("psf_{0}", extendedPropertyName.CleanAttribute()); if (extendedPropertyValue is bool) { labelFirst = false; fieldRenderField = () => htmlHelper.CheckBox(fieldName, (bool)extendedPropertyValue, null, null); } else if (extendedPropertyValue is DateTime) { fieldset.AddCssClass("datetime"); } else { fieldset.AddCssClass("textbox"); } PropertyAppearance appearance = plugin.GetAppearance(extendedPropertyName); if (appearance != null) { if (!string.IsNullOrEmpty(appearance.Width)) { fieldset.Attributes["style"] = string.Format("width:{0}", appearance.Width); fieldset.AddCssClass("hasWidth"); } //TODO: (erikpo) Add height (multiline) when appropriate } fieldset.InnerHtml = htmlHelper.fieldWithLabel( fieldName.CleanAttribute(), fieldRenderField, (plugin.GetLabelText(extendedPropertyName) ?? extendedPropertyName).CleanText().AutoAnchor(), labelFirst, true ); outputBuilder.Append(fieldset.ToString()); } } return(outputBuilder.ToString()); }