scinote-web/app/javascript/vue/protocol/step_elements/checklistItem.vue
artoscinote 23872f519b
Implement step element sorting modal [SCI-6849] (#4124)
* Implement step element sorting modal [SCI-6849]

* Implement step reordering modal [SCI-6850]

* Refactor reorderable items a bit [SCI-6850]
2022-05-30 13:45:51 +02:00

102 lines
3.2 KiB
Vue

<template>
<div class="step-checklist-item">
<div class="step-element-header" :class="{ 'locked': locked || editingText }">
<div class="step-element-grip">
<i class="fas fa-grip-vertical"></i>
</div>
<div class="step-element-name" :class="{ 'done': checklistItem.attributes.checked }">
<div class="sci-checkbox-container">
<input ref="checkbox" type="checkbox" class="sci-checkbox" :checked="checklistItem.attributes.checked" @change="toggleChecked" />
<span class="sci-checkbox-label">
</span>
</div>
<div class="step-checklist-text">
<InlineEdit
:value="checklistItem.attributes.text"
:characterLimit="10000"
:placeholder="''"
:allowBlank="true"
:autofocus="editingText"
:attributeName="`${i18n.t('ChecklistItem')} ${i18n.t('name')}`"
:multilinePaste="true"
@editingEnabled="enableTextEdit"
@editingDisabled="disableTextEdit"
@update="updateText"
@delete="checklistItem.attributes.id ? deleteElement() : removeItem()"
@multilinePaste="(data) => { $emit('multilinePaste', data) && removeItem() }"
/>
</div>
</div>
<div class="step-element-controls">
<button class="btn icon-btn btn-light" @click="enableTextEdit">
<i class="fas fa-pen"></i>
</button>
<button class="btn icon-btn btn-light" @click="showDeleteModal">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
<deleteElementModal v-if="confirmingDelete" @confirm="deleteElement" @cancel="closeDeleteModal"/>
</div>
</template>
<script>
import DeleteMixin from 'vue/protocol/mixins/components/delete.js'
import deleteElementModal from 'vue/protocol/modals/delete_element.vue'
import InlineEdit from 'vue/shared/inline_edit.vue'
export default {
name: 'Checklist',
components: { deleteElementModal, InlineEdit },
mixins: [DeleteMixin],
props: {
checklistItem: {
type: Object,
required: true
},
locked: {
type: Boolean,
default: false
}
},
data() {
return {
editingText: false
}
},
computed: {
element() { // remap and alias to work with delete mixin
return { attributes: { orderable: this.checklistItem.attributes } }
}
},
methods: {
enableTextEdit() {
this.editingText = true;
this.$emit('editStart');
},
disableTextEdit() {
this.editingText = false;
this.$emit('editEnd');
},
toggleChecked() {
this.checklistItem.attributes.checked = this.$refs.checkbox.checked;
this.update();
},
updateText(text) {
if (text.length === 0) {
this.disableTextEdit();
this.deleteElement();
} else {
this.checklistItem.attributes.text = text;
this.update();
}
},
removeItem() {
this.$emit('removeItem', this.checklistItem);
},
update() {
this.$emit('update', this.checklistItem);
}
}
}
</script>