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

110 lines
2.7 KiB
Vue
Raw Normal View History

<template>
<div class="flex flex-col">
<PageHeader>
2019-11-19 22:26:08 +05:30
<h1 slot="title" class="text-2xl font-bold" v-if="title">{{ title }}</h1>
<template slot="actions">
2019-11-22 00:50:30 +05:30
<FilterDropdown
ref="filterDropdown"
@change="applyFilter"
:fields="meta.fields"
/>
<Button class="ml-2" :icon="true" type="primary" @click="makeNewDoc">
2019-11-19 22:26:08 +05:30
<feather-icon name="plus" class="w-4 h-4 text-white" />
</Button>
<SearchBar class="ml-2" />
</template>
</PageHeader>
2019-11-09 01:27:56 +05:30
<div class="flex-1 flex h-full">
2019-11-22 00:50:30 +05:30
<List
ref="list"
:listConfig="listConfig"
:filters="filters"
class="flex-1"
/>
2019-10-05 01:48:10 +05:30
</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-23 02:02:37 +05:30
import listConfigs from './listConfig';
2019-11-22 00:50:30 +05:30
import Icon from '@/components/Icon';
import FilterDropdown from '@/components/FilterDropdown';
export default {
name: 'ListView',
props: ['doctype', 'filters'],
components: {
PageHeader,
List,
Button,
2019-11-22 00:50:30 +05:30
SearchBar,
Icon,
FilterDropdown
},
activated() {
2019-11-22 00:50:30 +05:30
if (typeof this.filters === 'object') {
this.$refs.filterDropdown.setFilter(this.filters);
}
},
methods: {
async makeNewDoc() {
2018-10-23 02:02:37 +05:30
const doctype = this.listConfig.doctype;
const doc = await frappe.getNewDoc(doctype);
if (this.listConfig.filters) {
doc.set(this.listConfig.filters);
}
2019-08-14 13:13:49 +05:30
if (this.filters) {
doc.set(this.filters);
}
let path = this.getFormPath(doc.name);
this.$router.push(path);
2018-10-23 02:02:37 +05:30
doc.on('afterInsert', () => {
let path = this.getFormPath(doc.name);
this.$router.replace(path);
2018-10-23 02:02:37 +05:30
});
},
2019-11-22 00:50:30 +05:30
applyFilter(filters) {
this.$refs.list.updateData(filters);
},
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-23 02:02:37 +05:30
}
},
computed: {
2019-11-22 00:50:30 +05:30
meta() {
return frappe.getMeta(this.doctype);
},
2018-10-23 02:02:37 +05:30
listConfig() {
if (listConfigs[this.doctype]) {
return listConfigs[this.doctype];
2019-08-01 18:30:52 +05:30
} else {
return {
title: this.doctype,
doctype: this.doctype,
2019-11-22 00:50:30 +05:30
columns: this.meta.getKeywordFields()
};
2019-08-01 18:30:52 +05:30
}
2019-08-14 13:13:49 +05:30
},
title() {
2019-11-22 00:50:30 +05:30
return this.listConfig.title || this.doctype;
}
}
};
</script>