Refactored field validation; work on Add Person
This commit is contained in:
@@ -1,65 +0,0 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Web;
|
||||
using System.Web.Script.Services;
|
||||
using System.Web.Services;
|
||||
using Swarmops.Logic.Support;
|
||||
|
||||
/// <summary>
|
||||
/// Summary description for FieldValidation
|
||||
/// </summary>
|
||||
[WebService (Namespace = "http://tempuri.org/")]
|
||||
[WebServiceBinding (ConformsTo = WsiProfiles.BasicProfile1_1)]
|
||||
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
|
||||
[ScriptService]
|
||||
public class FieldValidation : WebService
|
||||
{
|
||||
private CultureInfo GetUserCulture()
|
||||
{
|
||||
// Determine correct culture for parsing
|
||||
CultureInfo culture = null;
|
||||
|
||||
// Set default culture (English, United States, but that doesn't work so fake it to GB)
|
||||
string preferredCulture = "en-US";
|
||||
|
||||
// ----------- SET CULTURE ------------
|
||||
// Does the user have a culture preference?
|
||||
|
||||
if (HttpContext.Current.Request.Cookies["PreferredCulture"] != null)
|
||||
{
|
||||
// Yes, set it
|
||||
preferredCulture = HttpContext.Current.Request.Cookies["PreferredCulture"].Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No, determine from browser
|
||||
string browserPreference = "en-GB";
|
||||
if (HttpContext.Current.Request.UserLanguages != null &&
|
||||
HttpContext.Current.Request.UserLanguages.Length > 0)
|
||||
{
|
||||
browserPreference = HttpContext.Current.Request.UserLanguages[0];
|
||||
preferredCulture = browserPreference;
|
||||
}
|
||||
}
|
||||
|
||||
// Actually set the culture
|
||||
|
||||
try
|
||||
{
|
||||
culture = CultureInfo.CreateSpecificCulture (preferredCulture);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
culture = CultureInfo.InvariantCulture;
|
||||
}
|
||||
|
||||
return culture;
|
||||
}
|
||||
|
||||
|
||||
[WebMethod]
|
||||
public bool IsDateValid (string input)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
<%@ WebService Language="C#" CodeBehind="~/App_Code/FieldValidation.cs" Class="FieldValidation" %>
|
||||
@@ -32,7 +32,7 @@ namespace Swarmops.Frontend.Automation
|
||||
|
||||
|
||||
[WebMethod]
|
||||
public bool IsAmountValid(string amount)
|
||||
public static bool IsAmountValid(string amount)
|
||||
{
|
||||
AuthenticationData authData = GetAuthenticationDataAndCulture(); // sets culture
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Swarmops.Frontend.Automation
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public bool AreDocumentsUploaded(string guidString)
|
||||
public static bool AreDocumentsUploaded(string guidString)
|
||||
{
|
||||
Documents documents = Documents.RecentFromDescription(guidString);
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
|
||||
}
|
||||
|
||||
EasyUIControlsUsed = EasyUIControl.Tree;
|
||||
IncludedControlsUsed = IncludedControl.FileUpload;
|
||||
IncludedControlsUsed = IncludedControl.FileUpload | IncludedControl.JsonParameters;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
if (msg.d != true) {
|
||||
isValid = false;
|
||||
alertify.error("<asp:Literal runat="server" ID="LiteralErrorAmount" />");
|
||||
$('#<%=this.TextAmount.ClientID %>').focus();
|
||||
$('#<%=this.TextAmount.ClientID %>').addClass("entryError").focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -44,6 +44,7 @@
|
||||
function validateTextField (fieldId, message) {
|
||||
if ($(fieldId).val().length == 0) {
|
||||
alertify.error(message);
|
||||
$(fieldId).addClass("entryError");
|
||||
$(fieldId).focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
|
||||
}
|
||||
|
||||
EasyUIControlsUsed = EasyUIControl.Tree;
|
||||
IncludedControlsUsed = IncludedControl.JsonParameters;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +48,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
|
||||
this.LabelBankClearing.Text = Resources.Pages.Financial.RequestCashAdvance_BankClearing;
|
||||
this.LabelBankAccount.Text = Resources.Pages.Financial.RequestCashAdvance_BankAccount;
|
||||
|
||||
this.LiteralErrorAmount.Text = Resources.Pages.Financial.RequestCashAdvance_ValidationError_Amount;
|
||||
this.LiteralErrorAmount.Text = String.Format(Resources.Pages.Financial.RequestCashAdvance_ValidationError_Amount, CurrentOrganization.Currency.DisplayCode);
|
||||
this.LiteralErrorPurpose.Text = Resources.Pages.Financial.RequestCashAdvance_ValidationError_Purpose;
|
||||
this.LiteralErrorBudget.Text = Resources.Pages.Financial.RequestCashAdvance_ValidationError_Budget;
|
||||
this.LiteralErrorBankName.Text = Resources.Pages.Financial.RequestCashAdvance_ValidationError_BankName;
|
||||
|
||||
@@ -132,33 +132,34 @@
|
||||
function ValidateFields() {
|
||||
var isValid = true;
|
||||
|
||||
isValid = ValidateTextField('#<%= TextCity.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorCity" />") && isValid;
|
||||
isValid = ValidateTextField('#<%= TextStreet1.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorStreet" />") && isValid;
|
||||
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');
|
||||
var jsonData = {};
|
||||
jsonData.input = dateFieldContents;
|
||||
|
||||
$.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();
|
||||
data: $.toJSON(jsonData),
|
||||
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;
|
||||
$('#<%= TextDateOfBirth.ClientID %>').addClass("entryError");
|
||||
alertify.error("<asp:Literal runat="server" ID="LiteralErrorDate" />");
|
||||
$('#<%=this.TextDateOfBirth.ClientID %>').focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
isValid = ValidateTextField('#<%= TextCity.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorCity" />") && isValid;
|
||||
isValid = ValidateTextField('#<%= TextStreet1.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorStreet" />") && isValid;
|
||||
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?
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using Swarmops.Logic.Communications;
|
||||
using Swarmops.Logic.Communications.Transmission;
|
||||
using Swarmops.Logic.Security;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Support;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
@@ -68,6 +69,7 @@ namespace Swarmops.Frontend.Pages.v5.Swarm
|
||||
this.LiteralErrorMail.Text = Resources.Pages.Swarm.AddPerson_ErrorMail;
|
||||
this.LiteralErrorName.Text = Resources.Pages.Swarm.AddPerson_ErrorName;
|
||||
this.LiteralErrorStreet.Text = Resources.Pages.Swarm.AddPerson_ErrorStreet;
|
||||
this.LiteralErrorDate.Text = Resources.Pages.Swarm.AddPerson_ErrorDate;
|
||||
|
||||
this.BoxTitle.Text = PageTitle = String.Format (Resources.Pages.Swarm.AddPerson_Title,
|
||||
Participant.Localized (CurrentOrganization.RegularLabel));
|
||||
@@ -100,7 +102,12 @@ namespace Swarmops.Frontend.Pages.v5.Swarm
|
||||
|
||||
protected void ButtonSubmit_Click (object sender, EventArgs e)
|
||||
{
|
||||
// TODO: Parse birthdate
|
||||
DateTime dateOfBirth = new DateTime (1800, 1, 1); // null equivalent
|
||||
|
||||
if (this.TextDateOfBirth.Text.Length > 0)
|
||||
{
|
||||
dateOfBirth = DateTime.Parse (this.TextDateOfBirth.Text);
|
||||
}
|
||||
|
||||
Person newPerson = Person.Create (this.TextName.Text, this.TextMail.Text, string.Empty, this.TextPhone.Text,
|
||||
this.TextStreet1.Text + this.TextStreet2.Text,
|
||||
@@ -111,7 +118,11 @@ namespace Swarmops.Frontend.Pages.v5.Swarm
|
||||
|
||||
OutboundComm.CreateMembershipLetter (ParticipantMailType.MemberAddedWelcome, newMembership, CurrentUser);
|
||||
|
||||
// TODO: LOG
|
||||
SwarmopsLogEntry logEntry = SwarmopsLog.CreateEntry (newPerson,
|
||||
new Swarmops.Logic.Support.LogEntries.PersonAddedLogEntry (newMembership, CurrentUser));
|
||||
|
||||
logEntry.CreateAffectedObject (newMembership);
|
||||
logEntry.CreateAffectedObject (CurrentUser);
|
||||
|
||||
// Clear form and make way for next person
|
||||
|
||||
|
||||
Reference in New Issue
Block a user