2022-04-22 19:07:51 +08:00
|
|
|
<template>
|
2022-07-15 16:13:55 +08:00
|
|
|
<div ref="stepContainer" class="step-container"
|
2022-05-25 21:04:14 +08:00
|
|
|
:id="`stepContainer${step.id}`"
|
2022-05-24 21:54:22 +08:00
|
|
|
@drop.prevent="dropFile"
|
2022-07-20 19:39:04 +08:00
|
|
|
@dragenter.prevent="dragEnter($event)"
|
2022-05-24 21:54:22 +08:00
|
|
|
@dragover.prevent
|
2022-07-11 16:45:25 +08:00
|
|
|
:class="{ 'draging-file': dragingFile, 'showing-comments': showCommentsSidebar, 'editing-name': editingName }"
|
2022-05-25 21:04:14 +08:00
|
|
|
>
|
2022-07-15 16:13:55 +08:00
|
|
|
<div class="drop-message" @dragleave.prevent="!showFileModal ? dragingFile = false : null">
|
|
|
|
{{ i18n.t('protocols.steps.drop_message', { position: step.attributes.position + 1 }) }}
|
|
|
|
<StorageUsage v-if="showStorageUsage()" :step="step"/>
|
2022-05-24 21:54:22 +08:00
|
|
|
</div>
|
2022-07-11 16:45:25 +08:00
|
|
|
<div class="step-header">
|
2022-08-02 17:00:13 +08:00
|
|
|
<div class="step-element-header" :class="{ 'no-hover': !urls.update_url }">
|
2022-07-11 16:45:25 +08:00
|
|
|
<div class="step-controls">
|
2022-07-28 20:35:34 +08:00
|
|
|
<div v-if="reorderStepUrl" class="step-element-grip" @click="$emit('reorder')" :class="{ 'step-element--locked': !urls.update_url }">
|
2022-07-12 16:41:58 +08:00
|
|
|
<i class="fas fas-rotated-90 fa-exchange-alt"></i>
|
2022-07-11 16:45:25 +08:00
|
|
|
</div>
|
2022-07-13 21:15:01 +08:00
|
|
|
<div v-else class="step-element-grip-placeholder"></div>
|
2022-07-11 16:45:25 +08:00
|
|
|
<a class="step-collapse-link"
|
|
|
|
:href="'#stepBody' + step.id"
|
|
|
|
data-toggle="collapse"
|
2022-07-15 16:13:55 +08:00
|
|
|
data-remote="true"
|
|
|
|
@click="toggleCollapsed">
|
2022-07-11 16:45:25 +08:00
|
|
|
<span class="fas fa-caret-right"></span>
|
|
|
|
</a>
|
2022-08-10 21:39:45 +08:00
|
|
|
<div v-if="!inRepository" class="step-complete-container" :class="{ 'step-element--locked': !urls.state_url }">
|
2022-07-14 18:50:06 +08:00
|
|
|
<div :class="`step-state ${step.attributes.completed ? 'completed' : ''}`"
|
|
|
|
@click="changeState"
|
|
|
|
@keyup.enter="changeState"
|
|
|
|
tabindex="0"
|
|
|
|
:title="step.attributes.completed ? i18n.t('protocols.steps.status.uncomplete') : i18n.t('protocols.steps.status.complete')"
|
|
|
|
></div>
|
2022-07-11 16:45:25 +08:00
|
|
|
</div>
|
|
|
|
<div class="step-position">
|
|
|
|
{{ step.attributes.position + 1 }}.
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-08-19 21:59:46 +08:00
|
|
|
<div class="step-name-container" :class="{'step-element--locked': !urls.update_url}">
|
2022-07-11 16:45:25 +08:00
|
|
|
<InlineEdit
|
|
|
|
:value="step.attributes.name"
|
2022-07-26 19:33:43 +08:00
|
|
|
:class="{ 'step-element--locked': !urls.update_url }"
|
2022-07-11 16:45:25 +08:00
|
|
|
:characterLimit="255"
|
|
|
|
:allowBlank="false"
|
|
|
|
:attributeName="`${i18n.t('Step')} ${i18n.t('name')}`"
|
|
|
|
:autofocus="editingName"
|
2022-08-08 22:50:34 +08:00
|
|
|
:placeholder="i18n.t('protocols.steps.placeholder')"
|
|
|
|
:defaultValue="i18n.t('protocols.steps.default_name')"
|
2022-07-11 16:45:25 +08:00
|
|
|
@editingEnabled="editingName = true"
|
|
|
|
@editingDisabled="editingName = false"
|
2022-07-14 18:50:06 +08:00
|
|
|
:editOnload="step.newStep == true"
|
2022-07-11 16:45:25 +08:00
|
|
|
@update="updateName"
|
|
|
|
/>
|
|
|
|
</div>
|
2022-08-10 16:27:15 +08:00
|
|
|
<button v-if="urls.update_url && !editingName" class="step-name-edit-icon btn icon-btn btn-light " @click="editingName = true">
|
|
|
|
<i class="fas fa-pen"></i>
|
|
|
|
</button>
|
2022-04-28 17:13:38 +08:00
|
|
|
</div>
|
|
|
|
<div class="step-actions-container">
|
2022-07-06 20:11:48 +08:00
|
|
|
<div ref="actionsDropdownButton" v-if="urls.update_url" class="dropdown">
|
2022-04-29 18:29:42 +08:00
|
|
|
<button class="btn btn-light dropdown-toggle insert-button" type="button" :id="'stepInserMenu_' + step.id" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
|
|
|
{{ i18n.t('protocols.steps.insert.button') }}
|
|
|
|
<span class="caret"></span>
|
|
|
|
</button>
|
2022-08-11 17:10:12 +08:00
|
|
|
<ul ref="actionsDropdown" class="dropdown-menu insert-element-dropdown dropdown-menu-right" :aria-labelledby="'stepInserMenu_' + step.id">
|
2022-04-29 18:29:42 +08:00
|
|
|
<li class="title">
|
|
|
|
{{ i18n.t('protocols.steps.insert.title') }}
|
|
|
|
</li>
|
|
|
|
<li class="action" @click="createElement('table')">
|
|
|
|
<i class="fas fa-table"></i>
|
|
|
|
{{ i18n.t('protocols.steps.insert.table') }}
|
|
|
|
</li>
|
|
|
|
<li class="action" @click="createElement('checklist')">
|
|
|
|
<i class="fas fa-list"></i>
|
|
|
|
{{ i18n.t('protocols.steps.insert.checklist') }}
|
|
|
|
</li>
|
|
|
|
<li class="action" @click="createElement('text')">
|
|
|
|
<i class="fas fa-font"></i>
|
|
|
|
{{ i18n.t('protocols.steps.insert.text') }}
|
|
|
|
</li>
|
2022-09-02 21:09:56 +08:00
|
|
|
<li v-if="attachmentsReady" class="action" @click="showFileModal = true">
|
2022-05-18 17:12:53 +08:00
|
|
|
<i class="fas fa-paperclip"></i>
|
|
|
|
{{ i18n.t('protocols.steps.insert.attachment') }}
|
|
|
|
</li>
|
2022-04-29 18:29:42 +08:00
|
|
|
</ul>
|
|
|
|
</div>
|
2022-05-25 21:04:14 +08:00
|
|
|
<a href="#"
|
2022-06-07 18:10:10 +08:00
|
|
|
v-if="!inRepository"
|
2022-05-25 21:04:14 +08:00
|
|
|
ref="comments"
|
|
|
|
class="open-comments-sidebar btn icon-btn btn-light"
|
|
|
|
data-turbolinks="false"
|
|
|
|
data-object-type="Step"
|
2022-07-12 19:54:10 +08:00
|
|
|
@click="openCommentsSidebar"
|
2022-05-25 21:04:14 +08:00
|
|
|
:data-object-id="step.id">
|
|
|
|
<i class="fas fa-comment"></i>
|
|
|
|
<span class="comments-counter"
|
|
|
|
:id="`comment-count-${step.id}`"
|
|
|
|
:class="{'unseen': step.attributes.unseen_comments}"
|
|
|
|
>
|
|
|
|
{{ step.attributes.comments_count }}
|
|
|
|
</span>
|
|
|
|
</a>
|
2022-06-03 17:52:10 +08:00
|
|
|
<div v-if="urls.update_url" class="step-actions-container">
|
2022-05-30 19:45:51 +08:00
|
|
|
<div class="dropdown">
|
2022-08-18 17:35:30 +08:00
|
|
|
<button class="btn btn-light dropdown-toggle insert-button" type="button" :id="'stepOptionsMenu_' + step.id" data-toggle="dropdown" data-display="static" aria-haspopup="true" aria-expanded="true">
|
2022-07-14 00:02:35 +08:00
|
|
|
<i class="fas fa-ellipsis-h"></i>
|
2022-05-30 19:45:51 +08:00
|
|
|
</button>
|
2022-08-18 17:35:30 +08:00
|
|
|
<ul class="dropdown-menu dropdown-menu-right insert-element-dropdown" :aria-labelledby="'stepOptionsMenu_' + step.id">
|
2022-05-30 19:45:51 +08:00
|
|
|
<li class="title">
|
|
|
|
{{ i18n.t('protocols.steps.options_dropdown.title') }}
|
|
|
|
</li>
|
2022-07-05 18:49:12 +08:00
|
|
|
<li v-if="urls.reorder_elements_url" class="action" @click="openReorderModal" :class="{ 'disabled': elements.length < 2 }">
|
2022-07-11 16:54:18 +08:00
|
|
|
<i class="fas fas-rotated-90 fa-exchange-alt"></i>
|
2022-07-05 18:49:12 +08:00
|
|
|
{{ i18n.t('protocols.steps.options_dropdown.rearrange') }}
|
2022-05-30 19:45:51 +08:00
|
|
|
</li>
|
2022-08-23 23:54:33 +08:00
|
|
|
<li v-if="urls.duplicate_step_url" class="action" @click="duplicateStep">
|
|
|
|
<i class="fas fa-clone"></i>
|
|
|
|
{{ i18n.t('protocols.steps.options_dropdown.duplicate') }}
|
|
|
|
</li>
|
2022-07-05 18:49:12 +08:00
|
|
|
<li v-if="urls.delete_url" class="action" @click="showDeleteModal">
|
|
|
|
<i class="fas fa-trash"></i>
|
|
|
|
{{ i18n.t('protocols.steps.options_dropdown.delete') }}
|
2022-05-30 19:45:51 +08:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-28 17:13:38 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="collapse in" :id="'stepBody' + step.id">
|
2022-06-21 17:32:27 +08:00
|
|
|
<div class="step-elements">
|
2022-08-30 21:26:52 +08:00
|
|
|
<template v-for="(element, index) in orderedElements">
|
2022-06-21 17:32:27 +08:00
|
|
|
<component
|
|
|
|
:is="elements[index].attributes.orderable_type"
|
|
|
|
:key="index"
|
|
|
|
:element.sync="elements[index]"
|
|
|
|
:inRepository="inRepository"
|
2022-07-04 19:55:26 +08:00
|
|
|
:reorderElementUrl="elements.length > 1 ? urls.reorder_elements_url : ''"
|
2022-07-06 20:18:11 +08:00
|
|
|
:isNew="element.isNew"
|
2022-06-21 17:32:27 +08:00
|
|
|
@component:delete="deleteElement"
|
|
|
|
@update="updateElement"
|
|
|
|
@reorder="openReorderModal"
|
2022-08-22 20:02:19 +08:00
|
|
|
@component:insert="insertElement"
|
2022-06-21 17:32:27 +08:00
|
|
|
/>
|
|
|
|
</template>
|
2022-07-21 20:28:21 +08:00
|
|
|
<Attachments v-if="attachments.length"
|
|
|
|
:step="step"
|
2022-06-21 17:32:27 +08:00
|
|
|
:attachments="attachments"
|
2022-09-02 21:09:56 +08:00
|
|
|
:attachmentsReady="attachmentsReady"
|
2022-06-21 17:32:27 +08:00
|
|
|
@attachments:openFileModal="showFileModal = true"
|
2022-07-15 19:46:48 +08:00
|
|
|
@attachment:deleted="attachmentDeleted"
|
2022-07-21 20:28:21 +08:00
|
|
|
@attachment:uploaded="loadAttachments"
|
2022-06-21 17:32:27 +08:00
|
|
|
@attachments:order="changeAttachmentsOrder"
|
|
|
|
@attachments:viewMode="changeAttachmentsViewMode"
|
|
|
|
@attachment:viewMode="updateAttachmentViewMode"/>
|
|
|
|
</div>
|
2022-05-12 18:05:41 +08:00
|
|
|
</div>
|
2022-05-04 21:57:13 +08:00
|
|
|
<deleteStepModal v-if="confirmingDelete" @confirm="deleteStep" @cancel="closeDeleteModal"/>
|
2022-05-24 17:30:15 +08:00
|
|
|
<fileModal v-if="showFileModal"
|
|
|
|
:step="step"
|
|
|
|
@cancel="showFileModal = false"
|
|
|
|
@files="uploadFiles"
|
|
|
|
@attachmentUploaded="addAttachment"
|
|
|
|
@attachmentsChanged="loadAttachments"
|
2022-07-06 17:43:30 +08:00
|
|
|
@copyPasteImageModal="copyPasteImageModal"
|
|
|
|
/>
|
|
|
|
<clipboardPasteModal v-if="showClipboardPasteModal"
|
|
|
|
:step="step"
|
|
|
|
:image="pasteImages"
|
|
|
|
@files="uploadFiles"
|
|
|
|
@cancel="showClipboardPasteModal = false"
|
2022-05-24 17:30:15 +08:00
|
|
|
/>
|
2022-05-30 19:45:51 +08:00
|
|
|
<ReorderableItemsModal v-if="reordering"
|
2022-07-13 21:15:01 +08:00
|
|
|
:title="i18n.t('protocols.steps.modals.reorder_elements.title', { step_position: step.attributes.position + 1 })"
|
2022-05-30 19:45:51 +08:00
|
|
|
:items="reorderableElements"
|
|
|
|
@reorder="updateElementOrder"
|
|
|
|
@close="closeReorderModal"
|
|
|
|
/>
|
2022-04-22 19:07:51 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-05-30 19:45:51 +08:00
|
|
|
const ICON_MAP = {
|
|
|
|
'Checklist': 'fa-list-ul',
|
|
|
|
'StepText': 'fa-font',
|
|
|
|
'StepTable': 'fa-table'
|
|
|
|
}
|
|
|
|
|
2022-04-28 17:13:38 +08:00
|
|
|
import InlineEdit from 'vue/shared/inline_edit.vue'
|
2022-05-30 19:45:51 +08:00
|
|
|
import StepTable from 'vue/protocol/step_elements/table.vue'
|
|
|
|
import StepText from 'vue/protocol/step_elements/text.vue'
|
|
|
|
import Checklist from 'vue/protocol/step_elements/checklist.vue'
|
2022-05-04 21:57:13 +08:00
|
|
|
import deleteStepModal from 'vue/protocol/modals/delete_step.vue'
|
2022-05-19 17:13:34 +08:00
|
|
|
import Attachments from 'vue/protocol/attachments.vue'
|
|
|
|
import fileModal from 'vue/protocol/step_attachments/file_modal.vue'
|
2022-07-06 17:43:30 +08:00
|
|
|
import clipboardPasteModal from 'vue/protocol/step_attachments/clipboard_paste_modal.vue'
|
2022-05-30 19:45:51 +08:00
|
|
|
import ReorderableItemsModal from 'vue/protocol/modals/reorderable_items_modal.vue'
|
|
|
|
|
2022-08-04 17:06:25 +08:00
|
|
|
import UtilsMixin from 'vue/mixins/utils.js'
|
2022-05-19 17:13:34 +08:00
|
|
|
import AttachmentsMixin from 'vue/protocol/mixins/attachments.js'
|
2022-05-26 20:48:57 +08:00
|
|
|
import StorageUsage from 'vue/protocol/storage_usage.vue'
|
2022-04-28 17:13:38 +08:00
|
|
|
|
2022-04-22 19:07:51 +08:00
|
|
|
export default {
|
|
|
|
name: 'StepContainer',
|
|
|
|
props: {
|
|
|
|
step: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
2022-05-27 18:49:10 +08:00
|
|
|
},
|
|
|
|
inRepository: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true
|
|
|
|
},
|
2022-06-03 17:52:10 +08:00
|
|
|
reorderStepUrl: {
|
2022-07-14 21:09:28 +08:00
|
|
|
required: false
|
2022-06-03 17:52:10 +08:00
|
|
|
}
|
2022-04-22 19:07:51 +08:00
|
|
|
},
|
2022-04-29 18:29:42 +08:00
|
|
|
data() {
|
|
|
|
return {
|
2022-05-04 21:57:13 +08:00
|
|
|
elements: [],
|
2022-05-12 18:05:41 +08:00
|
|
|
attachments: [],
|
2022-09-02 21:09:56 +08:00
|
|
|
attachmentsReady: false,
|
2022-05-18 17:12:53 +08:00
|
|
|
confirmingDelete: false,
|
2022-05-25 21:04:14 +08:00
|
|
|
showFileModal: false,
|
2022-07-06 17:43:30 +08:00
|
|
|
showClipboardPasteModal: false,
|
2022-05-24 21:54:22 +08:00
|
|
|
showCommentsSidebar: false,
|
2022-05-30 19:45:51 +08:00
|
|
|
dragingFile: false,
|
2022-07-11 16:45:25 +08:00
|
|
|
reordering: false,
|
2022-07-15 16:13:55 +08:00
|
|
|
isCollapsed: false,
|
2022-07-11 16:45:25 +08:00
|
|
|
editingName: false
|
2022-04-29 18:29:42 +08:00
|
|
|
}
|
|
|
|
},
|
2022-05-30 19:45:51 +08:00
|
|
|
mixins: [UtilsMixin, AttachmentsMixin],
|
2022-04-29 18:29:42 +08:00
|
|
|
components: {
|
|
|
|
InlineEdit,
|
|
|
|
StepTable,
|
|
|
|
StepText,
|
2022-05-04 21:57:13 +08:00
|
|
|
Checklist,
|
2022-05-12 23:05:07 +08:00
|
|
|
deleteStepModal,
|
2022-05-18 17:12:53 +08:00
|
|
|
fileModal,
|
2022-07-06 17:43:30 +08:00
|
|
|
clipboardPasteModal,
|
2022-05-26 20:48:57 +08:00
|
|
|
Attachments,
|
2022-05-30 19:45:51 +08:00
|
|
|
StorageUsage,
|
|
|
|
ReorderableItemsModal
|
2022-04-29 18:29:42 +08:00
|
|
|
},
|
|
|
|
created() {
|
2022-05-24 17:30:15 +08:00
|
|
|
this.loadAttachments();
|
|
|
|
this.loadElements();
|
2022-04-29 18:29:42 +08:00
|
|
|
},
|
2022-05-25 21:04:14 +08:00
|
|
|
mounted() {
|
2022-07-11 16:45:25 +08:00
|
|
|
$(this.$refs.comments).data('closeCallback', this.closeCommentsSidebar);
|
2022-07-12 19:54:10 +08:00
|
|
|
$(this.$refs.comments).data('openCallback', this.closeCommentsSidebar);
|
2022-07-06 20:11:48 +08:00
|
|
|
$(this.$refs.actionsDropdownButton).on('shown.bs.dropdown hidden.bs.dropdown', this.handleDropdownPosition);
|
2022-05-25 21:04:14 +08:00
|
|
|
},
|
2022-05-30 19:45:51 +08:00
|
|
|
computed: {
|
|
|
|
reorderableElements() {
|
2022-08-30 21:26:52 +08:00
|
|
|
return this.orderedElements.map((e) => { return { id: e.id, attributes: e.attributes.orderable } })
|
|
|
|
},
|
|
|
|
orderedElements() {
|
|
|
|
return this.elements.sort((a, b) => a.attributes.position - b.attributes.position);
|
2022-06-03 17:52:10 +08:00
|
|
|
},
|
|
|
|
urls() {
|
|
|
|
return this.step.attributes.urls || {}
|
2022-05-30 19:45:51 +08:00
|
|
|
}
|
|
|
|
},
|
2022-04-22 19:07:51 +08:00
|
|
|
methods: {
|
2022-07-20 19:39:04 +08:00
|
|
|
dragEnter(e) {
|
2022-08-23 23:59:28 +08:00
|
|
|
if (this.showFileModal || !this.urls.upload_attachment_url) return;
|
2022-07-20 19:39:04 +08:00
|
|
|
|
|
|
|
// Detect if dragged element is a file
|
|
|
|
// https://stackoverflow.com/a/8494918
|
|
|
|
let dt = e.dataTransfer;
|
|
|
|
if (dt.types && (dt.types.indexOf ? dt.types.indexOf('Files') != -1 : dt.types.contains('Files'))) {
|
|
|
|
this.dragingFile = true;
|
|
|
|
}
|
|
|
|
},
|
2022-05-24 17:30:15 +08:00
|
|
|
loadAttachments() {
|
2022-09-02 21:09:56 +08:00
|
|
|
this.attachmentsReady = false
|
|
|
|
|
2022-06-03 17:52:10 +08:00
|
|
|
$.get(this.urls.attachments_url, (result) => {
|
2022-05-24 17:30:15 +08:00
|
|
|
this.attachments = result.data
|
2022-09-02 21:09:56 +08:00
|
|
|
|
|
|
|
if (this.attachments.findIndex((e) => e.attributes.attached === false) >= 0) {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.loadAttachments()
|
|
|
|
}, 10000)
|
|
|
|
} else {
|
|
|
|
this.attachmentsReady = true
|
|
|
|
}
|
2022-05-24 17:30:15 +08:00
|
|
|
});
|
2022-07-21 20:28:21 +08:00
|
|
|
this.showFileModal = false;
|
2022-05-24 17:30:15 +08:00
|
|
|
},
|
|
|
|
loadElements() {
|
2022-06-03 17:52:10 +08:00
|
|
|
$.get(this.urls.elements_url, (result) => {
|
2022-05-24 17:30:15 +08:00
|
|
|
this.elements = result.data
|
|
|
|
});
|
|
|
|
},
|
2022-07-15 16:13:55 +08:00
|
|
|
showStorageUsage() {
|
|
|
|
return (this.elements.length || this.attachments.length) && !this.isCollapsed && this.step.attributes.storage_limit;
|
|
|
|
},
|
|
|
|
toggleCollapsed() {
|
|
|
|
this.isCollapsed = !this.isCollapsed;
|
|
|
|
},
|
2022-05-04 21:57:13 +08:00
|
|
|
showDeleteModal() {
|
|
|
|
this.confirmingDelete = true;
|
|
|
|
},
|
|
|
|
closeDeleteModal() {
|
|
|
|
this.confirmingDelete = false;
|
|
|
|
},
|
2022-04-22 19:07:51 +08:00
|
|
|
deleteStep() {
|
|
|
|
$.ajax({
|
2022-06-03 17:52:10 +08:00
|
|
|
url: this.urls.delete_url,
|
2022-04-22 19:07:51 +08:00
|
|
|
type: 'DELETE',
|
|
|
|
success: (result) => {
|
|
|
|
this.$emit(
|
|
|
|
'step:delete',
|
|
|
|
result.data,
|
|
|
|
'delete'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2022-04-28 17:13:38 +08:00
|
|
|
},
|
|
|
|
changeState() {
|
2022-06-03 17:52:10 +08:00
|
|
|
if (!this.urls.state_url) return;
|
|
|
|
|
2022-05-03 21:18:48 +08:00
|
|
|
this.step.attributes.completed = !this.step.attributes.completed;
|
2022-07-07 20:33:38 +08:00
|
|
|
this.$emit('step:update', {
|
|
|
|
completed: this.step.attributes.completed,
|
|
|
|
position: this.step.attributes.position
|
|
|
|
});
|
2022-06-03 17:52:10 +08:00
|
|
|
$.post(this.urls.state_url, {completed: this.step.attributes.completed}).error(() => {
|
2022-05-03 21:18:48 +08:00
|
|
|
this.step.attributes.completed = !this.step.attributes.completed;
|
2022-07-07 20:33:38 +08:00
|
|
|
this.$emit('step:update', {
|
|
|
|
completed: this.step.attributes.completed,
|
|
|
|
position: this.step.attributes.position
|
|
|
|
});
|
2022-05-03 21:18:48 +08:00
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger');
|
2022-04-28 17:13:38 +08:00
|
|
|
})
|
|
|
|
},
|
2022-05-30 19:45:51 +08:00
|
|
|
deleteElement(position) {
|
2022-05-03 21:15:49 +08:00
|
|
|
this.elements.splice(position, 1)
|
2022-05-30 19:45:51 +08:00
|
|
|
let unorderedElements = this.elements.map( e => {
|
2022-05-03 21:15:49 +08:00
|
|
|
if (e.attributes.position >= position) {
|
|
|
|
e.attributes.position -= 1;
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
})
|
2022-07-15 19:46:48 +08:00
|
|
|
this.$emit('stepUpdated')
|
2022-05-03 21:15:49 +08:00
|
|
|
},
|
2022-08-12 16:17:45 +08:00
|
|
|
updateElement(element, skipRequest=false, callback) {
|
2022-05-05 18:56:31 +08:00
|
|
|
let index = this.elements.findIndex((e) => e.id === element.id);
|
2022-07-25 17:40:28 +08:00
|
|
|
this.elements[index].isNew = false;
|
2022-05-05 18:56:31 +08:00
|
|
|
|
2022-05-10 19:28:09 +08:00
|
|
|
if (skipRequest) {
|
2022-07-08 19:49:22 +08:00
|
|
|
this.elements[index].attributes.orderable = element.attributes.orderable;
|
2022-07-15 19:46:48 +08:00
|
|
|
this.$emit('stepUpdated');
|
2022-05-10 19:28:09 +08:00
|
|
|
} else {
|
|
|
|
$.ajax({
|
|
|
|
url: element.attributes.orderable.urls.update_url,
|
|
|
|
method: 'PUT',
|
|
|
|
data: element.attributes.orderable,
|
|
|
|
success: (result) => {
|
2022-07-08 19:49:22 +08:00
|
|
|
this.elements[index].attributes.orderable = result.data.attributes;
|
2022-07-15 19:46:48 +08:00
|
|
|
this.$emit('stepUpdated');
|
2022-08-12 16:17:45 +08:00
|
|
|
|
|
|
|
// optional callback after successful update
|
|
|
|
if(typeof callback === 'function') {
|
|
|
|
callback();
|
|
|
|
}
|
2022-05-10 19:28:09 +08:00
|
|
|
}
|
|
|
|
}).error(() => {
|
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger');
|
|
|
|
})
|
|
|
|
}
|
2022-05-05 18:56:31 +08:00
|
|
|
},
|
2022-05-30 19:45:51 +08:00
|
|
|
updateElementOrder(orderedElements) {
|
|
|
|
orderedElements.forEach((element, position) => {
|
|
|
|
let index = this.elements.findIndex((e) => e.id === element.id);
|
2022-06-01 18:30:09 +08:00
|
|
|
this.elements[index].attributes.position = position;
|
2022-05-30 19:45:51 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let elementPositions =
|
|
|
|
{
|
|
|
|
step_orderable_element_positions: this.elements.map(
|
|
|
|
(element) => [element.id, element.attributes.position]
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
2022-06-03 17:52:10 +08:00
|
|
|
url: this.urls.reorder_elements_url,
|
2022-05-30 19:45:51 +08:00
|
|
|
data: JSON.stringify(elementPositions),
|
|
|
|
contentType: "application/json",
|
|
|
|
dataType: "json",
|
2022-08-09 20:15:49 +08:00
|
|
|
error: (() => HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger')),
|
|
|
|
success: (() => this.$emit('stepUpdated'))
|
2022-05-30 19:45:51 +08:00
|
|
|
});
|
|
|
|
},
|
2022-04-28 17:13:38 +08:00
|
|
|
updateName(newName) {
|
|
|
|
$.ajax({
|
2022-06-03 17:52:10 +08:00
|
|
|
url: this.urls.update_url,
|
2022-04-28 17:13:38 +08:00
|
|
|
type: 'PATCH',
|
|
|
|
data: {step: {name: newName}},
|
|
|
|
success: (result) => {
|
2022-07-07 20:33:38 +08:00
|
|
|
this.$emit('step:update', {
|
|
|
|
name: result.data.attributes.name,
|
|
|
|
position: this.step.attributes.position
|
|
|
|
})
|
2022-04-28 17:13:38 +08:00
|
|
|
}
|
|
|
|
});
|
2022-04-29 18:29:42 +08:00
|
|
|
},
|
|
|
|
createElement(elementType) {
|
2022-06-03 17:52:10 +08:00
|
|
|
$.post(this.urls[`create_${elementType}_url`], (result) => {
|
2022-07-06 20:18:11 +08:00
|
|
|
result.data.isNew = true;
|
2022-04-29 18:29:42 +08:00
|
|
|
this.elements.push(result.data)
|
|
|
|
}).error(() => {
|
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger');
|
|
|
|
})
|
2022-05-16 17:05:18 +08:00
|
|
|
},
|
2022-05-24 17:13:47 +08:00
|
|
|
addAttachment(attachment) {
|
|
|
|
this.attachments.push(attachment);
|
2022-07-21 20:28:21 +08:00
|
|
|
this.showFileModal = false;
|
2022-05-25 21:04:14 +08:00
|
|
|
},
|
2022-07-12 19:54:10 +08:00
|
|
|
openCommentsSidebar() {
|
|
|
|
$('.comments-sidebar .close-btn').click();
|
|
|
|
this.showCommentsSidebar = true
|
|
|
|
},
|
2022-07-26 19:42:25 +08:00
|
|
|
attachmentDeleted(id) {
|
|
|
|
this.attachments = this.attachments.filter((a) => a.id !== id );
|
2022-07-15 19:46:48 +08:00
|
|
|
this.$emit('stepUpdated');
|
|
|
|
},
|
2022-05-25 21:04:14 +08:00
|
|
|
closeCommentsSidebar() {
|
|
|
|
this.showCommentsSidebar = false
|
2022-05-30 19:45:51 +08:00
|
|
|
},
|
|
|
|
openReorderModal() {
|
|
|
|
this.reordering = true;
|
|
|
|
},
|
|
|
|
closeReorderModal() {
|
|
|
|
this.reordering = false;
|
2022-07-06 17:43:30 +08:00
|
|
|
},
|
2022-07-06 20:11:48 +08:00
|
|
|
handleDropdownPosition() {
|
|
|
|
this.$refs.actionsDropdownButton.classList.toggle("dropup", !this.isInViewport(this.$refs.actionsDropdown));
|
|
|
|
},
|
|
|
|
isInViewport(el) {
|
|
|
|
let rect = el.getBoundingClientRect();
|
|
|
|
|
|
|
|
return (
|
|
|
|
rect.top >= 0 &&
|
|
|
|
rect.left >= 0 &&
|
|
|
|
rect.bottom <= (window.innerHeight || $(window).height()) &&
|
|
|
|
rect.right <= (window.innerWidth || $(window).width())
|
|
|
|
);
|
|
|
|
},
|
2022-07-06 17:43:30 +08:00
|
|
|
copyPasteImageModal(pasteImages) {
|
|
|
|
this.pasteImages = pasteImages;
|
|
|
|
this.showClipboardPasteModal = true;
|
2022-08-22 20:02:19 +08:00
|
|
|
},
|
|
|
|
insertElement(element) {
|
|
|
|
let position = element.attributes.position;
|
2022-08-30 21:26:52 +08:00
|
|
|
this.elements = this.elements.map( s => {
|
2022-08-22 20:02:19 +08:00
|
|
|
if (s.attributes.position >= position) {
|
|
|
|
s.attributes.position += 1;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
})
|
2022-08-30 21:26:52 +08:00
|
|
|
this.elements.push(element);
|
2022-08-23 23:54:33 +08:00
|
|
|
},
|
|
|
|
duplicateStep() {
|
|
|
|
$.post(this.urls.duplicate_step_url, (result) => {
|
|
|
|
this.$emit('step:insert', result.data);
|
2022-08-24 19:45:39 +08:00
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('protocols.steps.step_duplicated'), 'success');
|
|
|
|
}).error(() => {
|
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('protocols.steps.step_duplication_failed'), 'danger');
|
2022-08-23 23:54:33 +08:00
|
|
|
});
|
2022-05-24 17:13:47 +08:00
|
|
|
}
|
2022-04-22 19:07:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|