2022-05-11 21:51:26 +08:00
|
|
|
<template>
|
2023-07-24 19:28:44 +08:00
|
|
|
<div class="content__checklist-item">
|
2023-09-14 18:12:15 +08:00
|
|
|
<div class="checklist-item-header flex rounded pl-10 ml-[-2.325rem] items-center relative w-full group/checklist-item-header" :class="{ 'locked': locked || editingText, 'editing-name': editingText }">
|
2023-07-24 19:28:44 +08:00
|
|
|
<div v-if="reorderChecklistItemUrl"
|
2023-09-14 18:12:15 +08:00
|
|
|
class="absolute h-6 cursor-grab justify-center left-0 top-1 px-2 tw-hidden text-sn-grey element-grip step-element-grip--draggable"
|
2023-07-24 19:28:44 +08:00
|
|
|
:class="{ 'group-hover/checklist-item-header:flex': (!locked && !editingText && draggable) }"
|
|
|
|
>
|
2023-06-08 14:33:37 +08:00
|
|
|
<i class="sn-icon sn-icon-drag"></i>
|
2022-05-11 21:51:26 +08:00
|
|
|
</div>
|
2023-09-14 18:12:15 +08:00
|
|
|
<div class="flex items-start gap-2 grow pt-[1px]" :class="{ 'done': checklistItem.attributes.checked }">
|
2023-09-11 23:15:00 +08:00
|
|
|
<div v-if="!inRepository" class="sci-checkbox-container my-1.5 border-y border-transparent border-solid w-6" :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>
|
2023-07-24 19:28:44 +08:00
|
|
|
<div v-else class="w-6"></div>
|
2023-09-14 18:12:15 +08:00
|
|
|
<div class="pr-10 grow relative flex items-start" :class="{ 'pointer-events-none': !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"
|
2023-09-11 23:15:00 +08:00
|
|
|
:singleLine="false"
|
2022-05-11 21:51:26 +08:00
|
|
|
: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
|
|
|
/>
|
2023-09-14 18:12:15 +08:00
|
|
|
<span v-if="!checklistItem.attributes.urls || deleteUrl" class="absolute right-0 leading-6 tw-hidden group-hover/checklist-item-header:inline-block !text-sn-blue cursor-pointer" @click="showDeleteModal" tabindex="0">
|
|
|
|
<i class="sn-icon sn-icon-delete"></i>
|
|
|
|
</span>
|
2022-05-11 21:51:26 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-02-17 22:59:37 +08:00
|
|
|
<deleteElementModal v-if="confirmingDelete" @confirm="deleteElement" @cancel="closeDeleteModal"/>
|
2022-05-11 21:51:26 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-07-21 16:35:14 +08:00
|
|
|
import DeleteMixin from './mixins/delete.js'
|
|
|
|
import InlineEdit from '../inline_edit.vue'
|
|
|
|
import deleteElementModal from './modal/delete.vue'
|
2022-05-11 21:51:26 +08:00
|
|
|
|
|
|
|
export default {
|
2022-07-06 20:06:16 +08:00
|
|
|
name: 'ChecklistItem',
|
2023-02-17 22:59:37 +08:00
|
|
|
components: { InlineEdit, deleteElementModal },
|
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>
|