Permalink
Browse files

Added support to Dictionary in HtmlAttributes (All other files)

  • Loading branch information...
1 parent 847e8e4 commit 3ac00348accb54fa62032e024573a903e690e31e @luizbon luizbon committed Jun 14, 2013
Showing with 435 additions and 9 deletions.
  1. +1 −0 TwitterBootstrapMVC/ControlInterfaces/IBootstrapButton.cs
  2. +1 −0 TwitterBootstrapMVC/ControlInterfaces/IBootstrapCheckBox.cs
  3. +1 −0 TwitterBootstrapMVC/ControlInterfaces/IBootstrapDisplayText.cs
  4. +1 −0 TwitterBootstrapMVC/ControlInterfaces/IBootstrapDropDownList.cs
  5. +1 −0 TwitterBootstrapMVC/ControlInterfaces/IBootstrapFile.cs
  6. +1 −0 TwitterBootstrapMVC/ControlInterfaces/IBootstrapLabel.cs
  7. +1 −0 TwitterBootstrapMVC/ControlInterfaces/IBootstrapListBox.cs
  8. +1 −0 TwitterBootstrapMVC/ControlInterfaces/IBootstrapRadioButton.cs
  9. +1 −0 TwitterBootstrapMVC/ControlInterfaces/IBootstrapTextArea.cs
  10. +1 −0 TwitterBootstrapMVC/ControlInterfaces/IBootstrapTextBox.cs
  11. +6 −0 TwitterBootstrapMVC/Controls/Accordion.cs
  12. +6 −0 TwitterBootstrapMVC/Controls/Alert.cs
  13. +6 −0 TwitterBootstrapMVC/Controls/BootstrapActionLink.cs
  14. +6 −0 TwitterBootstrapMVC/Controls/BootstrapButton.cs
  15. +6 −0 TwitterBootstrapMVC/Controls/BootstrapCheckBox.cs
  16. +6 −0 TwitterBootstrapMVC/Controls/BootstrapControlGroupDisplayText.cs
  17. +6 −0 TwitterBootstrapMVC/Controls/BootstrapDropDownList.cs
  18. +9 −3 TwitterBootstrapMVC/Controls/BootstrapDropDownMenu.cs
  19. +6 −0 TwitterBootstrapMVC/Controls/BootstrapFile.cs
  20. +9 −3 TwitterBootstrapMVC/Controls/BootstrapIcon.cs
  21. +6 −0 TwitterBootstrapMVC/Controls/BootstrapLabel.cs
  22. +6 −0 TwitterBootstrapMVC/Controls/BootstrapLink.cs
  23. +6 −0 TwitterBootstrapMVC/Controls/BootstrapListBox.cs
  24. +6 −0 TwitterBootstrapMVC/Controls/BootstrapRadioButton.cs
  25. +6 −0 TwitterBootstrapMVC/Controls/BootstrapTextArea.cs
  26. +6 −0 TwitterBootstrapMVC/Controls/ButtonGroup.cs
  27. +6 −0 TwitterBootstrapMVC/Controls/Carousel.cs
  28. +6 −0 TwitterBootstrapMVC/Controls/Form.cs
  29. +6 −0 TwitterBootstrapMVC/Controls/FormActions.cs
  30. +8 −1 TwitterBootstrapMVC/Controls/Modal.cs
  31. +6 −0 TwitterBootstrapMVC/Controls/Table.cs
  32. +6 −0 TwitterBootstrapMVC/Controls/TableRow.cs
  33. +6 −0 TwitterBootstrapMVC/Controls/ToolBar.cs
  34. +7 −2 TwitterBootstrapMVC/Infrastructure/HtmlElement.cs
  35. +272 −0 TwitterBootstrapMVC/Properties/BootstrapActionLinkButton.cs
