From b1bff76159815bb24ff0a27524987d1536fa45aa Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Mon, 3 Aug 2020 08:26:28 -0400 Subject: [PATCH] Make ViewModel bool parameters nullable --- WebCms/Models/LeafDataQuery.cs | 8 ++++---- WebCms/Utility/QueryFilter.cs | 4 ++-- WebCms/Views/Shared/_LeafDataQuery.cshtml | 4 ++-- WebCms/WebCms.csproj | 1 + WebCms/scripts/LeafDataQuery.js | 11 +++++++++++ WebCms/scripts/site.js | 3 ++- 6 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 WebCms/scripts/LeafDataQuery.js diff --git a/WebCms/Models/LeafDataQuery.cs b/WebCms/Models/LeafDataQuery.cs index e5e4f89..ad5c7e8 100644 --- a/WebCms/Models/LeafDataQuery.cs +++ b/WebCms/Models/LeafDataQuery.cs @@ -57,10 +57,10 @@ namespace LeafWeb.WebCms.Models public string phips2 { get; set; } [Display(Name = "Show Only Successfully Completed")] - public bool compl { get; set; } + public bool? compl { get; set; } [Display(Name = "Only my data")] - public bool usr { get; set; } + public bool? usr { get; set; } public bool HasExtendedParameters => !( @@ -74,12 +74,12 @@ namespace LeafWeb.WebCms.Models && string.IsNullOrEmpty(pari) && string.IsNullOrEmpty(tleaf) && string.IsNullOrEmpty(phips2) - && !compl + && !(compl.HasValue && compl.Value) ); public bool HasParameters => HasExtendedParameters || !string.IsNullOrEmpty(q) - || usr; + || usr.HasValue && usr.Value; } } \ No newline at end of file diff --git a/WebCms/Utility/QueryFilter.cs b/WebCms/Utility/QueryFilter.cs index 0a19bdc..925c227 100644 --- a/WebCms/Utility/QueryFilter.cs +++ b/WebCms/Utility/QueryFilter.cs @@ -143,7 +143,7 @@ namespace LeafWeb.WebCms.Utility select li; } - if (query.compl) + if (query.compl.HasValue && query.compl.Value) { resultItems = from li in resultItems @@ -154,7 +154,7 @@ namespace LeafWeb.WebCms.Utility select li; } - if (query.usr && !string.IsNullOrEmpty(currentUserEmail)) + if (query.usr.HasValue && query.usr.Value && !string.IsNullOrEmpty(currentUserEmail)) { resultItems = from li in resultItems diff --git a/WebCms/Views/Shared/_LeafDataQuery.cshtml b/WebCms/Views/Shared/_LeafDataQuery.cshtml index 50601dd..2618078 100644 --- a/WebCms/Views/Shared/_LeafDataQuery.cshtml +++ b/WebCms/Views/Shared/_LeafDataQuery.cshtml @@ -1,12 +1,12 @@ @using System.Web.Mvc.Html @using ClientDependency.Core.Mvc -@using LeafWeb.WebCms.Utility @model LeafDataQuery @{ Html.RequiresJs("~/scripts/jquery.validate.min.js", 2); Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.min.js", 2); Html.RequiresJs("~/scripts/jquery.validate.custom.js", 2); Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.bootstrap.js", 2); + Html.RequiresJs("~/scripts/LeafDataQuery.js", 3); var actionName = string.Empty; var controllerName = string.Empty; @@ -25,7 +25,7 @@ htmlFormAction = (string)ViewData["htmlFormAction"]; } } -@using (Html.BeginUmbracoForm(actionName, controllerName, null, new { action = htmlFormAction })) +@using (Html.BeginUmbracoForm(actionName, controllerName, null, new { action = htmlFormAction, id = "leafdataquery" })) {
diff --git a/WebCms/WebCms.csproj b/WebCms/WebCms.csproj index bec3644..ef6e3ca 100644 --- a/WebCms/WebCms.csproj +++ b/WebCms/WebCms.csproj @@ -1130,6 +1130,7 @@ + diff --git a/WebCms/scripts/LeafDataQuery.js b/WebCms/scripts/LeafDataQuery.js new file mode 100644 index 0000000..20f18a9 --- /dev/null +++ b/WebCms/scripts/LeafDataQuery.js @@ -0,0 +1,11 @@ +$(function() { + $("form#leafdataquery .latr input.form-control") + .rules("add", + { + //required: true + required: function () + { + return !!$(".lat input.form-control").val(); + } + }); +}); \ No newline at end of file diff --git a/WebCms/scripts/site.js b/WebCms/scripts/site.js index 740b333..20a18f2 100644 --- a/WebCms/scripts/site.js +++ b/WebCms/scripts/site.js @@ -28,7 +28,8 @@ return false; }); - $("form:not(.confirm)").submit(function() { + $("form:not(.confirm)").submit(function () { + if (!$(this).valid()) return; var btn = $(this).find(":submit"); btn.prop("disabled", true); btn.html(