using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; namespace umbraco.editorControls { /// /// Extension methods for the Prevalue Editor /// public static class PrevalueEditorExtensions { /// /// Adds the prevalue controls. /// /// The collection. /// The controls. public static void AddPrevalueControls(this ControlCollection collection, params Control[] controls) { foreach (var control in controls) { collection.Add(control); } } /// /// Adds the prevalue row heading. /// /// The writer. /// The heading. public static void AddPrevalueHeading(this HtmlTextWriter writer, string heading) { writer.AddAttribute(HtmlTextWriterAttribute.Class, "row clearfix"); writer.RenderBeginTag(HtmlTextWriterTag.Div); // start 'row' writer.RenderBeginTag(HtmlTextWriterTag.H3); // start 'h3' writer.Write(heading); writer.RenderEndTag(); // end 'h3' writer.RenderEndTag(); // end 'row' } /// /// Adds a new row to the Prevalue Editor. /// /// The HtmlTextWriter. /// The label for the field. /// The controls for the field. public static void AddPrevalueRow(this HtmlTextWriter writer, string label, params Control[] controls) { writer.AddPrevalueRow(label, string.Empty, controls); } /// /// Adds a new row to the Prevalue Editor, (with an optional description). /// /// The HtmlTextWriter. /// The label for the field. /// The description for the field. /// The controls for the field. public static void AddPrevalueRow(this HtmlTextWriter writer, string label, string description, params Control[] controls) { writer.AddAttribute(HtmlTextWriterAttribute.Class, "row clearfix"); writer.RenderBeginTag(HtmlTextWriterTag.Div); // start 'row' writer.AddAttribute(HtmlTextWriterAttribute.Class, "label"); writer.RenderBeginTag(HtmlTextWriterTag.Div); // start 'label' var lbl = new HtmlGenericControl("label") { InnerText = label }; if (controls.Length > 0 && !string.IsNullOrEmpty(controls[0].ClientID)) { lbl.Attributes.Add("for", controls[0].ClientID); } lbl.RenderControl(writer); writer.RenderEndTag(); // end 'label' writer.AddAttribute(HtmlTextWriterAttribute.Class, "field"); writer.RenderBeginTag(HtmlTextWriterTag.Div); // start 'field' foreach (var control in controls) { control.RenderControl(writer); } writer.RenderEndTag(); // end 'field' if (!string.IsNullOrEmpty(description)) { writer.AddAttribute(HtmlTextWriterAttribute.Class, "description"); writer.RenderBeginTag(HtmlTextWriterTag.Div); // start 'description' Label desc = new Label() { Text = description }; desc.RenderControl(writer); writer.RenderEndTag(); // end 'description' } writer.RenderEndTag(); // end 'row' } } }