ldc-legaulois/resources/ts/bo/components/ReorderElements.vue
2024-04-16 10:33:39 +02:00

76 lines
2 KiB
Vue

<template>
<div class="container-fluid reorder-elements-component my-3">
<!-- ORDERABLE NODES -->
<div class="row justify-content-start">
<div class="col my-3">
<fieldset
class="border p-4"
>
<legend>
<span class="fs-5">{{ trans.methods.__('Réorganisez les éléments en les déplaçant.') }}</span>
</legend>
<div class="list-group">
<Draggable
:list="nodeList"
item-key="type"
>
<!-- LIST ITEM -->
<template #item="{ element, index } : {element: LaravelModel, index: number}">
<div class="list-group-item d-flex flux-column justify-content-between">
<span class="h6">
<FontAwesomeIcon
icon="fa-solid fa-align-justify"
class="handle text-secondary"
/>
<span>&nbsp;&nbsp;&nbsp;</span>
<strong>{{ element.label }}</strong>
</span>
</div>
</template>
</Draggable>
</div>
</fieldset>
</div>
<!-- INPUTS FOR SUBMISSION -->
<input
type="hidden"
name="jsonValue"
:value="JSON.stringify(nodeList)"
>
</div>
</div>
</template>
<script lang="ts" setup>
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { defineOptions, onMounted, ref, useAttrs } from "vue";
import Draggable from "vuedraggable";
import trans from "../../modules/trans";
defineOptions({
name: "ReorderElements",
inheritAttrs: true,
});
// * ATTRIBUTES
const attrs = useAttrs();
// * DATA
const nodeList = ref<Array<LaravelModelList>>([]);
// * LIFECYCLE
onMounted(() => {
const json = String(attrs.json ?? "{}"),
data = JSON.parse(json);
nodeList.value = data.nodeList ?? [];
});
</script>
<style lang="scss" scoped>
.reorder-elements-component {
.handle {
cursor: grab;
}
}
</style>