Org settings fixed with new controls

This commit is contained in:
Rick Falkvinge
2017-01-02 00:13:12 +01:00
parent ab5b82cf65
commit 5b0ed02e03
3 changed files with 68 additions and 100 deletions
+7 -3
View File
@@ -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);
+41 -79
View File
@@ -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();
}
}
</script>
@@ -144,17 +109,14 @@
<div title="<img src='/Images/Icons/iconshock-switch-red-64px.png' />">
<h2>Accounting Features</h2>
<div class="entryFields">
<Swarmops5:AjaxToggleSlider ID="ToggleBitcoinCold" Cookie="BitcoinCold" Label="Bitcoin Cold" runat="server" AjaxCallbackUrl="/Pages/v5/Admin/OrgSettings.aspx/SwitchToggled"/>
<Swarmops5:AjaxToggleSlider ID="ToggleBitcoinHot" Cookie="BitcoinHot" Label="Bitcoin Hot" runat="server" AjaxCallbackUrl="/Pages/v5/Admin/OrgSettings.aspx/SwitchToggled"/>
<Swarmops5:AjaxTextBox ID="TextDaysCashReserves" runat="server" CssClass="bitcoinHotField alignRight" ReadOnly="true" Placeholder="60-90" AjaxCallbackUrl="/Pages/v5/Admin/OrgSettings.aspx/StoreCallback" Cookie="BitcoinReserves" />
<label for="CheckEnableBitcoinCold"><asp:Literal ID="LiteralLabelBitcoinColdShort" runat="server" Text="Bitcoin Cold"/></label><div class="CheckboxContainer"><input type="checkbox" rel="BitcoinCold" class="EditCheck" id="CheckEnableBitcoinCold"/></div><br/>
<label for="CheckEnableBitcoinHot"><asp:Literal ID="LiteralLabelBitcoinHotShort" runat="server" Text="Bitcoin Hot"/></label><div class="CheckboxContainer"><input type="checkbox" rel="BitcoinHot" class="EditCheck" id="CheckEnableBitcoinHot"/></div><br/>
<Swarmops5:AjaxTextBox ID="AjaxTextBox1" runat="server" CssClass="bitcoinHotField alignRight" ReadOnly="true" Placeholder="60-90" AjaxCallbackUrl="/Pages/v5/Admin/OrgSettings.aspx/StoreCallback" Cookie="BitcoinReserves" />
<label for="CheckEnablePaypal"><asp:Literal ID="Literal1" runat="server" Text="Paypal"/></label><div class="CheckboxContainer"><input type="checkbox" rel="Paypal" class="EditCheck" id="CheckEnablePaypal"/></div><br/>
<Swarmops5:AjaxTextBox ID="TextPaypalAccountAddress" runat="server" Placeholder="paypal@example.org" CssClass="paypalAccountField" AjaxCallbackUrl="/Pages/v5/Admin/OrgSettings.aspx/StoreCallback" Cookie="PaypalAccountAddress" />
<label for="CheckEnableForex"><asp:Literal ID="Literal2" runat="server" Text="Forex Profit/Loss"/></label><div class="CheckboxContainer"><input type="checkbox" rel="Forex" class="EditCheck" id="CheckEnableForex"/></div><br/>
<label for="CheckEnableVat"><asp:Literal ID="Literal3" runat="server" Text="VAT In/Out"/></label><div class="CheckboxContainer"><input type="checkbox" rel="Vat" class="EditCheck" id="CheckEnableVat"/></div><br/>
<label for="CheckOpenFinancials"><asp:Literal ID="Literal4" runat="server" Text="Participant Financials"/></label><div class="CheckboxContainer"><input type="checkbox" rel="ParticipantFinancials" class="EditCheck" id="CheckOpenFinancials"/></div><br/>
<Swarmops5:AjaxToggleSlider ID="ToggleBitcoinCold" Cookie="BitcoinCold" OnChange="onChangeBitcoinEnable" Label="Bitcoin Cold" runat="server" AjaxCallbackUrl="/Pages/v5/Admin/OrgSettings.aspx/SwitchToggled"/>
<Swarmops5:AjaxToggleSlider ID="ToggleBitcoinHot" Cookie="BitcoinHot" OnChange="onChangeBitcoinEnable" Label="Bitcoin Hot" runat="server" AjaxCallbackUrl="/Pages/v5/Admin/OrgSettings.aspx/SwitchToggled"/>
<div class="bitcoinHotField"><Swarmops5:AjaxTextBox ID="TextDaysCashReserves" runat="server" CssClass="alignRight" ReadOnly="true" Placeholder="60-90" AjaxCallbackUrl="/Pages/v5/Admin/OrgSettings.aspx/StoreCallback" Cookie="BitcoinReserves" /></div>
<Swarmops5:AjaxToggleSlider ID="TogglePaypal" runat="server" Cookie="Paypal" OnChange="onChangePaypalEnable" Label="Paypal" AjaxCallbackUrl="/Pages/v5/Admin/OrgSettings.aspx/SwitchToggled"/>
<div class="paypalAccountField"><Swarmops5:AjaxTextBox ID="TextPaypalAccountAddress" runat="server" Placeholder="paypal@example.org" AjaxCallbackUrl="/Pages/v5/Admin/OrgSettings.aspx/StoreCallback" Cookie="PaypalAccountAddress" /></div>
<Swarmops5:AjaxToggleSlider ID="ToggleForex" runat="server" Cookie="Forex" Label="Forex Profit/Loss" AjaxCallbackUrl="/Pages/v5/Admin/OrgSettings.aspx/SwitchToggled"/>
<div style="display:none"><Swarmops5:AjaxToggleSlider ID="ToggleVat" Cookie="Vat" runat="server" Label="VAT In/Out" AjaxCallbackUrl="/Pages/v5/Admin/OrgSettings.aspx/SwitchToggled"/></div> <!-- disable until supported in invoicing -->
<Swarmops5:AjaxToggleSlider ID="ToggleOpenFinancials" Cookie="ParticipantFinancials" runat="server" Label="Participant Financials" AjaxCallbackUrl="/Pages/v5/Admin/OrgSettings.aspx/SwitchToggled"/>
</div>
<div class="entryLabels">
Enable bitcoin coldwallet tracking?<br/>
@@ -163,7 +125,7 @@
Enable Paypal tracking and IPN?<br/>
<span class="paypalAccountField">Paypal account mail address<br/></span>
Enable foreign currency accounts?<br/>
Enable Value Added Tax (VAT)?<br/>
<span style="display:none">Enable Value Added Tax (VAT)?<br/></span>
Enable Participant Financials?<br/>
</div>
<div id="divUseAccountPlan" style="display: none; width: 100%; text-align: center; margin-top: 20px; margin-bottom: 20px; border-top: 1px solid <%= CommonV5.GetColor (ColorType.Base, ColorVariant.Light) %>; border-bottom: 1px solid <%= CommonV5.GetColor (ColorType.Base, ColorVariant.Light) %>; background-color: <%= CommonV5.GetColor (ColorType.Base, ColorVariant.XLight) %>">
+20 -18
View File
@@ -110,7 +110,8 @@ namespace Swarmops.Frontend.Pages.Admin
this.DropMemberNumber.Items.Add (new ListItem ("Local for each organzation", "Local"));
this.DropTaxAuthority.Items.Clear();
this.DropTaxAuthority.Items.Add (new ListItem ("[SE] Sweden", "SE"));
this.DropTaxAuthority.Items.Add(new ListItem("[DE] Germany", "DE"));
this.DropTaxAuthority.Items.Add(new ListItem("[SE] Sweden", "SE"));
}
[WebMethod]
@@ -152,7 +153,7 @@ namespace Swarmops.Frontend.Pages.Admin
[WebMethod]
public static CallResult SwitchToggled (string switchName, bool switchValue)
public static AjaxInputCallResult SwitchToggled (string cookie, bool newValue)
{
AuthenticationData authData = GetAuthenticationDataAndCulture();
@@ -161,22 +162,18 @@ namespace Swarmops.Frontend.Pages.Admin
return null; // just don't... don't anything, actually
}
CallResult result = new CallResult();
AjaxInputCallResult result = new AjaxInputCallResult();
result.Success = true;
result.NewValue = newValue? "true": "false";
bool bitcoinNative = (authData.CurrentOrganization.Currency.Code == "BTC");
FinancialAccounts workAccounts = new FinancialAccounts();
switch (switchName)
switch (cookie)
{
case "BitcoinCold":
if (switchValue && !bitcoinNative)
{
result.RequireForex = true;
}
FinancialAccount coldAccount = authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinCold;
if (coldAccount == null)
{
@@ -200,11 +197,6 @@ namespace Swarmops.Frontend.Pages.Admin
}
break;
case "BitcoinHot":
if (switchValue && !bitcoinNative)
{
result.RequireForex = true;
}
FinancialAccount hotAccount = authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot;
if (hotAccount == null)
{
@@ -250,7 +242,7 @@ namespace Swarmops.Frontend.Pages.Admin
throw new InvalidOperationException();
}
if (!bitcoinNative && switchValue == false &&
if (!bitcoinNative && newValue == false &&
((authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinCold != null &&
authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinCold.Active) ||
(authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot != null &&
@@ -259,9 +251,9 @@ namespace Swarmops.Frontend.Pages.Admin
// bitcoin is active, and we're not bitcoin native, so we're not turning off forex
result.Success = false;
result.NewValue = "true";
result.DisplayMessage =
"Cannot disable forex: bitcoin accounts are active in a non-bitcoin-native organization.";
result.RequireForex = true;
}
else
{
@@ -317,7 +309,7 @@ namespace Swarmops.Frontend.Pages.Admin
}
break;
case "ParticipantFinancials":
authData.CurrentOrganization.ParticipantFinancialsEnabled = switchValue;
authData.CurrentOrganization.ParticipantFinancialsEnabled = newValue;
break;
default:
throw new NotImplementedException();
@@ -325,7 +317,7 @@ namespace Swarmops.Frontend.Pages.Admin
if (workAccounts.Count > 0 && String.IsNullOrEmpty (result.DisplayMessage))
{
if (switchValue) // switch has been turned on
if (newValue) // switch has been turned on
{
// accounts can always be re-enabled. This is not a create, it is a re-enable.
@@ -369,6 +361,7 @@ namespace Swarmops.Frontend.Pages.Admin
}
result.Success = false;
result.NewValue = "true";
}
else
{
@@ -395,6 +388,15 @@ namespace Swarmops.Frontend.Pages.Admin
}
public string OrganizationBitcoinNative
{
get
{
return CurrentOrganization.Currency.IsBitcoin.ToString().ToLowerInvariant(); // the tostring, tolower makes 'False' into 'false' the way JS wants it
}
}
[WebMethod]
static public AjaxInputCallResult StoreCallback(string newValue, string cookie)
{