Skip to content

Commit

Permalink
SrkToolkit.Web: restore Submit HtmlHelper extension
Browse files Browse the repository at this point in the history
  • Loading branch information
sandrock committed Mar 23, 2023
1 parent c03f2e5 commit ecfb20a
Showing 1 changed file with 161 additions and 161 deletions.
322 changes: 161 additions & 161 deletions Sources/SrkToolkit.Web.AspNetCore2/SrkHtmlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace SrkToolkit.Web
using SrkToolkit.Web.Open;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
Expand Down Expand Up @@ -545,161 +545,161 @@ public static HtmlString DisplayTime(this IHtmlHelper html, TimeSpan date, bool
return new HtmlString(display);
}
}

/// <summary>
/// Displays a duration.
/// </summary>
/// <param name="html"></param>
/// <param name="value"></param>
/// <returns></returns>
public static HtmlString DisplayTimeSpan(this IHtmlHelper html, TimeSpan? value)
{
return DisplayTimeSpan(html, value, false, null, true);
}

/// <summary>
/// Displays a duration.
/// </summary>
/// <param name="html"></param>
/// <param name="value"></param>
/// <param name="showMilliseconds"></param>
/// <returns></returns>
public static HtmlString DisplayTimeSpan(this IHtmlHelper html, TimeSpan? value, bool showMilliseconds)
{
return DisplayTimeSpan(html, value, showMilliseconds, null, true);
}

