From e8e192db9269371134349fcace1ef861f875c55a Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Fri, 10 Apr 2015 18:32:00 +0200 Subject: [PATCH] Lots of small fixes to everything --- Site5/App_Code/CommonV5.cs | 5 ++ Site5/App_Code/ControlV5Base.cs | 5 ++ Site5/App_Code/PageV5Base.cs | 2 +- Site5/App_GlobalResources/Global.resx | 25 ++++++ Site5/Automation/Json-GetPersonAvatar.aspx | 1 - Site5/Automation/Json-GetPersonAvatar.aspx.cs | 34 -------- Site5/Automation/Json-PositionsTree.aspx.cs | 50 +++++++++++- Site5/Automation/SwarmFunctions.aspx | 1 + Site5/Automation/SwarmFunctions.aspx.cs | 61 ++++++++++++++ Site5/Controls/v5/Swarm/AjaxComboPeople.ascx | 51 ++++++++++++ .../Controls/v5/Swarm/AjaxComboPeople.ascx.cs | 29 +++++++ Site5/Controls/v5/Swarm/ComboPeople.ascx | 80 ++++++++++++------- Site5/Controls/v5/Swarm/ComboPeople.ascx.cs | 1 + Site5/Controls/v5/Swarm/TreePositions.ascx | 23 +++++- Site5/Controls/v5/Swarm/TreePositions.ascx.cs | 12 +++ Site5/web.config | 9 ++- 16 files changed, 315 insertions(+), 74 deletions(-) delete mode 100644 Site5/Automation/Json-GetPersonAvatar.aspx delete mode 100644 Site5/Automation/Json-GetPersonAvatar.aspx.cs create mode 100644 Site5/Automation/SwarmFunctions.aspx create mode 100644 Site5/Automation/SwarmFunctions.aspx.cs create mode 100644 Site5/Controls/v5/Swarm/AjaxComboPeople.ascx create mode 100644 Site5/Controls/v5/Swarm/AjaxComboPeople.ascx.cs diff --git a/Site5/App_Code/CommonV5.cs b/Site5/App_Code/CommonV5.cs index d9f5b321..411cd38d 100644 --- a/Site5/App_Code/CommonV5.cs +++ b/Site5/App_Code/CommonV5.cs @@ -118,6 +118,11 @@ public class CommonV5 return result; } + public static string JavascriptEscape (string input) + { + return System.Uri.EscapeDataString (input).Replace ("'", "%27").Replace ("\"", "%22"); // makes it safe to embed in single/double quotes client-side + } + /* COLOR SCHEME diff --git a/Site5/App_Code/ControlV5Base.cs b/Site5/App_Code/ControlV5Base.cs index a980c44f..5ded74e6 100644 --- a/Site5/App_Code/ControlV5Base.cs +++ b/Site5/App_Code/ControlV5Base.cs @@ -63,4 +63,9 @@ public class ControlV5Base : UserControl base.OnLoad (e); } + protected string JavascriptEscape (string input) + { + return CommonV5.JavascriptEscape (input); + } + } \ No newline at end of file diff --git a/Site5/App_Code/PageV5Base.cs b/Site5/App_Code/PageV5Base.cs index 7d8c969d..d293133f 100644 --- a/Site5/App_Code/PageV5Base.cs +++ b/Site5/App_Code/PageV5Base.cs @@ -171,7 +171,7 @@ public class PageV5Base : Page public string JavascriptEscape (string input) { - return System.Uri.EscapeDataString (input).Replace ("'", "%27"); // makes it safe to embed in single quotes client-side + return CommonV5.JavascriptEscape (input); } } diff --git a/Site5/App_GlobalResources/Global.resx b/Site5/App_GlobalResources/Global.resx index 45884918..e67f9461 100644 --- a/Site5/App_GlobalResources/Global.resx +++ b/Site5/App_GlobalResources/Global.resx @@ -695,4 +695,29 @@ Position + + Type a name... + + + One month + + + One year + + + Six months + + + Three months + + + Two months + + + Two years + + + Until termination + Implicitly, until _manual_ (not automatic) termination + \ No newline at end of file diff --git a/Site5/Automation/Json-GetPersonAvatar.aspx b/Site5/Automation/Json-GetPersonAvatar.aspx deleted file mode 100644 index c6db12eb..00000000 --- a/Site5/Automation/Json-GetPersonAvatar.aspx +++ /dev/null @@ -1 +0,0 @@ -<%@ 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 deleted file mode 100644 index f21eea0e..00000000 --- a/Site5/Automation/Json-GetPersonAvatar.aspx.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -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-PositionsTree.aspx.cs b/Site5/Automation/Json-PositionsTree.aspx.cs index bbbcb74c..b7321884 100644 --- a/Site5/Automation/Json-PositionsTree.aspx.cs +++ b/Site5/Automation/Json-PositionsTree.aspx.cs @@ -42,19 +42,61 @@ namespace Swarmops.Frontend.Automation PositionAssignments assignments = position.Assignments; string expires = string.Empty; - string assignedName = Resources.Global.Swarm_Vacant + " " + Resources.Global.Swarm_AssignPerson + "" ; + if (assignments.Count > 0) { assignedName = assignments[0].Person.Canonical; + if (assignments[0].ExpiresDateTimeUtc.Year > 2000) // as in, "is defined" + { + expires = assignments[0].ExpiresDateTimeUtc.ToString ("yyyy-MM-dd"); + } } - string element = string.Format("\"id\":\"{0}\",\"positionTitle\":\"{1}\",\"assignedName\":\"{2}\",\"expires\":\"{3}\",\"minMax\":\"{4} / {5}\"", - position.Identity, JsonSanitize (localizedPositionName), JsonSanitize (assignedName), JsonSanitize (expires), position.MinCount, position.MaxCount == 0? @"∞" : position.MaxCount.ToString()); + string element = string.Format("\"id\":\"{0}-1\",\"positionTitle\":\"{1}\",\"assignedName\":\"{2}\",\"expires\":\"{3}\",\"minMax\":\"{4} / {5}\",\"iconType\":\"{6}\"", + position.Identity, JsonSanitize (localizedPositionName), JsonSanitize (assignedName), JsonSanitize (expires), position.MinCount, + position.MaxCount == 0? @"∞" : position.MaxCount.ToString(CultureInfo.InvariantCulture), + position.MaxCount == 1? "singular" : "plural"); // TODO: Add all assignments after the first one right here - if (position.Children.Count > 0) + int assignmentCount = 1; + + while (assignmentCount < assignments.Count) + { + // add more lines to match the number of assignments for this position + + elements.Add ("{" + element + "}"); + + expires = string.Empty; + if (assignments[assignmentCount].ExpiresDateTimeUtc.Year > 2000) // as in, "is defined" + { + expires = assignments[assignmentCount].ExpiresDateTimeUtc.ToString ("yyyy-MM-dd"); + } + element = + String.Format ( + "\"id\":\"{0}-{1}\",\"iconType\":\"hidden\",\"positionTitle\":\" \",\"assignedName\":\"{2}\",\"expires\":\"{3}\"", + position.Identity, assignmentCount+1, assignments[assignmentCount].Person.Canonical, expires); + + assignmentCount++; + } + + if (assignmentCount < position.MaxCount) + { + // finally, if the assigned count is less than max count, add a "assign another person" link + + elements.Add ("{" + element + "}"); + string addPerson = "" + + Resources.Global.Swarm_AssignMorePerson + ""; + + element = + String.Format( + "\"id\":\"{0}-0\",\"iconType\":\"hidden\",\"positionTitle\":\" \",\"assignedName\":\"{1}\"", + position.Identity, addPerson); + + } + + if (position.Children.Count > 0) // This should only trigger when position.MaxCount is also 1, or a very weird UI will result { element += ",\"state\":\"open\",\"children\":" + RecursePositionTree(positionNode.Children); } diff --git a/Site5/Automation/SwarmFunctions.aspx b/Site5/Automation/SwarmFunctions.aspx new file mode 100644 index 00000000..fb4edc88 --- /dev/null +++ b/Site5/Automation/SwarmFunctions.aspx @@ -0,0 +1 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SwarmFunctions.aspx.cs" Inherits="Swarmops.Frontend.Automation.SwarmFunctions" %> diff --git a/Site5/Automation/SwarmFunctions.aspx.cs b/Site5/Automation/SwarmFunctions.aspx.cs new file mode 100644 index 00000000..6e694b28 --- /dev/null +++ b/Site5/Automation/SwarmFunctions.aspx.cs @@ -0,0 +1,61 @@ +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; +using Swarmops.Logic.Security; +using Swarmops.Logic.Swarm; + +namespace Swarmops.Frontend.Automation +{ + public partial class SwarmFunctions : DataV5Base + { + protected void Page_Load (object sender, EventArgs e) + { + + } + + [WebMethod] + public static AjaxCallResult AssignPosition (string cookie) + { + string[] dataParts = cookie.Split ('-'); + int positionId = Convert.ToInt32(dataParts[0]); + int personId = Convert.ToInt32 (dataParts[2]); + + return new AjaxCallResult(); // TODO + } + + public class AvatarData : AjaxCallResult + { + public int PersonId { get; set; } + public string Canonical { get; set; } + public string Avatar16Url { get; set; } + public string Avatar24Url { get; set; } + } + + [WebMethod] + public static AvatarData GetPersonAvatar (int personId) + { + AuthenticationData authData = GetAuthenticationDataAndCulture(); + + People matches = People.FromSingle(Person.FromIdentity(personId)); + matches = Authorization.FilterPeopleToMatchAuthority(matches, authData.CurrentUser.GetAuthority()); // TODO: Change to Access + + if (matches.Count != 1) + { + throw new ArgumentException(); // no match, for whatever reason + } + + return new AvatarData + { + PersonId = personId, + Success = true, + Canonical = matches[0].Canonical, + Avatar16Url = matches[0].GetSecureAvatarLink (16), + Avatar24Url = matches[0].GetSecureAvatarLink (24) + }; + } + } +} \ No newline at end of file diff --git a/Site5/Controls/v5/Swarm/AjaxComboPeople.ascx b/Site5/Controls/v5/Swarm/AjaxComboPeople.ascx new file mode 100644 index 00000000..ea0055bb --- /dev/null +++ b/Site5/Controls/v5/Swarm/AjaxComboPeople.ascx @@ -0,0 +1,51 @@ +<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AjaxComboPeople.ascx.cs" Inherits="Swarmops.Frontend.Controls.v5.Swarm.AjaxComboPeople" %> +<%@ Register tagPrefix="Swarmops5Workaround" tagName="ComboPeople" src="~/Controls/v5/Swarm/ComboPeople.ascx" %> + + + + \ No newline at end of file diff --git a/Site5/Controls/v5/Swarm/AjaxComboPeople.ascx.cs b/Site5/Controls/v5/Swarm/AjaxComboPeople.ascx.cs new file mode 100644 index 00000000..b9218476 --- /dev/null +++ b/Site5/Controls/v5/Swarm/AjaxComboPeople.ascx.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace Swarmops.Frontend.Controls.v5.Swarm +{ + public partial class AjaxComboPeople : ControlV5Base + { + protected void Page_Load (object sender, EventArgs e) + { + Localize(); + + this.ComboPeople.OnClientSelect = this.ClientID + "_pvt_onSelectionChange"; + } + + private void Localize() + { + this.LiteralServerError.Text = JavascriptEscape(Resources.Global.Error_AjaxCallException); + } + + public string Cookie { set; get; } + public string OnChange { set; get; } + public string AjaxCallbackUrl { get; set; } + public string Placeholder { get; set; } + } +} \ No newline at end of file diff --git a/Site5/Controls/v5/Swarm/ComboPeople.ascx b/Site5/Controls/v5/Swarm/ComboPeople.ascx index c4f60446..0974dab7 100644 --- a/Site5/Controls/v5/Swarm/ComboPeople.ascx +++ b/Site5/Controls/v5/Swarm/ComboPeople.ascx @@ -20,20 +20,14 @@ // 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); - } - }); + SwarmopsJS.ajaxCall( + "/Automation/SwarmFunctions.aspx/GetPersonAvatar", + { personId: person.id }, + function(data) { + $('span#<%= this.ClientID %>_SpanPeople span input.textbox-text').css('background-image', "url('" + data.Avatar24Url + "')"); + }); + + <%=this.ClientID%>_selectedPersonIdPrivate = person.id; // call owner, if we have a callback @@ -44,33 +38,27 @@ } }); + <%=this.ClientID%>_placeholder(decodeURIComponent("<%=JavascriptEscape (this.Placeholder)%>")); + <% if (this.Selected != null) { %>; - $('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 %>'); + $('span#<%= this.ClientID %>_SpanPeople span input.textbox-text').css('background-image', "url('<%= this.Selected.GetSecureAvatarLink(24) %>')"); + $('span#<%= this.ClientID %>_SpanPeople span input.textbox-text').text('<%= this.Selected.Canonical %>'); <% } else if (this.NobodySelected) { %>; - $('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 %>'); + $('span#<%= this.ClientID %>_SpanPeople span input.textbox-text').css('background-image', "url('/Images/Icons/iconshock-warning-24px.png')"); + $('span#<%= this.ClientID %>_SpanPeople span input.textbox-text').text('<%= Resources.Global.Global_NoOwner %>'); <% } else { %>; - $('span#<%= this.ClientID %>_SpanPeople span input.combo-text').css('background', ''); + $('span#<%= this.ClientID %>_SpanPeople span input.textbox-text').css('background', ''); - <% } %>; - $('#<%=this.ClientID %>_SpanPeople span.combo input.combo-text').keydown(function (e) { - switch (e.which) { - case 40: // down - $('#<%=this.ClientID %>_SpanPeople span.combo span span.combo-arrow').click(); - break; - - default: return; // exit this handler for other keys - } - e.preventDefault(); // prevent the default action (scroll / move caret) - }); + <% } %> }); - + + var <%=this.ClientID%>_selectedPersonIdPrivate = 0; + var <%=this.ClientID %>_autoCompleteLoader = function(param,success,error){ var q = param.q || ''; if (q.length < 3) { @@ -99,6 +87,36 @@ var s = ' center;background-repeat:no-repeat">' + row.name + ''; return s; } + + function <%=this.ClientID %>_placeholder(newValue) { + $('span#<%= this.ClientID %>_SpanPeople span input.textbox-text').attr('placeholder', newValue); + } + + function <%=this.ClientID %>_avatarUrl(avatarUrl) { + $('span#<%= this.ClientID %>_SpanPeople span input.textbox-text').css('background-image', "url('" + avatarUrl + "')"); + } + + function <%=this.ClientID %>_selectedPersonId() { + return <%=this.ClientID%>_selectedPersonIdPrivate; + } + + function <%=this.ClientID %>_placeholder(newValue) { + $('span#<%= this.ClientID %>_SpanPeople span input.textbox-text').attr('placeholder', newValue); + } + + function <%=this.ClientID %>_val(newValue) { + return $('span#<%= this.ClientID %>_SpanPeople span input.textbox-text').val(newValue); + } + + function <%=this.ClientID %>_backgroundColor(newColor) { + $('span#<%= this.ClientID %>_SpanPeople span input.textbox-text').css('background-color', newColor); + } + + function <%=this.ClientID %>_backgroundToWhite() { + $('span#<%= this.ClientID %>_SpanPeople span input.textbox-text').animate({ backgroundColor: "#FFFFFF" }, 250); + } + + \ No newline at end of file diff --git a/Site5/Controls/v5/Swarm/ComboPeople.ascx.cs b/Site5/Controls/v5/Swarm/ComboPeople.ascx.cs index 9bf88d8b..137fc9ef 100644 --- a/Site5/Controls/v5/Swarm/ComboPeople.ascx.cs +++ b/Site5/Controls/v5/Swarm/ComboPeople.ascx.cs @@ -10,6 +10,7 @@ namespace Swarmops.Controls.Financial public string OnClientSelect { set; protected get; } public bool NobodySelected { set; protected get; } + public string Placeholder { get; set; } protected void Page_Load (object sender, EventArgs e) { diff --git a/Site5/Controls/v5/Swarm/TreePositions.ascx b/Site5/Controls/v5/Swarm/TreePositions.ascx index 197f9bbb..899ac35f 100644 --- a/Site5/Controls/v5/Swarm/TreePositions.ascx +++ b/Site5/Controls/v5/Swarm/TreePositions.ascx @@ -1,4 +1,5 @@ <%@ Control Language="C#" AutoEventWireup="true" CodeFile="TreePositions.ascx.cs" Inherits="Swarmops.Frontend.Controls.v5.Swarm.TreePositions" %> +<%@ Register TagPrefix="Swarmops5Workaround" TagName="ComboPeople" src="~/Controls/v5/Swarm/ComboPeople.ascx" %>