From edca76fe071653fb96475898c25b7c0ae9fad66e Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Wed, 18 Mar 2015 10:38:33 +0100 Subject: [PATCH] Refactored Javascript considerably --- Site5/App_GlobalResources/Pages.Ledgers.resx | 4 ++ Site5/Automation/Formatting.aspx | 1 + Site5/Automation/Formatting.aspx.cs | 31 +++++++++ Site5/Controls/v5/Base/ComboGeographies.ascx | 61 +++++++++++++++++ Site5/Controls/v5/Base/ModalDialog.ascx | 9 ++- Site5/Controls/v5/Financial/ComboBudgets.ascx | 2 +- Site5/Controls/v5/UI/IncludedScripts.ascx.cs | 5 +- Site5/Master-v5.master | 6 +- Site5/Pages/v5/Ledgers/AccountPlan.aspx | 4 +- .../Pages/v5/Ledgers/BalanceTransactions.aspx | 44 +++++------- .../v5/Ledgers/BalanceTransactions.aspx.cs | 2 + Site5/Pages/v5/Ledgers/InspectLedgers.aspx | 6 +- .../v5/Ledgers/Json-InspectLedgerData.aspx.cs | 2 +- Site5/Style/style-v5.css | 12 ++++ Site5/Swarmops-v5.js | 67 +++++++++++++++++++ 15 files changed, 218 insertions(+), 38 deletions(-) create mode 100644 Site5/Automation/Formatting.aspx create mode 100644 Site5/Automation/Formatting.aspx.cs create mode 100644 Site5/Swarmops-v5.js diff --git a/Site5/App_GlobalResources/Pages.Ledgers.resx b/Site5/App_GlobalResources/Pages.Ledgers.resx index 673ce1b7..e4f9cec6 100644 --- a/Site5/App_GlobalResources/Pages.Ledgers.resx +++ b/Site5/App_GlobalResources/Pages.Ledgers.resx @@ -693,6 +693,10 @@ Some auto-imported financial transactions can't be automatically matched to the ongoing accounting. This is where you manually match such transactions to "balance" them (if a transaction only has one part completed, like the money sent to the organization with no record of what the money is for, the transaction is said to be "unbalanced"). + + Balancing/Matching Transaction #<span id="spanModalTransactionId">67890</span> + The span text is replaced runtime. + Balance & Match Transactions diff --git a/Site5/Automation/Formatting.aspx b/Site5/Automation/Formatting.aspx new file mode 100644 index 00000000..453cfd93 --- /dev/null +++ b/Site5/Automation/Formatting.aspx @@ -0,0 +1 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Formatting.aspx.cs" Inherits="Swarmops.Frontend.Automation.Formatting" %> diff --git a/Site5/Automation/Formatting.aspx.cs b/Site5/Automation/Formatting.aspx.cs new file mode 100644 index 00000000..a1b715d0 --- /dev/null +++ b/Site5/Automation/Formatting.aspx.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Services; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace Swarmops.Frontend.Automation +{ + public partial class Formatting : DataV5Base + { + protected void Page_Load (object sender, EventArgs e) + { + // This page exists only for its web methods, which are called by Ajax. + } + + /// + /// Returns a culturally-formatted integer with thousands separators. + /// + /// The integer to format. + /// The formatted integer for display. + [WebMethod] + public static string FormatInteger (int input) + { + GetAuthenticationDataAndCulture(); + return input.ToString ("N0"); + } + + } +} \ No newline at end of file diff --git a/Site5/Controls/v5/Base/ComboGeographies.ascx b/Site5/Controls/v5/Base/ComboGeographies.ascx index 88712729..641b4e9e 100644 --- a/Site5/Controls/v5/Base/ComboGeographies.ascx +++ b/Site5/Controls/v5/Base/ComboGeographies.ascx @@ -54,6 +54,67 @@ e.preventDefault(); // prevent the default action (scroll / move caret) }); }); + + // below code from http://doc.javake.cn/jeasyui/www.jeasyui.com/forum/index.php-topic=1972.0.htm, understood to be in public domain: enables keyboard navigation + + (function () { + $.extend($.fn.combotree.methods, { + nav: function (jq, dir) { + return jq.each(function () { + var opts = $(this).combotree('options'); + var t = $(this).combotree('tree'); + var nodes = t.tree('getChildren'); + if (!nodes.length) { return } + var node = t.tree('getSelected'); + if (!node) { + t.tree('select', dir > 0 ? nodes[0].target : nodes[nodes.length - 1].target); + } else { + var index = 0; + for (var i = 0; i < nodes.length; i++) { + if (nodes[i].target == node.target) { + index = i; + break; + } + } + if (dir > 0) { + while (index < nodes.length - 1) { + index++; + if ($(nodes[index].target).is(':visible')) { break } + } + } else { + while (index > 0) { + index--; + if ($(nodes[index].target).is(':visible')) { break } + } + } + t.tree('select', nodes[index].target); + } + if (opts.selectOnNavigation) { + var node = t.tree('getSelected'); + $(node.target).trigger('click'); + $(this).combotree('showPanel'); + } + }); + } + }); + $.extend($.fn.combotree.defaults.keyHandler, { + up: function () { + $(this).combotree('nav', -1); + }, + down: function () { + $(this).combotree('nav', 1); + }, + enter: function () { + var t = $(this).combotree('tree'); + var node = t.tree('getSelected'); + if (node) { + $(node.target).trigger('click'); + } + $(this).combotree('hidePanel'); + } + }); + })(jQuery); + \ No newline at end of file diff --git a/Site5/Controls/v5/Base/ModalDialog.ascx b/Site5/Controls/v5/Base/ModalDialog.ascx index 910a1ecb..b59ac78f 100644 --- a/Site5/Controls/v5/Base/ModalDialog.ascx +++ b/Site5/Controls/v5/Base/ModalDialog.ascx @@ -13,10 +13,15 @@ } }); + $('#<%=this.ClientID%>').showModalDialog = <%=this.ClientID%>_open; }); + function <%=this.ClientID%>_open() { + $('#<%=this.ClientID%>_divModalCover').fadeIn(); + } + function <%=this.ClientID%>_close() { - $('#<%=this.ClientID %>_divModalCover').fadeOut(100); // fast - 1/4 of normal time + $('#<%=this.ClientID %>_divModalCover').fadeOut(100); // fast - 1/4 of normal time <% if (!string.IsNullOrEmpty (this.OnClientClose)) @@ -26,6 +31,8 @@ %> } + +
diff --git a/Site5/Controls/v5/Financial/ComboBudgets.ascx b/Site5/Controls/v5/Financial/ComboBudgets.ascx index 59b9de8d..f5e26a6d 100644 --- a/Site5/Controls/v5/Financial/ComboBudgets.ascx +++ b/Site5/Controls/v5/Financial/ComboBudgets.ascx @@ -45,7 +45,7 @@ }); }); - // below code from http://doc.javake.cn/jeasyui/www.jeasyui.com/forum/index.php-topic=1972.0.htm, understood to be in public domain + // below code from http://doc.javake.cn/jeasyui/www.jeasyui.com/forum/index.php-topic=1972.0.htm, understood to be in public domain: enables keyboard navigation (function () { $.extend($.fn.combotree.methods, { diff --git a/Site5/Controls/v5/UI/IncludedScripts.ascx.cs b/Site5/Controls/v5/UI/IncludedScripts.ascx.cs index 1ca22f52..0984b85d 100644 --- a/Site5/Controls/v5/UI/IncludedScripts.ascx.cs +++ b/Site5/Controls/v5/UI/IncludedScripts.ascx.cs @@ -28,8 +28,9 @@ namespace Swarmops.Frontend.Controls.v5.UI "\r\n"); break; case "jsonparameters": - scriptRef.Append ( - ""); + // Do nothing - this is now included stock, unconditionally + /*scriptRef.Append ( + "");*/ break; default: break; diff --git a/Site5/Master-v5.master b/Site5/Master-v5.master index 8d4b21e1..0b9efec0 100644 --- a/Site5/Master-v5.master +++ b/Site5/Master-v5.master @@ -18,6 +18,10 @@ + + + + @@ -41,7 +45,7 @@ - + diff --git a/Site5/Pages/v5/Ledgers/AccountPlan.aspx b/Site5/Pages/v5/Ledgers/AccountPlan.aspx index 820427f8..e23c5203 100644 --- a/Site5/Pages/v5/Ledgers/AccountPlan.aspx +++ b/Site5/Pages/v5/Ledgers/AccountPlan.aspx @@ -296,7 +296,7 @@ window.scrollTo(0, 0); $('body').css('overflow-y', 'hidden'); - $('#<%=this.DialogAccount.ClientID %>_divModalCover').fadeIn(); + <%=this.DialogAccount.ClientID %>_open(); setTimeout(function() { $('#divModalBox').animate({ "height": ($('#DivModalFields').outerHeight() + $('#HeaderModal').outerHeight()) + 40 + "px" }, 50); @@ -443,7 +443,7 @@ } function modalShow() { - $('#<%=this.DialogAccount.ClientID %>_divModalCover').fadeIn(); + <%=this.DialogAccount.ClientID %>_open(); } function onOwnerChange(personId) { diff --git a/Site5/Pages/v5/Ledgers/BalanceTransactions.aspx b/Site5/Pages/v5/Ledgers/BalanceTransactions.aspx index 2ba859b1..f03d0531 100644 --- a/Site5/Pages/v5/Ledgers/BalanceTransactions.aspx +++ b/Site5/Pages/v5/Ledgers/BalanceTransactions.aspx @@ -11,9 +11,10 @@ $('#gridTransactions').datagrid({ onLoadSuccess: function() { - $('img.LocalIconFix').click(function() { + $('img.LocalIconFix').click(function(e) { transactionId = $(this).attr("txId"); onFixTransaction(transactionId); + e.stopPropagation(); // prevents checking of row }); } @@ -24,8 +25,17 @@ function onFixTransaction(newTransactionId) { transactionId = newTransactionId; + SwarmopsJS.formatInteger(transactionId, function(result) { $('span#spanModalTransactionId').text(result); }); + <%= this.DialogTx.ClientID %>_open(); } + + @@ -53,32 +63,12 @@ -

