This commit is contained in:
James Cole
2019-09-06 16:29:52 +02:00
parent 377f31b910
commit a6164456e6
6 changed files with 68 additions and 47 deletions

View File

@@ -86,6 +86,7 @@
title="Source account"
:accountName="transaction.source_account.name"
:accountTypeFilters="transaction.source_account.allowed_types"
:defaultAccountTypeFilters="transaction.source_account.default_allowed_types"
:transactionType="transactionType"
:index="index"
v-on:clear:value="clearSource(index)"
@@ -97,6 +98,7 @@
title="Destination account"
:accountName="transaction.destination_account.name"
:accountTypeFilters="transaction.destination_account.allowed_types"
:defaultAccountTypeFilters="transaction.destination_account.default_allowed_types"
:transactionType="transactionType"
:index="index"
v-on:clear:value="clearDestination(index)"
@@ -393,10 +395,10 @@
}
},
redirectUser(groupId, button) {
console.log('In redirectUser()');
//console.log('In redirectUser()');
// if count is 0, send user onwards.
if (this.createAnother) {
console.log('Will create another.');
//console.log('Will create another.');
// do message:
this.success_message = '<a href="transactions/show/' + groupId + '">Transaction #' + groupId + '</a> has been stored.';
@@ -414,13 +416,13 @@
button.prop("disabled", false);
}
} else {
console.log('Will redirect to previous URL. (' + previousUri + ')');
// console.log('Will redirect to previous URL. (' + previousUri + ')');
window.location.href = window.previousUri + '?transaction_group_id=' + groupId + '&message=created';
}
},
collectAttachmentData(response) {
console.log('Now incollectAttachmentData()');
// console.log('Now incollectAttachmentData()');
let groupId = response.data.data.id;
// array of all files to be uploaded:
@@ -449,7 +451,7 @@
}
}
let count = toBeUploaded.length;
console.log('Found ' + toBeUploaded.length + ' attachments.');
// console.log('Found ' + toBeUploaded.length + ' attachments.');
// loop all uploads.
for (const key in toBeUploaded) {
@@ -483,7 +485,7 @@
let uploads = 0;
for (const key in fileData) {
if (fileData.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
console.log('Creating attachment #' + key);
// console.log('Creating attachment #' + key);
// axios thing, + then.
const uri = './api/v1/attachments';
const data = {
@@ -493,19 +495,19 @@
};
axios.post(uri, data)
.then(response => {
console.log('Created attachment #' + key);
console.log('Uploading attachment #' + key);
// console.log('Created attachment #' + key);
// console.log('Uploading attachment #' + key);
const uploadUri = './api/v1/attachments/' + response.data.data.id + '/upload';
axios.post(uploadUri, fileData[key].content)
.then(response => {
console.log('Uploaded attachment #' + key);
// console.log('Uploaded attachment #' + key);
uploads++;
if (uploads === count) {
// finally we can redirect the user onwards.
console.log('FINAL UPLOAD');
// console.log('FINAL UPLOAD');
this.redirectUser(groupId);
}
console.log('Upload complete!');
// console.log('Upload complete!');
return true;
}).catch(error => {
console.error('Could not upload');
@@ -522,7 +524,7 @@
setDefaultErrors: function () {
for (const key in this.transactions) {
if (this.transactions.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
console.log('Set default errors for key ' + key);
// console.log('Set default errors for key ' + key);
//this.transactions[key].description
this.transactions[key].errors = {
source_account: [],
@@ -664,7 +666,8 @@
currency_name: '',
currency_code: '',
currency_decimal_places: 2,
allowed_types: ['Asset account','Revenue account','Loan','Debt','Mortgage']
allowed_types: ['Asset account','Revenue account','Loan','Debt','Mortgage'],
default_allowed_types: ['Asset account','Revenue account','Loan','Debt','Mortgage']
},
destination_account: {
id: 0,
@@ -674,7 +677,8 @@
currency_name: '',
currency_code: '',
currency_decimal_places: 2,
allowed_types: ['Asset account','Expense account','Loan','Debt','Mortgage']
allowed_types: ['Asset account','Expense account','Loan','Debt','Mortgage'],
default_allowed_types: ['Asset account','Expense account','Loan','Debt','Mortgage']
}
});
if (this.transactions.length === 1) {
@@ -732,7 +736,8 @@
currency_name: model.currency_name,
currency_code: model.currency_code,
currency_decimal_places: model.currency_decimal_places,
allowed_types: this.transactions[index].source_account.allowed_types
allowed_types: this.transactions[index].source_account.allowed_types,
default_allowed_types: ['Asset account','Revenue account','Loan','Debt','Mortgage']
};
// force types on destination selector.
@@ -752,7 +757,8 @@
currency_name: model.currency_name,
currency_code: model.currency_code,
currency_decimal_places: model.currency_decimal_places,
allowed_types: this.transactions[index].destination_account.allowed_types
allowed_types: this.transactions[index].destination_account.allowed_types,
default_allowed_types: ['Asset account','Expense account','Loan','Debt','Mortgage']
};
// force types on destination selector.
@@ -760,7 +766,7 @@
}
},
clearSource: function (index) {
console.log('clearSource(' + index + ')');
// console.log('clearSource(' + index + ')');
// reset source account:
this.transactions[index].source_account = {
id: 0,
@@ -770,7 +776,8 @@
currency_name: '',
currency_code: '',
currency_decimal_places: 2,
allowed_types: this.transactions[index].source_account.allowed_types
allowed_types: this.transactions[index].source_account.allowed_types,
default_allowed_types: ['Asset account','Revenue account','Loan','Debt','Mortgage']
};
// reset destination allowed account types.
this.transactions[index].destination_account.allowed_types = [];
@@ -782,7 +789,7 @@
}
},
clearDestination: function (index) {
console.log('clearDestination(' + index + ')');
// console.log('clearDestination(' + index + ')');
// reset destination account:
this.transactions[index].destination_account = {
id: 0,
@@ -792,7 +799,8 @@
currency_name: '',
currency_code: '',
currency_decimal_places: 2,
allowed_types: this.transactions[index].destination_account.allowed_types
allowed_types: this.transactions[index].destination_account.allowed_types,
default_allowed_types: ['Asset account','Expense account','Loan','Debt','Mortgage']
};
// reset destination allowed account types.
this.transactions[index].source_account.allowed_types = [];