2022-07-06 17:43:30 +08:00
|
|
|
<template>
|
|
|
|
<div ref="modal" @keydown.esc="cancel"
|
|
|
|
@keyup.enter="uploadImage"
|
|
|
|
class="modal clipboardPreviewModal fade"
|
|
|
|
role="dialog" aria-hidden="true" tabindex="-1">
|
|
|
|
<div class="modal-dialog" role="document">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
2023-08-17 19:55:17 +08:00
|
|
|
<i class="sn-icon sn-icon-close"></i>
|
2022-07-06 17:43:30 +08:00
|
|
|
</button>
|
|
|
|
<h4 class="modal-title">{{i18n.t('assets.from_clipboard.modal_title')}}</h4>
|
|
|
|
</div>
|
|
|
|
<div class="modal-body">
|
2023-10-26 18:01:48 +08:00
|
|
|
<label class="sci-label">{{i18n.t('assets.from_clipboard.image_preview')}}</label>
|
2023-10-26 19:24:29 +08:00
|
|
|
<div class="flex justify-center w-full">
|
|
|
|
<canvas class="max-h-80 max-w-lg rounded border border-solid border-sn-light-grey" ref="preview" />
|
|
|
|
</div>
|
2023-10-26 18:01:48 +08:00
|
|
|
<div class="w-full py-6">
|
2023-10-26 19:32:17 +08:00
|
|
|
<label class="sci-label">{{i18n.t(`assets.from_clipboard.select_${objectType}`)}}</label>
|
2023-11-29 18:36:44 +08:00
|
|
|
<SelectDropdown
|
2023-10-26 18:01:48 +08:00
|
|
|
:value="target"
|
|
|
|
@change="setTarget"
|
|
|
|
:options="targets"
|
2023-11-29 18:36:44 +08:00
|
|
|
:searchable="true"
|
2023-10-26 18:01:48 +08:00
|
|
|
:placeholder="
|
|
|
|
i18n.t(`protocols.steps.modals.move_element.${objectType}.search_placeholder`)
|
|
|
|
"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<label class="sci-label">{{i18n.t('assets.from_clipboard.file_name')}}</label>
|
|
|
|
<div class="sci-input-container-v2">
|
|
|
|
<input id="clipboardImageName" type="text" class="sci-input-field !pr-16" v-model="fileName"
|
2022-07-15 19:46:48 +08:00
|
|
|
:placeholder="i18n.t('assets.from_clipboard.file_name_placeholder')" aria-describedby="image-name">
|
2023-10-26 18:01:48 +08:00
|
|
|
<span class="absolute right-2.5 text-sn-grey ">
|
|
|
|
.{{ extension }}
|
|
|
|
</span>
|
2022-07-06 17:43:30 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
2023-06-19 21:45:22 +08:00
|
|
|
<button type="button" class="btn btn-secondary" @click="cancel">{{i18n.t('general.cancel')}}</button>
|
2023-10-26 18:01:48 +08:00
|
|
|
<button type="button" class="btn btn-success" :disabled="!valid" @click="uploadImage">{{i18n.t('assets.from_clipboard.add_image')}}</button>
|
2022-07-06 17:43:30 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2023-11-29 18:36:44 +08:00
|
|
|
import SelectDropdown from "../../select_dropdown.vue";
|
2023-10-26 18:01:48 +08:00
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
export default {
|
|
|
|
name: 'clipboardPasteModal',
|
|
|
|
props: {
|
|
|
|
objects: Array,
|
|
|
|
image: DataTransferItem,
|
|
|
|
objectType: String,
|
|
|
|
selectedObjectId: String
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
target: null,
|
|
|
|
targets: [],
|
|
|
|
fileName: '',
|
|
|
|
extension: ''
|
|
|
|
};
|
|
|
|
},
|
|
|
|
components: {
|
2024-01-11 22:14:36 +08:00
|
|
|
SelectDropdown
|
2024-01-04 23:34:36 +08:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
valid() {
|
|
|
|
return this.target && this.fileName.length > 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
$(this.$refs.modal).modal('show');
|
|
|
|
this.appendImage(this.image);
|
|
|
|
$(this.$refs.modal).on('hidden.bs.modal', () => {
|
|
|
|
this.$emit('cancel');
|
|
|
|
});
|
2023-10-26 18:01:48 +08:00
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
if (this.selectedObjectId) this.target = this.selectedObjectId;
|
|
|
|
this.targets = this.objects.map((object) => [
|
|
|
|
object.id,
|
|
|
|
object.attributes.name
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
setTarget(target) {
|
|
|
|
this.target = target;
|
2023-10-26 18:01:48 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
cancel() {
|
|
|
|
$(this.$refs.modal).modal('hide');
|
2022-07-06 17:43:30 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
appendImage(item) {
|
|
|
|
const imageBlob = item.getAsFile();
|
|
|
|
if (imageBlob) {
|
|
|
|
const canvas = this.$refs.preview;
|
|
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
const img = new Image();
|
|
|
|
img.onload = function () {
|
|
|
|
canvas.width = this.width;
|
|
|
|
canvas.height = this.height;
|
|
|
|
ctx.drawImage(img, 0, 0);
|
|
|
|
};
|
|
|
|
const URLObj = window.URL || window.webkitURL;
|
|
|
|
img.src = URLObj.createObjectURL(imageBlob);
|
|
|
|
const extension = imageBlob.name.slice(
|
|
|
|
(Math.max(0, imageBlob.name.lastIndexOf('.')) || Infinity) + 1
|
|
|
|
);
|
|
|
|
this.extension = extension;
|
|
|
|
this.imageBlob = imageBlob;
|
2022-07-06 17:43:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
};
|
2022-07-06 17:43:30 +08:00
|
|
|
</script>
|