View
1 TwitterBootstrapMVC/ControlInterfaces/IBootstrapButton.cs
@@ -13,6 +13,7 @@ public interface IBootstrapButton<T> : IHtmlString
T Text(string text);
T Name(string name);
T Value(string value);
+ T HtmlAttributes(IDictionary<string, object> htmlAttributes);
T HtmlAttributes(object htmlAttributes);
T Size(ButtonSize size);
T Style(ButtonStyle style);
View
1 TwitterBootstrapMVC/ControlInterfaces/IBootstrapCheckBox.cs
@@ -12,6 +12,7 @@ public interface IBootstrapCheckBox : IHtmlString
{
IBootstrapCheckBox Id(string id);
IBootstrapCheckBox IsChecked(bool isChecked);
+ IBootstrapCheckBox HtmlAttributes(IDictionary<string, object> htmlAttributes);
IBootstrapCheckBox HtmlAttributes(object htmlAttributes);
IBootstrapCheckBox Tooltip(TooltipConfiguration configuration);
IBootstrapCheckBox Tooltip(string text);
View
1 TwitterBootstrapMVC/ControlInterfaces/IBootstrapDisplayText.cs
@@ -9,6 +9,7 @@ namespace TwitterBootstrapMVC.ControlInterfaces
{
public interface IBootstrapDisplayText : IHtmlString
{
+ IBootstrapDisplayText HtmlAttributes(IDictionary<string, object> htmlAttributes);
IBootstrapDisplayText HtmlAttributes(object htmlAttributes);
IBootstrapLabel Label();
View
1 TwitterBootstrapMVC/ControlInterfaces/IBootstrapDropDownList.cs
@@ -14,6 +14,7 @@ public interface IBootstrapDropDownList : IHtmlString
{
IBootstrapDropDownList Id(string id);
IBootstrapDropDownList OptionLabel(string optionLabel);
+ IBootstrapDropDownList HtmlAttributes(IDictionary<string, object> htmlAttributes);
IBootstrapDropDownList HtmlAttributes(object htmlAttributes);
IBootstrapDropDownList SelectedValue(object value);
IBootstrapDropDownList Prepend(string prependString);
View
1 TwitterBootstrapMVC/ControlInterfaces/IBootstrapFile.cs
@@ -10,6 +10,7 @@ namespace TwitterBootstrapMVC.ControlInterfaces
public interface IBootstrapFile : IHtmlString
{
IBootstrapFile Id(string id);
+ IBootstrapFile HtmlAttributes(IDictionary<string, object> htmlAttributes);
IBootstrapFile HtmlAttributes(object htmlAttributes);
IBootstrapFile HelpText();
IBootstrapFile HelpText(string text);
View
1 TwitterBootstrapMVC/ControlInterfaces/IBootstrapLabel.cs
@@ -14,6 +14,7 @@ public interface IBootstrapLabel : IHtmlString
{
IBootstrapLabel LabelText(string labelText);
IBootstrapLabel ShowRequiredStar(bool showRequiredStar);
+ IBootstrapLabel HtmlAttributes(IDictionary<string, object> htmlAttributes);
IBootstrapLabel HtmlAttributes(object htmlAttributes);
[EditorBrowsable(EditorBrowsableState.Never)]
View
1 TwitterBootstrapMVC/ControlInterfaces/IBootstrapListBox.cs
@@ -13,6 +13,7 @@ namespace TwitterBootstrapMVC.ControlInterfaces
public interface IBootstrapListBox : IHtmlString
{
IBootstrapListBox Id(string id);
+ IBootstrapListBox HtmlAttributes(IDictionary<string, object> htmlAttributes);
IBootstrapListBox HtmlAttributes(object htmlAttributes);
IBootstrapListBox HelpText();
IBootstrapListBox HelpText(string text);
View
1 TwitterBootstrapMVC/ControlInterfaces/IBootstrapRadioButton.cs
@@ -12,6 +12,7 @@ public interface IBootstrapRadioButton : IHtmlString
{
IBootstrapRadioButton Id(string id);
IBootstrapRadioButton IsChecked(bool isChecked);
+ IBootstrapRadioButton HtmlAttributes(IDictionary<string, object> htmlAttributes);
IBootstrapRadioButton HtmlAttributes(object htmlAttributes);
IBootstrapRadioButton Tooltip(TooltipConfiguration configuration);
IBootstrapRadioButton Tooltip(string text);
View
1 TwitterBootstrapMVC/ControlInterfaces/IBootstrapTextArea.cs
@@ -14,6 +14,7 @@ public interface IBootstrapTextArea : IHtmlString
IBootstrapTextArea Value(string value);
IBootstrapTextArea Rows(int rows);
IBootstrapTextArea Columns(int columns);
+ IBootstrapTextArea HtmlAttributes(IDictionary<string, object> htmlAttributes);
IBootstrapTextArea HtmlAttributes(object htmlAttributes);
IBootstrapTextArea Tooltip(TooltipConfiguration configuration);
IBootstrapTextArea Tooltip(string text);
View
1 TwitterBootstrapMVC/ControlInterfaces/IBootstrapTextBox.cs
@@ -15,6 +15,7 @@ public interface IBootstrapTextBox<T> : IHtmlString
{
T Id(string id);
T Value(object value);
+ T HtmlAttributes(IDictionary<string, object> htmlAttributes);
T HtmlAttributes(object htmlAttributes);
T Format(string format);
T Placeholder();
View
6 TwitterBootstrapMVC/Controls/Accordion.cs
@@ -24,6 +24,12 @@ public Accordion(string id)
EnsureHtmlAttribute("id", this.Id);
}
+ public Accordion HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ SetHtmlAttributes(htmlAttributes);
+ return this;
+ }
+
public Accordion HtmlAttributes(object htmlAttributes)
{
SetHtmlAttributes(htmlAttributes);
View
6 TwitterBootstrapMVC/Controls/Alert.cs
@@ -47,6 +47,12 @@ public Alert IsLongMessage()
return this;
}
+ public Alert HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ SetHtmlAttributes(htmlAttributes);
+ return this;
+ }
+
public Alert HtmlAttributes(object htmlAttributes)
{
SetHtmlAttributes(htmlAttributes);
View
6 TwitterBootstrapMVC/Controls/BootstrapActionLink.cs
@@ -140,6 +140,12 @@ public BootstrapActionLink RouteName(string routeName)
return this;
}
+ public BootstrapActionLink HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ this.htmlAttributes = htmlAttributes;
+ return this;
+ }
+
public BootstrapActionLink HtmlAttributes(object htmlAttributes)
{
this.htmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
View
6 TwitterBootstrapMVC/Controls/BootstrapButton.cs
@@ -80,6 +80,12 @@ public T Value(string value)
return (T)this;
}
+ public T HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ this._model.htmlAttributes = htmlAttributes;
+ return (T)this;
+ }
+
public T HtmlAttributes(object htmlAttributes)
{
this._model.htmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
View
6 TwitterBootstrapMVC/Controls/BootstrapCheckBox.cs
@@ -50,6 +50,12 @@ public IBootstrapCheckBox IsChecked(bool isChecked)
return this;
}
+ public IBootstrapCheckBox HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ this._model.htmlAttributes = htmlAttributes;
+ return this;
+ }
+
public IBootstrapCheckBox HtmlAttributes(object htmlAttributes)
{
this._model.htmlAttributes = htmlAttributes.ToDictionary();
View
6 TwitterBootstrapMVC/Controls/BootstrapControlGroupDisplayText.cs
@@ -24,6 +24,12 @@ public BootstrapControlGroupDisplayText(HtmlHelper html, string htmlFieldName, M
this._model.metadata = metadata;
}
+ public IBootstrapDisplayText HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ this._model.htmlAttributes = htmlAttributes;
+ return this;
+ }
+
public IBootstrapDisplayText HtmlAttributes(object htmlAttributes)
{
this._model.htmlAttributes = htmlAttributes.ToDictionary();
View
6 TwitterBootstrapMVC/Controls/BootstrapDropDownList.cs
@@ -42,6 +42,12 @@ public IBootstrapDropDownList OptionLabel(string optionLabel)
return this;
}
+ public IBootstrapDropDownList HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ this._model.htmlAttributes = htmlAttributes;
+ return this;
+ }
+
public IBootstrapDropDownList HtmlAttributes(object htmlAttributes)
{
this._model.htmlAttributes = htmlAttributes.ToDictionary();
View
12 TwitterBootstrapMVC/Controls/BootstrapDropDownMenu.cs
@@ -16,7 +16,7 @@ public class BootstrapDropDownMenu : IHtmlString
{
private List<BootstrapDropDownMenuItem> _menuItems;
private string _alignToDirection;
- private object _htmlAttributes;
+ private IDictionary<string, object> _htmlAttributes;
private int? _maxHeight;
public BootstrapDropDownMenu()
@@ -43,12 +43,18 @@ public BootstrapDropDownMenu MaxHeight(int heightInPixels)
return this;
}
- public BootstrapDropDownMenu HtmlAttributes(object htmlAttributes)
+ public BootstrapDropDownMenu HtmlAttributes(IDictionary<string, object> htmlAttributes)
{
this._htmlAttributes = htmlAttributes;
return this;
}
+ public BootstrapDropDownMenu HtmlAttributes(object htmlAttributes)
+ {
+ this._htmlAttributes = htmlAttributes.ToDictionary();
+ return this;
+ }
+
/// <summary>
/// Allign menu to "right" or "left"
/// </summary>
@@ -66,7 +72,7 @@ public BootstrapDropDownMenu AlignTo(string direction)
public string ToHtmlString()
{
TagBuilder ul = new TagBuilder("ul");
- ul.MergeAttributes(_htmlAttributes.ToDictionary().FormatHtmlAttributes());
+ ul.MergeAttributes(_htmlAttributes.FormatHtmlAttributes());
if(_maxHeight.HasValue)
{
ul.AddCssStyle("max-height", _maxHeight.ToString() + "px");
View
6 TwitterBootstrapMVC/Controls/BootstrapFile.cs
@@ -31,6 +31,12 @@ public IBootstrapFile Id(string id)
return this;
}
+ public IBootstrapFile HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ this._model.htmlAttributes = htmlAttributes;
+ return this;
+ }
+
public IBootstrapFile HtmlAttributes(object htmlAttributes)
{
this._model.htmlAttributes = htmlAttributes.ToDictionary();
View
12 TwitterBootstrapMVC/Controls/BootstrapIcon.cs
@@ -14,7 +14,7 @@ public class BootstrapIcon : IHtmlString
{
private Icons _icon;
private bool _isWhite;
- private object _htmlAttributes;
+ private IDictionary<string, object> _htmlAttributes;
private TooltipConfiguration _tooltipConfiguration;
private PopoverConfiguration _popoverConfiguration;
private string _iconCustomClass;
@@ -41,12 +41,18 @@ public BootstrapIcon White()
return this;
}
- public BootstrapIcon HtmlAttributes(object htmlAttributes)
+ public BootstrapIcon HtmlAttributes(IDictionary<string, object> htmlAttributes)
{
this._htmlAttributes = htmlAttributes;
return this;
}
+ public BootstrapIcon HtmlAttributes(object htmlAttributes)
+ {
+ this._htmlAttributes = htmlAttributes.ToDictionary();
+ return this;
+ }
+
public BootstrapIcon Tooltip(TooltipConfiguration configuration)
{
this._tooltipConfiguration = configuration;
@@ -75,7 +81,7 @@ public BootstrapIcon Popover(string title, string content)
public virtual string ToHtmlString()
{
TagBuilder i = new TagBuilder("i");
- var attrs = _htmlAttributes.ToDictionary().FormatHtmlAttributes() ?? new Dictionary<string, object>();
+ var attrs = _htmlAttributes.FormatHtmlAttributes() ?? new Dictionary<string, object>();
if (_tooltipConfiguration != null) attrs.AddRange(_tooltipConfiguration.ToDictionary());
if (_popoverConfiguration != null) attrs.AddRange(_popoverConfiguration.ToDictionary());
i.MergeAttributes(attrs, true);
View
6 TwitterBootstrapMVC/Controls/BootstrapLabel.cs
@@ -37,6 +37,12 @@ public IBootstrapLabel ShowRequiredStar(bool showRequiredStar)
return this;
}
+ public IBootstrapLabel HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ this._labelModel.htmlAttributes = htmlAttributes;
+ return this;
+ }
+
public IBootstrapLabel HtmlAttributes(object htmlAttributes)
{
this._labelModel.htmlAttributes = htmlAttributes.ToDictionary();
View
6 TwitterBootstrapMVC/Controls/BootstrapLink.cs
@@ -34,6 +34,12 @@ public BootstrapLink Id(string id)
return this;
}
+ public BootstrapLink HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ this.htmlAttributes = htmlAttributes;
+ return this;
+ }
+
public BootstrapLink HtmlAttributes(object htmlAttributes)
{
this.htmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
View
6 TwitterBootstrapMVC/Controls/BootstrapListBox.cs
@@ -35,6 +35,12 @@ public IBootstrapListBox Id(string id)
return this;
}
+ public IBootstrapListBox HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ this._model.htmlAttributes = htmlAttributes;
+ return this;
+ }
+
public IBootstrapListBox HtmlAttributes(object htmlAttributes)
{
this._model.htmlAttributes = htmlAttributes.ToDictionary();
View
6 TwitterBootstrapMVC/Controls/BootstrapRadioButton.cs
@@ -40,6 +40,12 @@ public IBootstrapRadioButton IsChecked(bool isChecked)
return this;
}
+ public IBootstrapRadioButton HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ this._model.htmlAttributes = htmlAttributes;
+ return this;
+ }
+
public IBootstrapRadioButton HtmlAttributes(object htmlAttributes)
{
this._model.htmlAttributes = htmlAttributes.ToDictionary();
View
6 TwitterBootstrapMVC/Controls/BootstrapTextArea.cs
@@ -52,6 +52,12 @@ public IBootstrapTextArea Columns(int columns)
return this;
}
+ public IBootstrapTextArea HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ this._model.htmlAttributes = htmlAttributes;
+ return this;
+ }
+
public IBootstrapTextArea HtmlAttributes(object htmlAttributes)
{
this._model.htmlAttributes = htmlAttributes.ToDictionary();
View
6 TwitterBootstrapMVC/Controls/ButtonGroup.cs
@@ -14,6 +14,12 @@ public ButtonGroup()
EnsureClass("btn-group");
}
+ public ButtonGroup HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ SetHtmlAttributes(htmlAttributes);
+ return this;
+ }
+
public ButtonGroup HtmlAttributes(object htmlAttributes)
{
SetHtmlAttributes(htmlAttributes);
View
6 TwitterBootstrapMVC/Controls/Carousel.cs
@@ -60,6 +60,12 @@ public Carousel WithJs()
return this;
}
+ public Carousel HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ SetHtmlAttributes(htmlAttributes);
+ return this;
+ }
+
public Carousel HtmlAttributes(object htmlAttributes)
{
SetHtmlAttributes(htmlAttributes);
View
6 TwitterBootstrapMVC/Controls/Form.cs
@@ -81,6 +81,12 @@ public Form(Task<ActionResult> taskResult)
actionTypePassed = ActionTypePassed.HtmlTaskResult;
}
+ public Form HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ this.htmlAttributes = htmlAttributes;
+ return this;
+ }
+
public Form HtmlAttributes(object htmlAttributes)
{
this.htmlAttributes = htmlAttributes.ObjectToHtmlAttributesDictionary();
View
6 TwitterBootstrapMVC/Controls/FormActions.cs
@@ -14,6 +14,12 @@ public FormActions()
EnsureClass("form-actions");
}
+ public FormActions HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ SetHtmlAttributes(htmlAttributes);
+ return this;
+ }
+
public FormActions HtmlAttributes(object htmlAttributes)
{
SetHtmlAttributes(htmlAttributes);
View
9 TwitterBootstrapMVC/Controls/Modal.cs
@@ -1,4 +1,5 @@
-using TwitterBootstrapMVC.Infrastructure;
+using System.Collections.Generic;
+using TwitterBootstrapMVC.Infrastructure;
namespace TwitterBootstrapMVC
{
@@ -16,6 +17,12 @@ public Modal Id(string id)
return this;
}
+ public Modal HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ SetHtmlAttributes(htmlAttributes);
+ return this;
+ }
+
public Modal HtmlAttributes(object htmlAttributes)
{
SetHtmlAttributes(htmlAttributes);
View
6 TwitterBootstrapMVC/Controls/Table.cs
@@ -48,6 +48,12 @@ public Table Caption(string caption)
return this;
}
+ public Table HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ SetHtmlAttributes(htmlAttributes);
+ return this;
+ }
+
public Table HtmlAttributes(object htmlAttributes)
{
SetHtmlAttributes(htmlAttributes);
View
6 TwitterBootstrapMVC/Controls/TableRow.cs
@@ -34,6 +34,12 @@ public TableRow Style(RowColor style)
return this;
}
+ public TableRow HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ SetHtmlAttributes(htmlAttributes);
+ return this;
+ }
+
public TableRow HtmlAttributes(object htmlAttributes)
{
SetHtmlAttributes(htmlAttributes);
View
6 TwitterBootstrapMVC/Controls/ToolBar.cs
@@ -14,6 +14,12 @@ public ToolBar()
EnsureClass("btn-toolbar");
}
+ public ToolBar HtmlAttributes(IDictionary<string, object> htmlAttributes)
+ {
+ SetHtmlAttributes(htmlAttributes);
+ return this;
+ }
+
public ToolBar HtmlAttributes(object htmlAttributes)
{
SetHtmlAttributes(htmlAttributes);
View
9 TwitterBootstrapMVC/Infrastructure/HtmlElement.cs
@@ -91,12 +91,17 @@ protected void EnsureHtmlAttribute(string key, string value, bool replaceExistin
}
}
- protected void SetHtmlAttributes(object htmlAttributes)
+ protected void SetHtmlAttributes(IDictionary<string, object> htmlAttributes)
{
- this.htmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
+ this.htmlAttributes = htmlAttributes;
if (!string.IsNullOrEmpty(this.classToEnsure)) EnsureClass(this.classToEnsure);
}
+ protected void SetHtmlAttributes(object htmlAttributes)
+ {
+ this.SetHtmlAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
+ }
+
protected void MergeHtmlAttribute(string key, string value)
{
if (this.htmlAttributes != null)
View
272 TwitterBootstrapMVC/Properties/BootstrapActionLinkButton.cs
@@ -0,0 +1,272 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Web;
+using System.Web.Mvc;
+using System.Web.Mvc.Ajax;
+using System.Web.Mvc.Html;
+using System.Web.Routing;
+using TwitterBootstrapMVC.ControlInterfaces;
+using TwitterBootstrapMVC.ControlModels;
+using TwitterBootstrapMVC.Infrastructure;
+using TwitterBootstrapMVC.Infrastructure.Enums;
+using TwitterBootstrapMVC.TypeExtensions;
+
+namespace TwitterBootstrapMVC.Controls
+{
+ public class BootstrapActionLinkButton : BootstrapButtonBase<BootstrapActionLinkButton>
+ {
+ private HtmlHelper html;
+ private AjaxHelper ajax;
+ private ActionResult _result;
+ private Task<ActionResult> _taskResult;
+ private string _routeName;
+ private string _actionName;
+ private string _controllerName;
+ private string _protocol;
+ private string _hostName;
+ private string _fragment;
+ private AjaxOptions _ajaxOptions;
+ private RouteValueDictionary _routeValues;
+ private ActionTypePassed _actionTypePassed;
+
+ public BootstrapActionLinkButton(HtmlHelper html, string linkText, ActionResult result)
+ : base("")
+ {
+ this.html = html;
+ this._model.text = linkText;
+ this._result = result;
+ this._model.size = ButtonSize.Default;
+ this._model.style = ButtonStyle.Default;
+ this._actionTypePassed = ActionTypePassed.HtmlActionResult;
+ }
+
+ public BootstrapActionLinkButton(HtmlHelper html, string linkText, Task<ActionResult> taskResult)
+ : base("")
+ {
+ this.html = html;
+ this._model.text = linkText;
+ this._taskResult = taskResult;
+ this._model.size = ButtonSize.Default;
+ this._model.style = ButtonStyle.Default;
+ this._actionTypePassed = ActionTypePassed.HtmlTaskResult;
+ }
+
+ public BootstrapActionLinkButton(HtmlHelper html, string linkText, string actionName)
+ : base("")
+ {
+ this.html = html;
+ this._model.text = linkText;
+ this._actionName = actionName;
+ this._model.size = ButtonSize.Default;
+ this._model.style = ButtonStyle.Default;
+ this._actionTypePassed = ActionTypePassed.HtmlRegular;
+ }
+
+ public BootstrapActionLinkButton(HtmlHelper html, string linkText, string actionName, string controllerName)
+ : base("")
+ {
+ this.html = html;
+ this._model.text = linkText;
+ this._actionName = actionName;
+ this._controllerName = controllerName;
+ this._model.size = ButtonSize.Default;
+ this._model.style = ButtonStyle.Default;
+ this._actionTypePassed = ActionTypePassed.HtmlRegular;
+ }
+
+ public BootstrapActionLinkButton(AjaxHelper ajax, string linkText, ActionResult result, AjaxOptions ajaxOptions)
+ : base("")
+ {
+ this.ajax = ajax;
+ this._model.text = linkText;
+ this._result = result;
+ this._model.size = ButtonSize.Default;
+ this._model.style = ButtonStyle.Default;
+ this._ajaxOptions = ajaxOptions;
+ this._actionTypePassed = ActionTypePassed.AjaxActionResult;
+ }
+
+ public BootstrapActionLinkButton(AjaxHelper ajax, string linkText, Task<ActionResult> taskResult, AjaxOptions ajaxOptions)
+ : base("")
+ {
+ this.ajax = ajax;
+ this._model.text = linkText;
+ this._taskResult = taskResult;
+ this._model.size = ButtonSize.Default;
+ this._model.style = ButtonStyle.Default;
+ this._ajaxOptions = ajaxOptions;
+ this._actionTypePassed = ActionTypePassed.AjaxTaskResult;
+ }
+
+ public BootstrapActionLinkButton(AjaxHelper ajax, string linkText, string actionName, AjaxOptions ajaxOptions)
+ : base("")
+ {
+ this.ajax = ajax;
+ this._model.text = linkText;
+ this._actionName = actionName;
+ this._model.size = ButtonSize.Default;
+ this._model.style = ButtonStyle.Default;
+ this._ajaxOptions = ajaxOptions;
+ this._actionTypePassed = ActionTypePassed.AjaxRegular;
+ }
+
+ public BootstrapActionLinkButton(AjaxHelper ajax, string linkText, string actionName, string controllerName, AjaxOptions ajaxOptions)
+ : base("")
+ {
+ this.ajax = ajax;
+ this._model.text = linkText;
+ this._actionName = actionName;
+ this._controllerName = controllerName;
+ this._model.size = ButtonSize.Default;
+ this._model.style = ButtonStyle.Default;
+ this._ajaxOptions = ajaxOptions;
+ this._actionTypePassed = ActionTypePassed.AjaxRegular;
+ }
+
+ public BootstrapActionLinkButton Protocol(string protocol)
+ {
+ this._protocol = protocol;
+ return this;
+ }
+
+ public BootstrapActionLinkButton HostName(string hostName)
+ {
+ this._hostName = hostName;
+ return this;
+ }
+
+ public BootstrapActionLinkButton Fragment(string fragment)
+ {
+ this._fragment = fragment;
+ return this;
+ }
+
+ public BootstrapActionLinkButton RouteName(string routeName)
+ {
+ this._routeName = routeName;
+ return this;
+ }
+
+ public BootstrapActionLinkButton RouteValues(object routeValues)
+ {
+ this._routeValues = HtmlHelper.AnonymousObjectToHtmlAttributes(routeValues);
+ return this;
+ }
+
+ public BootstrapActionLinkButton RouteValues(RouteValueDictionary routeValues)
+ {
+ this._routeValues = routeValues;
+ return this;
+ }
+
+ public BootstrapActionLinkButton DropDownToggle()
+ {
+ this._model.isDropDownToggle = true;
+ return this;
+ }
+
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override string ToHtmlString()
+ {
+ var mergedHtmlAttributes = _model.htmlAttributes;
+ mergedHtmlAttributes.AddOrMergeCssClass("class", "btn");
+ if(!string.IsNullOrEmpty(_model.id)) mergedHtmlAttributes.AddIfNotExist("id", _model.id);
+
+ mergedHtmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForButtonSize(_model.size));
+ mergedHtmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForButtonStyle(_model.style));
+
+ if (_model.buttonBlock) mergedHtmlAttributes.AddOrMergeCssClass("class", "btn-block");
+ if (_model.isDropDownToggle)
+ {
+ mergedHtmlAttributes.AddOrMergeCssClass("class", "dropdown-toggle");
+ mergedHtmlAttributes.AddIfNotExist("data-toggle", "dropdown");
+ }
+ if (_model.disabled) mergedHtmlAttributes.AddOrMergeCssClass("class", "disabled");
+
+ var input = string.Empty;
+ if (_model.iconPrepend != Icons._not_set || _model.iconAppend != Icons._not_set || !string.IsNullOrEmpty(_model.iconPrependCustomClass) || !string.IsNullOrEmpty(_model.iconAppendCustomClass))
+ {
+
+ string iPrependString = string.Empty;
+ string iAppendString = string.Empty;
+ if (_model.iconPrepend != Icons._not_set) iPrependString = new BootstrapIcon(_model.iconPrepend, _model.iconPrependIsWhite).ToHtmlString();
+ if (_model.iconAppend != Icons._not_set) iAppendString = new BootstrapIcon(_model.iconAppend, _model.iconAppendIsWhite).ToHtmlString();
+ if (!string.IsNullOrEmpty(_model.iconPrependCustomClass))
+ {
+ var i = new TagBuilder("i");
+ i.AddCssClass(_model.iconPrependCustomClass);
+ iPrependString = i.ToString(TagRenderMode.Normal);
+ }
+ if (!string.IsNullOrEmpty(_model.iconAppendCustomClass))
+ {
+ var i = new TagBuilder("i");
+ i.AddCssClass(_model.iconAppendCustomClass);
+ iPrependString = i.ToString(TagRenderMode.Normal);
+ }
+
+ string combined =
+ iPrependString +
+ (!string.IsNullOrEmpty(iPrependString) && (!string.IsNullOrEmpty(_model.text) || !string.IsNullOrEmpty(iAppendString)) ? " " : "") +
+ _model.text +
+ (!string.IsNullOrEmpty(iAppendString) && (!string.IsNullOrEmpty(_model.text) || !string.IsNullOrEmpty(iPrependString)) ? " " : "") +
+ iAppendString;
+
+ string holder = Guid.NewGuid().ToString();
+
+ input = GenerateActionLink(holder, mergedHtmlAttributes);
+ input = input.Replace(holder, combined);
+ }
+ else
+ {
+ input = GenerateActionLink(_model.text, mergedHtmlAttributes);
+ }
+
+ return MvcHtmlString.Create(input).ToString();
+ }
+
+ private string GenerateActionLink(string linkText, IDictionary<string, object> htmlAttributes)
+ {
+ string input = string.Empty;
+ switch (this._actionTypePassed)
+ {
+ case ActionTypePassed.HtmlRegular:
+ input = html.ActionLink(linkText, _actionName, _controllerName, _protocol, _hostName, _fragment, _routeValues, htmlAttributes).ToHtmlString();
+ break;
+ case ActionTypePassed.HtmlActionResult:
+ input = html.ActionLink(linkText, _result, htmlAttributes, _protocol, _hostName, _fragment).ToHtmlString();
+ break;
+ case ActionTypePassed.HtmlTaskResult:
+ input = html.ActionLink(linkText, _taskResult, htmlAttributes, _protocol, _hostName, _fragment).ToHtmlString();
+ break;
+ case ActionTypePassed.AjaxRegular:
+ input = ajax.ActionLink(linkText, _actionName, _controllerName, _protocol, _hostName, _fragment, _routeValues, _ajaxOptions, htmlAttributes).ToHtmlString();
+ break;
+ case ActionTypePassed.AjaxActionResult:
+ input = ajax.ActionLink(linkText, _result, _ajaxOptions, htmlAttributes).ToHtmlString();
+ break;
+ case ActionTypePassed.AjaxTaskResult:
+ input = ajax.ActionLink(linkText, _taskResult, _ajaxOptions, htmlAttributes).ToHtmlString();
+ break;
+ default:
+ break;
+ }
+ return input;
+ }
+
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override string ToString() { return ToHtmlString(); }
+
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override bool Equals(object obj) { return base.Equals(obj); }
+
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override int GetHashCode() { return base.GetHashCode(); }
+
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public new Type GetType() { return base.GetType(); }
+ }
+}

0 comments on commit 3ac0034

Please sign in to comment.