/// <summary>
/// Displays a duration.
/// </summary>
/// <param name="html"></param>
/// <param name="value"></param>
/// <param name="showMilliseconds"></param>
/// <param name="nullValue"></param>
/// <param name="asHtml"></param>
/// <returns></returns>
public static HtmlString DisplayTimeSpan(this IHtmlHelper html, TimeSpan? value, bool showMilliseconds, object nullValue, bool asHtml)
{
var b = new StringBuilder();
string tmp;

if (value == null && nullValue is TimeSpan)
{
value = (TimeSpan)nullValue;
}

if (value != null)
{
tmp = value.Value.ToInvariantString();

var lang = CultureInfo.CurrentCulture;
var title = value.Value.ToInvariantString()
+ " | " + value.Value.TotalDays.ToString("F2", lang) + " days"
+ " | " + value.Value.TotalHours.ToString("F2", lang) + " hours"
+ " | " + value.Value.TotalSeconds.ToString("F2", lang) + " seconds"
+ " | " + value.Value.TotalMilliseconds.ToString("F2", lang) + " milliseconds"
;

if (asHtml)
{
b.Append(@"<span class=""TimeSpan"" title=""");
b.Append(title.ProperHtmlAttributeEscape());
b.Append(@""">");
}

if (value.Value.Days != 0)
{
tmp = Math.Abs(value.Value.Days).ToString();
if (asHtml)
{
b.Append(@"<span class=""TimeSpanDays"">");
b.Append(tmp);
b.Append(@"</span>.");
}
else
{
b.Append(tmp);
b.Append(".");
}
}

if (value.Value.Days != 0 || value.Value.Hours != 0)
{
tmp = Math.Abs(value.Value.Hours).ToString("00");
if (asHtml)
{
b.Append(@"<span class=""TimeSpanHours"">");
b.Append(tmp);
b.Append(@"</span>:");
}
else
{
b.Append(tmp);
b.Append(":");
}
}

tmp = Math.Abs(value.Value.Minutes).ToString("00");
if (asHtml)
{
b.Append(@"<span class=""TimeSpanMinutes"">");
b.Append(tmp);
b.Append(@"</span>:");
}
else
{
b.Append(tmp);
b.Append(":");
}

tmp = Math.Abs(value.Value.Seconds).ToString("00");
if (asHtml)
{
b.Append(@"<span class=""TimeSpanSeconds"">");
b.Append(tmp);
b.Append(@"</span>");
}
else
{
b.Append(tmp);
}

if (showMilliseconds)
{
tmp = Math.Abs(value.Value.Milliseconds).ToString("000");
if (asHtml)
{
b.Append(@".<span class=""TimeSpanMs"">");
b.Append(tmp);
b.Append(@"</span>");
}
else
{
b.Append(".");
b.Append(tmp);
}
}

if (asHtml) b.Append(@"</span>");
}
else if (nullValue != null)
{
tmp = nullValue.ToString();
if (asHtml)
{
b.Append(@"<span class=""TimeSpan"">");
b.Append(tmp.ProperHtmlEscape());
b.Append(@"</span>");
}
else
{
b.Append(tmp);
}
}

return new HtmlString(b.ToString());
}


/// <summary>
/// Displays a duration.
/// </summary>
/// <param name="html"></param>
/// <param name="value"></param>
/// <returns></returns>
public static HtmlString DisplayTimeSpan(this IHtmlHelper html, TimeSpan? value)
{
return DisplayTimeSpan(html, value, false, null, true);
}

/// <summary>
/// Displays a duration.
/// </summary>
/// <param name="html"></param>
/// <param name="value"></param>
/// <param name="showMilliseconds"></param>
/// <returns></returns>
public static HtmlString DisplayTimeSpan(this IHtmlHelper html, TimeSpan? value, bool showMilliseconds)
{
return DisplayTimeSpan(html, value, showMilliseconds, null, true);
}

/// <summary>
/// Displays a duration.
/// </summary>
/// <param name="html"></param>
/// <param name="value"></param>
/// <param name="showMilliseconds"></param>
/// <param name="nullValue"></param>
/// <param name="asHtml"></param>
/// <returns></returns>
public static HtmlString DisplayTimeSpan(this IHtmlHelper html, TimeSpan? value, bool showMilliseconds, object nullValue, bool asHtml)
{
var b = new StringBuilder();
string tmp;

if (value == null && nullValue is TimeSpan)
{
value = (TimeSpan)nullValue;
}

if (value != null)
{
tmp = value.Value.ToInvariantString();

var lang = CultureInfo.CurrentCulture;
var title = value.Value.ToInvariantString()
+ " | " + value.Value.TotalDays.ToString("F2", lang) + " days"
+ " | " + value.Value.TotalHours.ToString("F2", lang) + " hours"
+ " | " + value.Value.TotalSeconds.ToString("F2", lang) + " seconds"
+ " | " + value.Value.TotalMilliseconds.ToString("F2", lang) + " milliseconds"
;

if (asHtml)
{
b.Append(@"<span class=""TimeSpan"" title=""");
b.Append(title.ProperHtmlAttributeEscape());
b.Append(@""">");
}

if (value.Value.Days != 0)
{
tmp = Math.Abs(value.Value.Days).ToString();
if (asHtml)
{
b.Append(@"<span class=""TimeSpanDays"">");
b.Append(tmp);
b.Append(@"</span>.");
}
else
{
b.Append(tmp);
b.Append(".");
}
}

if (value.Value.Days != 0 || value.Value.Hours != 0)
{
tmp = Math.Abs(value.Value.Hours).ToString("00");
if (asHtml)
{
b.Append(@"<span class=""TimeSpanHours"">");
b.Append(tmp);
b.Append(@"</span>:");
}
else
{
b.Append(tmp);
b.Append(":");
}
}

tmp = Math.Abs(value.Value.Minutes).ToString("00");
if (asHtml)
{
b.Append(@"<span class=""TimeSpanMinutes"">");
b.Append(tmp);
b.Append(@"</span>:");
}
else
{
b.Append(tmp);
b.Append(":");
}

tmp = Math.Abs(value.Value.Seconds).ToString("00");
if (asHtml)
{
b.Append(@"<span class=""TimeSpanSeconds"">");
b.Append(tmp);
b.Append(@"</span>");
}
else
{
b.Append(tmp);
}

if (showMilliseconds)
{
tmp = Math.Abs(value.Value.Milliseconds).ToString("000");
if (asHtml)
{
b.Append(@".<span class=""TimeSpanMs"">");
b.Append(tmp);
b.Append(@"</span>");
}
else
{
b.Append(".");
b.Append(tmp);
}
}

if (asHtml) b.Append(@"</span>");
}
else if (nullValue != null)
{
tmp = nullValue.ToString();
if (asHtml)
{
b.Append(@"<span class=""TimeSpan"">");
b.Append(tmp.ProperHtmlEscape());
b.Append(@"</span>");
}
else
{
b.Append(tmp);
}
}

return new HtmlString(b.ToString());
}

/// <summary>
/// Returns the date (to UTC) in JavaScript format like 'new Date(123456789000)'.
/// </summary>
Expand Down Expand Up @@ -1033,7 +1033,7 @@ public static MvcForm BeginFormEx(this IHtmlHelper IHtmlHelper, object htmlAttri
#endregion

#region Submit
/*

/// <summary>
/// Returns a submit input element by using the specified HTML helper and the name of the form field.
/// </summary>
Expand All @@ -1045,7 +1045,7 @@ public static HtmlString Submit(this IHtmlHelper html, string value)
var builder = new TagBuilder("input");
builder.MergeAttribute("type", "submit");
builder.MergeAttribute("value", value);
return new HtmlString(builder.ToString(TagRenderMode.SelfClosing));
return builder.ToHtmlString();
}

/// <summary>
Expand All @@ -1061,7 +1061,7 @@ public static HtmlString Submit(this IHtmlHelper html, string value, string name
builder.MergeAttribute("type", "submit");
builder.MergeAttribute("name", name);
builder.MergeAttribute("value", value);
return new HtmlString(builder.ToString(TagRenderMode.SelfClosing));
return builder.ToHtmlString();
}

/// <summary>
Expand All @@ -1080,9 +1080,9 @@ public static HtmlString Submit(this IHtmlHelper html, string value, string name
builder.MergeAttribute("type", "submit");
builder.MergeAttribute("name", name);
builder.MergeAttribute("value", value);
return new HtmlString(builder.ToString(TagRenderMode.SelfClosing));
return builder.ToHtmlString();
}
*/

#endregion

#region File
Expand Down

0 comments on commit ecfb20a

Please sign in to comment.