Account Plan: Changing owner works

This commit is contained in:
Rick Falkvinge
2014-09-14 10:33:17 +02:00
parent 021e1066fb
commit 301da96038
4 changed files with 64 additions and 11 deletions
+13 -5
View File
@@ -5,15 +5,16 @@
$('#<%=this.ClientID %>_DropPeople').combobox({
animate: true,
height: 30,
loader: autoCompleteLoader,
loader: <%=this.ClientID %>_autoCompleteLoader,
mode: 'remote',
valueField: 'id',
textField: 'name',
formatter: formatItem,
formatter: <%=this.ClientID %>_formatItem,
onSelect: function (person) {
// update avatar when person selected
$.ajax({
url: '/Automation/Json-GetPersonAvatar.aspx',
dataType: 'json',
@@ -28,6 +29,13 @@
error.apply(this, arguments);
}
});
// call owner, if we have a callback
<% if (!String.IsNullOrEmpty(this.OnClientSelect)) {
Response.Write (this.OnClientSelect + "(person.id);");
} %>
}
});
@@ -58,7 +66,7 @@
});
});
var autoCompleteLoader = function(param,success,error){
var <%=this.ClientID %>_autoCompleteLoader = function(param,success,error){
var q = param.q || '';
if (q.length < 3) {
success (new Array());
@@ -81,7 +89,7 @@
return false;
};
function formatItem(row)
function <%=this.ClientID %>_formatItem(row)
{
var s = '<span style="padding-left:20px;margin-left:4px;' + "background-image:url('" + row.avatar16Url + "');" + 'background-position:left center;background-repeat:no-repeat">' + row.name + '</span>';
return s;
@@ -17,6 +17,8 @@ namespace Swarmops.Controls.Financial
public Person Selected { set; protected get; }
public string OnClientSelect { set; protected get; }
public bool NobodySelected { set; protected get; }
}
}
+27 -2
View File
@@ -179,7 +179,7 @@
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) { // TODO: This needs four return values - changed, broken and changed, invalid, or not changed. Also, formatted number
if (msg.d.Result == "Invalid" || msg.d.Result == "NoPermission") {
if (msg.d.Result == 3 || msg.d.Result == 4) { // Invalid or NoPermission
$('#TextAccountBudget').css('background-color', '#FFA0A0');
alertify.error("There was an error attempting to set your proposed budget."); // TODO: Localize
} else { // msg.d.Result should be Changed here
@@ -208,6 +208,29 @@
$('#divModalCover').fadeIn();
}
function onOwnerChange(personId) {
$('span#<%= DropOwner.ClientID %>_SpanPeople span input.combo-text').css('background-color', '#FFFFE0');
$.ajax({
type: "POST",
url: "AccountPlan.aspx/SetAccountOwner",
data: "{'accountId':'" + escape(accountId) + "','newOwnerId':'" + escape(personId) + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
if (msg.d) { // all went ok
$('span#<%= DropOwner.ClientID %>_SpanPeople span input.combo-text').css('background-color', '#E0FFE0');
accountDirty = true;
} else {
$('span#<%= DropOwner.ClientID %>_SpanPeople span input.combo-text').css('background-color', '#FFA0A0');
// TODO: Reset combo box
alertify.error("There was an error setting the budget owner."); // TODO: Localize
}
$('span#<%= DropOwner.ClientID %>_SpanPeople span input.combo-text').animate({ backgroundColor: "#FFFFFF" }, 250);
}
});
}
var currentYear = <%=DateTime.Today.Year %>;
var modalAccountName = "";
@@ -216,6 +239,8 @@
var accountType = '';
var accountDirty = false;
</script>
<style>
.IconEdit {
@@ -263,7 +288,7 @@
<div class="entryFields"><input type="text" id="TextAccountName" />&nbsp;<br />
<Swarmops5:ComboBudgets ID="DropParents" runat="server" />&nbsp;<br/>
&nbsp;<br/>
<div id="DivEditProfitLossControls"><Swarmops5:ComboPeople ID="DropOwner" runat="server" />&nbsp;<br/>
<div id="DivEditProfitLossControls"><Swarmops5:ComboPeople ID="DropOwner" OnClientSelect="onOwnerChange" runat="server" />&nbsp;<br/>
<input type="text" id="TextAccountBudget" style="text-align: right"/>&nbsp;<br/>
&nbsp;<br/>
<div class="checkboxSpacer"></div><input type="checkbox" class="EditCheck" id="CheckAccountActive"/>
+22 -4
View File
@@ -9,6 +9,7 @@ using System.Web.UI.WebControls;
using Swarmops.Basic.Enums;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
using Swarmops.Logic.Swarm;
namespace Swarmops.Frontend.Pages.v5.Ledgers
{
@@ -115,6 +116,23 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
return true;
}
[WebMethod]
public static bool SetAccountOwner(int accountId, int newOwnerId)
{
AuthenticationData authData = GetAuthenticationDataAndCulture();
FinancialAccount account = FinancialAccount.FromIdentity(accountId);
if (!PrepareAccountChange(account, authData, false))
{
return false;
}
// TODO: Verify that authdata.AuthenticatedPerson can see personId, or this can be exploited to enumerate all people
account.Owner = Person.FromIdentity(newOwnerId);
return true;
}
[WebMethod]
public static ChangeAccountDataResult SetAccountBudget(int accountId, string budget)
{
@@ -175,21 +193,21 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
/// <summary>
/// The account data was changed and nothing more.
/// </summary>
Changed,
Changed = 1,
/// <summary>
/// The account has transactions in closed ledgers, so the account was broken in two -
/// the closed ledgers were kept, and all open ledgers were moved into a new account
/// with the new data.
/// </summary>
ChangedBroken,
ChangedBroken = 2,
/// <summary>
/// The user doesn't have write permissions.
/// </summary>
NoPermission,
NoPermission = 3,
/// <summary>
/// The data submitted was invalid (for example an unparsable number for budget).
/// </summary>
Invalid
Invalid = 4
}
public struct JsonAccountData