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