diff --git a/ng2-components/ng2-activiti-form/src/assets/translation.service.mock.ts b/ng2-components/ng2-activiti-form/src/assets/translation.service.mock.ts new file mode 100644 index 0000000000..e0aa69addb --- /dev/null +++ b/ng2-components/ng2-activiti-form/src/assets/translation.service.mock.ts @@ -0,0 +1,28 @@ +/*! + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Observable } from 'rxjs/Rx'; + +export class TranslationMock { + + get(key: string|Array, interpolateParams?: Object): Observable { + return Observable.of(key); + } + + addTranslationFolder() { + } +} diff --git a/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.html b/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.html index b093891fcb..e1ee54a494 100644 --- a/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.html +++ b/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.html @@ -14,7 +14,7 @@ -
+
- -
- +
diff --git a/ng2-components/ng2-activiti-processlist/src/components/activiti-start-process.component.ts b/ng2-components/ng2-activiti-processlist/src/components/activiti-start-process.component.ts index 941b40aae8..0419c35bc9 100644 --- a/ng2-components/ng2-activiti-processlist/src/components/activiti-start-process.component.ts +++ b/ng2-components/ng2-activiti-processlist/src/components/activiti-start-process.component.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { Component, Input, OnInit, OnChanges, SimpleChanges, ViewChild } from '@angular/core'; +import { Component, Input, OnInit, ViewChild } from '@angular/core'; import { AlfrescoTranslationService } from 'ng2-alfresco-core'; import { ActivitiStartForm } from 'ng2-activiti-form'; import { ActivitiProcessService } from './../services/activiti-process.service'; @@ -28,7 +28,7 @@ declare let componentHandler: any; templateUrl: './activiti-start-process.component.html', styleUrls: ['./activiti-start-process.component.css'] }) -export class ActivitiStartProcessButton implements OnInit, OnChanges { +export class ActivitiStartProcessButton implements OnInit { @Input() appId: string; @@ -56,10 +56,6 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges { this.load(this.appId); } - ngOnChanges(changes: SimpleChanges) { - console.log('changes', changes); - } - public load(appId: string) { this.activitiProcess.getProcessDefinitions(this.appId).subscribe( (res: any[]) => { @@ -79,7 +75,8 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges { public startProcess() { if (this.processDefinitionId && this.name) { - this.activitiProcess.startProcess(this.processDefinitionId, this.name).subscribe( + let formValues = this.startForm ? this.startForm.form.values : undefined; + this.activitiProcess.startProcess(this.processDefinitionId, this.name, formValues).subscribe( (res: any) => { this.cancel(); }, @@ -96,30 +93,22 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges { } } - hasFormKey() { - return true; + private getSelectedProcess(): any { + return this.processDefinitions.filter((processDefinition) => { + return processDefinition.id === this.processDefinitionId; + })[0]; } - onFormSaved($event: Event) { - $event.preventDefault(); - console.log('form saved'); + hasStartForm() { + let selectedProcessDefinition = this.getSelectedProcess(); + return selectedProcessDefinition && selectedProcessDefinition.hasStartForm; } - onFormCompleted($event: Event) { - $event.preventDefault(); - console.log('form saved'); + isStartFormMissingOrValid() { + return !this.startForm || this.startForm.form.isValid; } - onExecuteOutcome($event: Event) { - $event.preventDefault(); - console.log('form outcome executed'); - } - - onFormLoaded($event: Event) { - console.log('form loaded', $event); - } - - onFormError($event: Event) { - console.log('form error', $event); + validateForm() { + return this.processDefinitionId && this.name && this.isStartFormMissingOrValid(); } } diff --git a/ng2-components/ng2-activiti-processlist/src/services/activiti-process.service.ts b/ng2-components/ng2-activiti-processlist/src/services/activiti-process.service.ts index ec301c890e..57cc765830 100644 --- a/ng2-components/ng2-activiti-processlist/src/services/activiti-process.service.ts +++ b/ng2-components/ng2-activiti-processlist/src/services/activiti-process.service.ts @@ -226,10 +226,14 @@ export class ActivitiProcessService { .catch(this.handleError); } - startProcess(processDefinitionId: string, name: string) { - let startRequest: any = {}; - startRequest.name = name; - startRequest.processDefinitionId = processDefinitionId; + startProcess(processDefinitionId: string, name: string, startFormValues?: any) { + let startRequest: any = { + name: name, + processDefinitionId: processDefinitionId + }; + if (startFormValues) { + startRequest.values = startFormValues; + } return Observable.fromPromise( this.authService.getAlfrescoApi().activiti.processApi.startNewProcessInstance(startRequest) )