2018-06-27 14:38:27 +00:00
|
|
|
<template>
|
2018-07-16 11:20:24 +00:00
|
|
|
<div class="frappe-form-actions d-flex justify-content-between align-items-center">
|
2018-07-10 13:35:43 +00:00
|
|
|
<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>
|
2018-10-24 18:36:27 +00:00
|
|
|
<div class="ml-2" v-if="showPrint">
|
2018-07-16 14:12:00 +00:00
|
|
|
<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>
|
2018-07-10 13:35:43 +00:00
|
|
|
import frappe from 'frappejs';
|
2018-07-14 14:58:18 +00:00
|
|
|
import Dropdown from '../Dropdown';
|
2018-07-10 13:35:43 +00:00
|
|
|
|
2018-06-27 14:38:27 +00:00
|
|
|
export default {
|
2018-07-14 14:58:18 +00:00
|
|
|
props: ['doc', 'links'],
|
|
|
|
components: {
|
|
|
|
Dropdown
|
|
|
|
},
|
2018-07-10 13:35:43 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2018-07-12 07:47:56 +00:00
|
|
|
isDirty: false,
|
2018-07-15 07:00:47 +00:00
|
|
|
showSave: false,
|
2018-07-12 07:47:56 +00:00
|
|
|
showSubmit: false,
|
2018-07-15 07:00:47 +00:00
|
|
|
showRevert: false,
|
|
|
|
showNextAction: false,
|
2018-10-24 18:36:27 +00:00
|
|
|
showPrint: false,
|
2018-07-15 07:00:47 +00:00
|
|
|
disableSave: false
|
2019-08-05 11:46:35 +00:00
|
|
|
};
|
2018-07-10 13:35:43 +00:00
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.doc.on('change', () => {
|
2018-07-12 07:47:56 +00:00
|
|
|
this.updateShowSubmittable();
|
2018-07-10 13:35:43 +00:00
|
|
|
});
|
2018-07-12 07:47:56 +00:00
|
|
|
this.updateShowSubmittable();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
updateShowSubmittable() {
|
2018-10-22 20:51:34 +00:00
|
|
|
this.isDirty = this.doc._dirty;
|
|
|
|
|
2018-07-12 07:47:56 +00:00
|
|
|
this.showSubmit =
|
2019-08-05 11:46:35 +00:00
|
|
|
this.meta.isSubmittable &&
|
|
|
|
!this.isDirty &&
|
|
|
|
!this.doc.isNew() &&
|
|
|
|
this.doc.submitted === 0;
|
2018-07-12 07:47:56 +00:00
|
|
|
|
|
|
|
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;
|
2018-07-16 14:12:00 +00:00
|
|
|
|
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;
|
2018-10-24 18:36:27 +00:00
|
|
|
|
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;
|
2019-08-14 09:39:55 +00:00
|
|
|
},
|
|
|
|
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);
|
|
|
|
}
|
2018-07-12 07:47:56 +00:00
|
|
|
}
|
2018-07-10 13:35:43 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
meta() {
|
|
|
|
return frappe.getMeta(this.doc.doctype);
|
|
|
|
},
|
|
|
|
title() {
|
|
|
|
const _ = this._;
|
|
|
|
|
2018-11-09 19:07:14 +00:00
|
|
|
if (this.doc.isNew()) {
|
2019-08-14 09:39:55 +00:00
|
|
|
return _('New {0}', this.getFormTitle());
|
2018-07-10 13:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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>
|