mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
fix: Confirmation dialog before Invoice delete
This commit is contained in:
parent
37927caf3e
commit
d5a88398a8
@ -171,6 +171,7 @@ import FormControl from '@/components/Controls/FormControl';
|
|||||||
import Row from '@/components/Row';
|
import Row from '@/components/Row';
|
||||||
import Dropdown from '@/components/Dropdown';
|
import Dropdown from '@/components/Dropdown';
|
||||||
import { openSettings } from '@/pages/Settings/utils';
|
import { openSettings } from '@/pages/Settings/utils';
|
||||||
|
import { showMessageDialog } from '@/utils';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'InvoiceForm',
|
name: 'InvoiceForm',
|
||||||
@ -190,8 +191,6 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
meta: null,
|
|
||||||
itemsMeta: null,
|
|
||||||
doc: null,
|
doc: null,
|
||||||
partyDoc: null,
|
partyDoc: null,
|
||||||
printSettings: null,
|
printSettings: null,
|
||||||
@ -199,6 +198,12 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
meta() {
|
||||||
|
return frappe.getMeta(this.doctype);
|
||||||
|
},
|
||||||
|
itemsMeta() {
|
||||||
|
return frappe.getMeta(`${this.doctype}Item`);
|
||||||
|
},
|
||||||
itemTableFields() {
|
itemTableFields() {
|
||||||
return this.itemsMeta.tableFields.map(fieldname =>
|
return this.itemsMeta.tableFields.map(fieldname =>
|
||||||
this.itemsMeta.getField(fieldname)
|
this.itemsMeta.getField(fieldname)
|
||||||
@ -227,11 +232,29 @@ export default {
|
|||||||
template: `<span class="text-red-700">{{ _('Delete') }}</span>`
|
template: `<span class="text-red-700">{{ _('Delete') }}</span>`
|
||||||
},
|
},
|
||||||
condition: doc => !doc.isNew() && !doc.submitted,
|
condition: doc => !doc.isNew() && !doc.submitted,
|
||||||
|
action: () => {
|
||||||
|
showMessageDialog({
|
||||||
|
message: this._('Are you sure you want to delete {0} "{1}"?', [
|
||||||
|
this.doctype,
|
||||||
|
this.name
|
||||||
|
]),
|
||||||
|
description: this._('This action is permanent'),
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
label: 'Delete',
|
||||||
action: () => {
|
action: () => {
|
||||||
this.doc.delete().then(() => {
|
this.doc.delete().then(() => {
|
||||||
this.routeToList();
|
this.routeToList();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Cancel',
|
||||||
|
action() {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let actions = [...(this.meta.actions || []), deleteAction]
|
let actions = [...(this.meta.actions || []), deleteAction]
|
||||||
.filter(d => (d.condition ? d.condition(this.doc) : true))
|
.filter(d => (d.condition ? d.condition(this.doc) : true))
|
||||||
@ -247,10 +270,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
this.meta = frappe.getMeta(this.doctype);
|
|
||||||
this.itemsMeta = frappe.getMeta(`${this.doctype}Item`);
|
|
||||||
this.doc = await frappe.getDoc(this.doctype, this.name);
|
this.doc = await frappe.getDoc(this.doctype, this.name);
|
||||||
window.doc = this.doc;
|
|
||||||
this.doc.on('change', ({ changed }) => {
|
this.doc.on('change', ({ changed }) => {
|
||||||
if (changed === this.partyField.fieldname) {
|
if (changed === this.partyField.fieldname) {
|
||||||
this.fetchPartyDoc();
|
this.fetchPartyDoc();
|
||||||
|
18
src/utils.js
18
src/utils.js
@ -38,3 +38,21 @@ export function loadExistingDatabase() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function showMessageDialog({ message, description, buttons }) {
|
||||||
|
let buttonLabels = buttons.map(a => a.label);
|
||||||
|
remote.dialog.showMessageBox(
|
||||||
|
remote.getCurrentWindow(),
|
||||||
|
{
|
||||||
|
message,
|
||||||
|
detail: description,
|
||||||
|
buttons: buttonLabels
|
||||||
|
},
|
||||||
|
response => {
|
||||||
|
let button = buttons[response];
|
||||||
|
if (button && button.action) {
|
||||||
|
button.action();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user