properly implement editing items
This commit is contained in:
parent
8981b99f6e
commit
388b243955
4 changed files with 18 additions and 11 deletions
|
@ -21,7 +21,7 @@ module.exports = {
|
||||||
2
|
2
|
||||||
],
|
],
|
||||||
'linebreak-style': [
|
'linebreak-style': [
|
||||||
'error',
|
'off',
|
||||||
'unix'
|
'unix'
|
||||||
],
|
],
|
||||||
'quotes': [
|
'quotes': [
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<img class="img-fluid rounded mx-auto d-block mb-3" :src="`https://c3lf.de/api/1/thumbs/${item.file}`"/>
|
<img class="img-fluid rounded mx-auto d-block mb-3" :src="`https://c3lf.de/api/1/thumbs/${item.file}`"/>
|
||||||
<h6>Editing Item <span class="badge badge-secondary">#{{ item[badge] }}</span></h6>
|
<h6>Editing Item <span class="badge badge-secondary">#{{ item[badge] }}</span></h6>
|
||||||
<form>
|
<form>
|
||||||
<div class="form-group" v-for="field in fields" :key="field">
|
<div class="form-group" v-for="field in ['bezeichnung', 'container']" :key="field">
|
||||||
<label>{{ field }}</label>
|
<label>{{ field }}</label>
|
||||||
<input type="text" class="form-control" v-model="item[field]">
|
<input type="text" class="form-control" v-model="item[field]">
|
||||||
</div>
|
</div>
|
||||||
|
@ -14,9 +14,6 @@
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: 'Add',
|
name: 'Add',
|
||||||
props: ['item', 'badge', 'fields']
|
props: ['item', 'badge']
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
|
||||||
</style>
|
|
|
@ -67,6 +67,11 @@ const store = new Vuex.Store({
|
||||||
|
|
||||||
commit('replaceBoxes', resp.data);
|
commit('replaceBoxes', resp.data);
|
||||||
},
|
},
|
||||||
|
async updateItem({ getters }, item) {
|
||||||
|
axios.put(`https://c3lf.de/api/1/${getters.getEventSlug}/item/${item.iid}`, item, {
|
||||||
|
auth: getAuth(),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,11 @@
|
||||||
<EditItem
|
<EditItem
|
||||||
:item="selectedItem"
|
:item="selectedItem"
|
||||||
badge="item_uid"
|
badge="item_uid"
|
||||||
:fields="['bezeichnung', 'container']"
|
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #buttons>
|
<template #buttons>
|
||||||
<button type="button" class="btn btn-secondary" @click="closeModal()">Cancel</button>
|
<button type="button" class="btn btn-secondary" @click="closeModal()">Cancel</button>
|
||||||
<button type="button" class="btn btn-success">Save Changes</button>
|
<button type="button" class="btn btn-success" @click="saveSelectedItem()">Save Changes</button>
|
||||||
</template>
|
</template>
|
||||||
</Modal>
|
</Modal>
|
||||||
<div class="row" v-if="layout === 'table'">
|
<div class="row" v-if="layout === 'table'">
|
||||||
|
@ -28,7 +27,7 @@
|
||||||
:items="loadedItems"
|
:items="loadedItems"
|
||||||
:keyName="'uid'"
|
:keyName="'uid'"
|
||||||
v-slot="{ item }"
|
v-slot="{ item }"
|
||||||
@itemActivated="selectedItem = $event"
|
@itemActivated="openModalWith($event)"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
:src="`https://c3lf.de/api/1/thumbs/${item.file}`"
|
:src="`https://c3lf.de/api/1/thumbs/${item.file}`"
|
||||||
|
@ -57,9 +56,15 @@ export default {
|
||||||
components: { Table, Cards, Modal, EditItem },
|
components: { Table, Cards, Modal, EditItem },
|
||||||
computed: mapState(['loadedItems', 'layout']),
|
computed: mapState(['loadedItems', 'layout']),
|
||||||
methods: {
|
methods: {
|
||||||
closeModal: function () {
|
openModalWith(item) { // Opens the editing modal with a copy of the selected item.
|
||||||
console.log('asdasd');
|
this.selectedItem = { ...item };
|
||||||
|
},
|
||||||
|
closeModal() { // Closes the editing modal and discards the edited copy of the item.
|
||||||
this.selectedItem = null;
|
this.selectedItem = null;
|
||||||
|
},
|
||||||
|
saveSelectedItem() { // Saves the edited copy of the item.
|
||||||
|
this.$store.dispatch('updateItem', this.selectedItem);
|
||||||
|
this.closeModal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue