From 5b0ed02e03310424b0f500ca031b293bdee9e1a6 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Mon, 2 Jan 2017 00:13:12 +0100 Subject: [PATCH] Org settings fixed with new controls --- Site/Controls/v5/Base/AjaxToggleSlider.ascx | 10 +- Site/Pages/v5/Admin/OrgSettings.aspx | 120 +++++++------------- Site/Pages/v5/Admin/OrgSettings.aspx.cs | 38 ++++--- 3 files changed, 68 insertions(+), 100 deletions(-) diff --git a/Site/Controls/v5/Base/AjaxToggleSlider.ascx b/Site/Controls/v5/Base/AjaxToggleSlider.ascx index 9b0f9b83..94f5f25f 100644 --- a/Site/Controls/v5/Base/AjaxToggleSlider.ascx +++ b/Site/Controls/v5/Base/AjaxToggleSlider.ascx @@ -23,7 +23,7 @@ // The AJAX call expects the following function prototype: // // [WebMethod] - // public static AjaxInputCallbackResult FunctionName (bool newValue, string cookie); + // public static AjaxInputCallResult FunctionName (bool newValue, string cookie); // // The page must include IncludedControls.JsonParameters and IncludedControls.ColorAnimation among its script. @@ -61,11 +61,11 @@ { if (string.IsNullOrEmpty (this.Cookie)) { - Response.Write (this.OnChange + "(msg.NewValue);"); // JavaScript callback on successful change + Response.Write (this.OnChange + "(msg.NewValue === 'true');"); // JavaScript callback on successful change with boolean cast } else { - Response.Write (this.OnChange + "(msg.NewValue, '" + this.Cookie + "');"); // JavaScript callback on successful change + Response.Write (this.OnChange + "(msg.NewValue === 'true', '" + this.Cookie + "');"); // JavaScript callback on successful change } } @@ -103,6 +103,10 @@ $('#<%=this.ClientID%>_sliderContainer').data('toggles').toggle(newValue, true, true); } + function <%=this.ClientID%>_setValueAndCallback(newValue) { + $('#<%=this.ClientID%>_sliderContainer').data('toggles').toggle(newValue); + } + function <%=this.ClientID%>_initialize(initValue) { _initVal_<%=this.SliderCheckbox.ClientID%> = initValue; <%=this.ClientID%>_setValue(initValue); diff --git a/Site/Pages/v5/Admin/OrgSettings.aspx b/Site/Pages/v5/Admin/OrgSettings.aspx index e6056e3f..f946e486 100644 --- a/Site/Pages/v5/Admin/OrgSettings.aspx +++ b/Site/Pages/v5/Admin/OrgSettings.aspx @@ -10,63 +10,6 @@ $(document).ready(function() { $('#divTabs').tabs(); - $('.EditCheck').switchbutton({ - checkedLabel: SwarmopsJS.unescape('<%= this.Localized_SwitchLabelOn_Upper %>'), - uncheckedLabel: SwarmopsJS.unescape('<%= this.Localized_SwitchLabelOff_Upper %>') - }).change(function() { - - if (suppressSwitchResponse) { - return; - } - - $('#divUseAccountPlan').slideDown().fadeIn(); - - var jsonData = {}; - jsonData.switchName = $(this).attr("rel"); - jsonData.switchValue = $(this).prop('checked'); - - $.ajax({ - type: "POST", - url: "/Pages/v5/Admin/OrgSettings.aspx/SwitchToggled", - data: $.toJSON(jsonData), - contentType: "application/json; charset=utf-8", - dataType: "json", - success: function(msg) { - if (msg.d.Success) { - if (msg.d.DisplayMessage.length > 2) { // the 2 is rather arbitrary. Read as "if defined". - alertify.log(msg.d.DisplayMessage); - } - if (msg.d.RequireForex && !($('#CheckEnableForex').prop("checked"))) { - $("#CheckEnableForex").prop("checked", true).change(); - } - if (jsonData.switchName == "BitcoinHot") { - if (jsonData.switchValue) { - $('.bitcoinHotField').fadeIn(); - } else { - $('.bitcoinHotField').fadeOut(); - } - } - if (jsonData.switchName == "Paypal") { - if (jsonData.switchValue) { - $('.paypalAccountField').fadeIn(); - } else { - $('.paypalAccountField').fadeOut(); - } - } - } else { - alertify.error(msg.d.DisplayMessage); - if (msg.d.RequireForex && !($('#CheckEnableForex').prop("checked"))) { - $("#CheckEnableForex").prop("checked", true).change(); - } - } - }, - error: function(msg) { - // TODO: Reset switch, protest server unreachable - } - - }); - }); - // Ask for initial data $.ajax({ @@ -90,18 +33,16 @@ function initializeSettings(orgSettings) { console.log(orgSettings); <%=this.ToggleBitcoinCold.ClientID%>_initialize(orgSettings.AccountBitcoinCold); - suppressSwitchResponse = true; - $("#CheckEnableBitcoinCold").prop("checked", orgSettings.AccountBitcoinCold).change(); - $("#CheckEnableBitcoinHot").prop("checked", orgSettings.AccountBitcoinHot).change(); - $("#CheckEnablePaypal").prop("checked", orgSettings.AccountPaypal).change(); - $("#CheckEnableForex").prop("checked", orgSettings.AccountsForex).change(); - $("#CheckEnableVat").prop("checked", orgSettings.AccountsVat).change(); - $("#CheckParticipantFinancials").prop("checked", orgSettings.ParticipantFinancials).change(); + <%=this.ToggleBitcoinHot.ClientID%>_initialize(orgSettings.AccountBitcoinHot); + <%=this.TogglePaypal.ClientID%>_initialize(orgSettings.AccountPaypal); + <%=this.ToggleForex.ClientID%>_initialize(orgSettings.AccountsForex); + <%=this.ToggleVat.ClientID%>_initialize(orgSettings.AccountsVat); + <%=this.ToggleOpenFinancials.ClientID%>_initialize(orgSettings.ParticipantFinancials); + $("#<%=this.TextPaypalAccountAddress.ClientID%>_TextInput").val(orgSettings.PaypalAccountAddress); - suppressSwitchResponse = false; if (orgSettings.AccountBitcoinHot) { - $('.bitcoinHotField').show(); + /* $('.bitcoinHotField').show(); save for later */ } if (orgSettings.AccountPaypal) { @@ -117,7 +58,31 @@ } var suppressSwitchResponse = false; - var organizationNativeBtc = <%=this.OrganizationNativeBtc%>; + var organizationBitcoinNative = <%=this.OrganizationBitcoinNative%>; + + function onChangeBitcoinEnable(newValue, cookie) { + if (newValue && !organizationBitcoinNative) { + // Bitcoin has been enabled and the organization isn't bitcoin native + + <%=this.ToggleForex.ClientID%>_setValueAndCallback(true); + } + + if (cookie == "BitcoinHot") { + if (newValue) { + /*$('.bitcoinHotField').show(); save for later */ + } else { + $('.bitcoinHotField').hide(); + } + } + } + + function onChangePaypalEnable(newValue) { + if (newValue) { + $('.paypalAccountField').show(); + } else { + $('.paypalAccountField').hide(); + } + } @@ -144,17 +109,14 @@

Accounting Features

- - - -

-

- -

- -

-

-

+ + +
+ +
+ +
+