- - - - - - - - - - -
- -
-

-

,

- -
-
-

-
-
- - +

+

+

+

+

+

diff --git a/Site5/Pages/v5/Ledgers/BalanceTransactions.aspx.cs b/Site5/Pages/v5/Ledgers/BalanceTransactions.aspx.cs index dcdb6e20..1e49d526 100644 --- a/Site5/Pages/v5/Ledgers/BalanceTransactions.aspx.cs +++ b/Site5/Pages/v5/Ledgers/BalanceTransactions.aspx.cs @@ -31,6 +31,8 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers this.LabelGridHeaderDelta.Text = Resources.Pages.Ledgers.BalanceTransactions_GridHeader_Amount; this.LabelGridHeaderId.Text = Resources.Pages.Ledgers.BalanceTransactions_GridHeader_TransactionId; this.LabelGridHeaderDescription.Text = Resources.Pages.Ledgers.BalanceTransactions_GridHeader_Description; + + this.LiteralModalHeader.Text = Resources.Pages.Ledgers.BalanceTransactions_ModalHeader; } } } \ No newline at end of file diff --git a/Site5/Pages/v5/Ledgers/InspectLedgers.aspx b/Site5/Pages/v5/Ledgers/InspectLedgers.aspx index f7e8ded6..03309cd4 100644 --- a/Site5/Pages/v5/Ledgers/InspectLedgers.aspx +++ b/Site5/Pages/v5/Ledgers/InspectLedgers.aspx @@ -186,7 +186,7 @@ window.scrollTo(0, 0); $('body').css('overflow-y', 'hidden'); $('#<%=this.DialogEditTx.ClientID%>_divModalCover').fadeIn(); - $('span#spanModalTransactionId').text(transactionId); + SwarmopsJS.formatInteger(transactionId, function(result) { $('span#spanModalTransactionId').text(result); }); $('#gridTransaction').datagrid({ url: 'Json-InspectLedgerTxData.aspx?TxId=' + transactionId }); @@ -304,9 +304,9 @@ idField="id"> - + - + diff --git a/Site5/Pages/v5/Ledgers/Json-InspectLedgerData.aspx.cs b/Site5/Pages/v5/Ledgers/Json-InspectLedgerData.aspx.cs index 6f0582a0..af371648 100644 --- a/Site5/Pages/v5/Ledgers/Json-InspectLedgerData.aspx.cs +++ b/Site5/Pages/v5/Ledgers/Json-InspectLedgerData.aspx.cs @@ -174,7 +174,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers } result.Append ("{" + String.Format ( - "\"id\":\"{0}\",\"datetime\":\"{1:MMM-dd HH:mm}\",\"description\":\"{2}\"," + + "\"id\":\"{0:N0}\",\"datetime\":\"{1:MMM-dd HH:mm}\",\"description\":\"{2}\"," + "\"deltaPos\":\"{3}\",\"deltaNeg\":\"{4}\",\"balance\":\"{5:N0}\",\"action\":\"{6}\"", row.FinancialTransactionId, row.TransactionDateTime, diff --git a/Site5/Style/style-v5.css b/Site5/Style/style-v5.css index d8ab13b4..4a17148c 100644 --- a/Site5/Style/style-v5.css +++ b/Site5/Style/style-v5.css @@ -819,6 +819,18 @@ select.comboperson+span>input:focus } +input[type="radio"] { + vertical-align: text-bottom; + margin-left: 5px; +} + +label { + margin-left: 10px; + font-size: 120%; + font-weight: 500; +} + + /* IN-PAGE HEADERS */ h1, h2, h3 diff --git a/Site5/Swarmops-v5.js b/Site5/Swarmops-v5.js new file mode 100644 index 00000000..23d1116a --- /dev/null +++ b/Site5/Swarmops-v5.js @@ -0,0 +1,67 @@ +var SwarmopsJS = (function() { + var publicSymbols = {}, + initFunctions = []; + + publicSymbols.formatInteger = formatInteger; + function formatInteger (number, callbackSuccess, callbackError) + { + if (callbackSuccess === undefined) { + alert("FormatInteger() called without callbackSuccess parameter. This is not allowed."); + return ("[Undefined]"); + } + + var jsonData = {}; + jsonData.input = number; + + $.ajax({ + type: "POST", + contentType: "application/json; charset=utf-8", + url: '/Automation/Formatting.aspx/FormatInteger', + dataType: 'json', + data: $.toJSON(jsonData), + + success: function(data) { + callbackSuccess(data.d); + }, + + error: function(){ + if (callbackError !== undefined) { + callbackError(); + } else { + alertify.error("AJAX error calling SwarmopsJS.FormatInteger. Are the server and network still available?"); // TODO: Loc - how? + callbackSuccess("[Undefined]"); + } + } + }); + + } + + // Below copied from http://stackoverflow.com/questions/4578424/javascript-extend-a-function, assumed to be in public domain + + publicSymbols.init = init; + function init() { + var funcs = initFunctions; + + initFunctions = undefined; + + for (index = 0; index < funcs.length; ++index) { + try { funcs[index](); } catch (e) { } + } + } + + publicSymbols.addInitFunction = addInitFunction; + + function addInitFunction(f) { + if (initFunctions) { + // Init hasn't run yet, rememeber it + initFunctions.push(f); + } else { + // `init` has already run, call it almost immediately + // but *asynchronously* (so the caller never sees the + // call synchronously) + setTimeout(f, 0); + } + } + + return publicSymbols; +})(); \ No newline at end of file