Refactored field validation; work on Add Person

This commit is contained in:
Rick Falkvinge
2014-12-08 12:58:14 +01:00
parent 24d75fa23b
commit 407d5ef795
13 changed files with 153 additions and 50 deletions
+2
View File
@@ -246,6 +246,8 @@
<Compile Include="Support\Imagery.cs" />
<Compile Include="Support\IXmlPayload.cs" />
<Compile Include="Support\LogEntries\CashAdvanceRequestedLogEntry.cs" />
<Compile Include="Support\LogEntries\MembershipActionBase.cs" />
<Compile Include="Support\LogEntries\PersonAddedLogEntry.cs" />
<Compile Include="Support\LogEntries\SalaryCreatedLogEntry.cs" />
<Compile Include="Support\LogEntries\InboundInvoiceCreatedLogEntry.cs" />
<Compile Include="Support\LogEntries\ExpenseClaimFiledLogEntry.cs" />
@@ -15,6 +15,9 @@ namespace Swarmops.Logic.Support.LogEntries
public string Description { get; set; }
public int OwnerPersonId { get; set; }
public string OwnerPersonName { get; set; }
/// <summary>
/// Always in UTC
/// </summary>
public DateTime DateTime { get; set; }
}
}
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Swarmops.Logic.Support.LogEntries
{
[Serializable]
public class MembershipActionBase: LogEntryBase<MembershipActionBase>
{
public MembershipActionBase()
{
// do not call public ctor directly. Intended for serialization only.
}
public int MembershipId { get; set; }
/// <summary>
/// Always in UTC
/// </summary>
public DateTime DateTime { get; set; }
public int ActingPersonId { get; set; }
}
}
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Swarmops.Logic.Swarm;
namespace Swarmops.Logic.Support.LogEntries
{
[Serializable]
public class PersonAddedLogEntry: MembershipActionBase
{
[Obsolete("Do not call empty ctor directly. Intended for serialization only.", true)]
public PersonAddedLogEntry()
{
// Do not call empty ctor directly. Intended for serialization only.
}
public PersonAddedLogEntry (Membership membership, Person actingPerson)
{
DateTime = System.DateTime.UtcNow;
MembershipId = membership.Identity;
ActingPersonId = actingPerson.Identity;
}
}
}
+2 -28
View File
@@ -58,34 +58,8 @@ public class FieldValidation : WebService
[WebMethod]
public bool IsAmountValid (string amount)
public bool IsDateValid (string input)
{
CultureInfo culture = GetUserCulture();
// Try to parse the string we got as a double
try
{
Double.Parse (HttpUtility.UrlDecode (amount), NumberStyles.Number, culture);
return true;
}
catch (Exception)
{
}
return false;
}
[WebMethod]
public bool AreDocumentsUploaded (string guidString)
{
Documents documents = Documents.RecentFromDescription (guidString);
if (documents.Count == 0)
{
return false;
}
return true;
}
}
@@ -120,6 +120,9 @@
<data name="AddPerson_ErrorCity" xml:space="preserve">
<value>A valid city is required.</value>
</data>
<data name="AddPerson_ErrorDate" xml:space="preserve">
<value>Provide a valid date or leave this field empty.</value>
</data>
<data name="AddPerson_ErrorMail" xml:space="preserve">
<value>A valid email is required.</value>
</data>
+47
View File
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Web.Services;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Support;
namespace Swarmops.Frontend.Automation
{
@@ -11,6 +13,15 @@ namespace Swarmops.Frontend.Automation
{
}
[WebMethod]
public static bool IsDateValid (string input)
{
AuthenticationData authenticationData = GetAuthenticationDataAndCulture(); // sets culture
DateTime dummyResult;
return DateTime.TryParse (input, out dummyResult);
}
[WebMethod]
public static void TestFoo (string input)
{
@@ -19,6 +30,42 @@ namespace Swarmops.Frontend.Automation
System.Diagnostics.Trace.WriteLine (input);
}
[WebMethod]
public bool IsAmountValid(string amount)
{
AuthenticationData authData = GetAuthenticationDataAndCulture(); // sets culture
// Try to parse the string we got as a double
try
{
Double.Parse(amount, NumberStyles.Number);
return true;
}
catch (Exception)
{
}
return false;
}
[WebMethod]
public bool AreDocumentsUploaded(string guidString)
{
Documents documents = Documents.RecentFromDescription(guidString);
if (documents.Count == 0)
{
return false;
}
return true;
}
[WebMethod]
public static PostalCodesCities GetPostalCodesCities (string countryCode)
{
@@ -31,12 +31,9 @@
});
function validateFields() {
var isValid = true;
isValid = validateTextField('#<%=this.TextAccount.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorBankAccount" />") && isValid;
if ($('#<%=this.ComboBudgets.ClientID %>_DropBudgets').combotree('tree').tree('getSelected') == null) {
@@ -55,14 +52,17 @@
isValid = validateTextField('#<%=this.TextPurpose.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorPurpose" />") && isValid;
var jsonData = {};
jsonData.amount = $('#<%=this.TextAmount.ClientID %>').val();
$.ajax({
type: "POST",
url: "/Automation/FieldValidation.asmx/IsAmountValid",
data: "{'amount': '" + escape($('#<%=this.TextAmount.ClientID %>').val()) + "'}",
url: "/Automation/FieldValidation.aspx/IsAmountValid",
data: $.toJSON(jsonData),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false, // blocks until function returns - race conditions otherwise
success: function (msg) {
async: false, // blocks until function returns - race conditions otherwise
success: function(msg) {
if (msg.d != true) {
isValid = false;
$('#TextAmount').addClass("entryError");
@@ -74,7 +74,7 @@
$.ajax({
type: "POST",
url: "/Automation/FieldValidation.asmx/AreDocumentsUploaded",
url: "/Automation/FieldValidation.aspx/AreDocumentsUploaded",
data: "{'guidString': '<%=this.FileUpload.GuidString %>'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
@@ -104,6 +104,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial
}
EasyUIControlsUsed = EasyUIControl.Tree;
IncludedControlsUsed = IncludedControl.JsonParameters;
;
}
@@ -49,10 +49,13 @@
isValid = validateTextField('#<%=this.TextPurpose.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorPurpose" />") && isValid;
var jsonData = {};
jsonData.amount = $('#<%=this.TextAmount.ClientID %>').val();
$.ajax({
type: "POST",
url: "/Automation/FieldValidation.asmx/IsAmountValid",
data: "{'amount': '" + escape($('#<%=this.TextAmount.ClientID %>').val()) + "'}",
url: "/Automation/FieldValidation.aspx/IsAmountValid",
data: $.toJSON(jsonData),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false, // blocks until function returns - race conditions otherwise
@@ -68,7 +71,7 @@
$.ajax({
type: "POST",
url: "/Automation/FieldValidation.asmx/AreDocumentsUploaded",
url: "/Automation/FieldValidation.aspx/AreDocumentsUploaded",
data: "{'guidString': '<%=this.FileUpload.GuidString %>'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
@@ -19,10 +19,13 @@
isValid = validateTextField('#<%=this.TextPurpose.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorPurpose" />") && isValid;
var jsonData = {};
jsonData.amount = $('#<%=this.TextAmount.ClientID %>').val();
$.ajax({
type: "POST",
url: "/Automation/FieldValidation.asmx/IsAmountValid",
data: "{'amount': '" + escape($('#<%=this.TextAmount.ClientID %>').val()) + "'}",
url: "/Automation/FieldValidation.aspx/IsAmountValid",
data: $.toJSON(jsonData),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false, // blocks until function returns - race conditions otherwise
+23
View File
@@ -137,6 +137,29 @@
isValid = ValidateTextField('#<%= TextMail.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorMail" />") && isValid;
isValid = ValidateTextField('#<%= TextName.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorName" />") && isValid; // TODO: Actually validate geography?
var dateFieldContents = $('#<%= TextDateOfBirth.ClientID%>').val();
if (dateFieldContents.length > 0) {
alert('testing');
$.ajax({
type: "POST",
url: "/Automation/FieldValidation.aspx/IsDateValid",
data: "{'amount': '" + escape($('#<%=this.TextAmount.ClientID %>').val()) + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false, // blocks until function returns - race conditions otherwise
success: function (msg) {
if (msg.d != true) {
isValid = false;
$('#TextAmount').addClass("entryError");
alertify.error("<asp:Literal runat="server" ID="LiteralErrorAmount" />");
$('#<%=this.TextAmount.ClientID %>').focus();
}
}
});
}
return isValid;
}
+1 -8
View File
@@ -111,14 +111,7 @@ namespace Swarmops.Frontend.Pages.v5.Swarm
OutboundComm.CreateMembershipLetter (ParticipantMailType.MemberAddedWelcome, newMembership, CurrentUser);
// Person.Create()
// Send notify
// "Welcome to Swarmops. Your password is:\r\n\r\n" + randomPassword;
// Send password in mail
// TODO: LOG
// Clear form and make way for next person