mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-08-07 17:48:54 +00:00
#440 rename to 'ng2-activiti-form'
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
/*!
|
||||
* @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 {
|
||||
Component,
|
||||
OnInit, AfterViewChecked, OnChanges,
|
||||
SimpleChange,
|
||||
Input
|
||||
} from '@angular/core';
|
||||
import { MATERIAL_DESIGN_DIRECTIVES } from 'ng2-alfresco-core';
|
||||
|
||||
import { FormService } from './../services/form.service';
|
||||
import { FormModel, FormOutcomeModel } from './widgets/widget.model';
|
||||
|
||||
import { TabsWidget } from './widgets/tabs/tabs.widget';
|
||||
import { ContainerWidget } from './widgets/container/container.widget';
|
||||
|
||||
declare let __moduleName: string;
|
||||
declare var componentHandler;
|
||||
|
||||
@Component({
|
||||
moduleId: __moduleName,
|
||||
selector: 'activiti-form',
|
||||
templateUrl: './activiti-form.component.html',
|
||||
styleUrls: ['./activiti-form.component.css'],
|
||||
directives: [MATERIAL_DESIGN_DIRECTIVES, ContainerWidget, TabsWidget],
|
||||
providers: [FormService]
|
||||
})
|
||||
export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
||||
|
||||
@Input()
|
||||
taskId: string;
|
||||
|
||||
form: FormModel;
|
||||
debugMode: boolean = false;
|
||||
|
||||
hasForm(): boolean {
|
||||
return this.form ? true : false;
|
||||
}
|
||||
|
||||
constructor(private formService: FormService) {}
|
||||
|
||||
ngOnInit() {
|
||||
if (this.taskId) {
|
||||
this.loadForm(this.taskId);
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewChecked() {
|
||||
// workaround for MDL issues with dynamic components
|
||||
if (componentHandler) {
|
||||
componentHandler.upgradeAllRegistered();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges(changes: {[propertyName: string]: SimpleChange}) {
|
||||
let taskId = changes['taskId'];
|
||||
if (taskId && taskId.currentValue) {
|
||||
this.loadForm(taskId.currentValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
onOutcomeClicked(outcome: FormOutcomeModel, event?: Event) {
|
||||
if (outcome) {
|
||||
if (outcome.isSystem) {
|
||||
if (outcome.id === '$save') {
|
||||
return this.saveTaskForm();
|
||||
}
|
||||
}
|
||||
alert(`Outcome clicked: ${outcome.name}`);
|
||||
}
|
||||
}
|
||||
|
||||
private loadForm(taskId: string) {
|
||||
this.formService
|
||||
.getTaskForm(taskId)
|
||||
.subscribe(
|
||||
form => this.form = new FormModel(form),
|
||||
err => console.log(err)
|
||||
);
|
||||
}
|
||||
|
||||
private saveTaskForm() {
|
||||
let form = {
|
||||
values: this.form.values
|
||||
};
|
||||
this.formService.saveTaskForm(this.form.taskId, form).subscribe(
|
||||
(response) => {
|
||||
console.log(response);
|
||||
alert('Saved');
|
||||
},
|
||||
(err) => window.alert(err)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user