Assigning positions WORKS
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using NBitcoin;
|
||||
@@ -1108,6 +1109,28 @@ namespace Swarmops.Logic.Swarm
|
||||
return GetAvatarLink (pixelSize).Replace ("http://www", "https://secure");
|
||||
}
|
||||
|
||||
|
||||
public PositionAssignment PositionAssignment
|
||||
{
|
||||
get
|
||||
{
|
||||
PositionAssignments candidateSet = this.PositionAssignments;
|
||||
// candidateSet = (PositionAssignments) candidateSet.Where (assignment => assignment.Active); THIS THROWS, FIX WHEN THIS LOGIC IS NEEDED
|
||||
|
||||
if (candidateSet.Count != 1)
|
||||
{
|
||||
throw new ArgumentException ("No active position");
|
||||
}
|
||||
|
||||
return candidateSet[0];
|
||||
}
|
||||
}
|
||||
|
||||
public PositionAssignments PositionAssignments
|
||||
{
|
||||
get { return PositionAssignments.ForPerson (this); }
|
||||
}
|
||||
|
||||
public bool HasAccess (Access access)
|
||||
{
|
||||
if (access == null)
|
||||
@@ -1156,6 +1179,14 @@ namespace Swarmops.Logic.Swarm
|
||||
return true;
|
||||
}
|
||||
|
||||
// ENTERING TEMPORARY TERRITORY HERE, UNTIL REAL ACCESS COMPLETED
|
||||
|
||||
if (access.Organization == null)
|
||||
{
|
||||
access = new Access (Organization.FromIdentity (1), access.Aspect, access.Type);
|
||||
}
|
||||
|
||||
|
||||
if (access.Type == AccessType.Write)
|
||||
{
|
||||
ids = access.Organization.Parameters.TemporaryAccessListWrite;
|
||||
|
||||
@@ -25,5 +25,14 @@ namespace Swarmops.Logic.Swarm
|
||||
|
||||
return FromArray (SwarmDb.GetDatabaseForReading().GetPositionAssignments (positions));
|
||||
}
|
||||
|
||||
public static PositionAssignments ForPerson (Person person, bool includeTerminated = false)
|
||||
{
|
||||
if (!includeTerminated)
|
||||
{
|
||||
return FromArray (SwarmDb.GetDatabaseForReading().GetPositionAssignments (person, DatabaseCondition.ActiveTrue));
|
||||
}
|
||||
return FromArray(SwarmDb.GetDatabaseForReading().GetPositionAssignments(person));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,10 +134,20 @@
|
||||
<data name="Positions_AssignPersonToPosition" xml:space="preserve">
|
||||
<value>Assign this person to position</value>
|
||||
</data>
|
||||
<data name="Positions_ButtonAssign" xml:space="preserve">
|
||||
<value>Assign</value>
|
||||
<comment>Kind of "hire" but also for volunteers</comment>
|
||||
</data>
|
||||
<data name="Positions_ModalHeader" xml:space="preserve">
|
||||
<value>Assign person as <span id='{0}_modalPositionName'>...</span></value>
|
||||
<comment>Header for new assignment dialog</comment>
|
||||
</data>
|
||||
<data name="Positions_NoMorePeopleOnPosition" xml:space="preserve">
|
||||
<value>Failed: Can't assign any more people to this position.</value>
|
||||
</data>
|
||||
<data name="Positions_PleaseSelectPerson" xml:space="preserve">
|
||||
<value>Please select a person to assign.</value>
|
||||
</data>
|
||||
<data name="Positions_Vacant" xml:space="preserve">
|
||||
<value>(vacant)</value>
|
||||
<comment>For unassigned positions</comment>
|
||||
|
||||
@@ -680,6 +680,9 @@
|
||||
<data name="Swarm_Position" xml:space="preserve">
|
||||
<value>Position</value>
|
||||
</data>
|
||||
<data name="Error_DatabaseConcurrency" xml:space="preserve">
|
||||
<value>It seems another user beat you to this operation; the database changed while you were looking. Please examine the changed conditions and retry what you were trying to do.</value>
|
||||
</data>
|
||||
<data name="Swarm_TypeName" xml:space="preserve">
|
||||
<value>Type a name...</value>
|
||||
</data>
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Swarmops.Frontend.Automation
|
||||
// If level if system-wide, execute this block. Also, move the data to the real place, please
|
||||
|
||||
JsonPositions rootPositions = new JsonPositions();
|
||||
_customCookieClass = Request["CustomCookie"]; // may be null and that's ok
|
||||
_customCookieClass = "LocalPosition" + Request["Cookie"]; // may be null and that's ok
|
||||
|
||||
Tree<Position> systemPositions = Positions.ForSystem().Tree;
|
||||
|
||||
@@ -43,14 +43,15 @@ namespace Swarmops.Frontend.Automation
|
||||
PositionAssignments assignments = position.Assignments;
|
||||
|
||||
string expires = string.Empty;
|
||||
string assignedName = string.Format("{0} <a href='#' positionId='{3}' positionName='{4}' class='{1} LocalAssignPerson'>{2}</a>", Resources.Controls.Swarm.Positions_Vacant, _customCookieClass, Resources.Controls.Swarm.Positions_AssignPerson, position.Identity, JavascriptEscape(position.Localized()));
|
||||
string assignedName = string.Format("<a positionId='{3}' positionName='{4}' class='{1} LocalAssignPerson'>{2}</a> {0}", Resources.Controls.Swarm.Positions_Vacant, _customCookieClass, Resources.Controls.Swarm.Positions_AssignPerson, position.Identity, JavascriptEscape(position.Localized()));
|
||||
|
||||
if (assignments.Count > 0)
|
||||
{
|
||||
assignedName = assignments[0].Person.Canonical;
|
||||
if (assignments[0].ExpiresDateTimeUtc.Year > 2000) // as in, "is defined"
|
||||
int expireYear = assignments[0].ExpiresDateTimeUtc.Year;
|
||||
if (expireYear > 2000 && expireYear < 3000) // as in, "is defined"
|
||||
{
|
||||
expires = assignments[0].ExpiresDateTimeUtc.ToString ("yyyy-MM-dd");
|
||||
expires = assignments[0].ExpiresDateTimeUtc.ToString("yyyy-MMM-dd");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,9 +71,10 @@ namespace Swarmops.Frontend.Automation
|
||||
elements.Add ("{" + element + "}");
|
||||
|
||||
expires = string.Empty;
|
||||
if (assignments[assignmentCount].ExpiresDateTimeUtc.Year > 2000) // as in, "is defined"
|
||||
int expireYear = assignments[assignmentCount].ExpiresDateTimeUtc.Year;
|
||||
if (expireYear > 2000 && expireYear < 3000) // as in, "is defined"
|
||||
{
|
||||
expires = assignments[assignmentCount].ExpiresDateTimeUtc.ToString ("yyyy-MM-dd");
|
||||
expires = assignments[assignmentCount].ExpiresDateTimeUtc.ToString ("yyyy-MMM-dd");
|
||||
}
|
||||
element =
|
||||
String.Format (
|
||||
@@ -82,14 +84,14 @@ namespace Swarmops.Frontend.Automation
|
||||
assignmentCount++;
|
||||
}
|
||||
|
||||
if (assignmentCount < position.MaxCount)
|
||||
if (assignmentCount < position.MaxCount || (position.MaxCount == 0 && position.Assignments.Count > 0))
|
||||
{
|
||||
// finally, if the assigned count is less than max count, add a "assign another person" link
|
||||
|
||||
elements.Add ("{" + element + "}");
|
||||
string addPerson =
|
||||
string.Format (
|
||||
"<a href='#' positionId='{1}' positionName='{2}' class='{3} LocalAssignPerson'>{0}</a>",
|
||||
"<a positionId='{1}' positionName='{2}' class='{3} LocalAssignPerson'>{0}</a>",
|
||||
Resources.Controls.Swarm.Positions_AssignMorePerson, position.Identity,
|
||||
JavascriptEscape (position.Localized()), _customCookieClass);
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ using System.Web.Services;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using Swarmops.Logic.Security;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Swarm;
|
||||
using Swarmops.Common.Exceptions;
|
||||
|
||||
namespace Swarmops.Frontend.Automation
|
||||
{
|
||||
@@ -18,13 +20,53 @@ namespace Swarmops.Frontend.Automation
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public static AjaxCallResult AssignPosition (string cookie)
|
||||
public static AjaxCallResult AssignPosition (int personId, int positionId, int durationMonths, int organizationId, int geographyId)
|
||||
{
|
||||
string[] dataParts = cookie.Split ('-');
|
||||
int positionId = Convert.ToInt32(dataParts[0]);
|
||||
int personId = Convert.ToInt32 (dataParts[2]);
|
||||
AuthenticationData authData = GetAuthenticationDataAndCulture();
|
||||
Position position = Position.FromIdentity (positionId);
|
||||
Person person = Person.FromIdentity (personId);
|
||||
Organization organization = (organizationId == 0 ? null : Organization.FromIdentity (organizationId));
|
||||
Geography geography = (geographyId == 0 ? null : Geography.FromIdentity (geographyId));
|
||||
|
||||
return new AjaxCallResult(); // TODO
|
||||
if ((position.OrganizationId > 0 && authData.CurrentOrganization.Identity != position.OrganizationId) || person.Identity < 0)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
if (!authData.CurrentUser.HasAccess (new Access (AccessAspect.Administration)))
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
if (position.MaxCount > 0 && position.Assignments.Count >= position.MaxCount)
|
||||
{
|
||||
return new AjaxCallResult
|
||||
{
|
||||
Success = false,
|
||||
DisplayMessage = Resources.Controls.Swarm.Positions_NoMorePeopleOnPosition
|
||||
};
|
||||
}
|
||||
|
||||
// Deliberate: no requirement for membership (or equivalent) in order to be assigned to position.
|
||||
|
||||
Position currentUserPosition = authData.CurrentUser.PositionAssignment.Position; // excludes acting positions. May throw!
|
||||
DateTime? expiresUtc = null;
|
||||
|
||||
if (durationMonths > 0)
|
||||
{
|
||||
expiresUtc = DateTime.UtcNow.AddMonths (durationMonths);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
PositionAssignment.Create (organization, geography, position, person, authData.CurrentUser, currentUserPosition,
|
||||
expiresUtc, string.Empty);
|
||||
}
|
||||
catch (DatabaseConcurrencyException)
|
||||
{
|
||||
return new AjaxCallResult {Success = false, DisplayMessage = Resources.Global.Error_DatabaseConcurrency};
|
||||
}
|
||||
|
||||
return new AjaxCallResult() {Success = true};
|
||||
}
|
||||
|
||||
public class AvatarData : AjaxCallResult
|
||||
|
||||
@@ -119,6 +119,13 @@
|
||||
function <%=this.ClientID %>_clear() {
|
||||
<%=this.ClientID%>_val('');
|
||||
<%=this.ClientID%>_avatarUrl('');
|
||||
$('#<%=this.ClientID%>_DropPeople').combobox('reload');
|
||||
$('#<%=this.ClientID%>_DropPeople').combobox('clear');
|
||||
<%=this.ClientID%>_pvt_selectedPersonId = 0;
|
||||
}
|
||||
|
||||
function <%=this.ClientID %>_focus() {
|
||||
$('span#<%= this.ClientID %>_SpanPeople span input.textbox-text').focus();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
@@ -9,11 +9,13 @@
|
||||
{
|
||||
|
||||
onLoadSuccess: function () {
|
||||
$('.LocalAssignPerson').click(function () {
|
||||
currentPosition = $(this).attr("positionId");
|
||||
$('.LocalAssignPerson.LocalPosition<%=this.Cookie%>').click(function () {
|
||||
currentPositionId = $(this).attr("positionId");
|
||||
$('#<%= this.ClientID %>_modalPositionName').text(decodeURIComponent($(this).attr("positionName")));
|
||||
<%= this.DropPerson.ClientID%>_clear();
|
||||
$('#<%= this.DropDuration.ClientID%>').val("12"); // reset to 12-month default
|
||||
<%= this.DialogAdd.ClientID %>_open();
|
||||
<%= this.DropPerson.ClientID%>_focus();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,18 +23,43 @@
|
||||
});
|
||||
|
||||
$('#<%=this.ClientID%>_buttonAssign').click(function() {
|
||||
alert("foo!");
|
||||
var personId = <%=this.DropPerson.ClientID%>_selectedPersonId();
|
||||
|
||||
if (personId == 0) {
|
||||
// abort
|
||||
alert("No person selected, not assigning anybody");
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Check existing position for person; can't have two positions
|
||||
|
||||
SwarmopsJS.ajaxCall(
|
||||
"/Automation/SwarmFunctions.aspx/AssignPosition",
|
||||
{ personId: personId, positionId: currentPositionId, durationMonths: $('#<%= this.DropDuration.ClientID%>').val(), organizationId: 0, geographyId: 0 },
|
||||
function (result) {
|
||||
// Close modal and reload grid regardless of success or not
|
||||
// (the only failure here should be a concurrency error, in which case
|
||||
// the user needs to examine the new state anyway)
|
||||
|
||||
<%= this.DialogAdd.ClientID %>_close();
|
||||
$('#<%=this.ClientID%>_tablePositions').treegrid('reload');
|
||||
if (result.Success) {
|
||||
// success
|
||||
} else {
|
||||
alertify.error(result.DisplayMessage);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
var currentPosition = '';
|
||||
var currentPositionId = '';
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
<table id="<%=this.ClientID %>_tablePositions" title="" class="easyui-treegrid" style="width:680px;height:600px"
|
||||
url="/Automation/Json-PositionsTree.aspx"
|
||||
url="/Automation/Json-PositionsTree.aspx?Cookie=<%=this.Cookie %>"
|
||||
rownumbers="false"
|
||||
animate="true"
|
||||
fitColumns="true"
|
||||
@@ -41,7 +68,7 @@
|
||||
<tr>
|
||||
<th field="positionTitle" width="200"><asp:Literal ID="LiteralHeaderPosition" Text="Position XYZ" runat="server"/></th>
|
||||
<th field="assignedName" width="200"><asp:Literal ID="LiteralHeaderName" Text="AssignedName XYZ" runat="server" /></th>
|
||||
<th field="dateExpires" width="120"><asp:Literal ID="LiteralHeaderExpires" Text="ExpiresDate XYZ" runat="server" /></th>
|
||||
<th field="expires" width="120"><asp:Literal ID="LiteralHeaderExpires" Text="ExpiresDate XYZ" runat="server" /></th>
|
||||
<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>
|
||||
@@ -54,7 +81,7 @@
|
||||
<div class="entryFields">
|
||||
<Swarmops5Workaround:ComboPeople ID="DropPerson" runat="server" />​<br/>
|
||||
<asp:DropDownList ID="DropDuration" runat="server" />​<br/>
|
||||
<input type="button" id="<%=this.ClientID %>_buttonAssign" class="buttonAccentColor" value="Assign"/>
|
||||
<input type="button" id="<%=this.ClientID %>_buttonAssign" class="buttonAccentColor" value='<asp:Literal ID="LiteralButtonAssign" runat="server"/>' />
|
||||
</div>
|
||||
<div class="entryLabels">
|
||||
<asp:Label ID="LabelAssignPersonTo" runat="server" /><br/>
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace Swarmops.Frontend.Controls.v5.Swarm
|
||||
this.LabelAssignPersonTo.Text = Resources.Controls.Swarm.Positions_AssignPersonToPosition;
|
||||
this.LabelAssignmentDuration.Text = Resources.Controls.Swarm.Positions_AssignmentDuration;
|
||||
this.LabelModalHeader.Text = String.Format (Resources.Controls.Swarm.Positions_ModalHeader, this.ClientID);
|
||||
this.LiteralButtonAssign.Text = Resources.Controls.Swarm.Positions_ButtonAssign; // Wrongly flagged red-error by Resharper; this assignment is legit
|
||||
|
||||
this.DropDuration.Items.Add (new ListItem(Resources.Global.Timespan_Selection_OneMonth, "1"));
|
||||
this.DropDuration.Items.Add(new ListItem(Resources.Global.Timespan_Selection_TwoMonths, "2"));
|
||||
@@ -49,6 +50,7 @@ namespace Swarmops.Frontend.Controls.v5.Swarm
|
||||
public RoleLevel Level { get; set; }
|
||||
public int OrganizationId { get; set; }
|
||||
public int GeographyId { get; set; }
|
||||
public string Cookie { get; set; }
|
||||
|
||||
|
||||
public enum RoleLevel
|
||||
|
||||
Reference in New Issue
Block a user