Lots of work on a slider toggle control

This commit is contained in:
Falkvinge
2016-11-14 18:39:34 +01:00
parent c9db96ef7f
commit df0add0a18
8 changed files with 109 additions and 100 deletions
+2 -2
View File
@@ -19,7 +19,7 @@ namespace Resources {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option or rebuild the Visual Studio project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Web.Application.StronglyTypedResourceProxyBuilder", "11.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Web.Application.StronglyTypedResourceProxyBuilder", "14.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Global {
@@ -1447,7 +1447,7 @@ namespace Resources {
}
/// <summary>
/// Looks up a localized string similar to 2FA (disabling quarantines login).
/// Looks up a localized string similar to Two-factor authentication (disabling quarantines login).
/// </summary>
internal static string Master_EditPerson2FAEnable {
get {
+1 -1
View File
@@ -740,7 +740,7 @@
<value>Twitter ID</value>
</data>
<data name="Master_EditPerson2FAEnable" xml:space="preserve">
<value>2FA (disabling quarantines login)</value>
<value>Two-factor authentication (disabling quarantines login)</value>
<comment>This means that a disabling of two-factor authentication will notify the user and lock them out from logging back on for a while, typically 48 hours or seven days.</comment>
</data>
<data name="Master_EditPersonHeaderAccount" xml:space="preserve">
-11
View File
@@ -64,18 +64,7 @@ namespace Swarmops.Frontend
}
// Common localizations
// ReSharper disable InconsistentNaming
public string Localized_SwitchLabelOn_Upper
{
get { return CommonV5.JavascriptEscape(Resources.Global.Global_On.ToUpperInvariant()); }
}
public string Localized_SwitchLabelOff_Upper
{
get { return CommonV5.JavascriptEscape(Resources.Global.Global_Off.ToUpperInvariant()); }
}
}
}
+77 -67
View File
@@ -2,99 +2,109 @@
<script type="text/javascript">
var _initVal_<%=this.TextInput.ClientID%> = $('#<%=this.TextInput.ClientID%>').val();
var _initVal_<%=this.SliderCheckbox.ClientID%> = <%= this.InitialValue.ToString().ToLower() %>;
$(document).ready(function () {
$('#<%=this.TextInput.ClientID%>').blur(function() {
$('#<%=this.ClientID%>_sliderContainer').toggles(
{
on: <%= this.InitialValue.ToString().ToLower() %>,
checkbox: $('#<%=this.SliderCheckbox.ClientID%>'),
text:
{
on: SwarmopsJS.unescape('<%= this.Localized_SwitchLabelOn_Upper %>'),
off: SwarmopsJS.unescape('<%= this.Localized_SwitchLabelOff_Upper %>')
}
})
.on('toggle', function(e, active)
{
alert(active);
var currentValue = $('#<%=this.TextInput.ClientID%>').val();
if (active != _initVal_<%=this.SliderCheckbox.ClientID%>) {
var jsonData = {};
jsonData.newValue = active;
jsonData.cookie = '<%=this.Cookie%>';
if (currentValue != _initVal_<%=this.TextInput.ClientID%>) {
var jsonData = {};
jsonData.newValue = currentValue;
jsonData.cookie = '<%=this.Cookie%>';
// The AJAX call expects the following function prototype:
//
// [WebMethod]
// public static AjaxInputCallbackResult FunctionName (bool newValue, string cookie);
//
// The page must include IncludedControls.JsonParameters and IncludedControls.ColorAnimation among its script.
// The AJAX call expects the following function prototype:
//
// [WebMethod]
// public static AjaxInputCallbackResult FunctionName (string newValue, string cookie);
//
// The page must include IncludedControls.JsonParameters and IncludedControls.ColorAnimation among its script.
// $(this).css('background-color', '#FFFFA0'); -- TODO: Find a way to mark ongoing update for slider
$(this).css('background-color', '#FFFFA0');
if ("" != "<%=this.AjaxCallbackUrl%>") { // if there's a direct callback AJAX url
if ("" != "<%=this.AjaxCallbackUrl%>") { // if there's a direct callback AJAX url
SwarmopsJS.ajaxCall(
"<%=this.AjaxCallbackUrl%>",
jsonData,
$.proxy(function(msg) {
if (msg.Success == false) {
if (msg.DisplayMessage != null) {
alertify.error(msg.DisplayMessage);
SwarmopsJS.ajaxCall(
"<%=this.AjaxCallbackUrl%>",
jsonData,
$.proxy(function(msg) {
if (msg.Success == false) {
if (msg.DisplayMessage != null) {
alertify.error(msg.DisplayMessage);
} else {
alertify.error(SwarmopsJS.unescape('<%= this.Localized_AjaxGeneralErrorSettingValue %>'));
}
$(this).css('background-color', '#FFA0A0');
} else {
alertify.error(SwarmopsJS.unescape('<%= this.Localized_AjaxGeneralErrorSettingValue %>'));
if (msg.DisplayMessage != null) {
alertify.log(msg.DisplayMessage);
}
$(this).css('background-color', '#E0FFE0');
_initVal_<%=this.SliderCheckbox.ClientID%> = msg.NewValue;
}
$(this).css('background-color', '#FFA0A0');
} else {
if (msg.DisplayMessage != null) {
alertify.log(msg.DisplayMessage);
}
$(this).css('background-color', '#E0FFE0');
_initVal_<%=this.TextInput.ClientID%> = msg.NewValue;
}
$(this).val(_initVal_<%=this.TextInput.ClientID%>);
$(this).animate({ backgroundColor: "#FFFFFF" }, 250);
<%
$(this).val(msg.NewValue);
$(this).animate({ backgroundColor: "#FFFFFF" }, 250);
<%
if (!string.IsNullOrEmpty(this.OnChange))
{
if (string.IsNullOrEmpty (this.Cookie))
if (!string.IsNullOrEmpty(this.OnChange))
{
Response.Write (this.OnChange + "(msg.NewValue);"); // 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
}
}
else
{
Response.Write (this.OnChange + "(msg.NewValue, '" + this.Cookie + "');"); // JavaScript callback on successful change
}
}
%>
}, this),
$.proxy(function(msg) {
alertify.error(SwarmopsJS.unescape('<%= this.Localized_AjaxCallException %>'));
$(this).val(_initVal_<%=this.TextInput.ClientID%>);
$(this).css('background-color', '#FFA0A0');
$(this).animate({ backgroundColor: "#FFFFFF" }, 250);
}, this)
);
} else {
// if there's no AJAX callback URL given, the javascript handler must take care of it
// Resharper marks this code as unused because it falsely thinks the if condition above is always true
<%=this.OnChange%> (currentValue, '<%=this.Cookie%>', '<%=this.ClientID%>'); // JavaScript callback on successful change
%>
}, this),
$.proxy(function(msg) {
alertify.error(SwarmopsJS.unescape('<%= this.Localized_AjaxCallException %>'));
$(this).val(_initVal_<%=this.SliderCheckbox.ClientID%>);
$(this).css('background-color', '#FFA0A0');
$(this).animate({ backgroundColor: "#FFFFFF" }, 250);
}, this)
);
} else {
// if there's no AJAX callback URL given, the javascript handler must take care of it
// Resharper marks this code as unused because it falsely thinks the if condition above is always true
_initVal_<%=this.SliderCheckbox.ClientID%> = active;
<%=this.OnChange%> (active, '<%=this.Cookie%>', '<%=this.ClientID%>'); // JavaScript callback on successful change
}
}
}
});
});
});
}
);
function <%=this.ClientID%>_disable() {
$('#<%=this.TextInput.ClientID%>').attr ('disabled', 'disabled');
$('#<%=this.SliderCheckbox.ClientID%>').attr ('disabled', 'disabled');
}
function <%=this.ClientID%>_enable() {
$('#<%=this.TextInput.ClientID%>').removeAttr('disabled');
$('#<%=this.SliderCheckbox.ClientID%>').removeAttr('disabled');
}
function <%=this.ClientID%>_setValue(newValue) {
$('#<%=this.TextInput.ClientID%>').val(newValue);
$('#<%=this.SliderCheckbox.ClientID%>').val(newValue);
}
function <%=this.ClientID%>_initialize(initValue) {
_initVal_<%=this.TextInput.ClientID%> = initValue;
_initVal_<%=this.SliderCheckbox.ClientID%> = initValue;
<%=this.ClientID%>_setValue(initValue);
<%=this.ClientID%>_enable();
}
@@ -104,4 +114,4 @@
</script>
<asp:Label runat="server" ID="ToggleSliderLabel"></asp:Label>
<div class="toggle-iphone toggle-padding"><asp:Checkbox ID="SliderCheckbox" runat="server"/></div>
<div class="toggle-iphone toggle-padding" id="<%=this.ClientID %>_sliderContainer"><asp:Checkbox ID="SliderCheckbox" runat="server"/></div>
+16 -3
View File
@@ -12,12 +12,25 @@ namespace Swarmops.Frontend.Controls.Base
{
protected void Page_Load(object sender, EventArgs e)
{
this.ToggleSliderLabel.Text = this.Label;
}
public string Label { get; set; }
public string CallbackUrl { get; set; }
public string OnClientChange { get; set; }
public string AjaxCallbackUrl { get; set; }
public string OnChange { get; set; }
public string Cookie { get; set; }
public bool InitialValue { get; set; }
// ReSharper disable InconsistentNaming
public string Localized_SwitchLabelOn_Upper
{
get { return CommonV5.JavascriptEscape(Resources.Global.Global_On.ToUpperInvariant()); }
}
public string Localized_SwitchLabelOff_Upper
{
get { return CommonV5.JavascriptEscape(Resources.Global.Global_Off.ToUpperInvariant()); }
}
}
}
+10 -14
View File
@@ -259,7 +259,7 @@
<h2><span class="spanModalEditingPersonName">PERSONNAME</span>: <asp:Label ID="MasterLabelEditPersonHeaderSecurityProvisioning" runat="server" /></h2>
<div class="entryFields">
<input type="button" id="masterPersonEditButtonResetPassword" onclick="masterPersonEditorConfirmResetPassword(); return false;" value="#SendResetMail#" />&#8203;<br/>
<label for="MasterCheckEditPersonEnable2FA"><asp:Label ID="MasterLabelEditPersonSecurity2FA" runat="server" Text="Bitcoin Cold"/></label><div class="MasterToggles toggle-padding toggle-iphone"><input type="checkbox" rel="MasterPersonEdit2FA" class="EditCheck" id="MasterCheckEditPersonEnable2FA"/></div><br/>
<Swarmops5:AjaxToggleSlider ID="MasterToggleEditPerson2FA" runat="server" Label="2FALabel" Cookie="2FA" AjaxCallbackUrl="" OnChange="masterPersonEditorOnToggle"/>
</div>
<div class="entryLabels">
@@ -355,15 +355,6 @@
// This JavaScript block is for the Master Modal Person Editor.
$(document).ready(function() {
$('.MasterToggles').toggles(
{ text: {
on: SwarmopsJS.unescape('<%= this.Localized_SwitchLabelOn_Upper %>'),
off: SwarmopsJS.unescape('<%= this.Localized_SwitchLabelOff_Upper %>')
}
}).change(function() {});
});
function masterBeginEditPerson(personId) {
_master_PersonEditedId = personId;
@@ -415,6 +406,15 @@
var _master_PersonEditLoading = false;
function masterPersonEditorOnToggle(newValue, fieldName, controlName) {
// Do the AJAX call from here, as we need to also pass along the person ID of the person edited
// (the AjaxToggleSlider auto-callback is disabled for this reason)
alert("Field Change: " + fieldName + " changed to '" + newValue + "'");
}
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)
@@ -458,10 +458,6 @@
window[controlName + "_updateFailAnimate"](result.NewValue);
});
//alert("Field Change: " + fieldName + " changed to '" + newValue + "'");
}
function masterEndEditPerson() {
+2 -2
View File
@@ -373,13 +373,13 @@ namespace Swarmops.Frontend {
protected global::System.Web.UI.WebControls.Label MasterLabelEditPersonHeaderSecurityProvisioning;
/// <summary>
/// MasterLabelEditPersonSecurity2FA control.
/// MasterToggleEditPerson2FA control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label MasterLabelEditPersonSecurity2FA;
protected global::Swarmops.Frontend.Controls.Base.AjaxToggleSlider MasterToggleEditPerson2FA;
/// <summary>
/// MasterLabelEditPersonResetPassword control.
+1
View File
@@ -33,6 +33,7 @@
<add tagPrefix="Swarmops5" tagName="DropDown" src="~/Controls/v5/Base/DropDown.ascx" />
<add tagPrefix="Swarmops5" tagName="ComboPeople" src="~/Controls/v5/Swarm/ComboPeople.ascx" />
<add tagPrefix="Swarmops5" tagName="AjaxTextBox" src="~/Controls/v5/Base/AjaxTextBox.ascx" />
<add tagPrefix="Swarmops5" tagName="AjaxToggleSlider" src="~/Controls/v5/Base/AjaxToggleSlider.ascx" />
<add tagPrefix="Swarmops5" tagName="AjaxComboPeople" src="~/Controls/v5/Swarm/ComboPeople.ascx" />
<add tagPrefix="Swarmops5" tagName="ModalDialog" src="~/Controls/v5/Base/ModalDialog.ascx" />
<add tagPrefix="Swarmops5" tagName="ExternalScripts" src="~/Controls/v5/UI/ExternalScripts.ascx" />