[ADF-851] execute-outcome event for form service (#1989)

* execute-outcome event for form service

* readme updates
This commit is contained in:
Denys Vuika
2017-06-20 15:12:20 +01:00
committed by Eugenio Romano
parent b7ab008081
commit 201741aeee
4 changed files with 35 additions and 4 deletions

View File

@@ -314,6 +314,7 @@ class MyComponent {
| taskCompletedError | FormErrorEvent | Raised when a task is completed unsuccessfully | | taskCompletedError | FormErrorEvent | Raised when a task is completed unsuccessfully |
| taskSaved | FormEvent | Raised when a task is saved successfully | | taskSaved | FormEvent | Raised when a task is saved successfully |
| taskSavedError | FormErrorEvent | Raised when a task is saved unsuccessfully | | taskSavedError | FormErrorEvent | Raised when a task is saved unsuccessfully |
| executeOutcome | FormOutcomeEvent | Raised when a form outcome is executed |
### Methods ### Methods

View File

@@ -800,4 +800,18 @@ describe('ActivitiForm', () => {
expect(formComponent.isOutcomeButtonEnabled(outcome)).toBeFalsy(); expect(formComponent.isOutcomeButtonEnabled(outcome)).toBeFalsy();
}); });
it('should raise [executeOutcome] event for formService', (done) => {
formService.executeOutcome.subscribe(() => {
done();
});
let outcome = new FormOutcomeModel(new FormModel(), {
id: ActivitiForm.CUSTOM_OUTCOME_ID,
name: 'Custom'
});
formComponent.form = new FormModel();
formComponent.onOutcomeClicked(outcome);
});
}); });

View File

@@ -211,9 +211,7 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
onOutcomeClicked(outcome: FormOutcomeModel): boolean { onOutcomeClicked(outcome: FormOutcomeModel): boolean {
if (!this.readOnly && outcome && this.form) { if (!this.readOnly && outcome && this.form) {
let args = new FormOutcomeEvent(outcome); if (!this.onExecuteOutcome(outcome)) {
this.executeOutcome.emit(args);
if (args.defaultPrevented) {
return false; return false;
} }
@@ -491,4 +489,20 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
this.handleError(error); this.handleError(error);
this.formService.taskCompletedError.next(new FormErrorEvent(form, error)); this.formService.taskCompletedError.next(new FormErrorEvent(form, error));
} }
protected onExecuteOutcome(outcome: FormOutcomeModel): boolean {
let args = new FormOutcomeEvent(outcome);
this.formService.executeOutcome.next(args);
if (args.defaultPrevented) {
return false;
}
this.executeOutcome.emit(args);
if (args.defaultPrevented) {
return false;
}
return true;
}
} }

View File

@@ -18,7 +18,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs/Rx'; import { Observable, Subject } from 'rxjs/Rx';
import { AlfrescoApiService, LogService } from 'ng2-alfresco-core'; import { AlfrescoApiService, LogService } from 'ng2-alfresco-core';
import { FormValues } from './../components/widgets/core/index'; import { FormValues, FormOutcomeEvent } from './../components/widgets/core/index';
import { FormDefinitionModel } from '../models/form-definition.model'; import { FormDefinitionModel } from '../models/form-definition.model';
import { EcmModelService } from './ecm-model.service'; import { EcmModelService } from './ecm-model.service';
import { GroupModel } from './../components/widgets/core/group.model'; import { GroupModel } from './../components/widgets/core/group.model';
@@ -40,6 +40,8 @@ export class FormService {
taskSavedError: Subject<FormErrorEvent> = new Subject<FormErrorEvent>(); taskSavedError: Subject<FormErrorEvent> = new Subject<FormErrorEvent>();
formContentClicked: Subject<ContentLinkModel> = new Subject<ContentLinkModel>(); formContentClicked: Subject<ContentLinkModel> = new Subject<ContentLinkModel>();
executeOutcome: Subject<FormOutcomeEvent> = new Subject<FormOutcomeEvent>();
constructor(private ecmModelService: EcmModelService, constructor(private ecmModelService: EcmModelService,
private apiService: AlfrescoApiService, private apiService: AlfrescoApiService,
private logService: LogService) { private logService: LogService) {