Skip to content

Commit

Permalink
Merge pull request #278 from gisce/hotfix/bug_webclient#436
Browse files Browse the repository at this point in the history
Save form before running an export
  • Loading branch information
ecarreras authored Apr 11, 2023
2 parents 3bd10b1 + 3579612 commit eb1e043
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
4 changes: 2 additions & 2 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gisce/react-ooui",
"version": "1.1.32",
"version": "1.1.33",
"files": [
"dist",
"src",
Expand Down
44 changes: 39 additions & 5 deletions src/actionbar/FormActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,15 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
disabled={mustDisableButtons}
tooltip={t("actions")}
items={toolbar?.action}
onItemClick={(action: any) => {
onItemClick={async (action: any) => {
if (!action) {
return;
}
const savedSucceed = await onFormSave?.();

if (!savedSucceed) {
return;
}

runAction(action);
}}
Expand All @@ -352,10 +357,15 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
disabled={mustDisableButtons}
tooltip={t("reports")}
items={toolbar?.print}
onItemClick={(report: any) => {
onItemClick={async (report: any) => {
if (!report) {
return;
}
const savedSucceed = await onFormSave?.();

if (!savedSucceed) {
return;
}

runAction({
...report,
Expand All @@ -373,6 +383,12 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
return;
}

const savedSucceed = await onFormSave?.();

if (!savedSucceed) {
return;
}

openRelate({
relateData: relate,
values: (formRef.current as any).getValues(),
Expand All @@ -385,7 +401,13 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
<AttachmentsButton
disabled={mustDisableButtons}
attachments={attachments}
onAddNewAttachment={() => {
onAddNewAttachment={async () => {
const savedSucceed = await onFormSave?.();

if (!savedSucceed) {
return;
}

const res_id = currentId as number;
const res_model = currentModel as string;
openDefaultActionForModel({
Expand All @@ -400,7 +422,13 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
initialViewType: "form",
});
}}
onListAllAttachments={() => {
onListAllAttachments={async () => {
const savedSucceed = await onFormSave?.();

if (!savedSucceed) {
return;
}

const res_id = currentId as number;
const res_model = currentModel as string;
openDefaultActionForModel({
Expand All @@ -412,7 +440,13 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
initialViewType: "tree",
});
}}
onViewAttachmentDetails={(attachment: Attachment) => {
onViewAttachmentDetails={async (attachment: Attachment) => {
const savedSucceed = await onFormSave?.();

if (!savedSucceed) {
return;
}

openDefaultActionForModel({
model: "ir.attachment",
res_id: attachment.id,
Expand Down
6 changes: 3 additions & 3 deletions src/context/ActionViewContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type ActionViewContextType = {
setFormIsSaving?: (value: boolean) => void;
formHasChanges?: boolean;
setFormHasChanges?: (value: boolean) => void;
onFormSave?: () => void;
onFormSave?: () => Promise<void>;
formRef?: any;
searchTreeRef?: any;
onNewClicked: () => void;
Expand Down Expand Up @@ -141,8 +141,8 @@ const ActionViewProvider = (props: ActionViewProviderProps): any => {
}
}, [currentView]);

const callOnFormSave = () => {
(formRef.current as any)?.submitForm();
const callOnFormSave = async () => {
await (formRef.current as any)?.submitForm();
};

return (
Expand Down

0 comments on commit eb1e043

Please sign in to comment.