2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 15:50:56 +00:00

Add next action links for doctype meta

This commit is contained in:
Suraj Shetty 2018-07-14 20:28:18 +05:30
parent a69b73e47c
commit 38fe97f602
2 changed files with 38 additions and 10 deletions

View File

@ -3,6 +3,7 @@
<form-actions <form-actions
v-if="shouldRenderForm" v-if="shouldRenderForm"
:doc="doc" :doc="doc"
:links="links"
@save="save" @save="save"
@submit="submit" @submit="submit"
@revert="revert" @revert="revert"
@ -37,8 +38,9 @@ export default {
docLoaded: false, docLoaded: false,
notFound: false, notFound: false,
invalid: false, invalid: false,
invalidFields: [] invalidFields: [],
} links: []
};
}, },
computed: { computed: {
meta() { meta() {
@ -67,9 +69,11 @@ export default {
} }
this.docLoaded = true; this.docLoaded = true;
} catch(e) { } catch (e) {
this.notFound = true; this.notFound = true;
} }
this.setLinks();
this.doc.on('change', this.setLinks);
}, },
methods: { methods: {
async save() { async save() {
@ -84,13 +88,28 @@ export default {
} }
this.$emit('save', this.doc); this.$emit('save', this.doc);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
return; return;
} }
}, },
setLinks() {
if (this.meta.links) {
let links = [];
for (let link of this.meta.links) {
if (link.condition(this)) {
link.handler = () => {
link.action(this);
};
links.push(link);
}
}
this.links = links;
}
},
async submit() { async submit() {
this.doc.set('submitted', 1); this.doc.set('submitted', 1);
await this.save(); await this.save();
@ -105,7 +124,9 @@ export default {
if (!isValid && !this.invalidFields.includes(fieldname)) { if (!isValid && !this.invalidFields.includes(fieldname)) {
this.invalidFields.push(fieldname); this.invalidFields.push(fieldname);
} else if (isValid) { } else if (isValid) {
this.invalidFields = this.invalidFields.filter(invalidField => invalidField !== fieldname) this.invalidFields = this.invalidFields.filter(
invalidField => invalidField !== fieldname
);
} }
}, },
@ -113,7 +134,7 @@ export default {
const form = this.$el.querySelector('form'); const form = this.$el.querySelector('form');
let validity = form.checkValidity(); let validity = form.checkValidity();
this.invalid = !validity; this.invalid = !validity;
}, }
} }
}; };
</script> </script>

View File

@ -1,16 +1,23 @@
<template> <template>
<div class="frappe-form-actions d-flex justify-content-between align-items-center p-3 border-bottom"> <div class="frappe-form-actions d-flex justify-content-between align-items-center p-3 border-bottom">
<h5 class="m-0">{{ title }}</h5> <h5 class="m-0">{{ title }}</h5>
<f-button primary v-if="isDirty" @click="$emit('save')">{{ _('Save') }}</f-button> <div class="d-flex">
<f-button primary v-if="showSubmit" @click="$emit('submit')">{{ _('Submit') }}</f-button> <f-button primary v-if="isDirty" @click="$emit('save')">{{ _('Save') }}</f-button>
<f-button secondary v-if="showRevert" @click="$emit('revert')">{{ _('Revert') }}</f-button> <f-button primary v-if="showSubmit" @click="$emit('submit')">{{ _('Submit') }}</f-button>
<f-button secondary v-if="showRevert" @click="$emit('revert')">{{ _('Revert') }}</f-button>
<dropdown v-if="links.length" :label="'Next Action'" :options="links"></dropdown>
</div>
</div> </div>
</template> </template>
<script> <script>
import frappe from 'frappejs'; import frappe from 'frappejs';
import Dropdown from '../Dropdown';
export default { export default {
props: ['doc'], props: ['doc', 'links'],
components: {
Dropdown
},
data() { data() {
return { return {
isDirty: false, isDirty: false,