scinote-web/app/javascript/vue/shared/content/text.vue

107 lines
4 KiB
Vue
Raw Normal View History

<template>
2023-07-21 16:35:14 +08:00
<div class="content__text-container flex rounded pl-10 mb-4 relative w-full group/text_container" :class="{ 'edit': inEditMode, 'component__element--locked': !element.attributes.orderable.urls.update_url }" @keyup.enter="enableEditMode($event)" tabindex="0">
<div v-if="reorderElementUrl"
class="absolute items-center h-full justify-center left-0 p-2 tw-hidden text-sn-grey"
:class="{ 'group-hover/text_container:flex': !inEditMode }"
@click="$emit('reorder')"
>
2023-06-15 21:12:51 +08:00
<i class="sn-icon sn-icon-sort"></i>
</div>
2023-07-21 16:35:14 +08:00
<div v-else class="flex-none"></div>
<div class="bg-sn-light-grey rounded absolute right-0 flex z-10 tw-hidden" :class="{ 'group-hover/text_container:flex': !inEditMode && element.attributes.orderable.urls.update_url }">
2023-06-22 17:55:23 +08:00
<button v-if="element.attributes.orderable.urls.update_url" class="btn icon-btn btn-light btn-sm" tabindex="0" @click="enableEditMode($event)">
2023-06-15 21:12:51 +08:00
<i class="sn-icon sn-icon-edit"></i>
</button>
2023-06-22 17:55:23 +08:00
<button v-if="element.attributes.orderable.urls.duplicate_url" class="btn icon-btn btn-light btn-sm" tabindex="0" @click="duplicateElement">
2023-06-08 14:33:37 +08:00
<i class="sn-icon sn-icon-duplicate"></i>
</button>
2023-06-22 17:55:23 +08:00
<button v-if="element.attributes.orderable.urls.delete_url" class="btn icon-btn btn-light btn-sm" @click="showDeleteModal" tabindex="0">
2023-06-08 14:33:37 +08:00
<i class="sn-icon sn-icon-delete"></i>
</button>
2022-05-10 19:28:09 +08:00
</div>
<Tinymce
v-if="element.attributes.orderable.urls.update_url"
2022-05-10 19:28:09 +08:00
:value="element.attributes.orderable.text"
:value_html="element.attributes.orderable.text_view"
2022-07-13 21:15:01 +08:00
:placeholder="element.attributes.orderable.placeholder"
:inEditMode="inEditMode || isNew"
2022-05-10 19:28:09 +08:00
:updateUrl="element.attributes.orderable.urls.update_url"
2023-07-21 16:35:14 +08:00
:objectType="'TextContent'"
2022-05-10 19:28:09 +08:00
:objectId="element.attributes.orderable.id"
2023-07-21 16:35:14 +08:00
:fieldName="'text_component[text]'"
2022-05-10 19:28:09 +08:00
:lastUpdated="element.attributes.orderable.updated_at"
:assignableMyModuleId="assignableMyModuleId"
2023-05-17 17:40:14 +08:00
:characterLimit="1000000"
2022-05-10 19:28:09 +08:00
@update="update"
@editingDisabled="disableEditMode"
@editingEnabled="enableEditMode"
2022-05-10 19:28:09 +08:00
/>
<div class="view-text-element" v-else-if="element.attributes.orderable.text_view" v-html="element.attributes.orderable.text_view"></div>
2023-07-21 16:35:14 +08:00
<div v-else class="text-sn-grey">
2022-07-15 20:58:06 +08:00
{{ i18n.t("protocols.steps.text.empty_text") }}
</div>
<deleteElementModal v-if="confirmingDelete" @confirm="deleteElement($event)" @cancel="closeDeleteModal"/>
</div>
</template>
<script>
2023-07-21 16:35:14 +08:00
import DeleteMixin from './mixins/delete.js'
import DuplicateMixin from './mixins/duplicate.js'
import deleteElementModal from './modal/delete.vue'
import Tinymce from '../tinymce.vue'
2022-05-04 16:25:53 +08:00
export default {
2023-07-21 16:35:14 +08:00
name: 'TextContent',
components: { deleteElementModal, Tinymce },
mixins: [DeleteMixin, DuplicateMixin],
props: {
element: {
type: Object,
required: true
},
inRepository: {
type: Boolean,
required: true
},
reorderElementUrl: {
type: String
},
isNew: {
type: Boolean,
default: false
},
assignableMyModuleId: {
type: Number,
required: false
}
2022-05-10 19:28:09 +08:00
},
data() {
return {
inEditMode: false,
}
},
mounted() {
if (this.isNew) {
2022-12-14 21:32:23 +08:00
this.enableEditMode();
}
},
2022-05-10 19:28:09 +08:00
methods: {
enableEditMode() {
if (!this.element.attributes.orderable.urls.update_url) return
if (this.inEditMode) return
2022-05-10 19:28:09 +08:00
this.inEditMode = true
},
disableEditMode() {
this.inEditMode = false
},
update(data) {
this.element.attributes.orderable.text_view = data.attributes.text_view
this.element.attributes.orderable.text = data.attributes.text
this.element.attributes.orderable.name = data.attributes.name
this.element.attributes.orderable.updated_at = data.attributes.updated_at
2022-05-10 19:28:09 +08:00
this.$emit('update', this.element, true)
}
}
}
2022-05-03 19:42:43 +08:00
</script>