Work on Expensify; Delete might work

This commit is contained in:
Rick Falkvinge
2018-03-03 16:37:54 +01:00
parent b79d9cc235
commit 96a8f300ca
2 changed files with 155 additions and 50 deletions
+54 -21
View File
@@ -17,7 +17,33 @@
$(document).ready(function () {
$('#divTabs').tabs();
$('#buttonModalProceed').click(function() {
});
$('#buttonModalDelete').click(function () {
<%=this.DialogEditExpenseClaim.ClientID%>_close();
SwarmopsJS.ajaxCall(
'/Pages/v5/Financial/FileExpenseClaim.aspx/ExpensifyRecordDelete',
{ masterGuid: '<%=this.UploadExpensify.GuidString%>', recordGuid: currentlyEditedRecordGuid },
function(result) {
if (result.Success) {
// A record has been deleted. It is possible that a new one is displayed.
$('#expensifyDataGrid').datagrid('loadData', result.DataUpdate);
if (result.Guid.length > 1) // there's a new record
{
currentlyEditedRecordGuid = result.Guid;
displayExpensifyRecord(result);
}
}
});
});
});
@@ -95,30 +121,37 @@
},
function(result) {
if (result.Success) {
<%=this.CurrencyModalExpensifyAmount.ClientID%>_initialize(result.Amount);
<%=this.CurrencyModalExpensifyAmountVat.ClientID%>_initialize(result.AmountVat);
$('#textModalExpensifyDescription').val(result.Description);
<%=this.DialogEditExpenseClaim.ClientID%>_open();
$('#imgModalDocument').attr('src', '/Pages/v5/Support/StreamUpload.aspx?DocId=' + result.DocumentId);
$('#imgModalDocument').attr('data-zoom-image', '/Pages/v5/Support/StreamUpload.aspx?DocId=' + result.DocumentId + '&hq=1');
$('.zoomContainer').remove();
$('#imgModalDocument').removeData('elevateZoom');
$('#imgModalDocument').removeData('zoomImage');
setTimeout(function () {
$('#imgModalDocument').elevateZoom({
zoomType: "lens",
cursor: "crosshair",
zoomWindowFadeIn: 200,
zoomWindowFadeOut: 200,
lensShape: "round",
lensSize: 150
});
}, 50); // delay this slightly for race condition reasons
currentlyEditedRecordGuid = result.Guid;
displayExpensifyRecord(result);
}
});
}
function displayExpensifyRecord(record) {
<%=this.CurrencyModalExpensifyAmount.ClientID%>_initialize(record.Amount);
<%=this.CurrencyModalExpensifyAmountVat.ClientID%>_initialize(record.AmountVat);
$('#textModalExpensifyDescription').val(record.Description);
<%=this.DialogEditExpenseClaim.ClientID%>_open();
$('#imgModalDocument').attr('src', '/Pages/v5/Support/StreamUpload.aspx?DocId=' + record.DocumentId);
$('#imgModalDocument').attr('data-zoom-image', '/Pages/v5/Support/StreamUpload.aspx?DocId=' + record.DocumentId + '&hq=1');
$('.zoomContainer').remove();
$('#imgModalDocument').removeData('elevateZoom');
$('#imgModalDocument').removeData('zoomImage');
setTimeout(function () {
$('#imgModalDocument').elevateZoom({
zoomType: "lens",
cursor: "crosshair",
zoomWindowFadeIn: 200,
zoomWindowFadeOut: 200,
lensShape: "round",
lensSize: 150
});
}, 50); // delay this slightly for race condition reasons
}
var expensifyProcessingHalfway = false;
var currentlyEditedRecordGuid = '';
function onExpensifyUpload() {
$('#divExpensifyUploadFile').slideUp();
@@ -348,7 +381,7 @@
<Swarmops5:ComboBudgets ID="DropBudgets" ListType="Expensable" runat="server"/>
<Swarmops5:Currency ID="CurrencyModalExpensifyAmount" runat="server"/>
<div class="ifVatEnabled"><Swarmops5:Currency ID="CurrencyModalExpensifyAmountVat" runat="server"/></div>
<input type="button" class="buttonAccentColor HalfWidth NoInputFocus" value="Proceed &gt;&gt;"/><input type="button" class="buttonAccentColor Red HalfWidth NoInputFocus" value="Delete"/>
<input type="button" id="buttonModalProceed" class="buttonAccentColor HalfWidth NoInputFocus" value="Proceed &gt;&gt;"/><input type="button" id="buttonModalDelete" class="buttonAccentColor Red HalfWidth NoInputFocus" value="Delete"/>
</div>
<div class="entryLabels">Description<br/>Budget charged<br />Expense amount<br/><div class="ifVatEnabled">VAT amount of the total</div></div>
</DialogCode>
+101 -29
View File
@@ -5,6 +5,7 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Principal;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web;
@@ -514,12 +515,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial
List<ExpensifyOutputRecord> outputRecords = new List<ExpensifyOutputRecord>();
string doxString =
"<img src='/Images/Icons/iconshock-search-256px.png' onmouseover=\"this.src='/Images/Icons/iconshock-search-hot-256px.png';\" onmouseout=\"this.src='/Images/Icons/iconshock-search-256px.png';\" firstDocId='{0}' class='LocalIconViewDoc' style='cursor:pointer' height='20' width='20' />";
string editString =
"<img src='/Images/Icons/iconshock-wrench-128x96px-centered.png' height='18' width='24' class='LocalEditExpenseClaim' data-guid='{0}' />";
string docString =
"<a href='/Pages/v5/Support/StreamUpload.aspx?DocId={0}&hq=1' data-caption=\"{1}\" class='FancyBox_Gallery' data-fancybox='{2}'>";
@@ -527,17 +522,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial
foreach (ExpensifyRecord record in recordList)
{
outputRecords.Add(new ExpensifyOutputRecord
{
Budget = "<span class='LocalEditExpenseClaim' data-guid='" + record.Guid + "'>" + Resources.Global.Global_DropInits_SelectFinancialAccount + "</span>",
Description = record.CategoryCustom + " / " + record.Description,
CreatedDateTime = record.Timestamp.ToString("MMM dd"),
Amount = (record.AmountCents / 100.0).ToString("N2"),
AmountVat = (record.VatCents / 100.0).ToString("N2"),
Actions = String.Format(doxString, "D" + record.Documents[0].Identity.ToString(CultureInfo.InvariantCulture)) + String.Format(editString, record.Guid),
Guid = record.Guid
});
foreach (Document document in record.Documents)
{
documentsAll += String.Format(docString, document.Identity,
@@ -549,7 +533,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
AjaxCallExpensifyUploadResult result = new AjaxCallExpensifyUploadResult
{
Success = true,
Data = outputRecords.ToArray(),
Data = FormatExpensifyOutputRecords(recordList),
Documents = documentsAll
};
@@ -560,6 +544,85 @@ namespace Swarmops.Frontend.Pages.v5.Financial
}
private static ExpensifyOutputRecord[] FormatExpensifyOutputRecords(List<ExpensifyRecord> recordList)
{
List<ExpensifyOutputRecord> outputRecords = new List<ExpensifyOutputRecord>();
const string doxString =
"<img src='/Images/Icons/iconshock-search-256px.png' onmouseover=\"this.src='/Images/Icons/iconshock-search-hot-256px.png';\" onmouseout=\"this.src='/Images/Icons/iconshock-search-256px.png';\" firstDocId='{0}' class='LocalIconViewDoc' style='cursor:pointer' height='20' width='20' />";
const string editString =
"<img src='/Images/Icons/iconshock-wrench-128x96px-centered.png' height='18' width='24' class='LocalEditExpenseClaim' data-guid='{0}' />";
foreach (ExpensifyRecord record in recordList)
{
outputRecords.Add(new ExpensifyOutputRecord
{
Budget =
"<span class='LocalEditExpenseClaim' data-guid='" + record.Guid + "'>" +
Resources.Global.Global_DropInits_SelectFinancialAccount + "</span>",
Description = record.CategoryCustom + " / " + record.Description,
CreatedDateTime = record.Timestamp.ToString("MMM dd"),
Amount = (record.AmountCents/100.0).ToString("N2"),
AmountVat = (record.VatCents/100.0).ToString("N2"),
Actions =
String.Format(doxString,
"D" + record.Documents[0].Identity.ToString(CultureInfo.InvariantCulture)) +
String.Format(editString, record.Guid),
Guid = record.Guid
});
}
return outputRecords.ToArray();
}
[WebMethod]
public static AjaxCallExpensifyRecordResult ExpensifyRecordProceed(string masterGuid, string recordGuid,
int amountCents, int amountVat, int budgetId, string description)
{
List<ExpensifyRecord> recordList = (List<ExpensifyRecord>)GuidCache.Get("ExpensifyData-" + masterGuid);
throw new NotImplementedException();
}
public static AjaxCallExpensifyRecordResult ExpensifyRecordDelete(string masterGuid, string recordGuid)
{
List<ExpensifyRecord> recordList = (List<ExpensifyRecord>)GuidCache.Get("ExpensifyData-" + masterGuid);
int index = LocateRecordsetIndex(recordList, recordGuid);
recordList.RemoveAt(index);
GuidCache.Set("ExpensifyData-" + masterGuid, recordList);
if (index >= recordList.Count)
{
// We deleted the last record, so return a null record
return new AjaxCallExpensifyRecordResult
{
Guid = "", // indicates null record
DataUpdate = FormatExpensifyOutputRecords(recordList)
// TODO: CanCommit
};
}
// Display the record next in line
return new AjaxCallExpensifyRecordResult
{
Amount = (recordList[index].AmountCents / 100.0).ToString("N2"),
AmountVat = (recordList[index].VatCents / 100.0).ToString("N2"),
Description = recordList[index].Description,
DocumentId = recordList[index].Documents.First().Identity,
Guid = recordList[index].Guid,
ExistNext = (index < recordList.Count - 1 ? true : false),
Success = true,
DataUpdate = FormatExpensifyOutputRecords(recordList)
};
}
[WebMethod]
public static AjaxCallExpensifyUploadResult GetExpensifyUploadResult(string guid)
{
@@ -573,7 +636,22 @@ namespace Swarmops.Frontend.Pages.v5.Financial
public static AjaxCallExpensifyRecordResult GetExpensifyRecord(string masterGuid, string recordGuid)
{
List<ExpensifyRecord> recordList = (List<ExpensifyRecord>) GuidCache.Get("ExpensifyData-" + masterGuid);
int index = LocateRecordsetIndex(recordList, recordGuid);
return new AjaxCallExpensifyRecordResult
{
Amount = (recordList[index].AmountCents / 100.0).ToString("N2"),
AmountVat = (recordList[index].VatCents / 100.0).ToString("N2"),
Description = recordList[index].Description,
DocumentId = recordList[index].Documents.First().Identity,
Guid = recordGuid,
ExistNext = (index < recordList.Count - 1? true: false),
Success = true
};
}
private static int LocateRecordsetIndex(List<ExpensifyRecord> recordList, string recordGuid)
{
// Linear search for the GUID -- a report should have more than a couple dozen records at most
// so this is not a real need for optimization
@@ -587,19 +665,10 @@ namespace Swarmops.Frontend.Pages.v5.Financial
{
// not found
return new AjaxCallExpensifyRecordResult {Success = false};
throw new ArgumentException("Could not locate record GUID");
}
return new AjaxCallExpensifyRecordResult
{
Amount = (recordList[index].AmountCents / 100.0).ToString("N2"),
AmountVat = (recordList[index].VatCents / 100.0).ToString("N2"),
Description = recordList[index].Description,
DocumentId = recordList[index].Documents.First().Identity,
Guid = recordGuid,
ExistNext = (index < recordList.Count - 1? true: false),
Success = true
};
return index;
}
@@ -807,6 +876,9 @@ namespace Swarmops.Frontend.Pages.v5.Financial
public int DocumentId { get; set; }
public string Guid { get; set; }
public bool ExistNext { get; set; }
public ExpensifyOutputRecord[] DataUpdate { get; set; }
public bool CanCommit { get; set; }
}
}