Working v0

This commit is contained in:
2024-09-27 18:09:38 +02:00
parent f3116a6876
commit 8dfafa9404
25 changed files with 740 additions and 389 deletions
@@ -0,0 +1,104 @@
{% load i18n %}
{% block component %}
<v-data-table
:headers="items_headers"
:items="items"
:items-per-page="50"
:search="search"
:group-by="group_by"
loading
dense>
<template v-slot:top>
<v-toolbar flat>
<v-text-field v-model="search" append-icon="mdi-magnify" label="Search" single-line hide-details></v-text-field>
<v-divider class="mx-4" insert vertical></v-divider>
<v-spacer></v-spacer>
<v-dialog v-model="dialog" max-width="500px">
<template v-slot:activator="{ on, attrs }">
<v-btn color="primary" dark class="mb-2" v-bind="attrs" v-on="on">
<v-icon small class="mr-2">mdi-plus</v-icon>
{% trans "New" %}
</v-btn>
</template>
<v-card>
<v-card-title>
<span class="text-h5"> [[ editedItem.id ]]</span>
</v-card-title>
<v-card-text>
<v-container>
<v-row>
<template v-for="field in editable_fields">
<template v-if="field.field_widget == 'v-select'">
<v-select
v-model="editedItem[field.value]"
:items="items_relations[field.value]"
:label="field.text"
item-text="name"
item-value="id"
persistent-hint>
<template slot="item" slot-scope="data">
[[ data.item.name ]] - [[ data.item.custom_identifier ]]
</template>
</v-select>
</template>
<template v-else>
<component :is="field.field_widget" v-model="editedItem[field.value]" :label="field.text"></component>
</template>
</template>
</v-row>
</v-container>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="blue darken-1" text @click="close">
<v-icon small class="mr-2">mdi-cancel</v-icon>
{% trans "Cancel" %}
</v-btn>
<v-btn color="blue darken-1" text @click="save">
<v-icon small class="mr-2">mdi-content-save-edit</v-icon>
{% trans "Save" %}
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-dialog v-model="dialogDelete" max-width="500px">
<v-card>
<v-card-title class="text-h5">{% trans "Are you sure you want to delete this item?" %}</v-card-title>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="blue darken-1" text @click="closeDelete">
<v-icon small class="mr-2">mdi-cancel</v-icon>
{% trans "Cancel" %}
</v-btn>
<v-btn color="blue darken-1" text @click="deleteItemConfirm">
<v-icon small class="mr-2">mdi-delete-forever</v-icon>
{% trans "OK" %}
</v-btn>
<v-spacer></v-spacer>
</v-card-actions>
</v-card>
</v-dialog>
</v-toolbar>
</template>
<template v-slot:item.id="{ item }">
[[ item.id.slice(0, 8) ]]...
</template>
<template v-slot:item.actions="{ item }">
<v-icon small class="mr-2" @click="editItem(item)">mdi-pencil</v-icon>
<v-icon small @click="deleteItem(item)">mdi-delete</v-icon>
</template>
<template v-slot:no-data>
<v-btn color="primary" @click="initialize">{% trans "Reset" %}</v-btn>
</template>
</v-data-table>
{% endblock %}
@@ -0,0 +1,87 @@
{% block component %}
{{ name }} = {
template: "#{{ name }}",
delimiters: ["[[", "]]"],
props: ["crypto_key", "items", "items_headers", "items_relations", "group_by"],
data: function() {
return {
dialog: false,
dialogDelete: false,
editedIndex: -1,
defaultItem: {},
editedItem: {},
search: null,
}
},
computed: {
editable_fields: function() {
return this.items_headers.filter(e => e.editable)
},
},
watch: {
dialog (val) {
val || this.close()
},
dialogDelete (val) {
val || this.closeDelete()
},
},
methods: {
editItem (item) {
this.editedIndex = this.items.indexOf(item)
this.editedItem = Object.assign({}, item)
this.dialog = true
},
deleteItem (item) {
this.editedIndex = this.items.indexOf(item)
this.editedItem = Object.assign({}, item)
this.dialogDelete = true
},
deleteItemConfirm () {
var self = this
var item = this.items[this.editedIndex]
this.$emit("deleteItem", this.editedIndex)
this.closeDelete()
},
close () {
this.dialog = false
this.editedItem = Object.assign({}, this.defaultItem)
this.editedIndex = -1
},
closeDelete () {
this.dialogDelete = false
this.editedItem = Object.assign({}, this.defaultItem)
this.editedIndex = -1
},
save () {
if (this.editedIndex > -1) {
this.$emit("editItem", this.editedIndex, this.editedItem)
} else {
console.log('createItem emit', this.editedItem)
this.$emit("createItem", this.editedItem)
}
this.close()
},
}
}
{% endblock %}