2019-12-21 23:23:44 +01:00
|
|
|
<template>
|
2020-01-10 00:07:37 +01:00
|
|
|
<div class="section" v-if="twofaccountExists">
|
2020-01-06 17:00:56 +01:00
|
|
|
<div class="columns is-mobile is-centered">
|
|
|
|
<div class="column is-two-thirds-tablet is-half-desktop is-one-third-widescreen is-one-quarter-fullhd">
|
2020-01-12 19:55:17 +01:00
|
|
|
<h1 class="title">{{ $t('twofaccounts.forms.edit_account') }}</h1>
|
2020-01-06 17:00:56 +01:00
|
|
|
<form @submit.prevent="updateAccount">
|
|
|
|
<div class="field">
|
2020-01-12 19:55:17 +01:00
|
|
|
<label class="label">{{ $t('twofaccounts.service') }}</label>
|
2020-01-06 17:00:56 +01:00
|
|
|
<div class="control">
|
2020-01-12 19:55:17 +01:00
|
|
|
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.service.placeholder')" v-model="twofaccount.service" autofocus />
|
2020-01-02 00:09:19 +01:00
|
|
|
</div>
|
2020-01-14 12:23:31 +01:00
|
|
|
<p class="help is-danger" v-if="validationErrors.service">{{ validationErrors.service.toString() }}</p>
|
2020-01-02 00:09:19 +01:00
|
|
|
</div>
|
2020-01-06 17:00:56 +01:00
|
|
|
<div class="field">
|
2020-01-12 19:55:17 +01:00
|
|
|
<label class="label">{{ $t('twofaccounts.account') }}</label>
|
2020-01-06 17:00:56 +01:00
|
|
|
<div class="control">
|
2020-01-12 19:55:17 +01:00
|
|
|
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.account.placeholder')" v-model="twofaccount.account" />
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
2020-01-14 12:23:31 +01:00
|
|
|
<p class="help is-danger" v-if="validationErrors.account">{{ validationErrors.account.toString() }}</p>
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2020-01-12 19:55:17 +01:00
|
|
|
<label class="label">{{ $t('twofaccounts.icon') }}</label>
|
2020-01-06 17:00:56 +01:00
|
|
|
<div class="file is-dark">
|
|
|
|
<label class="file-label">
|
|
|
|
<input class="file-input" type="file" accept="image/*" v-on:change="uploadIcon" ref="iconInput">
|
|
|
|
<span class="file-cta">
|
|
|
|
<span class="file-icon">
|
|
|
|
<font-awesome-icon :icon="['fas', 'image']" />
|
|
|
|
</span>
|
2020-01-12 19:55:17 +01:00
|
|
|
<span class="file-label">{{ $t('twofaccounts.forms.choose_image') }}</span>
|
2020-01-06 17:00:56 +01:00
|
|
|
</span>
|
|
|
|
</label>
|
2020-01-08 23:22:51 +01:00
|
|
|
<span class="tag is-black is-large" v-if="tempIcon">
|
|
|
|
<img class="icon-preview" :src="'../storage/icons/' + tempIcon" >
|
2020-01-08 17:10:56 +01:00
|
|
|
<button class="delete is-small" @click.prevent="deleteIcon"></button>
|
2020-01-08 16:14:25 +01:00
|
|
|
</span>
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-01-14 12:23:31 +01:00
|
|
|
<p class="help is-danger help-for-file" v-if="validationErrors.icon">{{ validationErrors.icon.toString() }}</p>
|
2020-01-06 17:00:56 +01:00
|
|
|
<div class="field is-grouped">
|
|
|
|
<div class="control">
|
2020-01-12 19:55:17 +01:00
|
|
|
<button type="submit" class="button is-link">{{ $t('twofaccounts.forms.save') }}</button>
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
|
|
|
<div class="control">
|
2020-01-12 19:55:17 +01:00
|
|
|
<button class="button is-text" @click.prevent="cancelCreation">{{ $t('commons.cancel') }}</button>
|
2020-01-06 17:00:56 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
2019-12-21 23:23:44 +01:00
|
|
|
</div>
|
2020-01-02 00:09:19 +01:00
|
|
|
</div>
|
2019-12-21 23:23:44 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2020-01-08 16:14:25 +01:00
|
|
|
twofaccount: {
|
|
|
|
'service' : '',
|
|
|
|
'account' : '',
|
|
|
|
'uri' : '',
|
|
|
|
'icon' : ''
|
2020-01-08 23:22:51 +01:00
|
|
|
},
|
2020-01-10 00:07:37 +01:00
|
|
|
twofaccountExists: false,
|
2020-01-09 21:04:30 +01:00
|
|
|
tempIcon: '',
|
2020-01-14 12:23:31 +01:00
|
|
|
validationErrors: {}
|
2019-12-21 23:23:44 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-10 00:07:37 +01:00
|
|
|
created: function() {
|
2019-12-21 23:23:44 +01:00
|
|
|
this.getAccount();
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-01-16 22:21:05 +01:00
|
|
|
async getAccount () {
|
|
|
|
try {
|
|
|
|
const { data } = await axios.get('/api/twofaccounts/' + this.$route.params.twofaccountId)
|
|
|
|
|
|
|
|
this.twofaccount = data
|
2020-01-10 00:07:37 +01:00
|
|
|
this.twofaccountExists = true
|
2020-01-08 23:22:51 +01:00
|
|
|
|
|
|
|
// set account icon as temp icon
|
|
|
|
this.tempIcon = this.twofaccount.icon
|
2020-01-16 22:21:05 +01:00
|
|
|
}
|
|
|
|
catch (error) {
|
2020-01-17 00:23:38 +01:00
|
|
|
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
2020-01-16 22:21:05 +01:00
|
|
|
}
|
2019-12-21 23:23:44 +01:00
|
|
|
},
|
|
|
|
|
2020-01-16 22:21:05 +01:00
|
|
|
async updateAccount() {
|
2020-01-08 23:22:51 +01:00
|
|
|
|
|
|
|
// Set new icon and delete old one
|
|
|
|
if( this.tempIcon !== this.twofaccount.icon ) {
|
|
|
|
let oldIcon = ''
|
|
|
|
|
|
|
|
oldIcon = this.twofaccount.icon
|
|
|
|
|
|
|
|
this.twofaccount.icon = this.tempIcon
|
|
|
|
this.tempIcon = oldIcon
|
|
|
|
this.deleteIcon()
|
|
|
|
}
|
|
|
|
|
2020-01-16 22:21:05 +01:00
|
|
|
try {
|
|
|
|
await axios.put('/api/twofaccounts/' + this.$route.params.twofaccountId, this.twofaccount)
|
|
|
|
|
2020-01-07 15:46:48 +01:00
|
|
|
this.$router.push({name: 'accounts', params: { InitialEditMode: true }});
|
2020-01-16 22:21:05 +01:00
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
if( error.response.data.validation ) {
|
2020-01-14 12:23:31 +01:00
|
|
|
this.validationErrors = error.response.data.validation
|
|
|
|
}
|
|
|
|
else {
|
2020-01-17 00:23:38 +01:00
|
|
|
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
2020-01-14 12:23:31 +01:00
|
|
|
}
|
2020-01-16 22:21:05 +01:00
|
|
|
}
|
2019-12-21 23:23:44 +01:00
|
|
|
},
|
2020-01-05 23:21:28 +01:00
|
|
|
|
2020-01-08 23:22:51 +01:00
|
|
|
cancelCreation: function() {
|
|
|
|
// clean new temp icon
|
2020-01-16 22:21:05 +01:00
|
|
|
this.deleteIcon()
|
2020-01-08 23:22:51 +01:00
|
|
|
|
|
|
|
this.$router.push({name: 'accounts', params: { InitialEditMode: true }});
|
|
|
|
},
|
|
|
|
|
2020-01-16 22:21:05 +01:00
|
|
|
async uploadIcon(event) {
|
2020-01-05 23:21:28 +01:00
|
|
|
|
2020-01-08 23:22:51 +01:00
|
|
|
// clean possible tempIcon but keep original one
|
2020-01-16 22:21:05 +01:00
|
|
|
this.deleteIcon()
|
2020-01-05 23:21:28 +01:00
|
|
|
|
|
|
|
let imgdata = new FormData();
|
|
|
|
|
2020-01-09 21:04:30 +01:00
|
|
|
imgdata.append('icon', this.$refs.iconInput.files[0]);
|
2020-01-05 23:21:28 +01:00
|
|
|
|
|
|
|
let config = {
|
|
|
|
header : {
|
|
|
|
'Content-Type' : 'multipart/form-data',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-16 22:21:05 +01:00
|
|
|
try {
|
|
|
|
const { data } = await axios.post('/api/icon/upload', imgdata, config)
|
|
|
|
|
|
|
|
this.tempIcon = data;
|
|
|
|
this.validationErrors['icon'] = '';
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
if( error.response.data.validation ) {
|
|
|
|
this.validationErrors = error.response.data.validation
|
|
|
|
}
|
|
|
|
else {
|
2020-01-17 00:23:38 +01:00
|
|
|
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
2020-01-16 22:21:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-08 16:14:25 +01:00
|
|
|
},
|
|
|
|
|
2020-01-16 22:21:05 +01:00
|
|
|
async deleteIcon(event) {
|
2020-01-08 16:14:25 +01:00
|
|
|
|
2020-01-09 21:04:30 +01:00
|
|
|
if( this.tempIcon && this.tempIcon !== this.twofaccount.icon ) {
|
2020-01-16 22:21:05 +01:00
|
|
|
await axios.delete('/api/icon/delete/' + this.tempIcon)
|
2020-01-08 23:22:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.tempIcon = ''
|
|
|
|
},
|
2020-01-08 16:14:25 +01:00
|
|
|
|
2019-12-21 23:23:44 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
</script>
|