2018-10-10 18:51:03 +00:00
|
|
|
<template>
|
2019-10-04 20:18:10 +00:00
|
|
|
<div class="flex">
|
|
|
|
<div class="flex flex-col flex-1">
|
2019-10-05 21:42:08 +00:00
|
|
|
<PageHeader>
|
|
|
|
<h1 slot="title" class="text-xl font-bold" v-if="title">{{ title }}</h1>
|
|
|
|
<template slot="actions">
|
2019-10-11 09:55:50 +00:00
|
|
|
<Button type="primary" @click="makeNewDoc">
|
2019-10-05 21:42:08 +00:00
|
|
|
<Add class="w-3 h-3 stroke-current text-white" />
|
|
|
|
</Button>
|
|
|
|
<SearchBar class="ml-2" />
|
|
|
|
</template>
|
|
|
|
</PageHeader>
|
2019-10-11 10:58:37 +00:00
|
|
|
<div class="flex-1 flex">
|
|
|
|
<List :listConfig="listConfig" :filters="filters" class="flex-1" />
|
2019-10-04 20:18:10 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-10-10 18:51:03 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import frappe from 'frappejs';
|
2018-10-22 19:10:45 +00:00
|
|
|
import Observable from 'frappejs/utils/observable';
|
2018-10-10 18:51:03 +00:00
|
|
|
import PageHeader from '@/components/PageHeader';
|
2019-10-05 21:42:08 +00:00
|
|
|
import Button from '@/components/Button';
|
|
|
|
import Add from '@/components/Icons/Add';
|
|
|
|
import SearchBar from '@/components/SearchBar';
|
2018-10-10 18:51:03 +00:00
|
|
|
import List from './List';
|
2018-10-22 20:32:37 +00:00
|
|
|
import listConfigs from './listConfig';
|
2018-10-10 18:51:03 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ListView',
|
2019-10-11 09:55:50 +00:00
|
|
|
props: ['doctype', 'filters'],
|
2018-10-10 18:51:03 +00:00
|
|
|
components: {
|
|
|
|
PageHeader,
|
2019-10-05 21:42:08 +00:00
|
|
|
List,
|
|
|
|
Button,
|
|
|
|
Add,
|
|
|
|
SearchBar
|
2018-10-10 18:51:03 +00:00
|
|
|
},
|
2018-10-22 19:10:45 +00:00
|
|
|
created() {
|
|
|
|
frappe.listView = new Observable();
|
|
|
|
},
|
2018-10-10 18:51:03 +00:00
|
|
|
methods: {
|
2019-10-11 09:55:50 +00:00
|
|
|
async makeNewDoc() {
|
2018-10-22 20:32:37 +00:00
|
|
|
const doctype = this.listConfig.doctype;
|
|
|
|
const doc = await frappe.getNewDoc(doctype);
|
|
|
|
if (this.listConfig.filters) {
|
|
|
|
doc.set(this.listConfig.filters);
|
|
|
|
}
|
2019-08-14 07:43:49 +00:00
|
|
|
if (this.filters) {
|
|
|
|
doc.set(this.filters);
|
|
|
|
}
|
2019-10-11 09:55:50 +00:00
|
|
|
let path = this.getFormPath(doc.name);
|
|
|
|
this.$router.push(path);
|
2018-10-22 20:32:37 +00:00
|
|
|
doc.on('afterInsert', () => {
|
2019-10-11 09:55:50 +00:00
|
|
|
let path = this.getFormPath(doc.name);
|
|
|
|
this.$router.replace(path);
|
2018-10-22 20:32:37 +00:00
|
|
|
});
|
2019-10-11 09:55:50 +00:00
|
|
|
},
|
|
|
|
getFormPath(name) {
|
|
|
|
if (this.listConfig.formRoute) {
|
|
|
|
let path = this.listConfig.formRoute(name);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
path: `/list/${this.doctype}`,
|
|
|
|
query: {
|
|
|
|
edit: 1,
|
|
|
|
doctype: this.doctype,
|
|
|
|
name
|
|
|
|
}
|
|
|
|
};
|
2018-10-22 20:32:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
listConfig() {
|
2019-10-11 09:55:50 +00:00
|
|
|
if (listConfigs[this.doctype]) {
|
|
|
|
return listConfigs[this.doctype];
|
2019-08-01 13:00:52 +00:00
|
|
|
} else {
|
2019-10-13 12:03:01 +00:00
|
|
|
return {
|
|
|
|
title: this.doctype,
|
|
|
|
doctype: this.doctype,
|
|
|
|
columns: frappe.getMeta(this.doctype).getKeywordFields()
|
|
|
|
}
|
2019-08-01 13:00:52 +00:00
|
|
|
}
|
2019-08-14 07:43:49 +00:00
|
|
|
},
|
|
|
|
title() {
|
2019-10-05 21:42:08 +00:00
|
|
|
if (this.listConfig) {
|
|
|
|
return typeof this.listConfig.title === 'function'
|
|
|
|
? this.listConfig.title(this.filters)
|
|
|
|
: this.listConfig.title;
|
2019-08-14 07:43:49 +00:00
|
|
|
}
|
2019-10-11 09:55:50 +00:00
|
|
|
return this.doctype;
|
2018-10-10 18:51:03 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-01 11:52:58 +00:00
|
|
|
};
|
2018-10-10 18:51:03 +00:00
|
|
|
</script>
|