Fixed a scope bug for a JS state variable in a user control

This commit is contained in:
Rick Falkvinge
2016-10-07 06:09:47 +02:00
parent 04b66e59a7
commit a8cbfe310c
4 changed files with 37 additions and 16 deletions
+3 -2
View File
@@ -10,11 +10,12 @@ using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Swarm;
using Swarmops.Common.Exceptions;
using Swarmops.Frontend;
namespace Swarmops.Frontend.Automation
{
public partial class SwarmFunctions : Swarmops.Frontend.DataV5Base
public partial class SwarmFunctions : DataV5Base
{
protected void Page_Load (object sender, EventArgs e)
{
@@ -276,7 +277,7 @@ namespace Swarmops.Frontend.Automation
return new AjaxInputCallResult
{
Success = false,
DisplayMessage = Resources.Global.Global_FieldCannotBeEmpty,
DisplayMessage = JavascriptEscape(Resources.Global.Global_FieldCannotBeEmpty),
FailReason = AjaxInputCallResult.ErrorInvalidFormat,
NewValue = GetPersonValue (personId, field)
};
+1 -1
View File
@@ -174,7 +174,7 @@ namespace Swarmops.Frontend
return input.Replace ("\"", "\\\"").Replace (" ", " ").Trim();
}
public string JavascriptEscape (string input)
public static string JavascriptEscape (string input)
{
return CommonV5.JavascriptEscape (input);
}
+7 -7
View File
@@ -1,17 +1,17 @@
<%@ Control Language="C#" AutoEventWireup="True" CodeBehind="AjaxTextBox.ascx.cs" Inherits="Swarmops.Frontend.Controls.Base.AjaxTextBox" %>
<%-- ReSharper disable HeuristicallyUnreachableCode --%>
<%-- ReSharper disable once ConditionIsAlwaysConst --%>
<script type="text/javascript">
$(document).ready(function () {
var _initVal_<%=this.TextInput.ClientID%> = $('#<%=this.TextInput.ClientID%>').val();
var _initVal_<%=this.TextInput.ClientID%> = $('#<%=this.TextInput.ClientID%>').val();
$(document).ready(function () {
$('#<%=this.TextInput.ClientID%>').blur(function() {
var currentValue = $('#<%=this.TextInput.ClientID%>').val();
alert(currentValue + "\r\n" + _initVal_<%=this.TextInput.ClientID%>);
if (currentValue != _initVal_<%=this.TextInput.ClientID%>) {
var jsonData = {};
jsonData.newValue = currentValue;
@@ -24,7 +24,7 @@
//
// The page must include IncludedControls.JsonParameters and IncludedControls.ColorAnimation among its script.
$(this).css('background-color', '#FFFFE0');
$(this).css('background-color', '#FFFFA0');
if ("" != "<%=this.AjaxCallbackUrl%>") { // if there's a direct callback AJAX url
@@ -84,13 +84,13 @@
function <%=this.ClientID%>_updateSuccessAnimate(newValue) {
$('#<%=this.TextInput.ClientID%>').css('background-color', '#E0FFE0');
$('#<%=this.TextInput.ClientID%>').animate({ backgroundColor: "#FFFFFF" }, 250);
$('#<%=this.TextInput.ClientID%>').animate({ backgroundColor: "#FFFFFF" }, 500);
<%=this.ClientID%>_initialize(newValue);
}
function <%=this.ClientID%>_updateFailAnimate(newValue) {
$('#<%=this.TextInput.ClientID%>').css('background-color', '#FFA0A0');
$('#<%=this.TextInput.ClientID%>').animate({ backgroundColor: "#FFFFFF" }, 250);
$('#<%=this.TextInput.ClientID%>').animate({ backgroundColor: "#FFFFFF" }, 1000);
<%=this.ClientID%>_initialize(newValue);
}
+26 -6
View File
@@ -237,7 +237,7 @@
</div>
</div>
<div title="<img src='/Images/Icons/iconshock-lock-256px.png' height='64' width='64' />">
<h2><span class="spanModalEditingPersonName">PERSONNAME</span>: Security</h2>
<h2><span class="spanModalEditingPersonName">PERSONNAME</span>: Security (your own)</h2>
<div class="entryFields">...</div>
<div class="entryLabels">
New Password<br/>
@@ -246,6 +246,17 @@
Enter current password to save
</div>
</div>
<div title="<img src='/Images/Icons/iconshock-lock-256px.png' height='64' width='64' />">
<h2><span class="spanModalEditingPersonName">PERSONNAME</span>: Security provisioning</h2>
<div class="entryFields">
<input type="button" value="#SendResetMail#" />&#8203;<br/>
<input type="switch" todo="true"/>
</div>
<div class="entryLabels">
Mail a password-reset link<br/>
2FA (disabling sets login quarantine)
</div>
</div>
<!--
<div title="<img src='/Images/Icons/iconshock-foreman-128px.png' height='64' width='64' />">
<h2><span class="spanModalEditingPersonName">PERSONNAME</span>: Role and Responsibility</h2>
@@ -373,19 +384,18 @@
_master_PersonEditLoading = false;
} else {
// If secvio, notify
alert('Server error: Call to SwarmFunctions.aspx failed');
}
});
// Begin ajax query for data
// If success, populate; enable saving on change
// If secvio, notify
}
var _master_PersonEditedId = -1; // no person: zero means "self"
var _master_PersonEditLoading = false;
function masterPersonEditorOnFieldChange(newValue, fieldName, controlName) {
// Do the AJAX call from here, as we need to also pass along the person ID of the person edited
// (the AjaxTextBox auto-callback is disabled for this reason, code duplicated here)
@@ -407,9 +417,19 @@
"/Automation/SwarmFunctions.aspx/SetPersonEditorData",
jsonData,
function(result) {
window[controlName + "_updateSuccessAnimate"](result.NewValue);
console.log(result);
if (result.Success) {
window[controlName + "_updateSuccessAnimate"](result.NewValue);
} else {
window[controlName + "_updateFailAnimate"](result.NewValue);
if (result.DisplayMessage != '') {
alertify.error(SwarmopsJS.unescape(result.DisplayMessage));
}
}
},
function(result) {
console.log(result);
alert('fail');
window[controlName + "_updateFailAnimate"](result.NewValue);
});