Build v2 with some fixes for #4735

This commit is contained in:
James Cole
2021-05-08 18:23:50 +02:00
parent 9eaacf30ad
commit d0edae76f2
6 changed files with 37 additions and 17 deletions

View File

@@ -223,6 +223,9 @@ export default {
enableSubmit: true,
stayHere: false,
// force the submission (in case of deletes)
forceTransactionSubmission: false
}
},
components: {
@@ -275,7 +278,7 @@ export default {
for (let i in transactions) {
if (transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
console.log('Parsing transaction nr ' + i);
// console.log('Parsing transaction nr ' + i);
let result = this.parseTransaction(parseInt(i), transactions[i]);
this.transactions.push(result);
this.originalTransactions.push(lodashClonedeep(result));
@@ -489,9 +492,10 @@ export default {
let index = 0;
for (let i in this.transactions) {
if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
console.log('Now at index: ' + i);
// console.log('Now at index: ' + i);
if (index === payload.index) {
console.log('Delete!');
this.forceTransactionSubmission = true;
//console.log('Delete!');
this.transactions.splice(index, 1);
//console.log(delete this.transactions[i]);
}
@@ -499,7 +503,7 @@ export default {
}
}
$('#transactionTabs li:first-child a').tab('show');
// console.log(this.transactions);
// this.transactions.splice(payload.index, 1);
// console.log('length: ' + this.transactions.length);
@@ -530,6 +534,7 @@ export default {
this.transactions.push(newTransaction);
},
submitTransaction: function (event) {
// console.log('submitTransaction()');
event.preventDefault();
this.enableSubmit = false;
let submission = {transactions: []};
@@ -553,9 +558,11 @@ export default {
}
// loop each transaction (edited by the user):
// console.log('Start of loop submitTransaction');
for (let i in this.transactions) {
// console.log('Index ' + i);
if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
// console.log('Has index ' + i);
// original transaction present:
let currentTransaction = this.transactions[i];
let originalTransaction = this.originalTransactions.hasOwnProperty(i) ? this.originalTransactions[i] : {};
@@ -585,19 +592,28 @@ export default {
for (let ii in basicFields) {
if (basicFields.hasOwnProperty(ii) && /^0$|^[1-9]\d*$/.test(ii) && ii <= 4294967294) {
let fieldName = basicFields[ii];
// console.log('Now at field ' + fieldName);
let submissionFieldName = fieldName;
// if the original is undefined and the new one is null, just skip it.
if (currentTransaction[fieldName] === null && 'undefined' === typeof originalTransaction[fieldName]) {
// console.log('Will continue and skip');
continue;
}
if (currentTransaction[fieldName] !== originalTransaction[fieldName]) {
if (currentTransaction[fieldName] !== originalTransaction[fieldName] || true === this.forceTransactionSubmission) {
// console.log('we continue');
// some fields are ignored:
if ('foreign_amount' === submissionFieldName && '' === currentTransaction[fieldName]) {
// console.log('we skip!');
continue;
}
if ('foreign_currency_id' === submissionFieldName && 0 === currentTransaction[fieldName]) {
if ('foreign_currency_id' === submissionFieldName && 0 === currentTransaction[fieldName] ) {
// console.log('we skip!');
continue;
}
if ('foreign_currency_id' === submissionFieldName && '0' === currentTransaction[fieldName] ) {
// console.log('we skip!');
continue;
}
@@ -618,6 +634,7 @@ export default {
// otherwise save them and remember them for submission:
diff[submissionFieldName] = currentTransaction[fieldName];
shouldSubmit = true;
//console.log('Should submit is now TRUE');
}
}
}
@@ -671,15 +688,18 @@ export default {
submission.transactions.push(lodashClonedeep(diff));
shouldSubmit = true;
}
// console.log('Should submit index ' + i + '?');
// console.log(shouldSubmit);
}
}
this.submitUpdate(submission, shouldSubmit, shouldLinks, shouldUpload);
},
submitData: function (shouldSubmit, submission) {
//console.log('submitData');
// console.log('submitData');
// console.log(submission);
if (!shouldSubmit) {
//console.log('No need!');
// console.log('No need to submit transaction.');
return new Promise((resolve) => {
resolve({});
});
@@ -732,9 +752,9 @@ export default {
return this.deleteAllOriginalLinks().then(() => this.submitNewLinks());
},
submitAttachments: function (shouldSubmit, response) {
console.log('submitAttachments');
// console.log('submitAttachments');
if (!shouldSubmit) {
console.log('no need!');
// console.log('no need!');
this.submittedAttachments = 1;
return new Promise((resolve) => {
resolve({});
@@ -802,7 +822,7 @@ export default {
}
},
submitUpdate: function (submission, shouldSubmit, shouldLinks, shouldUpload) {
//console.log('submitUpdate()');
// console.log('submitUpdate()');
this.inError = false;
this.submitData(shouldSubmit, submission)