2019-10-04 20:18:10 +00:00
|
|
|
<template>
|
|
|
|
<div class="border-l h-full">
|
|
|
|
<div class="flex justify-end px-4 pt-4">
|
2019-10-29 19:33:26 +00:00
|
|
|
<Button :icon="true" @click="$router.back()">
|
2019-10-04 20:18:10 +00:00
|
|
|
<XIcon class="w-3 h-3 stroke-current text-gray-700" />
|
|
|
|
</Button>
|
2019-10-29 19:33:26 +00:00
|
|
|
<Button
|
|
|
|
:icon="true"
|
|
|
|
@click="insertDoc"
|
|
|
|
type="primary"
|
|
|
|
v-if="doc._notInserted"
|
|
|
|
class="ml-2 flex"
|
|
|
|
>
|
2019-10-05 21:41:16 +00:00
|
|
|
<feather-icon name="check" class="text-white" />
|
|
|
|
</Button>
|
2019-10-04 20:18:10 +00:00
|
|
|
</div>
|
2019-10-13 21:19:28 +00:00
|
|
|
<div class="pl-1 pr-4 pt-2 pb-4 border-b flex items-center justify-between">
|
2019-10-05 21:41:16 +00:00
|
|
|
<FormControl
|
|
|
|
ref="titleControl"
|
|
|
|
v-if="titleDocField"
|
|
|
|
:df="titleDocField"
|
|
|
|
:value="doc[titleDocField.fieldname]"
|
|
|
|
@change="value => valueChange(titleDocField, value)"
|
|
|
|
/>
|
2019-10-11 09:55:50 +00:00
|
|
|
<span v-if="statusText" class="text-xs text-gray-600">{{ statusText }}</span>
|
2019-10-04 20:18:10 +00:00
|
|
|
</div>
|
|
|
|
<div class="text-xs">
|
2019-10-13 12:03:01 +00:00
|
|
|
<template v-for="df in fields">
|
|
|
|
<FormControl
|
|
|
|
size="small"
|
|
|
|
v-if="df.fieldtype === 'Table'"
|
|
|
|
:df="df"
|
|
|
|
:value="doc[df.fieldname]"
|
|
|
|
@change="value => valueChange(df, value)"
|
|
|
|
/>
|
|
|
|
<div v-else class="grid border-b" style="grid-template-columns: 1fr 2fr">
|
|
|
|
<div class="py-2 pl-4 text-gray-600 flex items-center">{{ df.label }}</div>
|
|
|
|
<div class="py-2 pr-4">
|
|
|
|
<FormControl
|
|
|
|
size="small"
|
|
|
|
:df="df"
|
|
|
|
:value="doc[df.fieldname]"
|
|
|
|
@change="value => valueChange(df, value)"
|
|
|
|
@new-doc="doc => valueChange(df, doc.name)"
|
|
|
|
/>
|
|
|
|
</div>
|
2019-10-06 12:33:21 +00:00
|
|
|
</div>
|
2019-10-13 12:03:01 +00:00
|
|
|
</template>
|
2019-10-04 20:18:10 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import frappe from 'frappejs';
|
2019-10-11 09:55:50 +00:00
|
|
|
import { _ } from 'frappejs';
|
2019-10-04 20:18:10 +00:00
|
|
|
import Button from '@/components/Button';
|
|
|
|
import XIcon from '@/components/Icons/X';
|
2019-10-05 21:41:16 +00:00
|
|
|
import FormControl from '@/components/Controls/FormControl';
|
2019-10-04 20:18:10 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'QuickEditForm',
|
2019-10-29 19:33:26 +00:00
|
|
|
props: ['doctype', 'name', 'values', 'hideFields'],
|
2019-10-04 20:18:10 +00:00
|
|
|
components: {
|
|
|
|
Button,
|
2019-10-05 21:41:16 +00:00
|
|
|
XIcon,
|
|
|
|
FormControl
|
2019-10-04 20:18:10 +00:00
|
|
|
},
|
2019-10-06 12:33:21 +00:00
|
|
|
provide() {
|
|
|
|
return {
|
|
|
|
doctype: this.doctype,
|
|
|
|
name: this.name
|
2019-10-11 09:55:50 +00:00
|
|
|
};
|
2019-10-06 12:33:21 +00:00
|
|
|
},
|
2019-10-04 20:18:10 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2019-10-05 21:41:16 +00:00
|
|
|
meta: null,
|
2019-10-04 20:18:10 +00:00
|
|
|
doc: {},
|
2019-10-05 21:41:16 +00:00
|
|
|
fields: [],
|
|
|
|
titleDocField: null,
|
2019-10-11 09:55:50 +00:00
|
|
|
statusText: null
|
2019-10-04 20:18:10 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
async mounted() {
|
2019-10-11 09:55:50 +00:00
|
|
|
await this.fetchMetaAndDoc();
|
2019-10-05 21:41:16 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2019-10-11 09:55:50 +00:00
|
|
|
async fetchMetaAndDoc() {
|
|
|
|
this.meta = frappe.getMeta(this.doctype);
|
2019-10-29 19:33:26 +00:00
|
|
|
this.fields = this.meta
|
|
|
|
.getQuickEditFields()
|
|
|
|
.filter(df => !(this.hideFields || []).includes(df.fieldname));
|
2019-10-11 09:55:50 +00:00
|
|
|
this.titleDocField = this.meta.getField(this.meta.titleField);
|
|
|
|
await this.fetchDoc();
|
|
|
|
|
|
|
|
// setup the title field
|
2019-10-29 19:33:26 +00:00
|
|
|
if (
|
|
|
|
this.doc._notInserted &&
|
|
|
|
!this.titleDocField.readOnly &&
|
|
|
|
this.doc[this.titleDocField.fieldname]
|
|
|
|
) {
|
2019-10-11 09:55:50 +00:00
|
|
|
this.doc.set(this.titleDocField.fieldname, '');
|
2019-10-29 19:33:26 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
this.$refs.titleControl.focus();
|
|
|
|
}, 300);
|
2019-10-11 09:55:50 +00:00
|
|
|
}
|
|
|
|
if (this.values) {
|
|
|
|
this.doc.set(this.values);
|
|
|
|
}
|
|
|
|
},
|
2019-10-05 21:41:16 +00:00
|
|
|
valueChange(df, value) {
|
|
|
|
if (!value) return;
|
|
|
|
let oldValue = this.doc.get(df.fieldname);
|
2019-10-11 09:55:50 +00:00
|
|
|
if (
|
|
|
|
df.fieldname === 'name' &&
|
|
|
|
oldValue !== value &&
|
|
|
|
!this.doc._notInserted
|
|
|
|
) {
|
2019-10-05 21:41:16 +00:00
|
|
|
this.doc.rename(value);
|
|
|
|
this.doc.once('afterRename', () => {
|
2019-10-11 09:55:50 +00:00
|
|
|
this.$router.push({
|
|
|
|
path: `/list/${this.doctype}`,
|
|
|
|
query: {
|
|
|
|
edit: 1,
|
|
|
|
doctype: this.doctype,
|
|
|
|
name: this.name
|
|
|
|
}
|
|
|
|
});
|
2019-10-05 21:41:16 +00:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.doc.set(df.fieldname, value);
|
|
|
|
if (this.doc._dirty && !this.doc._notInserted) {
|
2019-10-13 12:03:01 +00:00
|
|
|
if (df.fieldtype === 'Table') {
|
|
|
|
console.log(value);
|
|
|
|
return;
|
|
|
|
}
|
2019-10-05 21:41:16 +00:00
|
|
|
this.updateDoc();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async fetchDoc() {
|
|
|
|
this.doc = await frappe.getDoc(this.doctype, this.name);
|
|
|
|
},
|
|
|
|
async updateDoc() {
|
2019-10-11 09:55:50 +00:00
|
|
|
this.statusText = _('Saving...');
|
2019-10-05 21:41:16 +00:00
|
|
|
try {
|
|
|
|
await this.doc.update();
|
|
|
|
this.triggerSaved();
|
|
|
|
} catch (e) {
|
|
|
|
await this.fetchDoc();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
triggerSaved() {
|
2019-10-11 09:55:50 +00:00
|
|
|
this.statusText = _('Saved');
|
|
|
|
setTimeout(() => (this.statusText = null), 1000);
|
2019-10-05 21:41:16 +00:00
|
|
|
},
|
|
|
|
insertDoc() {
|
|
|
|
this.doc.insert();
|
|
|
|
},
|
|
|
|
routeToList() {
|
|
|
|
this.$router.push(`/list/${this.doctype}`);
|
|
|
|
}
|
2019-10-04 20:18:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|