Better mobile setting

This commit is contained in:
syuilo 2018-05-20 14:01:47 +09:00
parent ff6409be3f
commit 853ee415ae
4 changed files with 95 additions and 60 deletions

View file

@ -10,11 +10,6 @@
<md-input v-model="name" :disabled="saving"/>
</md-field>
<md-field>
<label>%i18n:@description%</label>
<md-textarea v-model="description" :disabled="saving"/>
</md-field>
<md-field>
<md-icon>%fa:map-marker-alt%</md-icon>
<label>%i18n:@location%</label>
@ -27,6 +22,25 @@
<md-input type="date" v-model="birthday" :disabled="saving"/>
</md-field>
<md-field>
<label>%i18n:@description%</label>
<md-textarea v-model="description" :disabled="saving"/>
</md-field>
<md-field>
<label>%i18n:@avatar%</label>
<md-file @md-change="onAvatarChange"/>
</md-field>
<md-field>
<label>%i18n:@banner%</label>
<md-file @md-change="onBannerChange"/>
</md-field>
<md-dialog-alert
:md-active.sync="uploading"
md-content="%18n:!@uploading%"/>
<div>
<md-switch v-model="os.i.isBot" @change="onChangeIsBot">%i18n:@is-bot%</md-switch>
</div>
@ -40,6 +54,7 @@
<script lang="ts">
import Vue from 'vue';
import { apiUrl } from '../../../../config';
export default Vue.extend({
data() {
@ -48,7 +63,10 @@ export default Vue.extend({
location: null,
description: null,
birthday: null,
saving: false
avatarId: null,
bannerId: null,
saving: false,
uploading: false
};
},
@ -57,6 +75,8 @@ export default Vue.extend({
this.location = (this as any).os.i.profile.location;
this.description = (this as any).os.i.description;
this.birthday = (this as any).os.i.profile.birthday;
this.avatarId = (this as any).os.i.avatarId;
this.bannerId = (this as any).os.i.bannerId;
},
methods: {
@ -66,6 +86,50 @@ export default Vue.extend({
});
},
onAvatarChange([file]) {
this.uploading = true;
const data = new FormData();
data.append('file', file);
data.append('i', (this as any).os.i.token);
fetch(apiUrl + '/drive/files/create', {
method: 'POST',
body: data
})
.then(response => response.json())
.then(f => {
this.avatarId = f.id;
this.uploading = false;
})
.catch(e => {
this.uploading = false;
alert('%18n:!@upload-failed%');
});
},
onBannerChange([file]) {
this.uploading = true;
const data = new FormData();
data.append('file', file);
data.append('i', (this as any).os.i.token);
fetch(apiUrl + '/drive/files/create', {
method: 'POST',
body: data
})
.then(response => response.json())
.then(f => {
this.bannerId = f.id;
this.uploading = false;
})
.catch(e => {
this.uploading = false;
alert('%18n:!@upload-failed%');
});
},
save() {
this.saving = true;
@ -73,9 +137,16 @@ export default Vue.extend({
name: this.name || null,
location: this.location || null,
description: this.description || null,
birthday: this.birthday || null
}).then(() => {
birthday: this.birthday || null,
avatarId: this.avatarId,
bannerId: this.bannerId
}).then(i => {
this.saving = false;
(this as any).os.i.avatarId = i.avatarId;
(this as any).os.i.avatarUrl = i.avatarUrl;
(this as any).os.i.bannerId = i.bannerId;
(this as any).os.i.bannerUrl = i.bannerUrl;
alert('%i18n:!@saved%');
});
}