public static MvcHtmlString NgButton <TModel>(this HtmlHelper <TModel> htmleHelper, NgButton ngButton) { // --- Create the button ngButton.CssClass(BsClass.Button); ngButton.CssClass(BsClass.ButtonTheme.From(ngButton.Theme)); // --- Add an optional icon if (!string.IsNullOrEmpty(ngButton.IconName)) { var iconSpan = new BsHtmlElement(HtmlTag.Span); iconSpan.CssClass(ngButton.IconName); if (ngButton.IconAlignment == BsIconAlignment.Left) { ngButton.AddChild(iconSpan); ngButton.AddChild(new HtmlText("\u00a0")); ngButton.AddChild(new HtmlText(ngButton.Text)); } else { ngButton.AddChild(new HtmlText(ngButton.Text)); ngButton.AddChild(new HtmlText("\u00a0")); ngButton.AddChild(iconSpan); } } else { ngButton.AddChild(new HtmlText(ngButton.Text)); } return(ngButton.Markup); }
public static MvcHtmlString NgSearchButton <TModel>(this HtmlHelper <TModel> htmleHelper, string ngModel, string id = "Search", string name = "Search", string placeHolder = "Search") { // --- Create the input tag var inputGroup = new BsHtmlElement(HtmlTag.Div).CssClass(BsClass.Control.InputGroup); var input = new BsHtmlElement(HtmlTag.Input); input.CssClass(BsClass.Control.FormControl) .Attr(HtmlAttr.Id, id) .Attr(HtmlAttr.Name, name) .Attr(HtmlAttr.Placeholder, placeHolder) .Attr(NgTag.NgModel, ngModel); inputGroup.AddChild(input); var span = new BsHtmlElement(HtmlTag.Span).CssClass(BsClass.Control.InputGroupAddOn); inputGroup.AddChild(span); span.AddChild(new BsHtmlElement(HtmlTag.Span).CssClass(BsClass.GlyphFa.Search)); return(inputGroup.Markup); }
/// <summary> /// Renders a cancel button for a modal dialog /// </summary> /// <param name="ngClick">ng-click attribute value (cancel() by default)</param> /// <param name="theme">Button theme</param> /// <param name="buttonText">Button text (Resources.Gen_Cancel by default)</param> public MvcHtmlString CancelButton(string ngClick = null, BsButtonTheme theme = BsButtonTheme.Default, string buttonText = null) { if (ngClick == null) { ngClick = "cancel()"; } if (buttonText == null) { buttonText = Resources.Gen_Cancel; } var button = new BsHtmlElement(HtmlTag.Button); button .CssClass(BsClass.Button) .CssClass(BsClass.ButtonTheme.From(theme)) .Attr(NgTag.NgClick, ngClick); button.AddChild(new HtmlText(buttonText)); return(button.Markup); }
/// <summary> /// Renders a cancel button for a modal dialog /// </summary> /// <param name="ngClick">ng-click attribute value (cancel() by default)</param> /// <param name="theme">Button theme</param> /// <param name="buttonText">Button text (Resources.Gen_Cancel by default)</param> public MvcHtmlString OkButton(string ngClick = null, BsButtonTheme theme = BsButtonTheme.Success, string buttonText = null) { if (ngClick == null) { ngClick = "ok()"; } if (buttonText == null) { buttonText = Resources.Gen_Ok; } var button = new BsHtmlElement(HtmlTag.Button); button .CssClass(BsClass.Button) .CssClass(BsClass.ButtonTheme.From(theme)) .Attr(NgTag.NgClick, ngClick) .Attr(NgTag.NgDisabled, _form.FormName + ".$invalid || disableOk"); button.AddChild(new HtmlText(buttonText)); return(button.Markup); }
/// <summary> /// Builds a horizontal static text control /// </summary> /// <param name="modelMetadata">Model metadata</param> public MvcHtmlString BuildHorizontalStatic(ModelMetadata modelMetadata) { // --- The form group that encapsulates the label and the control var propName = CamelCase(modelMetadata.PropertyName); var formGroup = new BsFormGroup { Depth = _formBuilder.Depth + 1 }; var label = CreateTextLabel(modelMetadata); var staticDiv = new BsHtmlElement(HtmlTag.Div); staticDiv.ApplyColumnWidths(null, _formBuilder.BsForm.InputWidthXs, _formBuilder.BsForm.InputWidthSm, _formBuilder.BsForm.InputWidthMd, _formBuilder.BsForm.InputWidthLg); var staticText = new BsHtmlElement(HtmlTag.P); staticText.CssClass(BsClass.Control.Static); staticText.AddChild(new HtmlText(modelMetadata.Model.ToString())); staticDiv.AddChild(staticText); var hidden = new BsHtmlElement(HtmlTag.Input) .Attr(HtmlAttr.Type, "hidden") .Attr(HtmlAttr.Id, propName) .Attr(HtmlAttr.Name, propName) .Attr(NgTag.NgModel, string.Format("model.{0}", propName)); if (modelMetadata.Model != null) { var modelValue = modelMetadata.Model.ToString(); hidden .Attr(HtmlAttr.Value, modelValue) .Attr(NgTag.NgInit, string.Format("model.{0}={1}", propName, JsonConvert.SerializeObject(modelMetadata.Model))); } formGroup.AddChild(label).AddChild(staticDiv).AddChild(hidden); return(formGroup.Markup); }
/// <summary> /// Builds a horizontal input control /// </summary> /// <param name="modelMetadata">Model metadata</param> /// <param name="inputTagType">Type of the input tag</param> /// <param name="autoFocus">Autofocus type</param> /// <param name="validationOption">Validation type</param> public MvcHtmlString BuildHorizontalInput(ModelMetadata modelMetadata, InputTagType inputTagType, AutoFocus autoFocus, ValidationOption validationOption) { // --- The form group that encapsulates the label and the control var propName = CamelCase(modelMetadata.PropertyName); var formGroup = new BsFormGroup { Depth = _formBuilder.Depth + 1 }; var condition = string.Format("{0}{1}", "{0}.{1}.$invalid", validationOption == ValidationOption.WhenDirty ? " && {0}.{1}.$dirty" : ""); formGroup.Attr(NgTag.NgClass, string.Format("{{'has-error': " + condition + ", 'has-feedback': " + condition + "}}", _formBuilder.BsForm.FormName, propName)); if (inputTagType == InputTagType.Text) { var label = CreateTextLabel(modelMetadata); var inputDiv = new BsHtmlElement(HtmlTag.Div); inputDiv.ApplyColumnWidths(null, _formBuilder.BsForm.InputWidthXs, _formBuilder.BsForm.InputWidthSm, _formBuilder.BsForm.InputWidthMd, _formBuilder.BsForm.InputWidthLg); var input = CreateInput(inputTagType, autoFocus, modelMetadata, propName); // --- Assemble the elements formGroup.AddChild(label).AddChild(inputDiv); inputDiv.AddChild(input); // --- Add optional help text if (!string.IsNullOrEmpty(modelMetadata.Description)) { var helpText = new BsHtmlElement(HtmlTag.Span); helpText.CssClass(BsClass.Control.Help); helpText.AddChild(new HtmlText(modelMetadata.Description)); inputDiv.AddChild(helpText); } // --- Create validation tags AddValidationTags(inputDiv, modelMetadata, validationOption); } else if (inputTagType == InputTagType.CheckBox) { var sizingDiv = new BsHtmlElement(HtmlTag.Div); sizingDiv.ApplyColumnWidths(null, _formBuilder.BsForm.InputWidthXs, _formBuilder.BsForm.InputWidthSm, _formBuilder.BsForm.InputWidthMd, _formBuilder.BsForm.InputWidthLg); sizingDiv.ApplyColumnOffsets(null, _formBuilder.BsForm.LabelWidthXs, _formBuilder.BsForm.LabelWidthSm, _formBuilder.BsForm.LabelWidthMd, _formBuilder.BsForm.LabelWidthLg); var checkBoxDiv = new BsHtmlElement(HtmlTag.Div).CssClass(BsClass.Control.CheckBox); var label = new BsHtmlElement(HtmlTag.Label); var input = CreateInput(inputTagType, autoFocus, modelMetadata, propName); input.Attr(modelMetadata.Model != null && modelMetadata.Model.ToString().ToLower() == "true", HtmlAttr.Checked, HtmlAttr.Checked); var hiddenInput = new BsHtmlElement(HtmlTag.Input) .Attr(HtmlAttr.Name, modelMetadata.PropertyName) .Attr(HtmlAttr.Type, HtmlInputType.Hidden) .Attr(HtmlAttr.Value, "false"); // --- Assemble the elements formGroup.AddChild(sizingDiv); sizingDiv.AddChild(checkBoxDiv); checkBoxDiv.AddChild(label); label .AddChild(input) .AddChild(new HtmlText(modelMetadata.DisplayName ?? modelMetadata.PropertyName)) .AddChild(hiddenInput); } return(formGroup.Markup); }