fchat-rising/site/character_page/memo_dialog.vue

60 lines
1.9 KiB
Vue
Raw Normal View History

<template>
<Modal id="memoDialog" :action="'Memo for ' + name" buttonText="Save and Close" @close="onClose" @submit="save" dialog-class="modal-lg modal-dialog-centered">
2018-01-06 16:14:21 +00:00
<div class="form-group" v-if="editing">
<textarea v-model="message" maxlength="1000" class="form-control"></textarea>
</div>
<div v-else>
<p>{{message}}</p>
2018-01-06 16:14:21 +00:00
<p><a href="#" @click="editing=true">Edit</a></p>
</div>
2018-01-06 16:14:21 +00:00
</Modal>
</template>
<script lang="ts">
import Component from 'vue-class-component';
import {Prop} from 'vue-property-decorator';
2018-01-06 16:14:21 +00:00
import CustomDialog from '../../components/custom_dialog';
import Modal from '../../components/Modal.vue';
import * as Utils from '../utils';
import {methods} from './data_store';
import {Character} from './interfaces';
2018-01-06 16:14:21 +00:00
@Component({
components: {Modal}
})
export default class MemoDialog extends CustomDialog {
@Prop({required: true})
private readonly character!: Character;
private message = '';
editing = false;
saving = false;
get name(): string {
return this.character.character.name;
}
show(): void {
2018-01-06 16:14:21 +00:00
super.show();
if(this.character.memo !== undefined)
this.message = this.character.memo.memo;
2018-01-06 16:14:21 +00:00
}
onClose(): void {
this.editing = false;
}
async save(): Promise<void> {
try {
this.saving = true;
const memoReply = await methods.memoUpdate(this.character.character.id, this.message);
2018-01-06 16:14:21 +00:00
this.$emit('memo', this.message !== '' ? memoReply : undefined);
this.hide();
} catch(e) {
2018-01-06 16:14:21 +00:00
Utils.ajaxError(e, 'Unable to set memo.');
}
2018-01-06 16:14:21 +00:00
this.saving = false;
}
}
</script>