Terminating position assignments
This commit is contained in:
@@ -1212,6 +1212,24 @@ namespace Swarmops.Logic.Swarm
|
||||
return false;
|
||||
}
|
||||
|
||||
public Position GetPrimaryPosition (Organization organization)
|
||||
{
|
||||
PositionAssignments personAssignments = PositionAssignments.ForPerson (this);
|
||||
|
||||
foreach (PositionAssignment assignment in personAssignments)
|
||||
{
|
||||
if (assignment.OrganizationId == 0 || assignment.OrganizationId == organization.Identity)
|
||||
{
|
||||
// TODO: If "acting" is false, and no delegation, then...
|
||||
return assignment.Position;
|
||||
}
|
||||
}
|
||||
|
||||
// No hit. This is a totally valid case, so don't throw but return null.
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// A couple of special cases
|
||||
|
||||
public const int OpenLedgersIdentity = -1;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NBitcoin;
|
||||
@@ -97,5 +98,19 @@ namespace Swarmops.Logic.Swarm
|
||||
return FromIdentityAggressive (positionAssignmentId);
|
||||
}
|
||||
|
||||
public void Terminate (Person terminatingPerson, Position terminatingPosition, string terminationNotes)
|
||||
{
|
||||
// TODO: ADD ACCESS CONTROL AT LOGIC LAYER
|
||||
|
||||
SwarmDb.GetDatabaseForWriting()
|
||||
.TerminatePositionAssignment (this.Identity, terminatingPerson.Identity, terminatingPosition.Identity,
|
||||
terminationNotes);
|
||||
|
||||
base.TerminatedByPersonId = terminatingPerson.Identity;
|
||||
base.TerminatedByPositionId = terminatingPosition.Identity;
|
||||
base.Active = false;
|
||||
base.TerminationNotes = terminationNotes;
|
||||
base.TerminatedDateTimeUtc = DateTime.UtcNow; // may differ by milliseconds from actual value set, but shouldn't matter for practical purposes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
<value>Assign a fifth person...</value>
|
||||
</data>
|
||||
<data name="Positions_AssignFirstPerson" xml:space="preserve">
|
||||
<value>Assign somebody...</value>
|
||||
<value>Assign...</value>
|
||||
</data>
|
||||
<data name="Positions_AssignFourthPerson" xml:space="preserve">
|
||||
<value>Assign a fourth person...</value>
|
||||
@@ -168,4 +168,23 @@
|
||||
<value>(position is vacant)</value>
|
||||
<comment>For unassigned positions</comment>
|
||||
</data>
|
||||
<data name="Positions_ConfirmSelfTerminate" xml:space="preserve">
|
||||
<value><strong>QUIT YOUR POSITION?</strong><br/><br/>This is <strong>your</strong> assignment. Terminating your own assignment is the equivalent of saying "I QUIT". Doing so will take effect immediately. Is this what you wanted to do?<br/><br/></value>
|
||||
</data>
|
||||
<data name="Positions_ConfirmTerminate" xml:space="preserve">
|
||||
<value><strong>TERMINATE ASSIGNMENT?</strong><br/><br/>Do you want to terminate {0} from the assignment as {1}? This is the equivalent of firing somebody and usually needs to be in accordance with internal processes and local law.<br/><br/></value>
|
||||
<comment>{0} is the person name, {1} is the position title.</comment>
|
||||
</data>
|
||||
<data name="Positions_TerminateNo" xml:space="preserve">
|
||||
<value>Do Not Terminate</value>
|
||||
</data>
|
||||
<data name="Positions_TerminateSelfNo" xml:space="preserve">
|
||||
<value>Oops! No, go back!</value>
|
||||
</data>
|
||||
<data name="Positions_TerminateSelfYes" xml:space="preserve">
|
||||
<value>Yes, I Resign</value>
|
||||
</data>
|
||||
<data name="Positions_TerminateYes" xml:space="preserve">
|
||||
<value>Terminate Assignment</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -43,6 +43,7 @@ namespace Swarmops.Frontend.Automation
|
||||
PositionAssignments assignments = position.Assignments;
|
||||
|
||||
string expires = string.Empty;
|
||||
string action = string.Empty;
|
||||
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_AssignFirstPerson, position.Identity, JavascriptEscape(position.Localized()));
|
||||
|
||||
if (assignments.Count > 0)
|
||||
@@ -53,12 +54,14 @@ namespace Swarmops.Frontend.Automation
|
||||
{
|
||||
expires = assignments[0].ExpiresDateTimeUtc.ToString("yyyy-MMM-dd");
|
||||
}
|
||||
action = String.Format("<img class='LocalIconTerminate {1}' height='18' width='24' {2} assignmentId='{0}' />", assignments[0].Identity, _customCookieClass, assignments[0].PersonId == CurrentUser.Identity? "self='true'": string.Empty);
|
||||
}
|
||||
|
||||
string element = string.Format("\"id\":\"{0}-1\",\"positionTitle\":\"{1}\",\"assignedName\":\"{2}\",\"expires\":\"{3}\",\"minMax\":\"{4} / {5}\",\"iconType\":\"{6}\"",
|
||||
string element = string.Format("\"id\":\"{0}-1\",\"positionTitle\":\"{1}\",\"assignedName\":\"{2}\",\"expires\":\"{3}\",\"minMax\":\"{4} / {5}\",\"iconType\":\"{6}\",\"actions\":\"{7}\"",
|
||||
position.Identity, JsonSanitize (localizedPositionName), JsonSanitize (assignedName), JsonSanitize (expires), position.MinCount,
|
||||
position.MaxCount == 0? @"∞" : position.MaxCount.ToString(CultureInfo.InvariantCulture),
|
||||
position.MaxCount == 1? "Person" : "Group");
|
||||
position.MaxCount == 1? "Person" : "Group",
|
||||
action);
|
||||
|
||||
// TODO: Add all assignments after the first one right here
|
||||
|
||||
@@ -71,6 +74,8 @@ namespace Swarmops.Frontend.Automation
|
||||
elements.Add ("{" + element + "}");
|
||||
|
||||
expires = string.Empty;
|
||||
action = String.Format("<img class='LocalIconTerminate {1}' height='18' width='24' {2} assignmentId='{0}' />", assignments[assignmentCount].Identity, _customCookieClass, assignments[0].PersonId == CurrentUser.Identity ? "self='true'" : string.Empty);
|
||||
|
||||
int expireYear = assignments[assignmentCount].ExpiresDateTimeUtc.Year;
|
||||
if (expireYear > 2000 && expireYear < 3000) // as in, "is defined"
|
||||
{
|
||||
@@ -78,8 +83,8 @@ namespace Swarmops.Frontend.Automation
|
||||
}
|
||||
element =
|
||||
String.Format (
|
||||
"\"id\":\"{0}-{1}\",\"iconType\":\"Hidden\",\"positionTitle\":\" \",\"assignedName\":\"{2}\",\"expires\":\"{3}\"",
|
||||
position.Identity, assignmentCount+1, assignments[assignmentCount].Person.Canonical, expires);
|
||||
"\"id\":\"{0}-{1}\",\"iconType\":\"Hidden\",\"positionTitle\":\" \",\"assignedName\":\"{2}\",\"expires\":\"{3}\",\"actions\":\"{4}\"",
|
||||
position.Identity, assignmentCount+1, assignments[assignmentCount].Person.Canonical, expires, action);
|
||||
|
||||
assignmentCount++;
|
||||
}
|
||||
@@ -129,6 +134,11 @@ namespace Swarmops.Frontend.Automation
|
||||
return "[" + String.Join(",", elements.ToArray()) + "]";
|
||||
}
|
||||
|
||||
private bool HasHiringFiringPrivileges (Position position)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private string _customCookieClass;
|
||||
|
||||
private class JsonPosition
|
||||
|
||||
@@ -66,7 +66,56 @@ namespace Swarmops.Frontend.Automation
|
||||
return new AjaxCallResult {Success = false, DisplayMessage = Resources.Global.Error_DatabaseConcurrency};
|
||||
}
|
||||
|
||||
return new AjaxCallResult() {Success = true};
|
||||
return new AjaxCallResult {Success = true};
|
||||
}
|
||||
|
||||
|
||||
[WebMethod]
|
||||
public static AjaxCallResult TerminatePositionAssignment (int assignmentId)
|
||||
{
|
||||
AuthenticationData authData = GetAuthenticationDataAndCulture();
|
||||
|
||||
PositionAssignment assignment = PositionAssignment.FromIdentity (assignmentId);
|
||||
|
||||
if (assignment.OrganizationId == 0)
|
||||
{
|
||||
if (!authData.CurrentUser.HasAccess (new Access (AccessAspect.Administration))) // System-wide admin
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
}
|
||||
else // Org-specific assignment
|
||||
{
|
||||
if (assignment.GeographyId == 0)
|
||||
{
|
||||
if (!authData.CurrentUser.HasAccess (new Access(authData.CurrentOrganization, AccessAspect.Administration)))
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
}
|
||||
else // Org- and geo-specific assignment
|
||||
{
|
||||
if (
|
||||
!authData.CurrentUser.HasAccess (new Access (authData.CurrentOrganization,
|
||||
assignment.Position.Geography, AccessAspect.Administration)))
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ok, go ahead and terminate
|
||||
|
||||
try
|
||||
{
|
||||
assignment.Terminate(authData.CurrentUser, authData.CurrentUser.GetPrimaryPosition(authData.CurrentOrganization), string.Empty);
|
||||
}
|
||||
catch (DatabaseConcurrencyException)
|
||||
{
|
||||
return new AjaxCallResult {Success = false, DisplayMessage = Resources.Global.Error_DatabaseConcurrency};
|
||||
}
|
||||
|
||||
return new AjaxCallResult {Success = true};
|
||||
}
|
||||
|
||||
public class AvatarData : AjaxCallResult
|
||||
|
||||
@@ -2,7 +2,16 @@
|
||||
<%@ Register TagPrefix="Swarmops5Workaround" TagName="ComboPeople" src="~/Controls/v5/Swarm/ComboPeople.ascx" %>
|
||||
|
||||
<script language="javascript" type="text/javascript">
|
||||
function preload(arrayOfImages) {
|
||||
$(arrayOfImages).each(function () {
|
||||
(new Image()).src = this;
|
||||
});
|
||||
}
|
||||
|
||||
preload([
|
||||
'/Images/Abstract/ajaxloader-medium.gif',
|
||||
'/Images/Icons/iconshock-balloon-no-128x96px-hot.png'
|
||||
]);
|
||||
$(document).ready(function() {
|
||||
|
||||
$('#<%=this.ClientID%>_tablePositions').treegrid(
|
||||
@@ -24,9 +33,59 @@
|
||||
<%= this.DialogAdd.ClientID %>_open();
|
||||
<%= this.DropPerson.ClientID%>_focus();
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: RowStyler
|
||||
$('.LocalIconTerminate.LocalPosition<%=this.Cookie%>').css("cursor", "pointer").attr("src", "/Images/Icons/iconshock-balloon-no-128x96px.png");
|
||||
|
||||
$('.LocalIconTerminate.LocalPosition<%=this.Cookie%>').mouseover(function() {
|
||||
if ($(this).attr("rel") != "loading") {
|
||||
$(this).attr("src", "/Images/Icons/iconshock-balloon-no-128x96px-hot.png");
|
||||
}
|
||||
});
|
||||
|
||||
$('.LocalIconTerminate.LocalPosition<%=this.Cookie%>').mouseout(function () {
|
||||
if ($(this).attr("rel") != "loading") {
|
||||
$(this).attr("src", "/Images/Icons/iconshock-balloon-no-128x96px.png");
|
||||
}
|
||||
});
|
||||
|
||||
$('.LocalIconTerminate.LocalPosition<%=this.Cookie%>').click(function () {
|
||||
if ($(this).attr("rel") != "loading") {
|
||||
$(this).attr("rel", "loading");
|
||||
|
||||
var okLabel = decodeURIComponent('<asp:Literal ID="LiteralTerminateYes" runat="server" />');
|
||||
var cancelLabel = decodeURIComponent('<asp:Literal ID="LiteralTerminateNo" runat="server" />');
|
||||
var confirmQuestion = decodeURIComponent('<asp:Literal ID="LiteralConfirmTermination" runat="server" />');
|
||||
|
||||
if ($(this).attr("self") == "true") {
|
||||
okLabel = decodeURIComponent('<asp:Literal ID="LiteralTerminateSelfYes" runat="server" />');
|
||||
cancelLabel = decodeURIComponent('<asp:Literal ID="LiteralTerminateSelfNo" runat="server" />');
|
||||
confirmQuestion = decodeURIComponent('<asp:Literal ID="LiteralConfirmSelfTermination" runat="server" />');
|
||||
}
|
||||
|
||||
alertify.set({
|
||||
labels: {
|
||||
ok: okLabel,
|
||||
cancel: cancelLabel
|
||||
},
|
||||
buttonFocus: 'cancel'
|
||||
});
|
||||
|
||||
alertify.confirm(confirmQuestion,
|
||||
$.proxy(function (response) {
|
||||
if (response) {
|
||||
// user clicked the GREEN button, which is "confirm termination"
|
||||
|
||||
onConfirmTermination($(this).attr("assignmentId"));
|
||||
}
|
||||
$(this).attr("rel", ""); // clear state
|
||||
}, this));
|
||||
|
||||
return; // Do not process here - must wait for confirm dialog to return
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
$('#<%=this.ClientID%>_buttonAssign').click(function() {
|
||||
@@ -60,6 +119,18 @@
|
||||
|
||||
});
|
||||
|
||||
function onConfirmTermination(assignmentId) {
|
||||
SwarmopsJS.ajaxCall("/Automation/SwarmFunctions.aspx/TerminatePositionAssignment",
|
||||
{ assignmentId: assignmentId },
|
||||
function(result) {
|
||||
if (result.success) {
|
||||
$('#<%=this.ClientID%>_tablePositions').treegrid('reload');
|
||||
} else {
|
||||
alertify.error(result.DisplayMessage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var currentPositionId = '';
|
||||
|
||||
</script>
|
||||
@@ -76,7 +147,7 @@
|
||||
<th field="assignedName" width="200"><asp:Literal ID="LiteralHeaderName" Text="AssignedName 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>
|
||||
<th field="actions" width="50" align="center"><asp:Literal ID="LiteralHeaderAction" Text="XYZ" runat="server" /></th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
@@ -43,6 +43,14 @@ namespace Swarmops.Frontend.Controls.v5.Swarm
|
||||
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.LiteralTerminateNo.Text = JavascriptEscape (Resources.Controls.Swarm.Positions_TerminateNo);
|
||||
this.LiteralTerminateYes.Text = JavascriptEscape (Resources.Controls.Swarm.Positions_TerminateYes);
|
||||
this.LiteralTerminateSelfNo.Text = JavascriptEscape (Resources.Controls.Swarm.Positions_TerminateSelfNo);
|
||||
this.LiteralTerminateSelfYes.Text = JavascriptEscape (Resources.Controls.Swarm.Positions_TerminateSelfYes);
|
||||
this.LiteralConfirmTermination.Text = JavascriptEscape (Resources.Controls.Swarm.Positions_ConfirmTerminate);
|
||||
this.LiteralConfirmSelfTermination.Text =
|
||||
JavascriptEscape (Resources.Controls.Swarm.Positions_ConfirmSelfTerminate);
|
||||
|
||||
this.DropDuration.SelectedValue = "12";
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user