2019-10-04 20:18:10 +00:00
|
|
|
<template>
|
|
|
|
<div class="border-l h-full">
|
2019-11-19 19:08:49 +00:00
|
|
|
<div class="flex items-center justify-between px-4 pt-4">
|
|
|
|
<div class="flex items-center">
|
2019-12-03 13:10:21 +00:00
|
|
|
<Button :icon="true" @click="routeToPrevious">
|
2019-11-19 19:08:49 +00:00
|
|
|
<feather-icon name="x" class="w-4 h-4" />
|
|
|
|
</Button>
|
|
|
|
<span v-if="statusText" class="ml-2 text-base text-gray-600">{{
|
|
|
|
statusText
|
|
|
|
}}</span>
|
|
|
|
</div>
|
|
|
|
<div class="flex items-stretch">
|
2019-12-20 06:44:31 +00:00
|
|
|
<DropdownWithActions :actions="actions" />
|
2019-11-19 19:08:49 +00:00
|
|
|
<Button
|
|
|
|
:icon="true"
|
|
|
|
@click="insertDoc"
|
|
|
|
type="primary"
|
|
|
|
v-if="doc && doc._notInserted"
|
|
|
|
class="ml-2 text-white text-xs"
|
|
|
|
>
|
|
|
|
{{ _('Save') }}
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
:icon="true"
|
|
|
|
@click="submitDoc"
|
|
|
|
type="primary"
|
|
|
|
v-if="
|
|
|
|
meta &&
|
|
|
|
meta.isSubmittable &&
|
|
|
|
doc &&
|
|
|
|
!doc.submitted &&
|
|
|
|
!doc._notInserted
|
|
|
|
"
|
|
|
|
class="ml-2 text-white text-xs"
|
|
|
|
>
|
|
|
|
{{ _('Submit') }}
|
|
|
|
</Button>
|
|
|
|
</div>
|
2019-10-04 20:18:10 +00:00
|
|
|
</div>
|
2019-12-11 09:09:16 +00:00
|
|
|
<div class="px-4 pt-2 pb-4 flex-center" v-if="doc">
|
2019-11-19 19:08:49 +00:00
|
|
|
<div class="flex flex-col items-center">
|
2019-10-13 12:03:01 +00:00
|
|
|
<FormControl
|
2019-11-19 19:08:49 +00:00
|
|
|
v-if="imageField"
|
|
|
|
:df="imageField"
|
|
|
|
:value="doc[imageField.fieldname]"
|
|
|
|
@change="value => valueChange(imageField, value)"
|
2019-10-13 12:03:01 +00:00
|
|
|
size="small"
|
2019-11-19 19:08:49 +00:00
|
|
|
class="mb-1"
|
|
|
|
:letter-placeholder="
|
2019-12-04 18:40:46 +00:00
|
|
|
// for AttachImage field
|
2019-11-19 19:08:49 +00:00
|
|
|
doc[titleField.fieldname] ? doc[titleField.fieldname][0] : null
|
|
|
|
"
|
|
|
|
/>
|
|
|
|
<FormControl
|
|
|
|
input-class="text-center"
|
|
|
|
ref="titleControl"
|
|
|
|
v-if="titleField"
|
|
|
|
:df="titleField"
|
|
|
|
:value="doc[titleField.fieldname]"
|
|
|
|
@change="value => valueChange(titleField, value)"
|
|
|
|
@input="setTitleSize"
|
2019-10-13 12:03:01 +00:00
|
|
|
/>
|
2019-11-19 19:08:49 +00:00
|
|
|
</div>
|
2019-10-04 20:18:10 +00:00
|
|
|
</div>
|
2019-11-19 19:08:49 +00:00
|
|
|
<TwoColumnForm
|
|
|
|
ref="form"
|
|
|
|
v-if="doc"
|
|
|
|
:doc="doc"
|
|
|
|
:fields="fields"
|
|
|
|
:autosave="true"
|
|
|
|
:column-ratio="[1.1, 2]"
|
|
|
|
/>
|
2019-12-26 13:45:41 +00:00
|
|
|
<component v-if="doc && quickEditWidget" :is="quickEditWidget" />
|
2019-10-04 20:18:10 +00:00
|
|
|
</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';
|
2019-10-05 21:41:16 +00:00
|
|
|
import FormControl from '@/components/Controls/FormControl';
|
2019-11-19 19:08:49 +00:00
|
|
|
import TwoColumnForm from '@/components/TwoColumnForm';
|
2019-12-20 06:44:31 +00:00
|
|
|
import DropdownWithActions from '@/components/DropdownWithActions';
|
|
|
|
import { openQuickEdit, getActionsForDocument } from '@/utils';
|
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-11-19 19:08:49 +00:00
|
|
|
FormControl,
|
|
|
|
TwoColumnForm,
|
2019-12-20 06:44:31 +00:00
|
|
|
DropdownWithActions
|
2019-10-04 20:18:10 +00:00
|
|
|
},
|
2019-10-06 12:33:21 +00:00
|
|
|
provide() {
|
2019-11-19 19:08:49 +00:00
|
|
|
let vm = this;
|
2019-10-06 12:33:21 +00:00
|
|
|
return {
|
|
|
|
doctype: this.doctype,
|
2019-11-19 19:08:49 +00:00
|
|
|
name: this.name,
|
|
|
|
get doc() {
|
|
|
|
return vm.doc;
|
|
|
|
}
|
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-11-19 19:08:49 +00:00
|
|
|
doc: null,
|
|
|
|
titleField: null,
|
|
|
|
imageField: null,
|
2019-12-04 18:40:46 +00:00
|
|
|
statusText: null
|
2019-10-04 20:18:10 +00:00
|
|
|
};
|
|
|
|
},
|
2019-11-19 19:08:49 +00:00
|
|
|
async created() {
|
2019-10-11 09:55:50 +00:00
|
|
|
await this.fetchMetaAndDoc();
|
2019-10-05 21:41:16 +00:00
|
|
|
},
|
2019-11-19 19:08:49 +00:00
|
|
|
computed: {
|
|
|
|
meta() {
|
|
|
|
return frappe.getMeta(this.doctype);
|
|
|
|
},
|
|
|
|
fields() {
|
|
|
|
return this.meta
|
2019-10-29 19:33:26 +00:00
|
|
|
.getQuickEditFields()
|
|
|
|
.filter(df => !(this.hideFields || []).includes(df.fieldname));
|
2019-11-19 19:08:49 +00:00
|
|
|
},
|
|
|
|
actions() {
|
2019-12-20 06:44:31 +00:00
|
|
|
return getActionsForDocument(this.doc);
|
2019-12-26 13:45:41 +00:00
|
|
|
},
|
|
|
|
quickEditWidget() {
|
|
|
|
if (!this.meta.quickEditWidget) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return this.meta.quickEditWidget(this.doc);
|
2019-11-19 19:08:49 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async fetchMetaAndDoc() {
|
|
|
|
this.titleField = this.meta.getField(this.meta.titleField);
|
|
|
|
this.imageField = this.meta.getField('image');
|
2019-10-11 09:55:50 +00:00
|
|
|
await this.fetchDoc();
|
|
|
|
|
|
|
|
// setup the title field
|
2019-12-03 13:32:34 +00:00
|
|
|
if (this.doc.isNew() && this.doc[this.titleField.fieldname]) {
|
|
|
|
if (!this.titleField.readOnly) {
|
|
|
|
this.doc.set(this.titleField.fieldname, '');
|
|
|
|
setTimeout(() => {
|
|
|
|
this.$refs.titleControl.focus();
|
|
|
|
}, 300);
|
|
|
|
} else {
|
|
|
|
this.doc.set(this.titleField.fieldname, 'New ' + this.doc.doctype);
|
|
|
|
}
|
2019-10-11 09:55:50 +00:00
|
|
|
}
|
2019-11-19 19:08:49 +00:00
|
|
|
|
|
|
|
// set default values
|
2019-10-11 09:55:50 +00:00
|
|
|
if (this.values) {
|
|
|
|
this.doc.set(this.values);
|
|
|
|
}
|
2019-11-19 19:08:49 +00:00
|
|
|
|
|
|
|
// set title size
|
|
|
|
this.setTitleSize();
|
2019-10-11 09:55:50 +00:00
|
|
|
},
|
2019-11-19 19:08:49 +00:00
|
|
|
async fetchDoc() {
|
|
|
|
try {
|
|
|
|
this.doc = await frappe.getDoc(this.doctype, this.name);
|
|
|
|
|
2019-10-05 21:41:16 +00:00
|
|
|
this.doc.once('afterRename', () => {
|
2019-12-03 13:10:21 +00:00
|
|
|
openQuickEdit({
|
|
|
|
doctype: this.doctype,
|
|
|
|
name: this.doc.name
|
2019-10-11 09:55:50 +00:00
|
|
|
});
|
2019-10-05 21:41:16 +00:00
|
|
|
});
|
2019-11-19 19:08:49 +00:00
|
|
|
this.doc.on('beforeUpdate', () => {
|
|
|
|
this.statusText = _('Saving...');
|
|
|
|
});
|
|
|
|
this.doc.on('afterUpdate', () => {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.statusText = null;
|
|
|
|
}, 500);
|
|
|
|
});
|
2019-10-05 21:41:16 +00:00
|
|
|
} catch (e) {
|
2019-11-19 19:08:49 +00:00
|
|
|
this.$router.back();
|
2019-10-05 21:41:16 +00:00
|
|
|
}
|
|
|
|
},
|
2019-12-04 18:40:46 +00:00
|
|
|
valueChange(df, value) {
|
|
|
|
this.$refs.form.onChange(df, value);
|
|
|
|
},
|
2019-10-05 21:41:16 +00:00
|
|
|
insertDoc() {
|
2019-12-04 18:40:46 +00:00
|
|
|
this.$refs.form.insert();
|
2019-10-05 21:41:16 +00:00
|
|
|
},
|
2019-11-08 19:58:58 +00:00
|
|
|
submitDoc() {
|
2019-12-04 18:40:46 +00:00
|
|
|
this.$refs.form.submit();
|
2019-11-08 19:58:58 +00:00
|
|
|
},
|
2019-12-03 13:10:21 +00:00
|
|
|
routeToPrevious() {
|
|
|
|
this.$router.back();
|
|
|
|
},
|
2019-11-19 19:08:49 +00:00
|
|
|
setTitleSize() {
|
|
|
|
if (this.$refs.titleControl) {
|
|
|
|
let input = this.$refs.titleControl.getInput();
|
|
|
|
let value = input.value;
|
2019-12-03 13:32:34 +00:00
|
|
|
let valueLength = (value || '').length + 1;
|
2019-11-19 19:08:49 +00:00
|
|
|
if (valueLength < 7) {
|
|
|
|
valueLength = 7;
|
|
|
|
}
|
|
|
|
input.size = valueLength;
|
|
|
|
}
|
2019-10-05 21:41:16 +00:00
|
|
|
}
|
2019-10-04 20:18:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|