2
0
mirror of https://github.com/frappe/books.git synced 2025-01-23 15:18:24 +00:00

checkItem and deleteItems in List

This commit is contained in:
Faris Ansari 2018-06-04 14:58:26 +05:30
parent 57c0b21ed9
commit 0b6862e79c
3 changed files with 62 additions and 26 deletions

View File

@ -1,12 +1,19 @@
<template> <template>
<keep-alive> <keep-alive>
<div class="frappe-list"> <div class="frappe-list">
<list-actions :doctype="doctype" @new="newDoc"></list-actions> <list-actions
:doctype="doctype"
:showDelete="checkList.length"
@new="newDoc"
@delete="deleteCheckedItems"
/>
<ul class="list-group"> <ul class="list-group">
<list-item v-for="doc of data" :key="doc.name" <list-item v-for="doc of data" :key="doc.name"
:id="doc.name" :isActive="doc.name === $route.params.name" :id="doc.name"
@click.native="openForm(doc.name)" :isActive="doc.name === $route.params.name"
@keypress.native="selectAboveListItem" :isChecked="isChecked(doc.name)"
@clickItem="openForm(doc.name)"
@checkItem="toggleCheck(doc.name)"
> >
{{ doc[meta.titleField || 'name'] }} {{ doc[meta.titleField || 'name'] }}
</list-item> </list-item>
@ -29,6 +36,7 @@ export default {
data() { data() {
return { return {
data: [], data: [],
checkList: [],
activeItem: '' activeItem: ''
} }
}, },
@ -37,27 +45,47 @@ export default {
return frappe.getMeta(this.doctype); return frappe.getMeta(this.doctype);
} }
}, },
async mounted() { created() {
const data = await frappe.db.getAll({ frappe.db.on(`change:${this.doctype}`, () => {
doctype: this.doctype, this.updateList();
fields: ['name', ...this.meta.keywordFields]
}); });
},
this.data = data; mounted() {
this.updateList();
}, },
methods: { methods: {
async newDoc() { async newDoc() {
let doc = await frappe.getNewDoc(this.doctype); let doc = await frappe.getNewDoc(this.doctype);
this.$router.push(`/edit/${this.doctype}/${doc.name}`); this.$router.push(`/edit/${this.doctype}/${doc.name}`);
}, },
openForm(name) { async updateList() {
this.activeItem = name; const data = await frappe.db.getAll({
this.$router.push(`/edit/${this.doctype}/${name}`); doctype: this.doctype,
}, fields: ['name', ...this.meta.keywordFields]
selectAboveListItem(index) { });
console.log(index);
// this.openForm(this.data[index - 1].name); this.data = data;
},
openForm(name) {
this.activeItem = name;
this.$router.push(`/edit/${this.doctype}/${name}`);
},
async deleteCheckedItems() {
debugger
await frappe.db.deleteMany(this.doctype, this.checkList);
debugger
this.checkList = [];
},
toggleCheck(name) {
if (this.checkList.includes(name)) {
this.checkList = this.checkList.filter(docname => docname !== name);
} else {
this.checkList = this.checkList.concat(name);
} }
},
isChecked(name) {
return this.checkList.includes(name);
}
} }
} }
</script> </script>

View File

@ -1,11 +1,12 @@
<template> <template>
<div class="frappe-list-actions d-flex justify-content-between align-items-center p-3 border-bottom"> <div class="frappe-list-actions d-flex justify-content-between align-items-center p-3 border-bottom">
<h5 class="m-0">{{ doctype }} List</h5> <h5 class="m-0">{{ doctype }} List</h5>
<button class="btn btn-primary btn-sm" @click="$emit('new')">New</button> <button v-if="showDelete" class="btn btn-danger btn-sm" @click="$emit('delete')">Delete</button>
<button v-else class="btn btn-primary btn-sm" @click="$emit('new')">New</button>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
props: ['doctype'] props: ['doctype', 'showDelete']
} }
</script> </script>

View File

@ -1,7 +1,9 @@
<template> <template>
<div :class="['list-group-item d-flex align-items-center', isActive ? 'active' : '']"> <div :class="classList" @click.self="$emit('clickItem')">
<div class="custom-control custom-checkbox d-flex"> <div class="custom-control custom-checkbox d-flex">
<input type="checkbox" class="custom-control-input" :id="id"> <input type="checkbox" class="custom-control-input" :id="id"
:value="isChecked" @change="$emit('checkItem', isChecked)"
>
<label class="custom-control-label" :for="id"></label> <label class="custom-control-label" :for="id"></label>
</div> </div>
<slot></slot> <slot></slot>
@ -9,6 +11,11 @@
</template> </template>
<script> <script>
export default { export default {
props: ['id', 'isActive'] props: ['id', 'isActive', 'isChecked'],
computed: {
classList() {
return ['list-group-item d-flex align-items-center', this.isActive ? 'bg-light' : ''];
}
}
} }
</script> </script>