2022-05-11 21:51:26 +08:00
|
|
|
<template>
|
|
|
|
<div class="step-checklist-item">
|
2022-06-02 18:02:34 +08:00
|
|
|
<div class="step-element-header" :class="{ 'locked': locked || editingText, 'editing-name': editingText }">
|
2022-06-03 17:52:10 +08:00
|
|
|
<div v-if="reorderChecklistItemUrl" class="step-element-grip">
|
2022-05-11 21:51:26 +08:00
|
|
|
<i class="fas fa-grip-vertical"></i>
|
|
|
|
</div>
|
|
|
|
<div class="step-element-name" :class="{ 'done': checklistItem.attributes.checked }">
|
2022-06-07 18:10:10 +08:00
|
|
|
<div class="sci-checkbox-container" :class="{ 'disabled': !updateUrl || inRepository}">
|
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>
|
|
|
|
<div class="step-checklist-text">
|
|
|
|
<InlineEdit
|
2022-06-07 18:10:10 +08:00
|
|
|
v-if="!checklistItem.attributes.urls || updateUrl"
|
2022-05-11 21:51:26 +08:00
|
|
|
: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-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
|
|
|
/>
|
2022-06-03 17:52:10 +08:00
|
|
|
<span v-else>
|
|
|
|
{{ checklistItem.attributes.text }}
|
|
|
|
</span>
|
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-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;
|
|
|
|
},
|
|
|
|
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();
|
|
|
|
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-06-07 18:10:10 +08:00
|
|
|
if (!this.updateUrl) return
|
2022-05-11 21:51:26 +08:00
|
|
|
this.checklistItem.attributes.checked = this.$refs.checkbox.checked;
|
|
|
|
this.update();
|
|
|
|
},
|
|
|
|
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>
|