@@ -89,8 +160,8 @@
-
-
+
+
@@ -110,12 +181,14 @@ export default {
return {
account: {
category: '1',
- type: '1',
+ type: self.$constants.account.allAccountTypes.SingleAccount.toString(),
name: '',
- icon: "1",
+ icon: self.$constants.icons.defaultAccountIconId,
currency: self.$user.getUserInfo() ? self.$user.getUserInfo().defaultCurrency : self.$t('default.currency'),
comment: ''
},
+ subAccounts: [],
+ accountChoosingIcon: null,
submitting: false,
showIconSelection: false
};
@@ -154,36 +227,54 @@ export default {
},
allCurrencies() {
return this.$getAllCurrencies();
- },
- inputIsEmpty() {
- return !!this.inputEmptyProblemMessage;
- },
- inputIsInvalid() {
- return !!this.inputInvalidProblemMessage;
- },
- inputEmptyProblemMessage() {
- if (!this.account.category) {
- return 'Account category cannot be empty';
- } else if (!this.account.type) {
- return 'Account type cannot be empty';
- } else if (!this.account.name) {
- return 'Account name cannot be empty';
- } else if (!this.account.currency) {
- return 'Account currency cannot be empty';
- } else {
- return null;
- }
- },
- inputInvalidProblemMessage() {
- return null;
}
},
methods: {
+ addSubAccount() {
+ const self = this;
+
+ if (self.account.type !== self.$constants.account.allAccountTypes.MultiSubAccounts.toString()) {
+ return;
+ }
+
+ this.subAccounts.push({
+ category: null,
+ type: null,
+ name: '',
+ icon: this.account.icon,
+ currency: self.$user.getUserInfo() ? self.$user.getUserInfo().defaultCurrency : self.$t('default.currency'),
+ comment: ''
+ });
+ },
+ removeSubAccount(subAccount) {
+ for (let i = 0; i < this.subAccounts.length; i++) {
+ if (this.subAccounts[i] === subAccount) {
+ this.subAccounts.splice(i, 1);
+ }
+ }
+ },
+ showIconSelectionSheet(account) {
+ this.accountChoosingIcon = account;
+ this.showIconSelection = true
+ },
+ setSelectedIcon(accountIcon) {
+ if (!this.accountChoosingIcon) {
+ return;
+ }
+
+ this.accountChoosingIcon.icon = accountIcon.id;
+ this.accountChoosingIcon = null;
+ this.showIconSelection = false;
+ },
+ hideIconSelectionSheet() {
+ this.accountChoosingIcon = null;
+ this.showIconSelection = false;
+ },
add() {
const self = this;
const router = self.$f7router;
- let problemMessage = self.inputEmptyProblemMessage || self.inputInvalidProblemMessage;
+ let problemMessage = self.inputEmptyProblemMessage;
if (problemMessage) {
self.$alert(problemMessage);
@@ -193,13 +284,31 @@ export default {
self.submitting = true;
self.$showLoading(() => self.submitting);
+ const subAccounts = [];
+
+ if (self.account.type === self.$constants.account.allAccountTypes.MultiSubAccounts.toString()) {
+ for (let i = 0; i < self.subAccounts.length; i++) {
+ const subAccount = self.subAccounts[i];
+
+ subAccounts.push({
+ category: parseInt(self.account.category),
+ type: self.$constants.account.allAccountTypes.SingleAccount,
+ name: subAccount.name,
+ icon: subAccount.icon,
+ currency: subAccount.currency,
+ comment: subAccount.comment
+ });
+ }
+ }
+
self.$services.addAccount({
category: parseInt(self.account.category),
type: parseInt(self.account.type),
name: self.account.name,
icon: self.account.icon,
- currency: self.account.currency,
- comment: self.account.comment
+ currency: self.account.type === self.$constants.account.allAccountTypes.SingleAccount.toString() ? self.account.currency : self.$constants.currency.parentAccountCurrencyPlacehodler,
+ comment: self.account.comment,
+ subAccounts: self.account.type === self.$constants.account.allAccountTypes.SingleAccount.toString() ? null : subAccounts,
}).then(response => {
self.submitting = false;
self.$hideLoading();
@@ -241,6 +350,38 @@ export default {
this.account.icon = allCategories[i].defaultAccountIconId;
}
}
+ },
+ isInputEmpty() {
+ const isAccountEmpty = !!this.getInputEmptyProblemMessage(this.account, false);
+
+ if (isAccountEmpty) {
+ return true;
+ }
+
+ if (this.account.type === this.$constants.account.allAccountTypes.MultiSubAccounts.toString()) {
+ for (let i = 0; i < this.subAccounts.length; i++) {
+ const isSubAccountEmpty = !!this.getInputEmptyProblemMessage(this.subAccounts[i], true);
+
+ if (isSubAccountEmpty) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ },
+ getInputEmptyProblemMessage(account, isSubAccount) {
+ if (!isSubAccount && !account.category) {
+ return 'Account category cannot be empty';
+ } else if (!isSubAccount && !account.type) {
+ return 'Account type cannot be empty';
+ } else if (!account.name) {
+ return 'Account name cannot be empty';
+ } else if (account.type === this.$constants.account.allAccountTypes.SingleAccount.toString() && !account.currency) {
+ return 'Account currency cannot be empty';
+ } else {
+ return null;
+ }
}
}
}