Sharkey/src/client/components/page/page.post.vue

114 lines
2.4 KiB
Vue
Raw Normal View History

<template>
<div class="ngbfujlo">
2020-01-31 00:01:45 +02:00
<mk-textarea :value="text" readonly style="margin: 0;"></mk-textarea>
<mk-button class="button" primary @click="post()" :disabled="posting || posted"><fa v-if="posted" :icon="faCheck"/><fa v-else :icon="faPaperPlane"/></mk-button>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import { faCheck, faPaperPlane } from '@fortawesome/free-solid-svg-icons';
import MkTextarea from '../ui/textarea.vue';
import MkButton from '../ui/button.vue';
2020-04-19 03:05:20 +03:00
import { apiUrl } from '../../config';
export default Vue.extend({
components: {
MkTextarea,
MkButton,
},
props: {
value: {
required: true
},
2020-04-20 15:35:27 +03:00
hpml: {
required: true
}
},
data() {
return {
2020-04-20 15:35:27 +03:00
text: this.hpml.interpolate(this.value.text),
posted: false,
posting: false,
faCheck, faPaperPlane
};
},
watch: {
2020-04-20 15:35:27 +03:00
'hpml.vars': {
handler() {
2020-04-20 15:35:27 +03:00
this.text = this.hpml.interpolate(this.value.text);
},
deep: true
}
},
methods: {
2020-04-19 03:05:20 +03:00
upload() {
return new Promise((ok) => {
const dialog = this.$root.dialog({
type: 'waiting',
text: this.$t('uploading') + '...',
showOkButton: false,
showCancelButton: false,
cancelableByBgClick: false
});
2020-04-20 15:35:27 +03:00
const canvas = this.hpml.canvases[this.value.canvasId];
2020-04-19 03:05:20 +03:00
canvas.toBlob(blob => {
const data = new FormData();
data.append('file', blob);
data.append('i', this.$store.state.i.token);
if (this.$store.state.settings.uploadFolder) {
data.append('folderId', this.$store.state.settings.uploadFolder);
}
2020-04-19 03:05:20 +03:00
fetch(apiUrl + '/drive/files/create', {
method: 'POST',
body: data
})
.then(response => response.json())
.then(f => {
dialog.close();
ok(f);
})
});
});
},
async post() {
this.posting = true;
2020-04-19 03:05:20 +03:00
const file = this.value.attachCanvasImage ? await this.upload() : null;
this.$root.api('notes/create', {
text: this.text === '' ? null : this.text,
2020-04-19 03:05:20 +03:00
fileIds: file ? [file.id] : undefined,
}).then(() => {
this.posted = true;
this.$root.dialog({
type: 'success',
iconOnly: true, autoClose: true
});
});
}
}
});
</script>
<style lang="scss" scoped>
.ngbfujlo {
2020-04-19 03:05:20 +03:00
position: relative;
2020-01-31 00:01:45 +02:00
padding: 32px;
border-radius: 6px;
2020-01-31 00:01:45 +02:00
box-shadow: 0 2px 8px var(--shadow);
2020-04-19 03:05:20 +03:00
z-index: 1;
2020-01-31 00:01:45 +02:00
> .button {
margin-top: 32px;
}
@media (max-width: 600px) {
2020-01-31 00:01:45 +02:00
padding: 16px;
2020-01-31 00:01:45 +02:00
> .button {
margin-top: 16px;
}
}
}
</style>