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

110 lines
2.6 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">
<h5 class="m-0">{{ title }}</h5>
2018-07-14 14:58:18 +00:00
<div class="d-flex">
2019-08-05 11:46:35 +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>
<div class="ml-2" v-if="showPrint">
<f-button secondary v-if="showNextAction" @click="$emit('print')">{{ _('Print') }}</f-button>
</div>
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>
2018-07-13 05:16:15 +00:00
2018-06-27 14:38:27 +00:00
<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,
showPrint: false,
2018-07-15 07:00:47 +00:00
disableSave: false
2019-08-05 11:46:35 +00:00
};
},
created() {
this.doc.on('change', () => {
this.updateShowSubmittable();
});
this.updateShowSubmittable();
},
methods: {
updateShowSubmittable() {
2018-10-22 20:51:34 +00:00
this.isDirty = this.doc._dirty;
this.showSubmit =
2019-08-05 11:46:35 +00:00
this.meta.isSubmittable &&
!this.isDirty &&
!this.doc.isNew() &&
this.doc.submitted === 0;
this.showRevert =
2019-08-05 11:46:35 +00:00
this.meta.isSubmittable &&
!this.isDirty &&
!this.doc.isNew() &&
this.doc.submitted === 1;
2018-07-15 07:00:47 +00:00
2019-08-05 11:46:35 +00:00
this.showNextAction = 1;
2019-08-05 11:46:35 +00:00
this.showNextAction = !this.doc.isNew() && this.links.length;
2018-07-15 07:00:47 +00:00
2019-08-05 11:46:35 +00:00
this.showPrint = this.doc.submitted === 1 && this.meta.print;
2019-08-05 11:46:35 +00:00
this.showSave = this.doc.isNew()
? true
: this.meta.isSubmittable
? this.isDirty
? true
: false
: true;
2018-07-15 07:00:47 +00:00
2019-08-05 11:46:35 +00:00
this.disableSave = this.doc.isNew() ? false : !this.isDirty;
},
getFormTitle() {
const _ = this._;
try {
return _(
this.meta.getFormTitle(this.doc) ||
this.meta.label ||
this.doc.doctype
);
} catch (e) {
return _(this.meta.label || this.doc.doctype);
}
}
},
computed: {
meta() {
return frappe.getMeta(this.doc.doctype);
},
title() {
const _ = this._;
2018-11-09 19:07:14 +00:00
if (this.doc.isNew()) {
return _('New {0}', this.getFormTitle());
}
const titleField = this.meta.titleField || 'name';
return this.doc[titleField];
}
}
2019-08-05 11:46:35 +00:00
};
2018-06-27 14:38:27 +00:00
</script>