diff --git a/lib/core/src/lib/form/services/form.service.ts b/lib/core/src/lib/form/services/form.service.ts index 5505fb7ec49..184797bad9a 100644 --- a/lib/core/src/lib/form/services/form.service.ts +++ b/lib/core/src/lib/form/services/form.service.ts @@ -83,4 +83,8 @@ export class FormService implements FormValidationService { } return null; } + + getPreviewState(): boolean { + return false; + } } diff --git a/lib/core/src/lib/i18n/en.json b/lib/core/src/lib/i18n/en.json index 31a74009600..50ca7aa8999 100644 --- a/lib/core/src/lib/i18n/en.json +++ b/lib/core/src/lib/i18n/en.json @@ -35,7 +35,10 @@ "TITLE": "Start Form" }, "PREVIEW": { - "IMAGE_NOT_AVAILABLE": "Preview not available" + "IMAGE_NOT_AVAILABLE": "Preview not available", + "ATTACH_FILE_WIDGET": { + "ON_ATTACH_FILE_CLICK": "In preview mode you cannot attach a file" + } }, "FIELD": { "LOCALSTORAGE": "Local storage", diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts index 5ea0dbe8c2c..39426bee037 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts @@ -154,6 +154,7 @@ describe('AttachFileCloudWidgetComponent', () => { imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule, FormCloudModule, ContentModule.forRoot()], schemas: [CUSTOM_ELEMENTS_SCHEMA] }); + notificationService = TestBed.inject(NotificationService); downloadService = TestBed.inject(DownloadService); fixture = TestBed.createComponent(AttachFileCloudWidgetComponent); widget = fixture.componentInstance; @@ -241,6 +242,17 @@ describe('AttachFileCloudWidgetComponent', () => { expect(contentNodeSelectorPanelService.customModels).toEqual([]); }); + it('should display warning message when is in preview state', () => { + spyOn(notificationService, 'showWarning'); + spyOn(formService, 'getPreviewState').and.returnValue(true); + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam); + fixture.detectChanges(); + + clickOnAttachFileWidget('attach-file-alfresco'); + + expect(notificationService.showWarning).toHaveBeenCalledWith('FORM.PREVIEW.ATTACH_FILE_WIDGET.ON_ATTACH_FILE_CLICK'); + }); + describe('when is required', () => { it('should be able to display label with asterisk', async () => { widget.field = new FormFieldModel(new FormModel({ taskId: '' }), { @@ -874,7 +886,6 @@ describe('AttachFileCloudWidgetComponent', () => { let spyOnShowError: jasmine.Spy; beforeEach(() => { - notificationService = TestBed.inject(NotificationService); newVersionUploaderService = TestBed.inject(NewVersionUploaderService); spyOnOpenUploadNewVersionDialog = spyOn(newVersionUploaderService, 'openUploadNewVersionDialog').and.returnValue( of({ action: NewVersionUploaderDataAction.refresh } as any) diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts index 6e1a26c4f74..63e2541b672 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts @@ -65,6 +65,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i rootNodeId = ALIAS_USER_FOLDER; selectedNode: Node; + private previewState = false; private _nodesApi: NodesApi; get nodesApi(): NodesApi { this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance()); @@ -95,6 +96,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i } this.field.params.displayableCMProperties = this.field.params.displayableCMProperties ?? []; this.displayedColumns.splice(2, 0, ...(this.field.params.displayableCMProperties?.map(property => property?.name) || [])); + this.setPreviewState(); } isPathStaticType(): boolean { @@ -126,22 +128,26 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i } async openSelectDialog() { - const selectedMode = this.field.params.multiple ? 'multiple' : 'single'; - const nodeId = await this.getDestinationFolderNodeId(); - this.rootNodeId = nodeId ? nodeId : ALIAS_USER_FOLDER; - this.contentNodeSelectorPanelService.customModels = this.field.params.customModels; - - this.contentNodeSelectorService - .openUploadFileDialog(this.rootNodeId, selectedMode, this.isAlfrescoAndLocal(), true) - .subscribe((selections: Node[]) => { - selections.forEach(node => (node['isExternal'] = true)); - const selectionWithoutDuplication = this.removeExistingSelection(selections); - const hadFilesAttached = this.field.value?.length > 0; - this.fixIncompatibilityFromPreviousAndNewForm(selectionWithoutDuplication); - if(!hadFilesAttached) { - this.contentModelFormFileHandler(this.field.value.length > 0 ? this.field.value[0] : null); - } - }); + if (this.previewState) { + this.notificationService.showWarning('FORM.PREVIEW.ATTACH_FILE_WIDGET.ON_ATTACH_FILE_CLICK'); + } else { + const selectedMode = this.field.params.multiple ? 'multiple' : 'single'; + const nodeId = await this.getDestinationFolderNodeId(); + this.rootNodeId = nodeId ? nodeId : ALIAS_USER_FOLDER; + this.contentNodeSelectorPanelService.customModels = this.field.params.customModels; + + this.contentNodeSelectorService + .openUploadFileDialog(this.rootNodeId, selectedMode, this.isAlfrescoAndLocal(), true) + .subscribe((selections: Node[]) => { + selections.forEach(node => (node['isExternal'] = true)); + const selectionWithoutDuplication = this.removeExistingSelection(selections); + const hadFilesAttached = this.field.value?.length > 0; + this.fixIncompatibilityFromPreviousAndNewForm(selectionWithoutDuplication); + if (!hadFilesAttached) { + this.contentModelFormFileHandler(this.field.value.length > 0 ? this.field.value[0] : null); + } + }); + } } private async getDestinationFolderNodeId(): Promise { @@ -274,4 +280,8 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i ngOnDestroy() { this.contentNodeSelectorPanelService.customModels = []; } + + private setPreviewState(): void { + this.previewState = this.formService.getPreviewState(); + } }