2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00

fix: prevent editing of submitted submitable doctypes from quickform view

This commit is contained in:
18alantom 2021-11-08 17:05:30 +05:30
parent 8f64d95055
commit 08ae048db0

View File

@ -8,7 +8,8 @@
size="small" size="small"
:df="df" :df="df"
:value="doc[df.fieldname]" :value="doc[df.fieldname]"
@change="value => onChange(df, value)" :read-only="submitted"
@change="(value) => onChange(df, value)"
/> />
<template v-else> <template v-else>
<template v-if="inlineEditField === df && inlineEditDoc"> <template v-if="inlineEditField === df && inlineEditDoc">
@ -20,7 +21,7 @@
:column-ratio="columnRatio" :column-ratio="columnRatio"
:no-border="true" :no-border="true"
:focus-first-input="true" :focus-first-input="true"
@error="msg => $emit('error', msg)" @error="(msg) => $emit('error', msg)"
/> />
<div class="flex px-4 pb-2"> <div class="flex px-4 pb-2">
<Button <Button
@ -55,7 +56,7 @@
class="py-2 pr-4" class="py-2 pr-4"
@click="activateInlineEditing(df)" @click="activateInlineEditing(df)"
:class="{ :class="{
'pl-2': df.fieldtype === 'AttachImage' 'pl-2': df.fieldtype === 'AttachImage',
}" }"
> >
<FormControl <FormControl
@ -71,9 +72,10 @@
: doc[df.fieldname] : doc[df.fieldname]
" "
:class="{ 'p-2': df.fieldtype === 'Check' }" :class="{ 'p-2': df.fieldtype === 'Check' }"
@change="value => onChange(df, value)" :read-only="submitted"
@change="(value) => onChange(df, value)"
@focus="activateInlineEditing(df)" @focus="activateInlineEditing(df)"
@new-doc="newdoc => onChange(df, newdoc.name)" @new-doc="(newdoc) => onChange(df, newdoc.name)"
/> />
<div <div
class="text-sm text-red-600 mt-2 pl-2" class="text-sm text-red-600 mt-2 pl-2"
@ -101,10 +103,10 @@ let TwoColumnForm = {
autosave: Boolean, autosave: Boolean,
columnRatio: { columnRatio: {
type: Array, type: Array,
default: () => [1, 1] default: () => [1, 1],
}, },
noBorder: Boolean, noBorder: Boolean,
focusFirstInput: Boolean focusFirstInput: Boolean,
}, },
data() { data() {
return { return {
@ -112,20 +114,20 @@ let TwoColumnForm = {
inlineEditDoc: null, inlineEditDoc: null,
inlineEditFields: null, inlineEditFields: null,
inlineEditDisplayField: null, inlineEditDisplayField: null,
errors: {} errors: {},
}; };
}, },
provide() { provide() {
return { return {
doctype: this.doc.doctype, doctype: this.doc.doctype,
name: this.doc.name, name: this.doc.name,
doc: this.doc doc: this.doc,
}; };
}, },
components: { components: {
FormControl, FormControl,
Button, Button,
TwoColumnForm: () => TwoColumnForm TwoColumnForm: () => TwoColumnForm,
}, },
mounted() { mounted() {
if (this.focusFirstInput) { if (this.focusFirstInput) {
@ -135,8 +137,9 @@ let TwoColumnForm = {
methods: { methods: {
onChange(df, value) { onChange(df, value) {
if (value == null) { if (value == null) {
return; return
} }
let oldValue = this.doc.get(df.fieldname); let oldValue = this.doc.get(df.fieldname);
if (oldValue === value) { if (oldValue === value) {
@ -151,7 +154,7 @@ let TwoColumnForm = {
// reset error messages // reset error messages
this.$set(this.errors, df.fieldname, null); this.$set(this.errors, df.fieldname, null);
this.doc.set(df.fieldname, value).catch(e => { this.doc.set(df.fieldname, value).catch((e) => {
// set error message for this field // set error message for this field
this.$set(this.errors, df.fieldname, getErrorMessage(e, this.doc)); this.$set(this.errors, df.fieldname, getErrorMessage(e, this.doc));
}); });
@ -197,7 +200,7 @@ let TwoColumnForm = {
await this.doc.loadLinks(); await this.doc.loadLinks();
this.inlineEditField = null; this.inlineEditField = null;
} }
} },
}, },
computed: { computed: {
formFields() { formFields() {
@ -205,13 +208,16 @@ let TwoColumnForm = {
}, },
style() { style() {
let templateColumns = (this.columnRatio || [1, 1]) let templateColumns = (this.columnRatio || [1, 1])
.map(r => `${r}fr`) .map((r) => `${r}fr`)
.join(' '); .join(' ');
return { return {
'grid-template-columns': templateColumns 'grid-template-columns': templateColumns,
}; };
} },
} submitted() {
return Boolean(this.doc.meta.isSubmittable && this.doc.submitted);
},
},
}; };
export default TwoColumnForm; export default TwoColumnForm;