2
0
mirror of https://github.com/frappe/books.git synced 2024-09-21 03:39:02 +00:00
books/ui/components/Form/FormActions.vue

84 lines
2.1 KiB
Vue
Raw Normal View History

2018-06-27 14:38:27 +00:00
<template>
<div class="frappe-form-actions d-flex justify-content-between align-items-center p-3 border-bottom">
<h5 class="m-0">{{ title }}</h5>
2018-07-14 14:58:18 +00:00
<div class="d-flex">
2018-07-15 07:00:47 +00:00
<f-button primary v-if="showSave" :disabled="disableSave" @click="$emit('save')">{{ _('Save') }}</f-button>
2018-07-14 14:58:18 +00:00
<f-button primary v-if="showSubmit" @click="$emit('submit')">{{ _('Submit') }}</f-button>
<f-button secondary v-if="showRevert" @click="$emit('revert')">{{ _('Revert') }}</f-button>
2018-07-15 07:00:47 +00:00
<dropdown class="ml-2" v-if="showNextAction" :label="_('Actions')" :options="links"></dropdown>
2018-07-14 14:58:18 +00:00
</div>
2018-06-27 14:38:27 +00:00
</div>
</template>
<script>
import frappe from 'frappejs';
2018-07-14 14:58:18 +00:00
import Dropdown from '../Dropdown';
2018-06-27 14:38:27 +00:00
export default {
2018-07-14 14:58:18 +00:00
props: ['doc', 'links'],
components: {
Dropdown
},
data() {
return {
isDirty: false,
2018-07-15 07:00:47 +00:00
showSave: false,
showSubmit: false,
2018-07-15 07:00:47 +00:00
showRevert: false,
showNextAction: false,
disableSave: false
}
},
created() {
this.doc.on('change', () => {
this.isDirty = this.doc._dirty;
this.updateShowSubmittable();
});
this.updateShowSubmittable();
},
methods: {
updateShowSubmittable() {
this.showSubmit =
this.meta.isSubmittable
&& !this.isDirty
&& !this.doc._notInserted
&& this.doc.submitted === 0;
this.showRevert =
this.meta.isSubmittable
&& !this.isDirty
&& !this.doc._notInserted
&& this.doc.submitted === 1;
2018-07-15 07:00:47 +00:00
this.showNextAction =
!this.doc._notInserted
&& this.links.length;
this.showSave =
this.doc._notInserted ?
true :
this.meta.isSubmittable ?
(this.isDirty ? true : false) :
true;
this.disableSave =
this.doc._notInserted ? false : !this.isDirty;
}
},
computed: {
meta() {
return frappe.getMeta(this.doc.doctype);
},
title() {
const _ = this._;
if (this.doc._notInserted) {
return _('New {0}', _(this.doc.doctype));
}
const titleField = this.meta.titleField || 'name';
return this.doc[titleField];
}
}
2018-06-27 14:38:27 +00:00
}
</script>