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-09-22 17:59:39 +08:00
|
|
|
<div v-for="(item, index) in reorderedItems" :key="item.id" class="step-element-header flex items-center">
|
2022-07-20 16:14:23 +08:00
|
|
|
<div class="step-element-grip step-element-grip--draggable">
|
2023-06-08 14:33:37 +08:00
|
|
|
<i class="sn-icon sn-icon-drag"></i>
|
2022-05-30 19:45:51 +08:00
|
|
|
</div>
|
2023-09-21 14:52:41 +08:00
|
|
|
<div class="step-element-name text-center">
|
2022-05-30 19:45:51 +08:00
|
|
|
<strong v-if="includeNumbers" class="step-element-number">{{ index + 1 }}</strong>
|
|
|
|
<i v-if="item.attributes.icon" class="fas" :class="item.attributes.icon"></i>
|
2023-01-21 05:08:17 +08:00
|
|
|
<span :title="nameWithFallbacks(item)" v-if="nameWithFallbacks(item)">{{ nameWithFallbacks(item) }}</span>
|
2022-12-16 21:22:06 +08:00
|
|
|
<span :title="item.attributes.placeholder" v-else class="step-element-name-placeholder">{{ item.attributes.placeholder }}</span>
|
2022-05-30 19:45:51 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Draggable>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import Draggable from 'vuedraggable'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ReorderableItems',
|
|
|
|
components: {
|
|
|
|
Draggable
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
includeNumbers: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
reorderedItems: [...this.items]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
2023-08-09 19:58:25 +08:00
|
|
|
window.$(this.$refs.modal).modal('show');
|
|
|
|
window.$(this.$refs.modal).on('hidden.bs.modal', () => {
|
2023-04-10 15:27:44 +08:00
|
|
|
this.close();
|
|
|
|
})
|
2022-05-30 19:45:51 +08:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
close() {
|
|
|
|
this.$emit('reorder', this.reorderedItems);
|
2023-05-04 15:48:59 +08:00
|
|
|
this.$emit('close');
|
2022-12-12 23:17:57 +08:00
|
|
|
},
|
|
|
|
getTitle(item) {
|
|
|
|
let $item_html = $(item.attributes.text);
|
|
|
|
$item_html.remove('table, img');
|
|
|
|
let str = $item_html.text().trim();
|
|
|
|
return str.length > 56 ? str.slice(0, 56) + "..." : str;
|
2023-01-21 05:08:17 +08:00
|
|
|
},
|
|
|
|
nameWithFallbacks(item) {
|
2023-01-31 21:08:34 +08:00
|
|
|
return this.getTitle(item) || item.attributes.name;
|
2022-05-30 19:45:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|