fchat-rising/site/character_page/memo_dialog.vue

78 lines
2.1 KiB
Vue
Raw Normal View History

<template>
2019-01-03 17:38:17 +00:00
<Modal :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">
2019-01-03 17:38:17 +00:00
import {Component, Prop, Watch} from '@f-list/vue-ts';
2018-01-06 16:14:21 +00:00
import CustomDialog from '../../components/custom_dialog';
import Modal from '../../components/Modal.vue';
2019-01-03 17:38:17 +00:00
import {SimpleCharacter} from '../../interfaces';
2018-01-06 16:14:21 +00:00
import * as Utils from '../utils';
2023-03-12 05:43:58 +00:00
// import {methods} from './data_store';
import { MemoManager } from '../../chat/character/memo';
2019-01-03 17:38:17 +00:00
export interface Memo {
id: number
memo: string
character: SimpleCharacter
created_at: number
updated_at: number
}
2018-01-06 16:14:21 +00:00
@Component({
components: {Modal}
})
export default class MemoDialog extends CustomDialog {
@Prop({required: true})
2019-01-03 17:38:17 +00:00
readonly character!: {id: number, name: string};
2019-09-17 17:14:14 +00:00
@Prop
2019-01-03 17:38:17 +00:00
readonly memo?: Memo;
message = '';
editing = false;
saving = false;
get name(): string {
2019-01-03 17:38:17 +00:00
return this.character.name;
}
show(): void {
2018-01-06 16:14:21 +00:00
super.show();
2019-01-03 17:38:17 +00:00
this.setMemo();
}
@Watch('memo')
setMemo(): void {
if(this.memo !== undefined)
this.message = this.memo.memo;
2018-01-06 16:14:21 +00:00
}
onClose(): void {
this.editing = false;
}
async save(): Promise<void> {
try {
this.saving = true;
2023-03-12 05:43:58 +00:00
const memoManager = new MemoManager(this.character.name);
await memoManager.set(this.message);
this.$emit('memo', memoManager.get());
2018-01-06 16:14:21 +00:00
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;
}
}
2023-03-12 05:43:58 +00:00
</script>