From 8266598e0d82dfa04064874a83a8601c4ced4ed1 Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Tue, 21 Jul 2015 23:07:41 -0400 Subject: [PATCH] InputSize simplification --- Web/Utility/CustomExtensions.cs | 12 +++++++++--- Web/Views/Shared/EditorTemplates/Date.cshtml | 14 ++++---------- Web/Views/Shared/EditorTemplates/DateTime.cshtml | 15 +++++---------- Web/Views/Shared/EditorTemplates/Decimal.cshtml | 14 ++++---------- .../Shared/EditorTemplates/EmailAddress.cshtml | 14 ++++---------- Web/Views/Shared/EditorTemplates/Int32.cshtml | 15 +++++---------- Web/Views/Shared/EditorTemplates/Password.cshtml | 14 ++++---------- Web/Views/Shared/EditorTemplates/String.cshtml | 13 +++---------- 8 files changed, 38 insertions(+), 73 deletions(-) diff --git a/Web/Utility/CustomExtensions.cs b/Web/Utility/CustomExtensions.cs index 0e98cff..7121ca2 100644 --- a/Web/Utility/CustomExtensions.cs +++ b/Web/Utility/CustomExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Collections.Specialized; using System.ComponentModel.DataAnnotations; using System.Data.SqlTypes; using System.Linq; @@ -8,9 +7,7 @@ using System.Linq.Expressions; using System.Reflection; using System.Text; using System.Web.Mvc; -using System.Web.Routing; using MileageTraker.Web.Models; -using MiscUtil.Collections; namespace MileageTraker.Web.Utility { @@ -53,6 +50,15 @@ namespace MileageTraker.Web.Utility : enumeration.ToString(); } + public static Dictionary GetInputSizeClass(this HtmlHelper helper) + { + var inputSize = (string)helper.ViewData.ModelMetadata.AdditionalValues["InputSize"]; + //var cls = !string.IsNullOrEmpty(inputSize) ? new { @class = inputSize } : null; + + var dictionary = new Dictionary {{"class", inputSize}}; + return dictionary; + } + public static IEnumerable GetSelectListItems(this Enum enumeration) { var type = enumeration.GetType(); diff --git a/Web/Views/Shared/EditorTemplates/Date.cshtml b/Web/Views/Shared/EditorTemplates/Date.cshtml index 523a06a..48facab 100644 --- a/Web/Views/Shared/EditorTemplates/Date.cshtml +++ b/Web/Views/Shared/EditorTemplates/Date.cshtml @@ -1,13 +1,7 @@ -@model DateTime +@using MileageTraker.Web.Utility +@model DateTime @{ Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml"; - var inputSize = (string)ViewData.ModelMetadata.AdditionalValues["InputSize"]; -} -@if (!string.IsNullOrEmpty(inputSize)) -{ - @Html.TextBox("", (Model != DateTime.MinValue ? Model.ToShortDateString() : string.Empty ), new { @class = inputSize}) -} -else -{ - @Html.TextBox("", (Model != DateTime.MinValue ? Model.ToShortDateString() : string.Empty )) } + +@Html.TextBox("", (Model != DateTime.MinValue ? Model.ToShortDateString() : string.Empty ), Html.GetInputSizeClass()) diff --git a/Web/Views/Shared/EditorTemplates/DateTime.cshtml b/Web/Views/Shared/EditorTemplates/DateTime.cshtml index 5d0ce76..051b8c4 100644 --- a/Web/Views/Shared/EditorTemplates/DateTime.cshtml +++ b/Web/Views/Shared/EditorTemplates/DateTime.cshtml @@ -1,17 +1,12 @@ -@model DateTime? +@using MileageTraker.Web.Utility +@model DateTime? @{ Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml"; - var inputSize = (string)ViewData.ModelMetadata.AdditionalValues["InputSize"]; var val = Model.HasValue ? Model.Value.ToShortDateString() : string.Empty; } -@if (!string.IsNullOrEmpty(inputSize)) -{ - @Html.TextBox("", (Model != DateTime.MinValue ? val : string.Empty ), new { @class = inputSize}) -} -else -{ - @Html.TextBox("", (Model != DateTime.MinValue ? val : string.Empty )) -} + +@Html.TextBox("", (Model != DateTime.MinValue ? val : string.Empty ), Html.GetInputSizeClass()) + diff --git a/Web/Views/Shared/EditorTemplates/Decimal.cshtml b/Web/Views/Shared/EditorTemplates/Decimal.cshtml index 5300356..76ff337 100644 --- a/Web/Views/Shared/EditorTemplates/Decimal.cshtml +++ b/Web/Views/Shared/EditorTemplates/Decimal.cshtml @@ -1,12 +1,6 @@ -@{ +@using MileageTraker.Web.Utility +@{ Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml"; - var inputSize = (string)ViewData.ModelMetadata.AdditionalValues["InputSize"]; } -@if (!string.IsNullOrEmpty(inputSize)) -{ - @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @class = inputSize}) -} -else -{ - @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue) -} \ No newline at end of file + +@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, Html.GetInputSizeClass()) diff --git a/Web/Views/Shared/EditorTemplates/EmailAddress.cshtml b/Web/Views/Shared/EditorTemplates/EmailAddress.cshtml index 5300356..76ff337 100644 --- a/Web/Views/Shared/EditorTemplates/EmailAddress.cshtml +++ b/Web/Views/Shared/EditorTemplates/EmailAddress.cshtml @@ -1,12 +1,6 @@ -@{ +@using MileageTraker.Web.Utility +@{ Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml"; - var inputSize = (string)ViewData.ModelMetadata.AdditionalValues["InputSize"]; } -@if (!string.IsNullOrEmpty(inputSize)) -{ - @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @class = inputSize}) -} -else -{ - @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue) -} \ No newline at end of file + +@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, Html.GetInputSizeClass()) diff --git a/Web/Views/Shared/EditorTemplates/Int32.cshtml b/Web/Views/Shared/EditorTemplates/Int32.cshtml index 18ea7f8..eecf35e 100644 --- a/Web/Views/Shared/EditorTemplates/Int32.cshtml +++ b/Web/Views/Shared/EditorTemplates/Int32.cshtml @@ -1,12 +1,7 @@ -@{ +@using MileageTraker.Web.Utility + +@{ Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml"; - var inputSize = (string)ViewData.ModelMetadata.AdditionalValues["InputSize"]; -} -@if (!string.IsNullOrEmpty(inputSize)) -{ - @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @class = inputSize}) -} -else -{ - @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue) } + +@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, Html.GetInputSizeClass()) \ No newline at end of file diff --git a/Web/Views/Shared/EditorTemplates/Password.cshtml b/Web/Views/Shared/EditorTemplates/Password.cshtml index 99fcaa5..2c5d586 100644 --- a/Web/Views/Shared/EditorTemplates/Password.cshtml +++ b/Web/Views/Shared/EditorTemplates/Password.cshtml @@ -1,12 +1,6 @@ -@{ +@using MileageTraker.Web.Utility +@{ Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml"; - var inputSize = (string)ViewData.ModelMetadata.AdditionalValues["InputSize"]; -} -@if (!string.IsNullOrEmpty(inputSize)) -{ - @Html.Password("", ViewData.TemplateInfo.FormattedModelValue, new { @class = inputSize}) -} -else -{ - @Html.Password("", ViewData.TemplateInfo.FormattedModelValue) } + +@Html.Password("", ViewData.TemplateInfo.FormattedModelValue, Html.GetInputSizeClass()) \ No newline at end of file diff --git a/Web/Views/Shared/EditorTemplates/String.cshtml b/Web/Views/Shared/EditorTemplates/String.cshtml index 56f567c..2e6ec8d 100644 --- a/Web/Views/Shared/EditorTemplates/String.cshtml +++ b/Web/Views/Shared/EditorTemplates/String.cshtml @@ -1,17 +1,10 @@ -@{ +@using MileageTraker.Web.Utility +@{ Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml"; - var inputSize = (string)ViewData.ModelMetadata.AdditionalValues["InputSize"]; } @if (!(Model is Enum)) { - if (!string.IsNullOrEmpty(inputSize)) - { - @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @class = inputSize}) - } - else - { - @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue) - } + @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, Html.GetInputSizeClass()) } else {