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