2023-02-17 21:05:06 +05:30
|
|
|
<template>
|
2023-05-31 11:12:09 +05:30
|
|
|
<FormContainer :use-full-width="useFullWidth">
|
2023-06-23 12:35:44 +05:30
|
|
|
<template v-if="hasDoc" #header-left>
|
2023-04-13 11:46:51 +05:30
|
|
|
<Barcode
|
|
|
|
v-if="canShowBarcode"
|
2023-06-23 12:35:44 +05:30
|
|
|
class="h-8"
|
2023-04-13 11:46:51 +05:30
|
|
|
@item-selected="(name:string) => {
|
|
|
|
// @ts-ignore
|
|
|
|
doc?.addItem(name);
|
|
|
|
}"
|
|
|
|
/>
|
|
|
|
<ExchangeRate
|
2023-04-17 14:26:14 +05:30
|
|
|
v-if="canShowExchangeRate"
|
2023-04-13 11:46:51 +05:30
|
|
|
:disabled="doc?.isSubmitted || doc?.isCancelled"
|
|
|
|
:from-currency="fromCurrency"
|
|
|
|
:to-currency="toCurrency"
|
|
|
|
:exchange-rate="exchangeRate"
|
|
|
|
@change="
|
|
|
|
async (exchangeRate: number) =>
|
|
|
|
await doc.set('exchangeRate', exchangeRate)
|
|
|
|
"
|
|
|
|
/>
|
2023-04-17 14:26:14 +05:30
|
|
|
<p
|
|
|
|
v-if="schema.label && !(canShowBarcode || canShowExchangeRate)"
|
|
|
|
class="text-xl font-semibold items-center text-gray-600"
|
|
|
|
>
|
|
|
|
{{ schema.label }}
|
|
|
|
</p>
|
2023-03-06 11:56:54 +05:30
|
|
|
</template>
|
2023-06-23 12:35:44 +05:30
|
|
|
<template v-if="hasDoc" #header>
|
2023-04-13 11:46:51 +05:30
|
|
|
<Button
|
|
|
|
v-if="canShowLinks"
|
|
|
|
:icon="true"
|
|
|
|
:title="t`View linked entries`"
|
2023-06-23 12:35:44 +05:30
|
|
|
@click="showLinks = true"
|
2023-04-13 11:46:51 +05:30
|
|
|
>
|
|
|
|
<feather-icon name="link" class="w-4 h-4"></feather-icon>
|
|
|
|
</Button>
|
2023-03-06 15:13:54 +05:30
|
|
|
<Button
|
2023-03-23 12:25:25 +05:30
|
|
|
v-if="canPrint"
|
|
|
|
ref="printButton"
|
2023-03-06 15:13:54 +05:30
|
|
|
:icon="true"
|
2023-04-13 11:46:51 +05:30
|
|
|
:title="t`Open Print View`"
|
2023-06-23 12:35:44 +05:30
|
|
|
@click="routeTo(`/print/${doc.schemaName}/${doc.name}`)"
|
2023-03-06 15:13:54 +05:30
|
|
|
>
|
2023-04-13 11:46:51 +05:30
|
|
|
<feather-icon name="printer" class="w-4 h-4"></feather-icon>
|
2023-03-06 15:13:54 +05:30
|
|
|
</Button>
|
2023-05-31 11:12:09 +05:30
|
|
|
<Button
|
|
|
|
:icon="true"
|
|
|
|
:title="t`Toggle between form and full width`"
|
2023-06-23 12:35:44 +05:30
|
|
|
@click="toggleWidth"
|
2023-05-31 11:12:09 +05:30
|
|
|
>
|
|
|
|
<feather-icon
|
|
|
|
:name="useFullWidth ? 'minimize' : 'maximize'"
|
|
|
|
class="w-4 h-4"
|
|
|
|
></feather-icon>
|
|
|
|
</Button>
|
2023-02-20 10:22:19 +05:30
|
|
|
<DropdownWithActions
|
|
|
|
v-for="group of groupedActions"
|
|
|
|
:key="group.label"
|
|
|
|
:type="group.type"
|
|
|
|
:actions="group.actions"
|
|
|
|
>
|
|
|
|
<p v-if="group.group">
|
|
|
|
{{ group.group }}
|
|
|
|
</p>
|
|
|
|
<feather-icon v-else name="more-horizontal" class="w-4 h-4" />
|
|
|
|
</DropdownWithActions>
|
2023-02-21 11:04:35 +05:30
|
|
|
<Button v-if="doc?.canSave" type="primary" @click="sync">
|
2023-02-20 10:22:19 +05:30
|
|
|
{{ t`Save` }}
|
|
|
|
</Button>
|
2023-02-21 11:04:35 +05:30
|
|
|
<Button v-else-if="doc?.canSubmit" type="primary" @click="submit">{{
|
|
|
|
t`Submit`
|
|
|
|
}}</Button>
|
2023-02-20 10:22:19 +05:30
|
|
|
</template>
|
2023-02-17 21:05:06 +05:30
|
|
|
<template #body>
|
2024-03-25 23:16:13 +05:30
|
|
|
<FormHeader
|
|
|
|
:form-title="title"
|
|
|
|
class="
|
|
|
|
sticky
|
|
|
|
top-0
|
|
|
|
bg-white
|
|
|
|
dark:bg-gray-890
|
|
|
|
border-b
|
|
|
|
dark:border-gray-800
|
|
|
|
"
|
|
|
|
>
|
2023-04-17 14:26:14 +05:30
|
|
|
<StatusPill v-if="hasDoc" :doc="doc" />
|
2023-02-20 10:22:19 +05:30
|
|
|
</FormHeader>
|
2023-02-17 21:05:06 +05:30
|
|
|
|
|
|
|
<!-- Section Container -->
|
2024-03-25 23:16:13 +05:30
|
|
|
<div
|
|
|
|
v-if="hasDoc"
|
|
|
|
class="overflow-auto custom-scroll custom-scroll-thumb1"
|
|
|
|
>
|
2023-02-17 21:05:06 +05:30
|
|
|
<CommonFormSection
|
2023-06-26 13:40:23 +05:30
|
|
|
v-for="([n, fields], idx) in activeGroup.entries()"
|
|
|
|
:key="n + idx"
|
2023-02-17 21:05:06 +05:30
|
|
|
ref="section"
|
|
|
|
class="p-4"
|
2024-03-25 23:16:13 +05:30
|
|
|
:class="
|
|
|
|
idx !== 0 && activeGroup.size > 1
|
|
|
|
? 'border-t dark:border-gray-800'
|
|
|
|
: ''
|
|
|
|
"
|
2023-06-26 13:40:23 +05:30
|
|
|
:show-title="activeGroup.size > 1 && n !== t`Default`"
|
|
|
|
:title="n"
|
2023-02-17 21:05:06 +05:30
|
|
|
:fields="fields"
|
|
|
|
:doc="doc"
|
2023-02-21 11:04:35 +05:30
|
|
|
:errors="errors"
|
2023-06-23 12:35:44 +05:30
|
|
|
@editrow="(doc: Doc) => showRowEditForm(doc)"
|
2023-02-21 11:04:35 +05:30
|
|
|
@value-change="onValueChange"
|
2023-04-13 11:46:51 +05:30
|
|
|
@row-change="updateGroupedFields"
|
2023-02-17 21:05:06 +05:30
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Tab Bar -->
|
|
|
|
<div
|
2023-06-23 12:35:44 +05:30
|
|
|
v-if="groupedFields && groupedFields.size > 1"
|
2023-02-17 21:05:06 +05:30
|
|
|
class="
|
|
|
|
mt-auto
|
|
|
|
px-4
|
|
|
|
pb-4
|
|
|
|
flex
|
|
|
|
gap-8
|
2024-03-25 23:16:13 +05:30
|
|
|
border-t
|
|
|
|
dark:border-gray-800
|
2023-02-17 21:05:06 +05:30
|
|
|
flex-shrink-0
|
|
|
|
sticky
|
|
|
|
bottom-0
|
2024-03-25 23:16:13 +05:30
|
|
|
bg-white
|
|
|
|
dark:bg-gray-875
|
2023-02-17 21:05:06 +05:30
|
|
|
"
|
|
|
|
>
|
|
|
|
<div
|
2023-02-20 11:22:48 +05:30
|
|
|
v-for="key of groupedFields.keys()"
|
2023-02-17 21:05:06 +05:30
|
|
|
:key="key"
|
|
|
|
class="text-sm cursor-pointer"
|
|
|
|
:class="
|
|
|
|
key === activeTab
|
2024-03-25 20:13:54 +05:30
|
|
|
? 'text-gray-900 dark:text-gray-25 font-semibold border-t-2 border-gray-800 dark:border-gray-100'
|
|
|
|
: 'text-gray-700 dark:text-gray-200 '
|
2023-02-17 21:05:06 +05:30
|
|
|
"
|
|
|
|
:style="{
|
|
|
|
paddingTop: key === activeTab ? 'calc(1rem - 2px)' : '1rem',
|
|
|
|
}"
|
2023-06-23 12:35:44 +05:30
|
|
|
@click="activeTab = key"
|
2023-02-17 21:05:06 +05:30
|
|
|
>
|
|
|
|
{{ key }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
2023-02-20 11:22:48 +05:30
|
|
|
<template #quickedit>
|
2023-04-13 11:46:51 +05:30
|
|
|
<Transition name="quickedit">
|
|
|
|
<LinkedEntries
|
2023-04-17 12:19:41 +05:30
|
|
|
v-if="showLinks && canShowLinks"
|
2023-04-13 11:46:51 +05:30
|
|
|
:doc="doc"
|
|
|
|
@close="showLinks = false"
|
|
|
|
/>
|
|
|
|
</Transition>
|
2023-04-17 12:19:41 +05:30
|
|
|
<Transition name="quickedit">
|
|
|
|
<RowEditForm
|
|
|
|
v-if="row && !showLinks"
|
|
|
|
:doc="doc"
|
|
|
|
:fieldname="row.fieldname"
|
|
|
|
:index="row.index"
|
|
|
|
@previous="(i:number) => row!.index = i"
|
|
|
|
@next="(i:number) => row!.index = i"
|
|
|
|
@close="() => (row = null)"
|
|
|
|
/>
|
|
|
|
</Transition>
|
2023-02-20 11:22:48 +05:30
|
|
|
</template>
|
2023-02-17 21:05:06 +05:30
|
|
|
</FormContainer>
|
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
2023-02-21 11:04:35 +05:30
|
|
|
import { DocValue } from 'fyo/core/types';
|
2023-02-17 21:05:06 +05:30
|
|
|
import { Doc } from 'fyo/model/doc';
|
2023-04-17 12:19:41 +05:30
|
|
|
import { DEFAULT_CURRENCY } from 'fyo/utils/consts';
|
2023-02-17 21:05:06 +05:30
|
|
|
import { ValidationError } from 'fyo/utils/errors';
|
2023-02-20 10:22:19 +05:30
|
|
|
import { getDocStatus } from 'models/helpers';
|
2023-02-17 21:05:06 +05:30
|
|
|
import { ModelNameEnum } from 'models/types';
|
|
|
|
import { Field, Schema } from 'schemas/types';
|
2023-02-20 10:22:19 +05:30
|
|
|
import Button from 'src/components/Button.vue';
|
2023-04-17 12:19:41 +05:30
|
|
|
import Barcode from 'src/components/Controls/Barcode.vue';
|
|
|
|
import ExchangeRate from 'src/components/Controls/ExchangeRate.vue';
|
2023-02-20 10:22:19 +05:30
|
|
|
import DropdownWithActions from 'src/components/DropdownWithActions.vue';
|
2023-02-17 21:05:06 +05:30
|
|
|
import FormContainer from 'src/components/FormContainer.vue';
|
|
|
|
import FormHeader from 'src/components/FormHeader.vue';
|
2023-04-17 14:26:14 +05:30
|
|
|
import StatusPill from 'src/components/StatusPill.vue';
|
2023-02-21 11:04:35 +05:30
|
|
|
import { getErrorMessage } from 'src/utils';
|
2023-04-17 12:19:41 +05:30
|
|
|
import { shortcutsKey } from 'src/utils/injectionKeys';
|
2023-03-01 14:05:59 +05:30
|
|
|
import { docsPathMap } from 'src/utils/misc';
|
2023-03-21 13:22:49 +05:30
|
|
|
import { docsPathRef } from 'src/utils/refs';
|
2023-03-23 12:25:25 +05:30
|
|
|
import { ActionGroup, DocRef, UIGroupedFields } from 'src/utils/types';
|
2023-02-20 10:22:19 +05:30
|
|
|
import {
|
2023-03-15 14:02:52 +05:30
|
|
|
commonDocSubmit,
|
|
|
|
commonDocSync,
|
2023-02-22 15:51:20 +05:30
|
|
|
getDocFromNameIfExistsElseNew,
|
2023-02-20 10:22:19 +05:30
|
|
|
getFieldsGroupedByTabAndSection,
|
2023-04-24 13:05:50 +05:30
|
|
|
getFormRoute,
|
2023-02-20 10:22:19 +05:30
|
|
|
getGroupedActionsForDoc,
|
2023-03-06 15:13:54 +05:30
|
|
|
isPrintable,
|
|
|
|
routeTo,
|
2023-02-20 10:22:19 +05:30
|
|
|
} from 'src/utils/ui';
|
2023-03-23 12:25:25 +05:30
|
|
|
import { useDocShortcuts } from 'src/utils/vueUtils';
|
2023-04-17 12:19:41 +05:30
|
|
|
import { computed, defineComponent, inject, nextTick, ref } from 'vue';
|
|
|
|
import CommonFormSection from './CommonFormSection.vue';
|
2023-04-13 11:46:51 +05:30
|
|
|
import LinkedEntries from './LinkedEntries.vue';
|
2023-04-17 12:19:41 +05:30
|
|
|
import RowEditForm from './RowEditForm.vue';
|
2023-02-17 21:05:06 +05:30
|
|
|
|
|
|
|
export default defineComponent({
|
2023-06-23 12:35:44 +05:30
|
|
|
components: {
|
|
|
|
FormContainer,
|
|
|
|
FormHeader,
|
|
|
|
CommonFormSection,
|
|
|
|
Button,
|
|
|
|
DropdownWithActions,
|
|
|
|
Barcode,
|
|
|
|
ExchangeRate,
|
|
|
|
LinkedEntries,
|
|
|
|
RowEditForm,
|
|
|
|
StatusPill,
|
|
|
|
},
|
|
|
|
provide() {
|
|
|
|
return {
|
|
|
|
doc: computed(() => this.docOrNull),
|
|
|
|
};
|
|
|
|
},
|
2023-02-17 21:05:06 +05:30
|
|
|
props: {
|
2023-02-20 11:22:48 +05:30
|
|
|
name: { type: String, default: '' },
|
2023-02-21 11:04:35 +05:30
|
|
|
schemaName: { type: String, default: ModelNameEnum.SalesInvoice },
|
2023-02-17 21:05:06 +05:30
|
|
|
},
|
2023-03-23 12:25:25 +05:30
|
|
|
setup() {
|
|
|
|
const shortcuts = inject(shortcutsKey);
|
|
|
|
const docOrNull = ref(null) as DocRef;
|
|
|
|
let context = 'CommonForm';
|
|
|
|
if (shortcuts) {
|
|
|
|
context = useDocShortcuts(shortcuts, docOrNull, 'CommonForm', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
docOrNull,
|
|
|
|
shortcuts,
|
|
|
|
context,
|
|
|
|
printButton: ref<InstanceType<typeof Button> | null>(null),
|
|
|
|
};
|
|
|
|
},
|
2023-02-17 21:05:06 +05:30
|
|
|
data() {
|
|
|
|
return {
|
2023-02-21 11:04:35 +05:30
|
|
|
errors: {},
|
2023-03-15 12:48:10 +05:30
|
|
|
activeTab: this.t`Default`,
|
2023-02-21 11:04:35 +05:30
|
|
|
groupedFields: null,
|
2023-03-06 15:13:54 +05:30
|
|
|
isPrintable: false,
|
2023-04-13 11:46:51 +05:30
|
|
|
showLinks: false,
|
2023-05-31 11:12:09 +05:30
|
|
|
useFullWidth: false,
|
2023-04-17 12:19:41 +05:30
|
|
|
row: null,
|
2023-02-20 11:22:48 +05:30
|
|
|
} as {
|
2023-02-21 11:04:35 +05:30
|
|
|
errors: Record<string, string>;
|
2023-02-20 11:22:48 +05:30
|
|
|
activeTab: string;
|
2023-02-21 11:04:35 +05:30
|
|
|
groupedFields: null | UIGroupedFields;
|
2023-03-06 15:13:54 +05:30
|
|
|
isPrintable: boolean;
|
2023-04-13 11:46:51 +05:30
|
|
|
showLinks: boolean;
|
2023-05-31 11:12:09 +05:30
|
|
|
useFullWidth: boolean;
|
2023-04-17 12:19:41 +05:30
|
|
|
row: null | { index: number; fieldname: string };
|
2023-02-20 11:22:48 +05:30
|
|
|
};
|
2023-02-17 21:05:06 +05:30
|
|
|
},
|
|
|
|
computed: {
|
2023-04-13 11:46:51 +05:30
|
|
|
canShowBarcode(): boolean {
|
|
|
|
if (!this.fyo.singles.InventorySettings?.enableBarcodes) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.hasDoc) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.doc.isSubmitted || this.doc.isCancelled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
return typeof this.doc?.addItem === 'function';
|
|
|
|
},
|
2023-04-17 14:26:14 +05:30
|
|
|
canShowExchangeRate(): boolean {
|
|
|
|
return this.hasDoc && !!this.doc.isMultiCurrency;
|
|
|
|
},
|
2023-04-13 11:46:51 +05:30
|
|
|
exchangeRate(): number {
|
|
|
|
if (!this.hasDoc || typeof this.doc.exchangeRate !== 'number') {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.doc.exchangeRate;
|
|
|
|
},
|
|
|
|
fromCurrency(): string {
|
|
|
|
const currency = this.doc?.currency;
|
|
|
|
if (typeof currency !== 'string') {
|
|
|
|
return this.toCurrency;
|
|
|
|
}
|
|
|
|
|
|
|
|
return currency;
|
|
|
|
},
|
|
|
|
toCurrency(): string {
|
|
|
|
const currency = this.fyo.singles.SystemSettings?.currency;
|
|
|
|
if (typeof currency !== 'string') {
|
|
|
|
return DEFAULT_CURRENCY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return currency;
|
|
|
|
},
|
2023-03-23 12:25:25 +05:30
|
|
|
canPrint(): boolean {
|
|
|
|
if (!this.hasDoc) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !this.doc.isCancelled && !this.doc.dirty && this.isPrintable;
|
|
|
|
},
|
2023-04-13 11:46:51 +05:30
|
|
|
canShowLinks(): boolean {
|
2023-04-17 12:19:41 +05:30
|
|
|
if (!this.hasDoc) {
|
2023-04-13 11:46:51 +05:30
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.doc.schema.isSubmittable && !this.doc.isSubmitted) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.doc.inserted;
|
|
|
|
},
|
2023-02-17 21:05:06 +05:30
|
|
|
hasDoc(): boolean {
|
2023-03-23 12:25:25 +05:30
|
|
|
return this.docOrNull instanceof Doc;
|
2023-02-17 21:05:06 +05:30
|
|
|
},
|
2023-02-20 10:22:19 +05:30
|
|
|
status(): string {
|
|
|
|
if (!this.hasDoc) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return getDocStatus(this.doc);
|
|
|
|
},
|
2023-02-17 21:05:06 +05:30
|
|
|
doc(): Doc {
|
2023-06-23 12:35:44 +05:30
|
|
|
const doc = this.docOrNull;
|
2023-02-17 21:05:06 +05:30
|
|
|
if (!doc) {
|
|
|
|
throw new ValidationError(
|
|
|
|
this.t`Doc ${this.schema.label} ${this.name} not set`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return doc;
|
|
|
|
},
|
|
|
|
title(): string {
|
2023-02-20 10:22:19 +05:30
|
|
|
if (this.schema.isSubmittable && this.docOrNull?.notInserted) {
|
2023-02-17 21:05:06 +05:30
|
|
|
return this.t`New Entry`;
|
|
|
|
}
|
2023-02-20 10:22:19 +05:30
|
|
|
|
2023-04-24 13:05:50 +05:30
|
|
|
return this.docOrNull?.name || this.t`New Entry`;
|
2023-02-17 21:05:06 +05:30
|
|
|
},
|
|
|
|
schema(): Schema {
|
|
|
|
const schema = this.fyo.schemaMap[this.schemaName];
|
|
|
|
if (!schema) {
|
|
|
|
throw new ValidationError(`no schema found with ${this.schemaName}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return schema;
|
|
|
|
},
|
|
|
|
activeGroup(): Map<string, Field[]> {
|
2023-02-21 11:04:35 +05:30
|
|
|
if (!this.groupedFields) {
|
|
|
|
return new Map();
|
|
|
|
}
|
|
|
|
|
2023-02-20 11:22:48 +05:30
|
|
|
const group = this.groupedFields.get(this.activeTab);
|
2023-02-17 21:05:06 +05:30
|
|
|
if (!group) {
|
2023-04-20 13:27:07 +05:30
|
|
|
const tab = [...this.groupedFields.keys()][0];
|
2023-06-26 13:40:23 +05:30
|
|
|
return this.groupedFields.get(tab) ?? new Map<string, Field[]>();
|
2023-02-17 21:05:06 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return group;
|
|
|
|
},
|
2023-02-20 10:22:19 +05:30
|
|
|
groupedActions(): ActionGroup[] {
|
|
|
|
if (!this.hasDoc) {
|
|
|
|
return [];
|
|
|
|
}
|
2023-02-17 21:05:06 +05:30
|
|
|
|
2023-02-20 10:22:19 +05:30
|
|
|
return getGroupedActionsForDoc(this.doc);
|
|
|
|
},
|
|
|
|
},
|
2023-06-26 13:40:23 +05:30
|
|
|
beforeMount() {
|
2023-06-23 12:35:44 +05:30
|
|
|
this.useFullWidth = !!this.fyo.singles.Misc?.useFullWidth;
|
|
|
|
},
|
|
|
|
async mounted() {
|
|
|
|
if (this.fyo.store.isDevelopment) {
|
|
|
|
// @ts-ignore
|
|
|
|
window.cf = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
await this.setDoc();
|
|
|
|
this.replacePathAfterSync();
|
|
|
|
this.updateGroupedFields();
|
|
|
|
if (this.groupedFields) {
|
|
|
|
this.activeTab = [...this.groupedFields.keys()][0];
|
|
|
|
}
|
|
|
|
this.isPrintable = await isPrintable(this.schemaName);
|
|
|
|
},
|
|
|
|
activated(): void {
|
|
|
|
this.useFullWidth = !!this.fyo.singles.Misc?.useFullWidth;
|
|
|
|
docsPathRef.value = docsPathMap[this.schemaName] ?? '';
|
|
|
|
this.shortcuts?.pmod.set(this.context, ['KeyP'], () => {
|
|
|
|
if (!this.canPrint) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.printButton?.$el.click();
|
|
|
|
});
|
|
|
|
this.shortcuts?.pmod.set(this.context, ['KeyL'], () => {
|
|
|
|
if (!this.canShowLinks && !this.showLinks) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.showLinks = !this.showLinks;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
deactivated(): void {
|
|
|
|
docsPathRef.value = '';
|
|
|
|
this.showLinks = false;
|
|
|
|
this.row = null;
|
|
|
|
},
|
2023-02-20 10:22:19 +05:30
|
|
|
methods: {
|
2023-03-06 15:13:54 +05:30
|
|
|
routeTo,
|
2023-05-31 11:12:09 +05:30
|
|
|
async toggleWidth() {
|
|
|
|
const value = !this.useFullWidth;
|
|
|
|
await this.fyo.singles.Misc?.setAndSync('useFullWidth', value);
|
|
|
|
this.useFullWidth = value;
|
|
|
|
},
|
2023-02-21 11:51:32 +05:30
|
|
|
updateGroupedFields(): void {
|
2023-02-21 11:04:35 +05:30
|
|
|
if (!this.hasDoc) {
|
2023-02-21 11:51:32 +05:30
|
|
|
return;
|
2023-02-21 11:04:35 +05:30
|
|
|
}
|
|
|
|
|
2023-02-21 11:51:32 +05:30
|
|
|
this.groupedFields = getFieldsGroupedByTabAndSection(
|
|
|
|
this.schema,
|
|
|
|
this.doc
|
|
|
|
);
|
2023-02-21 11:04:35 +05:30
|
|
|
},
|
2023-03-23 12:25:25 +05:30
|
|
|
async sync(useDialog?: boolean) {
|
|
|
|
if (await commonDocSync(this.doc, useDialog)) {
|
2023-02-21 11:51:32 +05:30
|
|
|
this.updateGroupedFields();
|
2023-02-21 11:04:35 +05:30
|
|
|
}
|
|
|
|
},
|
|
|
|
async submit() {
|
2023-03-15 14:02:52 +05:30
|
|
|
if (await commonDocSubmit(this.doc)) {
|
2023-02-21 11:51:32 +05:30
|
|
|
this.updateGroupedFields();
|
2023-02-21 11:04:35 +05:30
|
|
|
}
|
|
|
|
},
|
2023-02-20 10:22:19 +05:30
|
|
|
async setDoc() {
|
|
|
|
if (this.hasDoc) {
|
|
|
|
return;
|
|
|
|
}
|
2023-02-17 21:05:06 +05:30
|
|
|
|
2023-02-22 15:51:20 +05:30
|
|
|
this.docOrNull = await getDocFromNameIfExistsElseNew(
|
|
|
|
this.schemaName,
|
|
|
|
this.name
|
|
|
|
);
|
2023-02-21 11:04:35 +05:30
|
|
|
},
|
2023-06-26 13:40:23 +05:30
|
|
|
replacePathAfterSync() {
|
2023-04-24 13:05:50 +05:30
|
|
|
if (!this.hasDoc || this.doc.inserted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-26 13:40:23 +05:30
|
|
|
this.doc.once('afterSync', async () => {
|
2023-04-24 13:05:50 +05:30
|
|
|
const route = getFormRoute(this.schemaName, this.doc.name!);
|
2023-06-26 13:40:23 +05:30
|
|
|
await this.$router.replace(route);
|
2023-04-24 13:05:50 +05:30
|
|
|
});
|
|
|
|
},
|
2023-04-17 12:19:41 +05:30
|
|
|
async showRowEditForm(doc: Doc) {
|
|
|
|
if (this.showLinks) {
|
2023-04-13 11:46:51 +05:30
|
|
|
this.showLinks = false;
|
|
|
|
await nextTick();
|
|
|
|
}
|
|
|
|
|
2023-04-17 12:19:41 +05:30
|
|
|
const index = doc.idx;
|
|
|
|
const fieldname = doc.parentFieldname;
|
|
|
|
|
|
|
|
if (typeof index === 'number' && typeof fieldname === 'string') {
|
|
|
|
this.row = { index, fieldname };
|
|
|
|
}
|
2023-02-20 11:22:48 +05:30
|
|
|
},
|
2023-02-21 11:04:35 +05:30
|
|
|
async onValueChange(field: Field, value: DocValue) {
|
|
|
|
const { fieldname } = field;
|
|
|
|
delete this.errors[fieldname];
|
|
|
|
|
|
|
|
try {
|
|
|
|
await this.doc.set(fieldname, value);
|
|
|
|
} catch (err) {
|
|
|
|
if (!(err instanceof Error)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.errors[fieldname] = getErrorMessage(err, this.doc);
|
|
|
|
}
|
|
|
|
|
2023-02-21 11:51:32 +05:30
|
|
|
this.updateGroupedFields();
|
2023-02-21 11:04:35 +05:30
|
|
|
},
|
2023-02-20 10:22:19 +05:30
|
|
|
},
|
|
|
|
});
|
2023-02-17 21:05:06 +05:30
|
|
|
</script>
|