2018-06-27 14:38:27 +00:00
|
|
|
<template>
|
|
|
|
<div class="frappe-list">
|
|
|
|
<list-actions
|
|
|
|
:doctype="doctype"
|
|
|
|
:showDelete="checkList.length"
|
2018-08-18 15:54:17 +00:00
|
|
|
@new="$emit('newDoc')"
|
2018-06-27 14:38:27 +00:00
|
|
|
@delete="deleteCheckedItems"
|
|
|
|
/>
|
|
|
|
<ul class="list-group">
|
|
|
|
<list-item v-for="doc of data" :key="doc.name"
|
|
|
|
:id="doc.name"
|
|
|
|
:isActive="doc.name === $route.params.name"
|
|
|
|
:isChecked="isChecked(doc.name)"
|
|
|
|
@clickItem="openForm(doc.name)"
|
2018-07-09 14:55:24 +00:00
|
|
|
@checkItem="toggleCheck(doc.name)"
|
|
|
|
>
|
|
|
|
<indicator v-if="hasIndicator" :color="getIndicatorColor(doc)" />
|
|
|
|
<span class="d-inline-block ml-2">
|
|
|
|
{{ doc[meta.titleField || 'name'] }}
|
|
|
|
</span>
|
2018-06-27 14:38:27 +00:00
|
|
|
</list-item>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import frappe from 'frappejs';
|
|
|
|
import ListActions from './ListActions';
|
|
|
|
import ListItem from './ListItem';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'List',
|
2018-07-12 15:17:46 +00:00
|
|
|
props: ['doctype'],
|
2018-06-27 14:38:27 +00:00
|
|
|
components: {
|
2018-07-09 14:55:24 +00:00
|
|
|
ListActions,
|
|
|
|
ListItem
|
2018-06-27 14:38:27 +00:00
|
|
|
},
|
|
|
|
data() {
|
2018-07-09 14:55:24 +00:00
|
|
|
return {
|
|
|
|
data: [],
|
|
|
|
checkList: [],
|
|
|
|
activeItem: ''
|
|
|
|
};
|
2018-06-27 14:38:27 +00:00
|
|
|
},
|
|
|
|
computed: {
|
2018-07-09 14:55:24 +00:00
|
|
|
meta() {
|
|
|
|
return frappe.getMeta(this.doctype);
|
|
|
|
},
|
|
|
|
hasIndicator() {
|
|
|
|
return Boolean(this.meta.indicators);
|
|
|
|
}
|
2018-06-27 14:38:27 +00:00
|
|
|
},
|
|
|
|
created() {
|
|
|
|
frappe.db.on(`change:${this.doctype}`, () => {
|
|
|
|
this.updateList();
|
|
|
|
});
|
2018-07-12 16:27:23 +00:00
|
|
|
this.$root.$on('navbarSearch', this.updateList);
|
|
|
|
this.$root.$emit('newList');
|
2018-06-27 14:38:27 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.updateList();
|
|
|
|
},
|
|
|
|
methods: {
|
2018-08-18 15:54:17 +00:00
|
|
|
async updateList(query = null) {
|
|
|
|
let filters = null;
|
2018-07-12 15:17:46 +00:00
|
|
|
if (query) {
|
|
|
|
filters = {
|
2018-08-18 15:54:17 +00:00
|
|
|
keywords: ['like', query]
|
|
|
|
};
|
2018-07-12 15:17:46 +00:00
|
|
|
}
|
2018-08-18 15:54:17 +00:00
|
|
|
|
|
|
|
const indicatorField = this.hasIndicator
|
|
|
|
? this.meta.indicators.key
|
|
|
|
: null;
|
|
|
|
|
2018-07-09 14:55:24 +00:00
|
|
|
const fields = [
|
|
|
|
'name',
|
|
|
|
indicatorField,
|
|
|
|
this.meta.titleField,
|
|
|
|
...this.meta.keywordFields
|
|
|
|
].filter(Boolean);
|
|
|
|
|
2018-06-27 14:38:27 +00:00
|
|
|
const data = await frappe.db.getAll({
|
|
|
|
doctype: this.doctype,
|
2018-07-09 14:55:24 +00:00
|
|
|
fields,
|
2018-07-12 15:17:46 +00:00
|
|
|
filters: filters || null
|
2018-06-27 14:38:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.data = data;
|
|
|
|
},
|
|
|
|
openForm(name) {
|
2018-07-09 14:55:24 +00:00
|
|
|
this.activeItem = name;
|
2018-08-18 15:54:17 +00:00
|
|
|
this.$emit('openForm', name);
|
2018-06-27 14:38:27 +00:00
|
|
|
},
|
|
|
|
async deleteCheckedItems() {
|
|
|
|
await frappe.db.deleteMany(this.doctype, this.checkList);
|
2018-09-07 10:08:15 +00:00
|
|
|
this.$router.push(`/list/${this.doctype}`);
|
2018-06-27 14:38:27 +00:00
|
|
|
this.checkList = [];
|
|
|
|
},
|
|
|
|
toggleCheck(name) {
|
|
|
|
if (this.checkList.includes(name)) {
|
2018-07-09 14:55:24 +00:00
|
|
|
this.checkList = this.checkList.filter(docname => docname !== name);
|
2018-06-27 14:38:27 +00:00
|
|
|
} else {
|
2018-07-09 14:55:24 +00:00
|
|
|
this.checkList = this.checkList.concat(name);
|
2018-06-27 14:38:27 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
isChecked(name) {
|
|
|
|
return this.checkList.includes(name);
|
2018-07-09 14:55:24 +00:00
|
|
|
},
|
|
|
|
getIndicatorColor(doc) {
|
|
|
|
return this.meta.getIndicatorColor(doc);
|
2018-06-27 14:38:27 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-09 14:55:24 +00:00
|
|
|
};
|
2018-06-27 14:38:27 +00:00
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
2018-08-18 15:54:17 +00:00
|
|
|
@import '../../styles/variables';
|
2018-06-27 14:38:27 +00:00
|
|
|
|
|
|
|
.list-group-item {
|
2018-07-09 14:55:24 +00:00
|
|
|
border-left: none;
|
|
|
|
border-right: none;
|
|
|
|
border-radius: 0;
|
2018-06-27 14:38:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.list-group-item:first-child {
|
2018-07-09 14:55:24 +00:00
|
|
|
border-top: none;
|
2018-06-27 14:38:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.list-group-item:not(.active):hover {
|
2018-07-09 14:55:24 +00:00
|
|
|
background-color: $light;
|
2018-06-27 14:38:27 +00:00
|
|
|
}
|
|
|
|
</style>
|