get rid of slots

This commit is contained in:
rinpatch 2018-12-13 15:44:37 +01:00
parent 6de4dcc7c9
commit 457132fb37
2 changed files with 9 additions and 43 deletions

View File

@ -78,42 +78,18 @@ const UserSettings = {
uploadFile (slot, e) {
const file = e.target.files[0]
if (!file) { return }
var error = () => {}
switch (slot) {
case 0:
error = (error) => { this.avatarUploadError = error }
break
case 1:
error = (error) => { this.bannerUploadError = error }
break
case 2:
error = (error) => { this.backgroundUploadError = error }
break
}
var limit = [this.$store.state.instance.avatarlimit, this.$store.state.instance.bannerlimit, this.$store.state.instance.backgroundlimit]
if (file.size > limit[slot]) {
const filesize = fileSizeFormatService.fileSizeFormat(file.size)
const allowedsize = fileSizeFormatService.fileSizeFormat(limit[slot])
error(this.$t('upload.error.base') + ' ' + this.$t('upload.error.file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit}))
this[slot + 'UploadError'] = this.$t('upload.error.base') + ' ' + this.$t('upload.error.file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit})
return
}
// eslint-disable-next-line no-undef
const reader = new FileReader()
reader.onload = ({target}) => {
const img = target.result
var preview = () => {}
switch (slot) {
case 0:
preview = (preview) => { this.avatarPreview = preview }
break
case 1:
preview = (preview) => { this.bannerPreview = preview }
break
case 2:
preview = (preview) => { this.backgroundPreview = preview }
break
}
preview(img)
this[slot + 'Preview'] = img
}
reader.readAsDataURL(file)
},
@ -149,17 +125,7 @@ const UserSettings = {
})
},
clearUploadError (slot) {
switch (slot) {
case 0:
this.avatarUploadError = null
break
case 1:
this.bannerUploadError = null
break
case 2:
this.backgroundUploadError = null
break
}
this[slot + 'UploadError'] = null
},
submitBanner () {
if (!this.bannerPreview) { return }

View File

@ -39,13 +39,13 @@
<img class="new-avatar" v-bind:src="avatarPreview" v-if="avatarPreview">
</img>
<div>
<input type="file" @change="uploadFile(0, $event)" ></input>
<input type="file" @change="uploadFile('avatar', $event)" ></input>
</div>
<i class="icon-spin4 animate-spin" v-if="avatarUploading"></i>
<button class="btn btn-default" v-else-if="avatarPreview" @click="submitAvatar">{{$t('general.submit')}}</button>
<div class='alert error' v-if="avatarUploadError">
Error: {{ avatarUploadError }}
<i class="icon-cancel" @click="clearUploadError(0)"></i>
<i class="icon-cancel" @click="clearUploadError('avatar')"></i>
</div>
</div>
<div class="setting-item">
@ -56,13 +56,13 @@
<img class="banner" v-bind:src="bannerPreview" v-if="bannerPreview">
</img>
<div>
<input type="file" @change="uploadFile(1, $event)" ></input>
<input type="file" @change="uploadFile('banner', $event)" ></input>
</div>
<i class=" icon-spin4 animate-spin uploading" v-if="bannerUploading"></i>
<button class="btn btn-default" v-else-if="bannerPreview" @click="submitBanner">{{$t('general.submit')}}</button>
<div class='alert error' v-if="bannerUploadError">
Error: {{ bannerUploadError }}
<i class="icon-cancel" @click="clearUploadError(1)"></i>
<i class="icon-cancel" @click="clearUploadError('banner')"></i>
</div>
</div>
<div class="setting-item">
@ -71,13 +71,13 @@
<img class="bg" v-bind:src="backgroundPreview" v-if="backgroundPreview">
</img>
<div>
<input type="file" @change="uploadFile(2, $event)" ></input>
<input type="file" @change="uploadFile('background', $event)" ></input>
</div>
<i class=" icon-spin4 animate-spin uploading" v-if="backgroundUploading"></i>
<button class="btn btn-default" v-else-if="backgroundPreview" @click="submitBg">{{$t('general.submit')}}</button>
<div class='alert error' v-if="backgroundUploadError">
Error: {{ backgroundUploadError }}
<i class="icon-cancel" @click="clearUploadError(2)"></i>
<i class="icon-cancel" @click="clearUploadError('background')"></i>
</div>
</div>
</div>