2022-04-29 18:29:42 +08:00
|
|
|
<template>
|
2023-10-19 17:45:01 +08:00
|
|
|
<div class="content__text-container pr-8">
|
2023-10-09 17:28:18 +08:00
|
|
|
<div class="sci-divider my-6" v-if="!inRepository"></div>
|
2023-09-14 18:12:15 +08:00
|
|
|
<div class="text-header h-9 flex rounded mb-1 items-center relative w-full group/text-header" :class="{ 'editing-name': editingName, 'locked': !element.attributes.orderable.urls.update_url }">
|
2023-09-05 22:23:42 +08:00
|
|
|
<div v-if="element.attributes.orderable.urls.update_url || element.attributes.orderable.name"
|
2023-09-06 20:58:59 +08:00
|
|
|
class="grow-1 text-ellipsis whitespace-nowrap grow my-1 font-bold"
|
|
|
|
:class="{'pointer-events-none': !element.attributes.orderable.urls.update_url}"
|
|
|
|
>
|
2023-09-04 19:58:11 +08:00
|
|
|
<InlineEdit
|
|
|
|
:value="element.attributes.orderable.name"
|
|
|
|
:characterLimit="255"
|
|
|
|
:placeholder="i18n.t('protocols.steps.text.text_name')"
|
|
|
|
:allowBlank="true"
|
|
|
|
:autofocus="editingName"
|
|
|
|
:attributeName="`${i18n.t('Text')} ${i18n.t('name')}`"
|
|
|
|
@editingEnabled="enableNameEdit"
|
|
|
|
@editingDisabled="disableNameEdit"
|
|
|
|
@update="updateName"
|
|
|
|
/>
|
|
|
|
</div>
|
2023-09-13 18:12:36 +08:00
|
|
|
<MenuDropdown
|
|
|
|
class="ml-auto"
|
|
|
|
:listItems="this.actionMenu"
|
2023-09-18 21:32:53 +08:00
|
|
|
:btnClasses="'btn btn-light icon-btn btn-sm'"
|
2023-09-13 18:12:36 +08:00
|
|
|
:position="'right'"
|
|
|
|
:btnIcon="'sn-icon sn-icon-more-hori'"
|
|
|
|
@edit="enableNameEdit"
|
|
|
|
@duplicate="duplicateElement"
|
|
|
|
@move="showMoveModal"
|
|
|
|
@delete="showDeleteModal"
|
|
|
|
></MenuDropdown>
|
2022-05-10 19:28:09 +08:00
|
|
|
</div>
|
2023-10-26 16:23:14 +08:00
|
|
|
<div class="flex rounded min-h-[2.25rem] mb-4 relative group/text_container content__text-body" :class="{ 'edit': inEditMode, 'component__element--locked': !element.attributes.orderable.urls.update_url }" @keyup.enter="enableEditMode($event)" tabindex="0">
|
2023-09-04 19:58:11 +08:00
|
|
|
<Tinymce
|
|
|
|
v-if="element.attributes.orderable.urls.update_url"
|
|
|
|
:value="element.attributes.orderable.text"
|
|
|
|
:value_html="element.attributes.orderable.text_view"
|
|
|
|
:placeholder="element.attributes.orderable.placeholder"
|
|
|
|
:inEditMode="inEditMode || isNew"
|
|
|
|
:updateUrl="element.attributes.orderable.urls.update_url"
|
|
|
|
:objectType="'TextContent'"
|
|
|
|
:objectId="element.attributes.orderable.id"
|
|
|
|
:fieldName="'text_component[text]'"
|
|
|
|
:lastUpdated="element.attributes.orderable.updated_at"
|
|
|
|
:assignableMyModuleId="assignableMyModuleId"
|
|
|
|
:characterLimit="1000000"
|
|
|
|
@update="updateText"
|
|
|
|
@editingDisabled="disableEditMode"
|
|
|
|
@editingEnabled="enableEditMode"
|
|
|
|
/>
|
2024-01-31 16:32:19 +08:00
|
|
|
<div class="view-text-element" v-else-if="element.attributes.orderable.text_view" v-html="wrappedTables"></div>
|
2023-09-04 19:58:11 +08:00
|
|
|
<div v-else class="text-sn-grey">
|
|
|
|
{{ i18n.t("protocols.steps.text.empty_text") }}
|
|
|
|
</div>
|
2022-07-15 20:58:06 +08:00
|
|
|
</div>
|
2022-05-30 19:45:51 +08:00
|
|
|
<deleteElementModal v-if="confirmingDelete" @confirm="deleteElement($event)" @cancel="closeDeleteModal"/>
|
2023-08-21 15:22:56 +08:00
|
|
|
<moveElementModal v-if="movingElement"
|
|
|
|
:parent_type="element.attributes.orderable.parent_type"
|
|
|
|
:targets_url="element.attributes.orderable.urls.move_targets_url"
|
|
|
|
@confirm="moveElement($event)" @cancel="closeMoveModal"/>
|
2022-04-29 18:29:42 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
<script>
|
|
|
|
import DeleteMixin from './mixins/delete.js';
|
|
|
|
import MoveMixin from './mixins/move.js';
|
|
|
|
import DuplicateMixin from './mixins/duplicate.js';
|
|
|
|
import deleteElementModal from './modal/delete.vue';
|
|
|
|
import moveElementModal from './modal/move.vue';
|
|
|
|
import InlineEdit from '../inline_edit.vue';
|
|
|
|
import Tinymce from '../tinymce.vue';
|
|
|
|
import MenuDropdown from '../menu_dropdown.vue';
|
2022-05-04 16:25:53 +08:00
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
export default {
|
|
|
|
name: 'TextContent',
|
|
|
|
components: {
|
|
|
|
deleteElementModal, Tinymce, moveElementModal, InlineEdit, MenuDropdown
|
|
|
|
},
|
|
|
|
mixins: [DeleteMixin, DuplicateMixin, MoveMixin],
|
|
|
|
props: {
|
|
|
|
element: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
2022-05-10 19:28:09 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
inRepository: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true
|
2022-05-10 19:28:09 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
reorderElementUrl: {
|
|
|
|
type: String
|
|
|
|
},
|
|
|
|
isNew: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2022-07-07 19:43:29 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
assignableMyModuleId: {
|
|
|
|
type: Number,
|
|
|
|
required: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
inEditMode: false,
|
|
|
|
editingName: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
if (this.isNew) {
|
|
|
|
this.enableEditMode();
|
|
|
|
}
|
|
|
|
this.$nextTick(() => {
|
2024-01-31 16:32:19 +08:00
|
|
|
const textElements = document.querySelectorAll('.view-text-element');
|
|
|
|
if (textElements.length > 0) {
|
|
|
|
textElements.forEach((textElement) => {
|
|
|
|
this.highlightText(textElement);
|
|
|
|
});
|
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
computed: {
|
2024-01-31 16:32:19 +08:00
|
|
|
wrappedTables() {
|
|
|
|
return window.wrapTables(this.element.attributes.orderable.text_view);
|
2024-01-04 23:34:36 +08:00
|
|
|
},
|
|
|
|
actionMenu() {
|
|
|
|
const menu = [];
|
|
|
|
if (this.element.attributes.orderable.urls.update_url) {
|
|
|
|
menu.push({
|
|
|
|
text: I18n.t('general.edit'),
|
|
|
|
emit: 'edit'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (this.element.attributes.orderable.urls.duplicate_url) {
|
|
|
|
menu.push({
|
|
|
|
text: I18n.t('general.duplicate'),
|
|
|
|
emit: 'duplicate'
|
2023-11-17 22:01:28 +08:00
|
|
|
});
|
2023-09-13 18:12:36 +08:00
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
if (this.element.attributes.orderable.urls.move_targets_url) {
|
|
|
|
menu.push({
|
|
|
|
text: I18n.t('general.move'),
|
|
|
|
emit: 'move'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (this.element.attributes.orderable.urls.delete_url) {
|
|
|
|
menu.push({
|
|
|
|
text: I18n.t('general.delete'),
|
|
|
|
emit: 'delete'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
enableEditMode() {
|
|
|
|
if (!this.element.attributes.orderable.urls.update_url) return;
|
|
|
|
if (this.inEditMode) return;
|
|
|
|
this.inEditMode = true;
|
|
|
|
},
|
|
|
|
disableEditMode() {
|
|
|
|
this.inEditMode = false;
|
|
|
|
},
|
|
|
|
enableNameEdit() {
|
|
|
|
this.editingName = true;
|
|
|
|
},
|
|
|
|
disableNameEdit() {
|
|
|
|
this.editingName = false;
|
|
|
|
},
|
|
|
|
updateName(name) {
|
|
|
|
this.element.attributes.orderable.name = name;
|
|
|
|
$.ajax({
|
|
|
|
url: this.element.attributes.orderable.urls.update_url,
|
|
|
|
method: 'PUT',
|
|
|
|
data: { text_component: { name } }
|
|
|
|
});
|
|
|
|
this.$emit('update', this.element, true);
|
|
|
|
},
|
|
|
|
updateText(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;
|
|
|
|
this.$emit('update', this.element, true);
|
2023-09-13 18:12:36 +08:00
|
|
|
},
|
2024-01-31 16:32:19 +08:00
|
|
|
highlightText(textElToHighlight) {
|
|
|
|
Prism.highlightAllUnder(textElToHighlight);
|
2022-05-03 21:15:49 +08:00
|
|
|
}
|
2022-04-29 18:29:42 +08:00
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
};
|
2022-05-03 19:42:43 +08:00
|
|
|
</script>
|