public static Plugin Apply(this Plugin plugin, PluginEditInput input, bool?enabled)
 {
     return(new Plugin(plugin.Site.ID, plugin.ID, plugin.VirtualPath, enabled.HasValue ? enabled.Value : input.Enabled.GetValueOrDefault(plugin.Enabled), input.PropertyValues == null ? plugin.ExtendedProperties : input.GetExtendedProperties(plugin.ExtendedProperties)));
 }
Exemple #2
0
        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());
        }