From 89c79957e716ddc892ffb70387c29904cfd53eb0 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Mon, 24 Feb 2014 15:47:45 +0000 Subject: [PATCH] Committing more work to account plan --- Logic/Swarm/People.cs | 2 +- .../Json-ExpensableBudgetsTree.aspx | 2 +- .../Json-ExpensableBudgetsTree.aspx.cs | 2 +- .../Json-FinancialAccountsTree.aspx.cs | 5 +- Site5/Automation/Json-GetPersonAvatar.aspx | 1 + Site5/Automation/Json-GetPersonAvatar.aspx.cs | 35 +++++++++ .../Automation/Json-SearchPeoplePattern.aspx | 1 + .../Json-SearchPeoplePattern.aspx.cs | 46 ++++++++++++ Site5/Controls/v5/Swarm/ComboPeople.ascx | 75 +++++++++++++++---- Site5/Pages/v5/Ledgers/AccountPlan.aspx | 5 +- Site5/Pages/v5/Ledgers/AccountPlan.aspx.cs | 6 +- Site5/Style/v5-easyui-elements.css | 23 +++--- 12 files changed, 171 insertions(+), 32 deletions(-) create mode 100644 Site5/Automation/Json-GetPersonAvatar.aspx create mode 100644 Site5/Automation/Json-GetPersonAvatar.aspx.cs create mode 100644 Site5/Automation/Json-SearchPeoplePattern.aspx create mode 100644 Site5/Automation/Json-SearchPeoplePattern.aspx.cs diff --git a/Logic/Swarm/People.cs b/Logic/Swarm/People.cs index 3983581d..f2dffd30 100644 --- a/Logic/Swarm/People.cs +++ b/Logic/Swarm/People.cs @@ -91,7 +91,7 @@ namespace Swarmops.Logic.Swarm return null; // If no valid search string was supplied } - public static People FromBirtDatePattern (DateTime fromdate, DateTime todate) + public static People FromBirthDatePattern (DateTime fromdate, DateTime todate) { return People.FromArray(SwarmDb.GetDatabaseForReading().GetPeopleFromBirthdate(fromdate, todate)); } diff --git a/Site5/Automation/Json-ExpensableBudgetsTree.aspx b/Site5/Automation/Json-ExpensableBudgetsTree.aspx index cbf11b75..8e1b0d5b 100644 --- a/Site5/Automation/Json-ExpensableBudgetsTree.aspx +++ b/Site5/Automation/Json-ExpensableBudgetsTree.aspx @@ -1 +1 @@ -<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-ExpensableBudgetsTree.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Financial.Json_ExpensableBudgetsTree" %> \ No newline at end of file +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-ExpensableBudgetsTree.aspx.cs" Inherits="Swarmops.Frontend.Automation.Json_ExpensableBudgetsTree" %> \ No newline at end of file diff --git a/Site5/Automation/Json-ExpensableBudgetsTree.aspx.cs b/Site5/Automation/Json-ExpensableBudgetsTree.aspx.cs index 0347430a..d53d4358 100644 --- a/Site5/Automation/Json-ExpensableBudgetsTree.aspx.cs +++ b/Site5/Automation/Json-ExpensableBudgetsTree.aspx.cs @@ -10,7 +10,7 @@ using Swarmops.Logic.Swarm; using Swarmops.Logic.Security; using Swarmops.Logic.Structure; -namespace Swarmops.Frontend.Pages.v5.Financial +namespace Swarmops.Frontend.Automation { public partial class Json_ExpensableBudgetsTree : DataV5Base { diff --git a/Site5/Automation/Json-FinancialAccountsTree.aspx.cs b/Site5/Automation/Json-FinancialAccountsTree.aspx.cs index 5d9161ab..d9ff9f93 100644 --- a/Site5/Automation/Json-FinancialAccountsTree.aspx.cs +++ b/Site5/Automation/Json-FinancialAccountsTree.aspx.cs @@ -55,7 +55,10 @@ namespace Swarmops.Frontend.Pages.v5.Financial treeMap[account.ParentIdentity].Add(account); } - accountsJson = RecurseTreeMap(treeMap, 0); + if (treeMap.ContainsKey(0)) + { + accountsJson = RecurseTreeMap(treeMap, 0); + } accountsJson = "[{\"id\":\"0\",\"text\":\"" + JsonSanitize(Resources.Global.ResourceManager.GetString("Financial_" + accountType.ToString())) + diff --git a/Site5/Automation/Json-GetPersonAvatar.aspx b/Site5/Automation/Json-GetPersonAvatar.aspx new file mode 100644 index 00000000..c6db12eb --- /dev/null +++ b/Site5/Automation/Json-GetPersonAvatar.aspx @@ -0,0 +1 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-GetPersonAvatar.aspx.cs" Inherits="Swarmops.Frontend.Automation.Json_GetPersonAvatar" %> diff --git a/Site5/Automation/Json-GetPersonAvatar.aspx.cs b/Site5/Automation/Json-GetPersonAvatar.aspx.cs new file mode 100644 index 00000000..50761b3e --- /dev/null +++ b/Site5/Automation/Json-GetPersonAvatar.aspx.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; +using Swarmops.Logic.Security; +using Swarmops.Logic.Swarm; + +namespace Swarmops.Frontend.Automation +{ + public partial class Json_GetPersonAvatar : DataV5Base + { + protected void Page_Load(object sender, EventArgs e) + { + Response.ContentType = "application/json"; + + string personId = Request.QueryString["personId"]; + string onePerson = string.Empty; + + People matches = People.FromSingle(Person.FromIdentity(Int32.Parse(personId))); + + matches = Authorization.FilterPeopleToMatchAuthority(matches, CurrentUser.GetAuthority()); + + if (matches.Count == 1) // still allowed + { + onePerson = '{' + String.Format("\"id\":\"{0}\",\"name\":\"{1}\",\"avatar16Url\":\"{2}\",\"avatar24Url\":\"{3}\"", matches[0].Identity, JsonSanitize(matches[0].Canonical), matches[0].GetSecureAvatarLink(16), matches[0].GetSecureAvatarLink(24)) + '}'; + } + + Response.Output.WriteLine(onePerson); + + Response.End(); + } + } +} \ No newline at end of file diff --git a/Site5/Automation/Json-SearchPeoplePattern.aspx b/Site5/Automation/Json-SearchPeoplePattern.aspx new file mode 100644 index 00000000..50b7659a --- /dev/null +++ b/Site5/Automation/Json-SearchPeoplePattern.aspx @@ -0,0 +1 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-SearchPeoplePattern.aspx.cs" Inherits="Swarmops.Frontend.Automation.Json_SearchPeoplePattern" %> diff --git a/Site5/Automation/Json-SearchPeoplePattern.aspx.cs b/Site5/Automation/Json-SearchPeoplePattern.aspx.cs new file mode 100644 index 00000000..ac5cc2e8 --- /dev/null +++ b/Site5/Automation/Json-SearchPeoplePattern.aspx.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; +using Swarmops.Logic.Financial; +using Swarmops.Logic.Security; +using Swarmops.Logic.Swarm; + +namespace Swarmops.Frontend.Automation +{ + public partial class Json_SearchPeoplePattern : DataV5Base + { + protected void Page_Load(object sender, EventArgs e) + { + Response.ContentType = "application/json"; + + string pattern = Request.QueryString["namePattern"]; + + People matches = People.FromNamePattern(pattern); + + matches = Authorization.FilterPeopleToMatchAuthority(matches, CurrentUser.GetAuthority()); + + if (matches.Count > 20) + { + matches.RemoveRange(20, matches.Count - 20); + } + + List jsonPeople = new List(); + + foreach (Person person in matches) + { + string onePerson = '{' + String.Format("\"id\":\"{0}\",\"name\":\"{1}\",\"avatar16Url\":\"{2}\"", person.Identity, JsonSanitize(person.Canonical), person.GetSecureAvatarLink(16)) + '}'; + jsonPeople.Add(onePerson); + } + + string result = '[' + String.Join(",", jsonPeople.ToArray()) + ']'; + + Response.Output.WriteLine(result); + + Response.End(); + } + } +} \ No newline at end of file diff --git a/Site5/Controls/v5/Swarm/ComboPeople.ascx b/Site5/Controls/v5/Swarm/ComboPeople.ascx index 9c06bc7a..59eb89a3 100644 --- a/Site5/Controls/v5/Swarm/ComboPeople.ascx +++ b/Site5/Controls/v5/Swarm/ComboPeople.ascx @@ -4,28 +4,48 @@ $(document).ready(function () { $('#<%=this.ClientID %>_DropPeople').combobox({ animate: true, - height: 30 + height: 30, + loader: autoCompleteLoader, + mode: 'remote', + valueField: 'id', + textField: 'name', + formatter: formatItem, + + onSelect: function (person) { + // update avatar when person selected + + $.ajax({ + url: '/Automation/Json-GetPersonAvatar.aspx', + dataType: 'json', + data: { + personId: person.id + }, + success: function(data){ + $('span#<%= this.ClientID %>_SpanPeople span input.combo-text').css('background-image', "url('" + data.avatar24Url + "')"); + + }, + error: function(){ + error.apply(this, arguments); + } + }); + } }); <% if (this.Selected != null) - { %> - - $('span#<%= this.ClientID %>_SpanPeople span input.combo-text').css('background', "url('<%= this.Selected.GetSecureAvatarLink(24) %>')"); + { %>; + $('span#<%= this.ClientID %>_SpanPeople span input.combo-text').css('background-image', "url('<%= this.Selected.GetSecureAvatarLink(24) %>')"); $('span#<%= this.ClientID %>_SpanPeople span input.combo-text').text('<%= this.Selected.Canonical %>'); <% } else if (this.NobodySelected) - { %> - - $('span#<%= this.ClientID %>_SpanPeople span input.combo-text').css('background', "url('/Images/Icons/iconshock-warning-24px.png')"); + { %>; + $('span#<%= this.ClientID %>_SpanPeople span input.combo-text').css('background-image', "url('/Images/Icons/iconshock-warning-24px.png')"); $('span#<%= this.ClientID %>_SpanPeople span input.combo-text').text('<%= Resources.Global.Global_NoOwner %>'); - <% } else { %> - + <% } else { %>; $('span#<%= this.ClientID %>_SpanPeople span input.combo-text').css('background', ''); - <% } %> - + <% } %>; $('#<%=this.ClientID %>_SpanPeople span.combo input.combo-text').keydown(function (e) { switch (e.which) { case 40: // down @@ -37,6 +57,35 @@ e.preventDefault(); // prevent the default action (scroll / move caret) }); }); - + + var autoCompleteLoader = function(param,success,error){ + var q = param.q || ''; + if (q.length <= 3) { + return false; + } + $.ajax({ + url: '/Automation/Json-SearchPeoplePattern.aspx', + dataType: 'json', + data: { + maxRows: 20, + namePattern: q + }, + success: function(data){ + console.log(data); + success(data); + }, + error: function(){ + error.apply(this, arguments); + } + }); + return false; + }; + + function formatItem(row) + { + var s = '' + row.name + ''; + return s; + } + - \ No newline at end of file + \ No newline at end of file diff --git a/Site5/Pages/v5/Ledgers/AccountPlan.aspx b/Site5/Pages/v5/Ledgers/AccountPlan.aspx index 7140fa95..f695ca36 100644 --- a/Site5/Pages/v5/Ledgers/AccountPlan.aspx +++ b/Site5/Pages/v5/Ledgers/AccountPlan.aspx @@ -69,6 +69,7 @@ } window.scrollTo(0, 0); + $('body').css('overflow-y', 'hidden'); $('#divModalCover').fadeIn(); $.ajax({ @@ -78,8 +79,6 @@ contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { - console.log(msg.d); - $('#CheckAccountActive').switchButton( {checked: msg.d.Open }); $('#CheckAccountExpensable').switchButton( {checked: msg.d.Expensable }); $('#CheckAccountAdministrative').switchButton( {checked: msg.d.Administrative }); @@ -175,7 +174,7 @@