2022-05-30 19:45:51 +08:00
|
|
|
<template>
|
|
|
|
<div ref="modal" @keydown.esc="close" class="modal sci-reorderable-items" tabindex="-1" role="dialog">
|
|
|
|
<div class="modal-dialog" role="document">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
2023-08-17 19:55:17 +08:00
|
|
|
<button @click="close" type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="sn-icon sn-icon-close"></i></button>
|
2022-05-30 19:45:51 +08:00
|
|
|
<h4 class="modal-title">
|
|
|
|
{{ title }}
|
|
|
|
</h4>
|
|
|
|
</div>
|
|
|
|
<div class="modal-body">
|
|
|
|
<Draggable
|
|
|
|
v-model="reorderedItems"
|
|
|
|
:ghostClass="'step-checklist-item-ghost'"
|
|
|
|
:dragClass="'step-checklist-item-drag'"
|
|
|
|
:chosenClass="'step-checklist-item-chosen'"
|
|
|
|
:handle="'.step-element-grip'"
|
2023-11-02 17:38:33 +08:00
|
|
|
item-key="id"
|
2022-05-30 19:45:51 +08:00
|
|
|
>
|
2023-11-02 17:38:33 +08:00
|
|
|
<template #item="{element, index}">
|
|
|
|
<div class="step-element-header flex items-center">
|
|
|
|
<div class="step-element-grip step-element-grip--draggable">
|
|
|
|
<i class="sn-icon sn-icon-drag"></i>
|
|
|
|
</div>
|
2023-11-20 18:38:41 +08:00
|
|
|
<div class="step-element-name text-center flex items-center gap-2">
|
2023-11-02 17:38:33 +08:00
|
|
|
<strong v-if="includeNumbers" class="step-element-number">{{ index + 1 }}</strong>
|
|
|
|
<i v-if="element.attributes.icon" class="fas" :class="element.attributes.icon"></i>
|
|
|
|
<span :title="nameWithFallbacks(element)" v-if="nameWithFallbacks(element)">{{ nameWithFallbacks(element) }}</span>
|
|
|
|
<span :title="element.attributes.placeholder" v-else class="step-element-name-placeholder">{{ element.attributes.placeholder }}</span>
|
|
|
|
</div>
|
2022-05-30 19:45:51 +08:00
|
|
|
</div>
|
2023-11-02 17:38:33 +08:00
|
|
|
</template>
|
2022-05-30 19:45:51 +08:00
|
|
|
</Draggable>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
2024-01-04 23:34:36 +08:00
|
|
|
<script>
|
|
|
|
import Draggable from 'vuedraggable';
|
2022-05-30 19:45:51 +08:00
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
export default {
|
|
|
|
name: 'ReorderableItems',
|
|
|
|
components: {
|
|
|
|
Draggable
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
2022-05-30 19:45:51 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
required: true
|
2022-05-30 19:45:51 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
includeNumbers: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
reorderedItems: [...this.items]
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
window.$(this.$refs.modal).modal('show');
|
|
|
|
window.$(this.$refs.modal).on('hidden.bs.modal', () => {
|
|
|
|
this.close();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
close() {
|
|
|
|
this.$emit('reorder', this.reorderedItems);
|
|
|
|
this.$emit('close');
|
2022-05-30 19:45:51 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
getTitle(item) {
|
|
|
|
const $item_html = $(item.attributes.text);
|
|
|
|
$item_html.remove('table, img');
|
|
|
|
const str = $item_html.text().trim();
|
|
|
|
return str.length > 56 ? `${str.slice(0, 56)}...` : str;
|
2022-05-30 19:45:51 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
nameWithFallbacks(item) {
|
|
|
|
return this.getTitle(item) || item.attributes.name;
|
2022-05-30 19:45:51 +08:00
|
|
|
}
|
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
};
|
2022-05-30 19:45:51 +08:00
|
|
|
</script>
|