55 lines
1.1 KiB
Vue
55 lines
1.1 KiB
Vue
<template>
|
|
<div>
|
|
<span @click="edit" v-if="!editmode">
|
|
{{ newProgress }} pages | {{ progress }}%
|
|
</span>
|
|
<span v-show="editmode">
|
|
<input type="number" @keydown.esc="cancelEdit" @keydown.enter="submit" ref="readPagesInput" min="0"
|
|
:max="totalPages" v-model.number="newProgress" />
|
|
</span>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import {EventBus} from "../event-bus";
|
|
|
|
export default {
|
|
name: 'Progresseditor',
|
|
components: {
|
|
EventBus
|
|
},
|
|
props: {
|
|
totalPages: Number,
|
|
readPages: Number
|
|
},
|
|
data() {
|
|
return {
|
|
editmode: false,
|
|
newProgress: this.readPages
|
|
}
|
|
},
|
|
computed: {
|
|
progress() {
|
|
return Math.round(this.newProgress / this.totalPages * 100);
|
|
}
|
|
},
|
|
mounted() {
|
|
},
|
|
created() {
|
|
this.newProgress = this.readPages;
|
|
},
|
|
methods: {
|
|
edit: function () {
|
|
this.editmode = true;
|
|
setTimeout(() => this.$refs.readPagesInput.focus(), 1)
|
|
},
|
|
cancelEdit: function () {
|
|
this.editmode = false;
|
|
},
|
|
submit: function () {
|
|
this.editmode = false;
|
|
window.EventBus.$emit('updateProgress', {readPages: this.newProgress});
|
|
}
|
|
}
|
|
}
|
|
</script> |