Assigning / removing works everywhere in Positions

This commit is contained in:
Rick Falkvinge
2015-05-02 01:33:35 +02:00
parent bdc99b8736
commit a190e36fe8
6 changed files with 73 additions and 7 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ namespace Swarmops.Logic.Swarm
{
int geographyId = 0;
if (position.PositionLevel == PositionLevel.Geography)
if (position.PositionLevel == PositionLevel.Geography || position.PositionLevel == PositionLevel.GeographyDefault)
{
geographyId = geography.Identity;
}
+27
View File
@@ -4,7 +4,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Swarmops.Basic.Types.Swarm;
using Swarmops.Common.Enums;
using Swarmops.Database;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Support;
namespace Swarmops.Logic.Swarm
@@ -13,6 +15,31 @@ namespace Swarmops.Logic.Swarm
{
public static PositionAssignments ForPosition (Position position, bool includeTerminated = false)
{
if (position.PositionLevel == PositionLevel.GeographyDefault ||
position.PositionLevel == PositionLevel.Geography)
{
// a bit complex; we need to ask the database directly for these geographies
if (!includeTerminated)
{
return
FromArray (
SwarmDb.GetDatabaseForReading()
.GetPositionAssignments (position, position.Geography,
DatabaseCondition.ActiveTrue));
}
// otherwise, if asking for all assignments (even clsoed), remove "DatabaseCondition.ActiveTrue"
return
FromArray(
SwarmDb.GetDatabaseForReading()
.GetPositionAssignments(position, position.Geography));
}
// otherwise, global (geo-unbound) position
return ForPositions (Positions.FromSingle (position), includeTerminated);
}
@@ -155,7 +155,7 @@
<comment>Kind of "hire" but also for volunteers</comment>
</data>
<data name="Positions_ModalHeader" xml:space="preserve">
<value>Assign person as &lt;span id='{0}_modalPositionName'&gt;...&lt;/span&gt;</value>
<value>Assign person as &lt;span id='{0}_modalPositionName'&gt;...&lt;/span&gt; &lt;span id='{0}_modalGeographyName'&gt; &lt;/span&gt;</value>
<comment>Header for new assignment dialog</comment>
</data>
<data name="Positions_NoMorePeopleOnPosition" xml:space="preserve">
+10 -2
View File
@@ -86,6 +86,7 @@ namespace Swarmops.Frontend.Automation
{
throw new InvalidOperationException("Positions are not initialized or are missing.");
}
_displayAssignments = false; // Suppresses assignment lookup, which would fail for default positions
Response.Output.WriteLine(RecursePositionTree(positions.Tree.RootNodes)); // TODO: turn off assignability!
@@ -120,7 +121,7 @@ namespace Swarmops.Frontend.Automation
{
Position position = positionNode.Data;
string localizedPositionName = position.Localized (positionNode.Data.MaxCount != 1);
PositionAssignments assignments = position.Assignments;
PositionAssignments assignments = new PositionAssignments();
string nodeState = "open";
if (position.GeographyId != _geographyId)
@@ -131,7 +132,13 @@ namespace Swarmops.Frontend.Automation
string expires = string.Empty;
string action = string.Empty;
string assignedName = Resources.Controls.Swarm.Positions_Vacant;
string assignedName = string.Empty;
if (_displayAssignments)
{
assignments = position.Assignments;
assignedName = Resources.Controls.Swarm.Positions_Vacant;
}
if (_assignable)
{
@@ -252,6 +259,7 @@ namespace Swarmops.Frontend.Automation
private string _customCookieClass;
private bool _assignable = false; // TODO: Maybe make this more dynamic later
private bool _displayAssignments = true;
private int _geographyId;
+16
View File
@@ -6,6 +6,7 @@ using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using Swarmops.Common.Enums;
using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Swarm;
@@ -28,6 +29,12 @@ namespace Swarmops.Frontend.Automation
Person person = Person.FromIdentity (personId);
Geography geography = (geographyId == 0 ? null : Geography.FromIdentity (geographyId));
if (position.PositionLevel == PositionLevel.Geography ||
position.PositionLevel == PositionLevel.GeographyDefault)
{
position.AssignGeography (geography);
}
if ((position.OrganizationId > 0 && authData.CurrentOrganization.Identity != position.OrganizationId) || person.Identity < 0)
{
throw new UnauthorizedAccessException();
@@ -180,5 +187,14 @@ namespace Swarmops.Frontend.Automation
Avatar24Url = person.GetSecureAvatarLink (24)
};
}
[WebMethod]
public static AjaxCallResult GetGeographyName (int geographyId)
{
// This is not sensitive, so no access control, just culture setting
GetAuthenticationDataAndCulture();
return new AjaxCallResult {Success = true, DisplayMessage = Geography.FromIdentity (geographyId).Name};
}
}
}
+18 -3
View File
@@ -26,8 +26,21 @@
onLoadSuccess: function () {
$('.LocalAssignPerson.LocalPosition<%=this.Cookie%>').click(function () {
current<%=this.Cookie%>PositionId = $(this).attr("positionId");
current<%=this.ClientID%>PositionId = $(this).attr("positionId");
$('#<%= this.ClientID %>_modalPositionName').text(decodeURIComponent($(this).attr("positionName")));
$('#<%= this.ClientID %>_modalGeographyName').text('');
var thisGeographyId = $(this).attr("geographyId");
current<%=this.ClientID%>GeographyId = '0';
if (thisGeographyId != '0' && thisGeographyId != '1') {
current<%=this.ClientID%>GeographyId = thisGeographyId;
SwarmopsJS.ajaxCall("/Automation/SwarmFunctions.aspx/GetGeographyName",
{ geographyId: thisGeographyId },
function(result) {
if (result.Success) {
$('#<%= this.ClientID %>_modalGeographyName').text(result.DisplayMessage);
}
});
}
<%= this.DropPerson.ClientID%>_clear();
$('#<%= this.DropDuration.ClientID%>').val("12"); // reset to 12-month default
<%= this.DialogAdd.ClientID %>_open();
@@ -120,7 +133,7 @@
SwarmopsJS.ajaxCall(
"/Automation/SwarmFunctions.aspx/AssignPosition",
{ personId: personId, positionId: current<%=this.Cookie%>PositionId, durationMonths: $('#<%= this.DropDuration.ClientID%>').val(), geographyId: 0 },
{ personId: personId, positionId: current<%=this.ClientID%>PositionId, durationMonths: $('#<%= this.DropDuration.ClientID%>').val(), geographyId: current<%=this.ClientID%>GeographyId },
function (result) {
// Close modal and reload grid regardless of success or not
// (the only failure here should be a concurrency error, in which case
@@ -151,7 +164,9 @@
});
}
var current<%=this.Cookie%>PositionId = '';
var current<%=this.ClientID%>PositionId = '';
var current<%=this.ClientID%>GeographyId = '';
var displayed<%=this.ClientID%>GeographyId = '<%=this.GeographyId%>';
</script>