2
0
mirror of https://github.com/frappe/books.git synced 2025-01-10 18:24:40 +00:00
books/src/pages/ListView/ListView.vue

93 lines
2.3 KiB
Vue
Raw Normal View History

<template>
<div class="flex flex-col">
<PageHeader>
2019-11-19 16:56:08 +00:00
<h1 slot="title" class="text-2xl font-bold" v-if="title">{{ title }}</h1>
<template slot="actions">
<Button :icon="true" type="primary" @click="makeNewDoc">
2019-11-19 16:56:08 +00:00
<feather-icon name="plus" class="w-4 h-4 text-white" />
</Button>
<SearchBar class="ml-2" />
</template>
</PageHeader>
2019-11-08 19:57:56 +00:00
<div class="flex-1 flex h-full">
<List :listConfig="listConfig" :filters="filters" class="flex-1" />
2019-10-04 20:18:10 +00:00
</div>
</div>
</template>
<script>
import frappe from 'frappejs';
import Observable from 'frappejs/utils/observable';
import PageHeader from '@/components/PageHeader';
import Button from '@/components/Button';
import SearchBar from '@/components/SearchBar';
import List from './List';
2018-10-22 20:32:37 +00:00
import listConfigs from './listConfig';
export default {
name: 'ListView',
props: ['doctype', 'filters'],
components: {
PageHeader,
List,
Button,
SearchBar
},
created() {
frappe.listView = new Observable();
},
methods: {
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);
}
let path = this.getFormPath(doc.name);
this.$router.push(path);
2018-10-22 20:32:37 +00:00
doc.on('afterInsert', () => {
let path = this.getFormPath(doc.name);
this.$router.replace(path);
2018-10-22 20:32:37 +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() {
if (listConfigs[this.doctype]) {
return listConfigs[this.doctype];
2019-08-01 13:00:52 +00:00
} else {
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() {
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
}
return this.doctype;
}
}
};
</script>