Lots of small fixes to everything

This commit is contained in:
Rick Falkvinge
2015-04-10 18:32:00 +02:00
parent 4b976be456
commit e8e192db92
16 changed files with 315 additions and 74 deletions
+5
View File
@@ -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
+5
View File
@@ -63,4 +63,9 @@ public class ControlV5Base : UserControl
base.OnLoad (e);
}
protected string JavascriptEscape (string input)
{
return CommonV5.JavascriptEscape (input);
}
}
+1 -1
View File
@@ -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);
}
}
+25
View File
@@ -695,4 +695,29 @@
<data name="Swarm_Position" xml:space="preserve">
<value>Position</value>
</data>
<data name="Swarm_TypeName" xml:space="preserve">
<value>Type a name...</value>
</data>
<data name="Timespan_Selection_OneMonth" xml:space="preserve">
<value>One month</value>
</data>
<data name="Timespan_Selection_OneYear" xml:space="preserve">
<value>One year</value>
</data>
<data name="Timespan_Selection_SixMonths" xml:space="preserve">
<value>Six months</value>
</data>
<data name="Timespan_Selection_ThreeMonths" xml:space="preserve">
<value>Three months</value>
</data>
<data name="Timespan_Selection_TwoMonths" xml:space="preserve">
<value>Two months</value>
</data>
<data name="Timespan_Selection_TwoYears" xml:space="preserve">
<value>Two years</value>
</data>
<data name="Timespan_Selection_UntilTermination" xml:space="preserve">
<value>Until termination</value>
<comment>Implicitly, until _manual_ (not automatic) termination</comment>
</data>
</root>
@@ -1 +0,0 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-GetPersonAvatar.aspx.cs" Inherits="Swarmops.Frontend.Automation.Json_GetPersonAvatar" %>
@@ -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();
}
}
}
+46 -4
View File
@@ -42,19 +42,61 @@ namespace Swarmops.Frontend.Automation
PositionAssignments assignments = position.Assignments;
string expires = string.Empty;
string assignedName = Resources.Global.Swarm_Vacant + " <a href='#' class='LocalAssignPerson'>" + Resources.Global.Swarm_AssignPerson + "</a>" ;
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? @"&infin;" : 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? @"&infin;" : 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\":\"&nbsp;\",\"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 = "<a href='#' class='LocalAssignPerson'>" +
Resources.Global.Swarm_AssignMorePerson + "</a>";
element =
String.Format(
"\"id\":\"{0}-0\",\"iconType\":\"hidden\",\"positionTitle\":\"&nbsp;\",\"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);
}
+1
View File
@@ -0,0 +1 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SwarmFunctions.aspx.cs" Inherits="Swarmops.Frontend.Automation.SwarmFunctions" %>
+61
View File
@@ -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)
};
}
}
}
@@ -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" %>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
<%= ComboPeople.ClientID %>_placeholder(decodeURIComponent('<%=JavascriptEscape(this.Placeholder)%>'));
});
function <%=this.ClientID%>_pvt_onSelectionChange(newPersonId) {
<%= ComboPeople.ClientID %>_backgroundColor ('#FFFFE0');
SwarmopsJS.ajaxCall(
"<%=this.AjaxCallbackUrl%>",
{ cookie: <%=this.ClientID%>_cookieValue },
function(result) {
<%= ComboPeople.ClientID %>_backgroundColor('#E0FFE0');
<%= ComboPeople.ClientID %>_backgroundToWhite();
<%=this.ClientID%>_selectedId = newPersonId;
<% if (!String.IsNullOrEmpty(this.OnChange))
{
Response.Write (this.OnChange + "(newPersonId);");
}%>
},
function(error) {
<%= ComboPeople.ClientID %>_backgroundColor ('#FFA0A0');
<%= ComboPeople.ClientID %>_backgroundToWhite();
alertify.error(decodeURIComponent('<asp:Literal ID="LiteralServerError" runat="server"/>'));
});
}
function <%=this.ClientID%>_cookie(newValue) {
if (newValue !== undefined) {
<%=this.ClientID%>_cookieValue = newValue;
}
return <%=this.ClientID%>_cookieValue;
}
function <%=this.ClientID%>_clear() {
<%=this.ComboPeople.ClientID%>_val('');
}
var <%=this.ClientID%>_cookieValue = '<%=this.Cookie%>';
var <%=this.ClientID%>_selectedId = 0;
</script>
<Swarmops5Workaround:ComboPeople ID="ComboPeople" runat="server" />
@@ -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; }
}
}
+49 -31
View File
@@ -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 = '<span style="padding-<%= _nearEdge %>:20px;margin-<%= _nearEdge %>:4px;' + "background-image:url('" + row.avatar16Url + "');" + 'background-position:<%= _nearEdge %> center;background-repeat:no-repeat">' + row.name + '</span>';
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);
}
</script>
<span id="<%=this.ClientID %>_SpanPeople" class="fakePlaceholderText"><select class="easyui-combobox comboperson" url="" name="DropPeople" id="<%=this.ClientID %>_DropPeople" animate="true" style="width:324px"></select></span>
@@ -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)
{
+21 -2
View File
@@ -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" %>
<script language="javascript" type="text/javascript">
@@ -8,7 +9,10 @@
{
onLoadSuccess: function () {
// Anything here
$('.LocalAssignPerson').click(function () {
<%= this.DropPerson.ClientID%>_val('');
<%= this.DialogAdd.ClientID %>_open();
});
}
});
@@ -32,5 +36,20 @@
<th field="minMax" width="80" align="center"><asp:Literal ID="LiteralHeaderMinMax" Text="Min/Max" runat="server" /></th>
<th field="actionIcon" width="50" align="center"><asp:Literal ID="LiteralHeaderAction" Text="XYZ" runat="server" /></th>
</tr>
</thead>
</thead>
</table>
<Swarmops5:ModalDialog id="DialogAdd" runat="server">
<DialogCode>
<h2>Assigning to ASDSADASDASDASD</h2>
<div class="entryFields">
<Swarmops5Workaround:ComboPeople ID="DropPerson" runat="server" />&#8203;<br/>
<asp:DropDownList ID="DropDuration" runat="server" />&#8203;<br/>
<input type="button" class="buttonAccentColor" value="Assign"/>
</div>
<div class="entryLabels">
Assign this person to the position:<br/>
Assignment duration:
</div>
</DialogCode>
</Swarmops5:ModalDialog>
@@ -19,6 +19,7 @@ namespace Swarmops.Frontend.Controls.v5.Swarm
protected void Page_Load (object sender, EventArgs e)
{
Localize();
this.DropPerson.Placeholder = Resources.Global.Swarm_TypeName;
}
private void Localize()
@@ -28,6 +29,17 @@ namespace Swarmops.Frontend.Controls.v5.Swarm
this.LiteralHeaderPosition.Text = Resources.Global.Swarm_Position;
this.LiteralHeaderExpires.Text = Resources.Global.Swarm_AssignmentExpires;
this.LiteralHeaderMinMax.Text = Resources.Global.Global_MinMax;
this.DropDuration.Items.Add (new ListItem(Resources.Global.Timespan_Selection_OneMonth, "1"));
this.DropDuration.Items.Add(new ListItem(Resources.Global.Timespan_Selection_TwoMonths, "2"));
this.DropDuration.Items.Add(new ListItem(Resources.Global.Timespan_Selection_ThreeMonths, "3"));
this.DropDuration.Items.Add(new ListItem(Resources.Global.Timespan_Selection_SixMonths, "6"));
this.DropDuration.Items.Add(new ListItem(Resources.Global.Timespan_Selection_OneYear, "12"));
this.DropDuration.Items.Add(new ListItem(Resources.Global.Timespan_Selection_TwoYears, "24"));
this.DropDuration.Items.Add(new ListItem(Resources.Global.Timespan_Selection_UntilTermination, "-1"));
this.DropDuration.SelectedValue = "12";
}
public RoleLevel Level { get; set; }
+8 -1
View File
@@ -24,7 +24,14 @@
<authorization>
<deny users="?" />
</authorization>
<pages controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID" />
<pages controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID">
<controls>
<add tagPrefix="Swarmops5" tagName="ComboPeople" src="~/Controls/v5/Swarm/ComboPeople.ascx" />
<add tagPrefix="Swarmops5" tagName="AjaxTextBox" src="~/Controls/v5/Base/AjaxTextBox.ascx" />
<add tagPrefix="Swarmops5" tagName="AjaxComboPeople" src="~/Controls/v5/Swarm/ComboPeople.ascx" />
<add tagPrefix="Swarmops5" tagName="ModalDialog" src="~/Controls/v5/Base/ModalDialog.ascx" />
</controls>
</pages>
</system.web>
<system.web.extensions>
<scripting>