mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
[AAE-8740] Add a confirmation message in ADW
This commit is contained in:
@@ -161,6 +161,7 @@ export abstract class FormBaseComponent {
|
|||||||
* @param outcome Form outcome model
|
* @param outcome Form outcome model
|
||||||
*/
|
*/
|
||||||
onOutcomeClicked(outcome: FormOutcomeModel): boolean {
|
onOutcomeClicked(outcome: FormOutcomeModel): boolean {
|
||||||
|
debugger
|
||||||
if (!this.readOnly && outcome && this.form) {
|
if (!this.readOnly && outcome && this.form) {
|
||||||
|
|
||||||
if (!this.onExecuteOutcome(outcome)) {
|
if (!this.onExecuteOutcome(outcome)) {
|
||||||
|
@@ -65,6 +65,7 @@ export class FormModel implements ProcessFormModel {
|
|||||||
|
|
||||||
readonly id: string | number;
|
readonly id: string | number;
|
||||||
readonly name: string;
|
readonly name: string;
|
||||||
|
readonly confirmMessage: {show: boolean, message: string};
|
||||||
readonly taskId: string;
|
readonly taskId: string;
|
||||||
readonly taskName = FormModel.UNSET_TASK_NAME;
|
readonly taskName = FormModel.UNSET_TASK_NAME;
|
||||||
readonly processDefinitionId: string;
|
readonly processDefinitionId: string;
|
||||||
@@ -93,6 +94,7 @@ export class FormModel implements ProcessFormModel {
|
|||||||
if (json) {
|
if (json) {
|
||||||
this.id = json.id;
|
this.id = json.id;
|
||||||
this.name = json.name;
|
this.name = json.name;
|
||||||
|
this.confirmMessage = json.confirmMessage || {};
|
||||||
this.taskId = json.taskId;
|
this.taskId = json.taskId;
|
||||||
this.taskName = json.taskName || json.name || FormModel.UNSET_TASK_NAME;
|
this.taskName = json.taskName || json.name || FormModel.UNSET_TASK_NAME;
|
||||||
this.processDefinitionId = json.processDefinitionId;
|
this.processDefinitionId = json.processDefinitionId;
|
||||||
|
@@ -689,6 +689,7 @@ fdescribe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should require form with appName and taskId to complete', () => {
|
it('should require form with appName and taskId to complete', () => {
|
||||||
|
debugger;
|
||||||
spyOn(formCloudService, 'completeTaskForm').and.stub();
|
spyOn(formCloudService, 'completeTaskForm').and.stub();
|
||||||
|
|
||||||
formComponent.form = null;
|
formComponent.form = null;
|
||||||
@@ -744,60 +745,73 @@ fdescribe('FormCloudComponent', () => {
|
|||||||
expect(formComponent.parseForm(null)).toBeNull();
|
expect(formComponent.parseForm(null)).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
fit('should open confirmation dialog on complete task', () => {
|
it('should open confirmation dialog on complete task', () => {
|
||||||
spyOn(matDialog, 'open').and.returnValue({
|
// spyOn(matDialog, 'open').and.returnValue({ beforeClosed: () => of() } as any);
|
||||||
afterClosed: () => of(false)
|
|
||||||
} as any);
|
|
||||||
|
|
||||||
|
spyOn(matDialog, 'open').and.returnValue({ afterClosed: () => of(false) } as any);
|
||||||
|
formComponent.form = new FormModel({
|
||||||
|
confirmMessage: {
|
||||||
|
show: true,
|
||||||
|
message: 'Are you sure you want to submit the form?'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
formComponent.completeTaskForm();
|
formComponent.completeTaskForm();
|
||||||
expect(matDialog.open).toHaveBeenCalled();
|
expect(matDialog.open).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
// fit('should submit form when user confirms', () => {
|
it('should submit form when user confirms', () => {
|
||||||
// fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
// spyOn(matDialog, 'open').and.returnValue({
|
const afterClose = of(true);
|
||||||
// afterClosed: () => of(true)
|
|
||||||
// } as any);
|
|
||||||
|
|
||||||
// spyOn(formComponent['formCloudService'], 'completeTaskForm').and.returnValue(Promise.resolve(false));
|
spyOn(matDialog, 'open').and.returnValue({
|
||||||
|
afterClosed: () => afterClose
|
||||||
|
} as any);
|
||||||
|
|
||||||
// const taskId = '123-223';
|
spyOn(formComponent['formCloudService'], 'completeTaskForm').and.returnValue(Promise.resolve(false));
|
||||||
// const appVersion = 1;
|
const outcome = 'complete';
|
||||||
// const appName = 'test-app';
|
|
||||||
// const processInstanceId = '333-444';
|
|
||||||
|
|
||||||
// const formModel = new FormModel({
|
const taskId = '123-223';
|
||||||
// id: '23',
|
const appVersion = 1;
|
||||||
// taskId,
|
const appName = 'test-app';
|
||||||
// fields: [
|
const processInstanceId = '333-444';
|
||||||
// { id: 'field1' },
|
|
||||||
// { id: 'field2' }
|
|
||||||
// ]
|
|
||||||
// });
|
|
||||||
|
|
||||||
// formComponent.appVersion = appVersion;
|
const formModel = new FormModel({
|
||||||
// formComponent.form = formModel;
|
id: '23',
|
||||||
// formComponent.taskId = taskId;
|
taskId,
|
||||||
// formComponent.appName = appName;
|
fields: [
|
||||||
// formComponent.processInstanceId = processInstanceId;
|
{ id: 'field1' },
|
||||||
// formComponent.completeTaskForm('outcome');
|
{ id: 'field2' }
|
||||||
// expect(matDialog.open).toHaveBeenCalled();
|
],
|
||||||
// expect(formComponent['formCloudService'].completeTaskForm).toHaveBeenCalledWith(appName, formModel.taskId, processInstanceId, formModel.id, formModel.values, 'outcome', appVersion);
|
confirmMessage: {
|
||||||
// });
|
show: true,
|
||||||
|
message: 'Are you sure you want to submit the form?'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// fit('should not confirm form if user rejects', () => {
|
formComponent.appVersion = appVersion;
|
||||||
// spyOn(matDialog, 'open').and.returnValue({
|
formComponent.form = formModel;
|
||||||
// afterClosed: () => of(false)
|
formComponent.taskId = taskId;
|
||||||
// } as any);
|
formComponent.appName = appName;
|
||||||
|
formComponent.processInstanceId = processInstanceId;
|
||||||
|
formComponent.completeTaskForm(outcome);
|
||||||
|
expect(matDialog.open).toHaveBeenCalled();
|
||||||
|
|
||||||
// spyOn(formComponent['formCloudService'], 'completeTaskForm').and.returnValue(Promise.resolve(false));
|
expect(formComponent['formCloudService'].completeTaskForm).toHaveBeenCalledWith(appName, formModel.taskId, processInstanceId, formModel.id, formModel.values, outcome, appVersion);
|
||||||
// formComponent.completeTaskForm();
|
});
|
||||||
|
|
||||||
// expect(formCloudService.completeTaskForm).not.toHaveBeenCalled();
|
it('should not confirm form if user rejects', () => {
|
||||||
|
const outcome = 'complete';
|
||||||
|
|
||||||
// formComponent.completeTaskForm('outcome');
|
spyOn(matDialog, 'open').and.returnValue({
|
||||||
// expect(formComponent['formCloudService'].completeTaskForm).not.toHaveBeenCalled();
|
afterClosed: () => of(false)
|
||||||
// });
|
} as any);
|
||||||
|
|
||||||
|
spyOn(formComponent['formCloudService'], 'completeTaskForm').and.returnValue(Promise.resolve(false));
|
||||||
|
formComponent.completeTaskForm(outcome);
|
||||||
|
|
||||||
|
expect(formComponent['formCloudService'].completeTaskForm).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('should parse form from json', () => {
|
it('should parse form from json', () => {
|
||||||
const form = formComponent.parseForm({
|
const form = formComponent.parseForm({
|
||||||
|
@@ -272,30 +272,70 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
|
|
||||||
completeTaskForm(outcome?: string) {
|
completeTaskForm(outcome?: string) {
|
||||||
debugger;
|
debugger;
|
||||||
// this.form.values.confirmMessage
|
|
||||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
|
||||||
data: {
|
|
||||||
title: 'Save the form',
|
|
||||||
message: 'Do you want to save the form?'
|
|
||||||
},
|
|
||||||
minWidth: '250px'
|
|
||||||
});
|
|
||||||
|
|
||||||
dialogRef.afterClosed().subscribe((result) => {
|
// const confirmMessage = this.form.json.confirmMessage.message;
|
||||||
if (result === true) {
|
|
||||||
if (this.form && this.appName && this.taskId) {
|
if (this.form?.confirmMessage?.show === true) {
|
||||||
this.formCloudService
|
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||||
.completeTaskForm(this.appName, this.taskId, this.processInstanceId, `${this.form.id}`, this.form.values, outcome, this.appVersion)
|
data: {
|
||||||
.pipe(takeUntil(this.onDestroy$))
|
title: 'Save the form',
|
||||||
.subscribe(
|
message: this.form.confirmMessage.message
|
||||||
() => {
|
},
|
||||||
this.onTaskCompleted(this.form);
|
minWidth: '450px'
|
||||||
},
|
});
|
||||||
(error) => this.onTaskCompletedError(error)
|
|
||||||
);
|
dialogRef.afterClosed().subscribe((result) => {
|
||||||
|
if (result === true) {
|
||||||
|
if (this.form && this.appName && this.taskId) {
|
||||||
|
this.formCloudService
|
||||||
|
.completeTaskForm(this.appName, this.taskId, this.processInstanceId, `${this.form.id}`, this.form.values, outcome, this.appVersion)
|
||||||
|
.pipe(takeUntil(this.onDestroy$))
|
||||||
|
.subscribe(
|
||||||
|
() => {
|
||||||
|
this.onTaskCompleted(this.form);
|
||||||
|
},
|
||||||
|
(error) => this.onTaskCompletedError(error)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (this.form && this.appName && this.taskId) {
|
||||||
|
this.formCloudService
|
||||||
|
.completeTaskForm(this.appName, this.taskId, this.processInstanceId, `${this.form.id}`, this.form.values, outcome, this.appVersion)
|
||||||
|
.pipe(takeUntil(this.onDestroy$))
|
||||||
|
.subscribe(
|
||||||
|
() => {
|
||||||
|
this.onTaskCompleted(this.form);
|
||||||
|
},
|
||||||
|
(error) => this.onTaskCompletedError(error)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
// const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||||
|
// data: {
|
||||||
|
// title: 'Save the form',
|
||||||
|
// message: this.form.confirmMessage.message
|
||||||
|
// },
|
||||||
|
// minWidth: '450px'
|
||||||
|
// });
|
||||||
|
|
||||||
|
// dialogRef.afterClosed().subscribe((result) => {
|
||||||
|
// if (result === true) {
|
||||||
|
// if (this.form && this.appName && this.taskId) {
|
||||||
|
// this.formCloudService
|
||||||
|
// .completeTaskForm(this.appName, this.taskId, this.processInstanceId, `${this.form.id}`, this.form.values, outcome, this.appVersion)
|
||||||
|
// .pipe(takeUntil(this.onDestroy$))
|
||||||
|
// .subscribe(
|
||||||
|
// () => {
|
||||||
|
// this.onTaskCompleted(this.form);
|
||||||
|
// },
|
||||||
|
// (error) => this.onTaskCompletedError(error)
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
parseForm(formCloudRepresentationJSON: any): FormModel {
|
parseForm(formCloudRepresentationJSON: any): FormModel {
|
||||||
|
Reference in New Issue
Block a user