mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-15 19:53:08 +02:00
110 lines
2.2 KiB
Vue
110 lines
2.2 KiB
Vue
<template>
|
|
<div class="ngbfujlo">
|
|
<mk-textarea :value="text" readonly style="margin: 0;"></mk-textarea>
|
|
<mk-button class="button" primary @click="post()" :disabled="posting || posted">{{ posted ? $t('posted') : $t('post') }}</mk-button>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import Vue from 'vue';
|
|
import i18n from '../../i18n';
|
|
import MkTextarea from '../ui/textarea.vue';
|
|
import MkButton from '../ui/button.vue';
|
|
import { apiUrl } from '../../config';
|
|
|
|
export default Vue.extend({
|
|
i18n,
|
|
components: {
|
|
MkTextarea,
|
|
MkButton,
|
|
},
|
|
props: {
|
|
value: {
|
|
required: true
|
|
},
|
|
script: {
|
|
required: true
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
text: this.script.interpolate(this.value.text),
|
|
posted: false,
|
|
posting: false,
|
|
};
|
|
},
|
|
watch: {
|
|
'script.vars': {
|
|
handler() {
|
|
this.text = this.script.interpolate(this.value.text);
|
|
},
|
|
deep: true
|
|
}
|
|
},
|
|
methods: {
|
|
upload() {
|
|
return new Promise((ok) => {
|
|
const dialog = this.$root.dialog({
|
|
type: 'waiting',
|
|
text: this.$t('uploading') + '...',
|
|
showOkButton: false,
|
|
showCancelButton: false,
|
|
cancelableByBgClick: false
|
|
});
|
|
const canvas = this.script.aoiScript.canvases[this.value.canvasId];
|
|
canvas.toBlob(blob => {
|
|
const data = new FormData();
|
|
data.append('file', blob);
|
|
data.append('i', this.$store.state.i.token);
|
|
|
|
fetch(apiUrl + '/drive/files/create', {
|
|
method: 'POST',
|
|
body: data
|
|
})
|
|
.then(response => response.json())
|
|
.then(f => {
|
|
dialog.close();
|
|
ok(f);
|
|
})
|
|
});
|
|
});
|
|
},
|
|
async post() {
|
|
this.posting = true;
|
|
const file = this.value.attachCanvasImage ? await this.upload() : null;
|
|
this.$root.api('notes/create', {
|
|
text: this.text,
|
|
fileIds: file ? [file.id] : undefined,
|
|
}).then(() => {
|
|
this.posted = true;
|
|
this.$root.dialog({
|
|
type: 'success',
|
|
iconOnly: true, autoClose: true
|
|
});
|
|
});
|
|
}
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.ngbfujlo {
|
|
position: relative;
|
|
padding: 32px;
|
|
border-radius: 6px;
|
|
box-shadow: 0 2px 8px var(--shadow);
|
|
z-index: 1;
|
|
|
|
> .button {
|
|
margin-top: 32px;
|
|
}
|
|
|
|
@media (max-width: 600px) {
|
|
padding: 16px;
|
|
|
|
> .button {
|
|
margin-top: 16px;
|
|
}
|
|
}
|
|
}
|
|
</style>
|