2022-05-11 21:51:26 +08:00
|
|
|
<template>
|
2022-08-23 16:10:20 +08:00
|
|
|
<div class="step-checklist-item" :class="{ 'step-element--locked': !checklistItem.attributes.isNew && !(updateUrl || toggleUrl) }">
|
2022-06-02 18:02:34 +08:00
|
|
|
<div class="step-element-header" :class="{ 'locked': locked || editingText, 'editing-name': editingText }">
|
2022-07-21 15:57:14 +08:00
|
|
|
<div v-if="reorderChecklistItemUrl" class="step-element-grip step-element-grip--draggable" :class="{ 'step-element-grip--disabled': !draggable }">
|
2022-05-11 21:51:26 +08:00
|
|
|
<i class="fas fa-grip-vertical"></i>
|
|
|
|
</div>
|
2022-07-15 20:58:06 +08:00
|
|
|
<div v-else class="step-element-grip-placeholder"></div>
|
2022-05-11 21:51:26 +08:00
|
|
|
<div class="step-element-name" :class="{ 'done': checklistItem.attributes.checked }">
|
2022-08-24 00:10:28 +08:00
|
|
|
<div v-if="!inRepository" class="sci-checkbox-container" :class="{ 'disabled': !toggleUrl }">
|
2022-06-03 17:52:10 +08:00
|
|
|
<input ref="checkbox"
|
|
|
|
type="checkbox"
|
|
|
|
class="sci-checkbox"
|
2022-07-12 16:41:58 +08:00
|
|
|
:disabled="checklistItem.attributes.isNew"
|
2022-06-03 17:52:10 +08:00
|
|
|
:checked="checklistItem.attributes.checked" @change="toggleChecked($event)" />
|
|
|
|
<span class="sci-checkbox-label" >
|
2022-05-11 21:51:26 +08:00
|
|
|
</span>
|
|
|
|
</div>
|
2022-07-15 20:58:06 +08:00
|
|
|
<div v-else class="sci-checkbox-view-mode"></div>
|
2022-08-24 00:10:28 +08:00
|
|
|
<div class="step-checklist-text" :class="{ 'step-element--locked': !checklistItem.attributes.isNew && !updateUrl }">
|
2022-05-11 21:51:26 +08:00
|
|
|
<InlineEdit
|
|
|
|
:value="checklistItem.attributes.text"
|
2022-07-08 18:51:43 +08:00
|
|
|
:sa_value="checklistItem.attributes.sa_text"
|
2022-05-11 21:51:26 +08:00
|
|
|
:characterLimit="10000"
|
2022-07-11 17:52:38 +08:00
|
|
|
:placeholder="'Add a checklist item...'"
|
2022-05-11 21:51:26 +08:00
|
|
|
:allowBlank="true"
|
|
|
|
:autofocus="editingText"
|
|
|
|
:attributeName="`${i18n.t('ChecklistItem')} ${i18n.t('name')}`"
|
|
|
|
:multilinePaste="true"
|
2022-07-12 16:41:58 +08:00
|
|
|
:editOnload="checklistItem.attributes.isNew"
|
2022-07-08 18:51:43 +08:00
|
|
|
:smartAnnotation="true"
|
2022-07-25 17:21:31 +08:00
|
|
|
:saveOnEnter="false"
|
|
|
|
:allowNewLine="true"
|
2022-05-11 21:51:26 +08:00
|
|
|
@editingEnabled="enableTextEdit"
|
|
|
|
@editingDisabled="disableTextEdit"
|
|
|
|
@update="updateText"
|
2022-07-06 20:06:16 +08:00
|
|
|
@delete="removeItem()"
|
2022-05-26 20:02:02 +08:00
|
|
|
@multilinePaste="(data) => { $emit('multilinePaste', data) && removeItem() }"
|
2022-05-11 21:51:26 +08:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="step-element-controls">
|
2022-07-06 20:31:55 +08:00
|
|
|
<button v-if="!checklistItem.attributes.urls || updateUrl" class="btn icon-btn btn-light" @click="enableTextEdit" tabindex="-1">
|
2022-05-11 21:51:26 +08:00
|
|
|
<i class="fas fa-pen"></i>
|
|
|
|
</button>
|
2022-07-12 16:41:58 +08:00
|
|
|
<button v-if="!checklistItem.attributes.urls || deleteUrl" class="btn icon-btn btn-light" @click="deleteElement" tabindex="-1">
|
2022-05-11 21:51:26 +08:00
|
|
|
<i class="fas fa-trash"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import DeleteMixin from 'vue/protocol/mixins/components/delete.js'
|
|
|
|
import InlineEdit from 'vue/shared/inline_edit.vue'
|
|
|
|
|
|
|
|
export default {
|
2022-07-06 20:06:16 +08:00
|
|
|
name: 'ChecklistItem',
|
2022-07-12 16:41:58 +08:00
|
|
|
components: { InlineEdit },
|
2022-05-11 21:51:26 +08:00
|
|
|
mixins: [DeleteMixin],
|
|
|
|
props: {
|
|
|
|
checklistItem: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
2022-05-26 20:02:02 +08:00
|
|
|
},
|
|
|
|
locked: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2022-06-03 17:52:10 +08:00
|
|
|
},
|
2022-07-21 15:57:14 +08:00
|
|
|
draggable: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2022-06-07 18:10:10 +08:00
|
|
|
inRepository: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true
|
|
|
|
},
|
2022-06-03 17:52:10 +08:00
|
|
|
reorderChecklistItemUrl: {
|
|
|
|
type: String
|
2022-05-11 21:51:26 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
editingText: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
element() { // remap and alias to work with delete mixin
|
2022-06-02 17:15:32 +08:00
|
|
|
return({
|
|
|
|
attributes: {
|
|
|
|
orderable: this.checklistItem.attributes,
|
|
|
|
position: this.checklistItem.attributes.position
|
|
|
|
}
|
|
|
|
});
|
2022-06-07 18:10:10 +08:00
|
|
|
},
|
|
|
|
updateUrl() {
|
|
|
|
if (!this.checklistItem.attributes.urls) return
|
|
|
|
|
|
|
|
return this.checklistItem.attributes.urls.update_url;
|
|
|
|
},
|
2022-07-14 21:09:28 +08:00
|
|
|
toggleUrl() {
|
|
|
|
if (!this.checklistItem.attributes.urls) return
|
|
|
|
|
|
|
|
return this.checklistItem.attributes.urls.toggle_url;
|
|
|
|
},
|
2022-06-07 18:10:10 +08:00
|
|
|
deleteUrl() {
|
|
|
|
if (!this.checklistItem.attributes.urls) return
|
|
|
|
|
|
|
|
return this.checklistItem.attributes.urls.delete_url;
|
2022-05-11 21:51:26 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
enableTextEdit() {
|
|
|
|
this.editingText = true;
|
2022-05-26 20:02:02 +08:00
|
|
|
this.$emit('editStart');
|
2022-05-11 21:51:26 +08:00
|
|
|
},
|
|
|
|
disableTextEdit() {
|
2022-07-12 16:41:58 +08:00
|
|
|
if (this.checklistItem.attributes.isNew) {
|
|
|
|
this.removeItem();
|
2022-08-01 19:25:29 +08:00
|
|
|
this.$emit('editEnd');
|
2022-08-02 16:18:25 +08:00
|
|
|
this.editingText = false;
|
2022-07-12 16:41:58 +08:00
|
|
|
return;
|
|
|
|
}
|
2022-05-11 21:51:26 +08:00
|
|
|
this.editingText = false;
|
2022-05-26 20:02:02 +08:00
|
|
|
this.$emit('editEnd');
|
2022-05-11 21:51:26 +08:00
|
|
|
},
|
2022-06-03 17:52:10 +08:00
|
|
|
toggleChecked(e) {
|
2022-07-14 21:09:28 +08:00
|
|
|
if (!this.toggleUrl) return
|
2022-05-11 21:51:26 +08:00
|
|
|
this.checklistItem.attributes.checked = this.$refs.checkbox.checked;
|
2022-07-14 21:09:28 +08:00
|
|
|
this.$emit('toggle', this.checklistItem);
|
2022-05-11 21:51:26 +08:00
|
|
|
},
|
|
|
|
updateText(text) {
|
|
|
|
if (text.length === 0) {
|
|
|
|
this.disableTextEdit();
|
2022-07-06 20:06:16 +08:00
|
|
|
this.removeItem();
|
2022-05-11 21:51:26 +08:00
|
|
|
} else {
|
|
|
|
this.checklistItem.attributes.text = text;
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeItem() {
|
2022-07-06 20:06:16 +08:00
|
|
|
if (this.deleteUrl) {
|
|
|
|
this.deleteElement();
|
|
|
|
} else {
|
|
|
|
this.$emit('removeItem', this.checklistItem.attributes.position);
|
|
|
|
}
|
2022-05-11 21:51:26 +08:00
|
|
|
},
|
|
|
|
update() {
|
|
|
|
this.$emit('update', this.checklistItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|