Refactor AjaxInputEditBox, work on Person Edit
This commit is contained in:
@@ -306,6 +306,21 @@ public class AjaxCallResult
|
||||
}
|
||||
|
||||
|
||||
public class AjaxInputCallResult: AjaxCallResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Must always be set if Success is true, and contain canonically formatted new value
|
||||
/// </summary>
|
||||
public string NewValue { get; set; }
|
||||
/// <summary>
|
||||
/// When Success is false, valid FailReason values are "AccessDenied", "ServerError" and "InvalidFormat"
|
||||
/// </summary>
|
||||
public string FailReason { get; set; }
|
||||
|
||||
public const string ErrorAccessDenied = "AccessDenied";
|
||||
public const string ErrorServerError = "ServerError";
|
||||
public const string ErrorInvalidFormat = "InvalidFormat";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -256,5 +256,17 @@ namespace Swarmops.Frontend.Automation
|
||||
TwitterId = person.TwitterId
|
||||
};
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public static AjaxInputCallResult SetPersonEditorData(string newValue, string cookie)
|
||||
{
|
||||
return new AjaxInputCallResult
|
||||
{
|
||||
Success = true,
|
||||
NewValue = "The change call was successful"
|
||||
};
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
var _initVal_<%=this.TextInput.ClientID%> = $('#<%=this.TextInput.ClientID%>').val();
|
||||
|
||||
$('#<%=this.TextInput.ClientID%>').blur(function () {
|
||||
$('#<%=this.TextInput.ClientID%>').blur(function() {
|
||||
|
||||
var currentValue = $('#<%=this.TextInput.ClientID%>').val();
|
||||
|
||||
@@ -17,67 +17,60 @@
|
||||
// The AJAX call expects the following function prototype:
|
||||
//
|
||||
// [WebMethod]
|
||||
// public static AjaxTextBox.CallbackResult FunctionName (string newValue, string cookie);
|
||||
// public static AjaxInputCallbackResult FunctionName (string newValue, string cookie);
|
||||
//
|
||||
// The page must include IncludedControls.JsonParameters and IncludedControls.ColorAnimation among its script.
|
||||
//
|
||||
// The AJAX return value expects this structure:
|
||||
//
|
||||
// msg.d {
|
||||
// int ResultCode; // 0 - Unknown, 1 - Success, 2 - [Value was] Changed, 3 - Invalid [value], 4 - NoPermission
|
||||
// string NewData; // string as it should be displayed after change - overrides input and current value
|
||||
// };
|
||||
|
||||
$(this).css('background-color', '#FFFFE0');
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "<%=this.AjaxCallbackUrl%>",
|
||||
data: $.toJSON(jsonData),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
success: $.proxy(function (msg) {
|
||||
if (msg.d.ResultCode == 3 || msg.d.ResultCode == 4) { // Invalid or NoPermission
|
||||
if (msg.d.DisplayMessage != null)
|
||||
{
|
||||
alertify.error (msg.d.DisplayMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
SwarmopsJS.ajaxCall(
|
||||
"<%=this.AjaxCallbackUrl%>",
|
||||
jsonData,
|
||||
$.proxy(function(msg) {
|
||||
if (msg.Success == false) {
|
||||
if (msg.DisplayMessage != null) {
|
||||
alertify.error(msg.DisplayMessage);
|
||||
} else {
|
||||
alertify.error("There was an error attempting to set this value."); // TODO: Localize
|
||||
}
|
||||
$(this).css('background-color', '#FFA0A0');
|
||||
} else { // msg.d.Result should be Changed or Success here
|
||||
if (msg.d.DisplayMessage != null)
|
||||
{
|
||||
alertify.log (msg.d.DisplayMessage);
|
||||
} else {
|
||||
if (msg.DisplayMessage != null) {
|
||||
alertify.log(msg.DisplayMessage);
|
||||
}
|
||||
$(this).css('background-color', '#E0FFE0');
|
||||
_initVal_<%=this.TextInput.ClientID%> = msg.d.NewData;
|
||||
_initVal_<%=this.TextInput.ClientID%> = msg.NewValue;
|
||||
}
|
||||
$(this).val(_initVal_<%=this.TextInput.ClientID%>);
|
||||
$(this).animate({ backgroundColor: "#FFFFFF" }, 250);
|
||||
<%
|
||||
|
||||
if (!string.IsNullOrEmpty (this.OnChange))
|
||||
if (!string.IsNullOrEmpty(this.OnChange))
|
||||
{
|
||||
Response.Write (this.OnChange + "(msg.d.NewData);"); // JavaScript callback on successful change
|
||||
if (string.IsNullOrEmpty (this.Cookie))
|
||||
{
|
||||
Response.Write (this.OnChange + "(msg.NewValue);"); // JavaScript callback on successful change
|
||||
}
|
||||
else
|
||||
{
|
||||
Response.Write (this.OnChange + "(msg.NewValue, '" + this.Cookie + "');"); // JavaScript callback on successful change
|
||||
}
|
||||
}
|
||||
|
||||
%>
|
||||
}, this),
|
||||
error: $.proxy(function (msg) {
|
||||
$.proxy(function(msg) {
|
||||
alertify.error("<%= Resources.Global.Error_AjaxCallException %>");
|
||||
$(this).val (_initVal_<%=this.TextInput.ClientID%>);
|
||||
$(this).val(_initVal_<%=this.TextInput.ClientID%>);
|
||||
$(this).css('background-color', '#FFA0A0');
|
||||
$(this).animate({ backgroundColor: "#FFFFFF" }, 250);
|
||||
}, this)
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
function <%=this.ClientID%>_disable() {
|
||||
$('#<%=this.TextInput.ClientID%>').attr ('disabled', 'disabled');
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Swarmops.Frontend.Controls.v5.Base
|
||||
public string Placeholder { get; set; }
|
||||
|
||||
// Ajax result codes and classes
|
||||
|
||||
/*
|
||||
public const int CodeUnknown = 0;
|
||||
public const int CodeSuccess = 1;
|
||||
public const int CodeChanged = 2;
|
||||
@@ -57,6 +57,6 @@ namespace Swarmops.Frontend.Controls.v5.Base
|
||||
public int ResultCode { get; set; }
|
||||
public string DisplayMessage { get; set; } // may be empty
|
||||
public string NewData { get; set; }
|
||||
};
|
||||
};*/
|
||||
}
|
||||
}
|
||||
+17
-4
@@ -218,13 +218,13 @@
|
||||
|
||||
<!-- assorted popups, for use by all pages -->
|
||||
|
||||
<Swarmops5:ModalDialog ID="ModalMasterEditPerson" runat="server">
|
||||
<Swarmops5:ModalDialog ID="ModalMasterEditPerson" OnClientClose="masterEndEditPerson" runat="server">
|
||||
<DialogCode>
|
||||
<div id="divTabsEditPerson" class="easyui-tabs" data-options="tabWidth:70,tabHeight:70">
|
||||
<div title="<img src='/Images/Icons/iconshock-redshirt-128px.png' width='64' height='64' />">
|
||||
<h2><span class="spanModalEditingPersonName">PERSONNAME</span>: Account</h2>
|
||||
<div class="entryFields">
|
||||
<Swarmops5:AjaxTextBox ID="MasterEditPersonName" runat="server" />​<br/>
|
||||
<Swarmops5:AjaxTextBox ID="MasterEditPersonName" runat="server" OnChange="masterPersonEditorOnFieldChange" Cookie="Name" AjaxCallbackUrl="/Automation/SwarmFunctions.aspx/SetPersonEditorData" />​<br/>
|
||||
<Swarmops5:AjaxTextBox ID="MasterEditPersonMail" runat="server" />​<br/>
|
||||
<Swarmops5:AjaxTextBox ID="MasterEditPersonPhone" runat="server" />​<br/>
|
||||
<Swarmops5:AjaxTextBox ID="MasterEditPersonTwitterId" runat="server" />
|
||||
@@ -346,7 +346,7 @@
|
||||
<%= this.MasterEditPersonPhone.ClientID %>_disableClear();
|
||||
<%= this.MasterEditPersonTwitterId.ClientID %>_disableClear();
|
||||
|
||||
$('span.spanModalEditingPersonName').text("Loading"); // TODO: Localize
|
||||
$('span.spanModalEditingPersonName').text(decodeURIComponent('<%=Uri.EscapeDataString(Resources.Global.Global_LoadingPlaceholderShort)%>'));
|
||||
|
||||
<%=this.ModalMasterEditPerson.ClientID%>_open();
|
||||
|
||||
@@ -354,6 +354,9 @@
|
||||
personId: personId
|
||||
};
|
||||
|
||||
_master_PersonEditLoading = false;
|
||||
_master_PersonEditedId = personId;
|
||||
|
||||
SwarmopsJS.ajaxCall('/Automation/SwarmFunctions.aspx/GetPersonEditorData', personEditorData, function(data) {
|
||||
if (data.Success) {
|
||||
$('span.spanModalEditingPersonName').text(data.Name);
|
||||
@@ -362,8 +365,10 @@
|
||||
<%= this.MasterEditPersonMail.ClientID %>_initialize(data.Mail);
|
||||
<%= this.MasterEditPersonPhone.ClientID %>_initialize(data.Phone);
|
||||
<%= this.MasterEditPersonTwitterId.ClientID %>_initialize(data.TwitterId);
|
||||
|
||||
_master_PersonEditLoading = false;
|
||||
} else {
|
||||
alert('Call to SwarmFunctions.aspx failed');
|
||||
alert('Server error: Call to SwarmFunctions.aspx failed');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -376,6 +381,14 @@
|
||||
var _master_PersonEditedId = -1; // no person: zero means "self"
|
||||
var _master_PersonEditLoading = false;
|
||||
|
||||
function masterPersonEditorOnFieldChange(newValue, fieldName) {
|
||||
alert("Field Change: " + fieldName + " changed to '" + newValue + "'");
|
||||
}
|
||||
|
||||
function masterEndEditPerson() {
|
||||
alert("EndEditPerson");
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</form>
|
||||
|
||||
@@ -396,47 +396,48 @@ namespace Swarmops.Frontend.Pages.v5.Admin
|
||||
|
||||
|
||||
[WebMethod]
|
||||
static public AjaxTextBox.CallbackResult StoreCallback(string newValue, string cookie)
|
||||
static public AjaxInputCallResult StoreCallback(string newValue, string cookie)
|
||||
{
|
||||
AjaxTextBox.CallbackResult result = new AjaxTextBox.CallbackResult();
|
||||
AjaxInputCallResult result = new AjaxInputCallResult();
|
||||
AuthenticationData authenticationData = GetAuthenticationDataAndCulture();
|
||||
|
||||
if (!authenticationData.Authority.HasAccess (new Access (authenticationData.CurrentOrganization, AccessAspect.Administration, AccessType.Write)))
|
||||
{
|
||||
result.ResultCode = AjaxTextBox.CodeNoPermission;
|
||||
result.Success = false; // this is the default on initialization, but let's be explicit about it
|
||||
result.FailReason = AjaxInputCallResult.ErrorAccessDenied;
|
||||
return result;
|
||||
}
|
||||
|
||||
switch (cookie)
|
||||
{
|
||||
case "VanityDomain":
|
||||
result.NewData = newValue.Trim();
|
||||
result.ResultCode = AjaxTextBox.CodeSuccess;
|
||||
authenticationData.CurrentOrganization.VanityDomain = result.NewData;
|
||||
result.Success = true;
|
||||
result.NewValue = newValue.Trim();
|
||||
authenticationData.CurrentOrganization.VanityDomain = result.NewValue;
|
||||
break;
|
||||
|
||||
case "OpenLedgersDomain":
|
||||
result.NewData = newValue.Trim();
|
||||
result.ResultCode = AjaxTextBox.CodeSuccess;
|
||||
authenticationData.CurrentOrganization.OpenLedgersDomain = result.NewData;
|
||||
result.Success = true;
|
||||
result.NewValue = newValue.Trim();
|
||||
authenticationData.CurrentOrganization.OpenLedgersDomain = result.NewValue;
|
||||
break;
|
||||
|
||||
case "PaypalAccountAddress":
|
||||
result.NewData = newValue.Trim();
|
||||
result.ResultCode = AjaxTextBox.CodeSuccess;
|
||||
authenticationData.CurrentOrganization.PaypalAccountMailAddress = result.NewData;
|
||||
result.Success = true;
|
||||
result.NewValue = newValue.Trim();
|
||||
authenticationData.CurrentOrganization.PaypalAccountMailAddress = result.NewValue;
|
||||
break;
|
||||
|
||||
case "GovernmentRegistrationId":
|
||||
result.NewData = newValue.Trim();
|
||||
result.ResultCode = AjaxTextBox.CodeSuccess;
|
||||
authenticationData.CurrentOrganization.GovernmentRegistrationId = result.NewData;
|
||||
result.Success = true;
|
||||
result.NewValue = newValue.Trim();
|
||||
authenticationData.CurrentOrganization.GovernmentRegistrationId = result.NewValue;
|
||||
break;
|
||||
|
||||
case "TaxPaymentOcr":
|
||||
result.NewData = newValue.Trim();
|
||||
result.ResultCode = AjaxTextBox.CodeSuccess;
|
||||
authenticationData.CurrentOrganization.TaxPaymentOcr = result.NewData;
|
||||
result.Success = true;
|
||||
result.NewValue = newValue.Trim();
|
||||
authenticationData.CurrentOrganization.TaxPaymentOcr = result.NewValue;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -194,14 +194,15 @@ namespace Swarmops.Frontend.Pages.v5.Admin
|
||||
|
||||
|
||||
[WebMethod]
|
||||
static public AjaxTextBox.CallbackResult StoreCallback(string newValue, string cookie)
|
||||
static public AjaxInputCallResult StoreCallback(string newValue, string cookie)
|
||||
{
|
||||
AjaxTextBox.CallbackResult result = new AjaxTextBox.CallbackResult();
|
||||
AjaxInputCallResult result = new AjaxInputCallResult();
|
||||
AuthenticationData authData = GetAuthenticationDataAndCulture();
|
||||
|
||||
if (!authData.Authority.HasAccess (new Access (AccessAspect.Administration, AccessType.Write)))
|
||||
{
|
||||
result.ResultCode = AjaxTextBox.CodeNoPermission;
|
||||
result.Success = false; // this is default on init, but let's be explicit about it
|
||||
result.FailReason = AjaxInputCallResult.ErrorAccessDenied;
|
||||
return result; // fail silently
|
||||
}
|
||||
|
||||
@@ -226,7 +227,8 @@ namespace Swarmops.Frontend.Pages.v5.Admin
|
||||
catch (FormatException)
|
||||
{
|
||||
result.DisplayMessage = Resources.Pages.Admin.SystemSettings_Error_SmtpHostPort;
|
||||
result.ResultCode = AjaxTextBox.CodeInvalid;
|
||||
result.FailReason = AjaxInputCallResult.ErrorInvalidFormat;
|
||||
result.Success = false;
|
||||
return result; // return early
|
||||
}
|
||||
}
|
||||
@@ -238,13 +240,14 @@ namespace Swarmops.Frontend.Pages.v5.Admin
|
||||
|
||||
OutboundComm.CreateNotification(Organization.Sandbox, Logic.Communications.Payload.NotificationResource.System_MailServerTest);
|
||||
|
||||
result.ResultCode = AjaxTextBox.CodeChanged;
|
||||
result.NewData = FormatSmtpAccessString (user, pass, host, port);
|
||||
result.Success = true;
|
||||
result.NewValue = FormatSmtpAccessString (user, pass, host, port);
|
||||
result.DisplayMessage = Resources.Pages.Admin.SystemSettings_TestMailSent;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.ResultCode = AjaxTextBox.CodeInvalid;
|
||||
result.Success = false;
|
||||
result.FailReason = AjaxInputCallResult.ErrorInvalidFormat;
|
||||
result.DisplayMessage = Resources.Pages.Admin.SystemSettings_Error_SmtpSyntax;
|
||||
}
|
||||
break;
|
||||
@@ -261,26 +264,26 @@ namespace Swarmops.Frontend.Pages.v5.Admin
|
||||
|
||||
SystemSettings.ExternalUrl = newValue;
|
||||
|
||||
result.NewData = newValue;
|
||||
result.ResultCode = AjaxTextBox.CodeSuccess;
|
||||
result.NewValue = newValue;
|
||||
result.Success = true;
|
||||
break;
|
||||
|
||||
case "InstallationName":
|
||||
result.NewData = newValue.Trim();
|
||||
result.ResultCode = AjaxTextBox.CodeSuccess;
|
||||
SystemSettings.InstallationName = result.NewData;
|
||||
result.NewValue = newValue.Trim();
|
||||
result.Success = true;
|
||||
SystemSettings.InstallationName = result.NewValue;
|
||||
break;
|
||||
|
||||
case "AdminSender":
|
||||
result.NewData = newValue.Trim();
|
||||
result.ResultCode = AjaxTextBox.CodeSuccess;
|
||||
SystemSettings.InstallationName = result.NewData;
|
||||
result.NewValue = newValue.Trim();
|
||||
result.Success = true;
|
||||
SystemSettings.InstallationName = result.NewValue;
|
||||
break;
|
||||
|
||||
case "AdminAddress":
|
||||
result.NewData = newValue.Trim();
|
||||
result.ResultCode = AjaxTextBox.CodeSuccess;
|
||||
SystemSettings.AdminNotificationAddress = result.NewData;
|
||||
result.NewValue = newValue.Trim();
|
||||
result.Success = true;
|
||||
SystemSettings.AdminNotificationAddress = result.NewValue;
|
||||
break;
|
||||
|
||||
case "WebsocketServer":
|
||||
@@ -291,14 +294,15 @@ namespace Swarmops.Frontend.Pages.v5.Admin
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
result.ResultCode = AjaxTextBox.CodeSuccess;
|
||||
result.NewData = newValue.Trim();
|
||||
result.NewValue = newValue.Trim();
|
||||
result.Success = true;
|
||||
SystemSettings.WebsocketPortServer = newPort;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
result.ResultCode = AjaxTextBox.CodeInvalid;
|
||||
result.NewData = SystemSettings.WebsocketPortServer.ToString(CultureInfo.InvariantCulture);
|
||||
result.Success = false;
|
||||
result.FailReason = AjaxInputCallResult.ErrorInvalidFormat;
|
||||
result.NewValue = SystemSettings.WebsocketPortServer.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -311,14 +315,15 @@ namespace Swarmops.Frontend.Pages.v5.Admin
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
result.ResultCode = AjaxTextBox.CodeSuccess;
|
||||
result.NewData = newValue.Trim();
|
||||
result.NewValue = newValue.Trim();
|
||||
result.Success = true;
|
||||
SystemSettings.WebsocketPortClient = newPort;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
result.ResultCode = AjaxTextBox.CodeInvalid;
|
||||
result.NewData = SystemSettings.WebsocketPortClient.ToString(CultureInfo.InvariantCulture);
|
||||
result.Success = false;
|
||||
result.FailReason = AjaxInputCallResult.ErrorInvalidFormat;
|
||||
result.NewValue = SystemSettings.WebsocketPortClient.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user