Skip to content
Permalink
Browse files

createupdateaccount.vue loads the correct account when navigating dir…

…ectly between accounts
  • Loading branch information...
matthiaswh committed Mar 25, 2017
1 parent b815eec commit ae0900071073c3b8a858b04f8c30fbf67e826e87
Showing with 29 additions and 12 deletions.
  1. +27 −11 src/app/accounts/components/CreateUpdateAccount.vue
  2. +2 −1 src/app/accounts/routes.js
@@ -60,25 +60,19 @@ import { CATEGORIES } from '../../../consts';
export default { export default {
name: 'accounts-create-edit-view', name: 'accounts-create-edit-view',
props: ['accountId'],
data: () => { data: () => {
return { return {
categories: CATEGORIES, categories: CATEGORIES,
selectedAccount: {}, editing: false,
editing: false selectedAccount: {}
}; };
}, },
mounted () { mounted () {
if ('accountId' in this.$route.params) { if (this.accountId) {
this.loadAccounts().then(() => { this.loadAccount();
let selectedAccount = this.getAccountById(this.$route.params.accountId);
if (selectedAccount) {
this.editing = true;
this.selectedAccount = Object.assign({}, selectedAccount);
}
// TODO: the object does not exist, how do we handle this scenario?
});
} }
}, },
@@ -108,13 +102,35 @@ export default {
processSave () { processSave () {
this.editing ? this.saveAccount() : this.saveNewAccount(); this.editing ? this.saveAccount() : this.saveNewAccount();
},
loadAccount () {
let vm = this;
this.loadAccounts().then(() => {
let selectedAccount = vm.getAccountById(vm.accountId);
if (selectedAccount) {
vm.editing = true;
vm.selectedAccount = Object.assign({}, selectedAccount);
}
// TODO: the object does not exist, how do we handle this scenario?
});
} }
}, },
computed: { computed: {
...mapGetters([ ...mapGetters([
'getAccountById' 'getAccountById'
]) ])
},
watch: {
accountId (newId) {
if (newId) {
this.loadAccount();
}
this.editing = false;
this.selectedAccount = {};
}
} }
}; };
</script> </script>
@@ -14,6 +14,7 @@ export default [
{ {
path: '/accounts/:accountId/update', path: '/accounts/:accountId/update',
component: components.CreateUpdateAccount, component: components.CreateUpdateAccount,
name: 'updateAccount' name: 'updateAccount',
props: true
} }
]; ];

0 comments on commit ae09000

Please sign in to comment.
You can’t perform that action at this time.