From 3e6b741556b692e0bbed3152f4b1cd132766aec3 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Sat, 10 Nov 2018 00:37:14 +0530 Subject: [PATCH] Use isNew() instead of _notInserted --- backends/database.js | 4 ++-- model/document.js | 6 +++++- ui/components/Form/Form.vue | 4 ++-- ui/components/Form/FormActions.vue | 12 ++++++------ ui/components/Form/FormLayout.vue | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/backends/database.js b/backends/database.js index dfe5a19b..67096c4c 100644 --- a/backends/database.js +++ b/backends/database.js @@ -195,8 +195,8 @@ module.exports = class Database extends Observable { } triggerChange(doctype, name) { - this.trigger(`change:${doctype}`, { name: name }, 500); - this.trigger(`change`, { doctype: name, name: name }, 500); + this.trigger(`change:${doctype}`, { name }, 500); + this.trigger(`change`, { doctype, name }, 500); } async insert(doctype, doc) { diff --git a/model/document.js b/model/document.js index b81607de..051a6459 100644 --- a/model/document.js +++ b/model/document.js @@ -188,7 +188,7 @@ module.exports = class BaseDocument extends Observable { } async compareWithCurrentDoc() { - if (frappe.isServer && !this._notInserted) { + if (frappe.isServer && !this.isNew()) { let currentDoc = await frappe.db.get(this.doctype, this.name); // check for conflict @@ -347,4 +347,8 @@ module.exports = class BaseDocument extends Observable { } return _values[fieldname]; } + + isNew() { + return this._notInserted; + } }; diff --git a/ui/components/Form/Form.vue b/ui/components/Form/Form.vue index e9ac15f0..64ea7839 100644 --- a/ui/components/Form/Form.vue +++ b/ui/components/Form/Form.vue @@ -56,7 +56,7 @@ export default { try { this.doc = await frappe.getDoc(this.doctype, this.name); - if (this.doc._notInserted && this.meta.fields.map(df => df.fieldname).includes('name')) { + if (this.doc.isNew() && this.meta.fields.map(df => df.fieldname).includes('name')) { // For a user editable name field, // it should be unset since it is autogenerated this.doc.set('name', ''); @@ -82,7 +82,7 @@ export default { if (this.invalid) return; try { - if (this.doc._notInserted) { + if (this.doc.isNew()) { await this.doc.insert(); } else { await this.doc.update(); diff --git a/ui/components/Form/FormActions.vue b/ui/components/Form/FormActions.vue index cae77d36..d3c0b75d 100644 --- a/ui/components/Form/FormActions.vue +++ b/ui/components/Form/FormActions.vue @@ -46,19 +46,19 @@ export default { this.showSubmit = this.meta.isSubmittable && !this.isDirty - && !this.doc._notInserted + && !this.doc.isNew() && this.doc.submitted === 0; this.showRevert = this.meta.isSubmittable && !this.isDirty - && !this.doc._notInserted + && !this.doc.isNew() && this.doc.submitted === 1; this.showNextAction = 1 this.showNextAction = - !this.doc._notInserted + !this.doc.isNew() && this.links.length; this.showPrint = @@ -66,14 +66,14 @@ export default { && this.meta.print this.showSave = - this.doc._notInserted ? + this.doc.isNew() ? true : this.meta.isSubmittable ? (this.isDirty ? true : false) : true; this.disableSave = - this.doc._notInserted ? false : !this.isDirty; + this.doc.isNew() ? false : !this.isDirty; } }, computed: { @@ -83,7 +83,7 @@ export default { title() { const _ = this._; - if (this.doc._notInserted) { + if (this.doc.isNew()) { return _('New {0}', _(this.doc.doctype)); } diff --git a/ui/components/Form/FormLayout.vue b/ui/components/Form/FormLayout.vue index 7eed8b6c..6492a3e2 100644 --- a/ui/components/Form/FormLayout.vue +++ b/ui/components/Form/FormLayout.vue @@ -58,7 +58,7 @@ export default { return false; } - if (fieldname === 'name' && !this.doc._notInserted) { + if (fieldname === 'name' && !this.doc.isNew()) { return false; }