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-22 01:24:58 +08:00
|
|
|
class="absolute h-6 cursor-grab justify-center left-0 top-0.5 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-22 01:24:58 +08:00
|
|
|
<div class="flex items-start gap-2 grow" :class="{ 'done': checklistItem.attributes.checked }">
|
2023-10-11 17:33:04 +08:00
|
|
|
<div v-if="!inRepository" class="sci-checkbox-container my-1.5 border-0 border-y border-transparent border-solid" :class="{ 'disabled': !toggleUrl }" :style="toggleUrl && 'pointer-events: initial'">
|
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-10-09 17:39:22 +08:00
|
|
|
<div v-else class="h-1 w-1 bg-sn-black rounded-full mt-auto mb-auto"></div>
|
2023-09-22 01:24:58 +08:00
|
|
|
<div class="pr-24 relative flex items-start max-w-[90ch]"
|
|
|
|
:class="{
|
|
|
|
'pointer-events-none': !checklistItem.attributes.isNew && !updateUrl,
|
|
|
|
'flex-grow': editingText,
|
|
|
|
}">
|
2022-05-11 21:51:26 +08:00
|
|
|
<InlineEdit
|
2023-10-06 20:32:39 +08:00
|
|
|
:class="{ 'pointer-events-none': reordering }"
|
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"
|
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')}`"
|
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()"
|
2023-09-22 01:24:58 +08:00
|
|
|
@keypress="keyPressHandler"
|
|
|
|
@blur="editingText = false"
|
2022-05-11 21:51:26 +08:00
|
|
|
/>
|
2023-09-22 01:24:58 +08:00
|
|
|
<span v-if="!editingText && (!checklistItem.attributes.urls || deleteUrl)" class="absolute right-0 top-0.5 leading-6 tw-hidden group-hover/checklist-item-header:inline-block !text-sn-blue cursor-pointer" @click="showDeleteModal" tabindex="0">
|
2023-09-14 18:12:15 +08:00
|
|
|
<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
|
2023-10-06 20:32:39 +08:00
|
|
|
},
|
|
|
|
reordering: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true
|
2022-05-11 21:51:26 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2023-09-22 01:24:58 +08:00
|
|
|
editingText: false,
|
|
|
|
deleting: false
|
2022-05-11 21:51:26 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
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) {
|
2023-09-22 01:24:58 +08:00
|
|
|
if (this.deleting) return
|
|
|
|
|
2022-07-12 16:41:58 +08:00
|
|
|
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
|
|
|
},
|
2023-09-22 01:24:58 +08:00
|
|
|
updateText(text, withKey) {
|
2022-05-11 21:51:26 +08:00
|
|
|
if (text.length === 0) {
|
|
|
|
this.disableTextEdit();
|
|
|
|
} else {
|
|
|
|
this.checklistItem.attributes.text = text;
|
2023-09-22 01:24:58 +08:00
|
|
|
this.update(withKey);
|
2022-05-11 21:51:26 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
removeItem() {
|
2023-09-22 01:24:58 +08:00
|
|
|
this.deleting = true;
|
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
|
|
|
},
|
2023-09-22 01:24:58 +08:00
|
|
|
update(withKey) {
|
|
|
|
this.$emit('update', this.checklistItem, withKey);
|
|
|
|
},
|
|
|
|
keyPressHandler(e) {
|
|
|
|
if (e.key === 'Enter' && e.shiftKey) {
|
|
|
|
this.checklistItem.attributes.with_paragraphs = true;
|
|
|
|
}
|
|
|
|
},
|
2022-05-11 21:51:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|