mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-907] - Form reacts to data added in input (#2016)
* [ADF-907] Enable activiti form to react on value data changes * [ADF-907] - Form reacts to data added in input] * [ADF - 907] added mock json for form * [ADF-907] added new event of the form to the event list * [ADF - 907] Added return column to README * [ADF - 907] Added return column to README
This commit is contained in:
@@ -15,9 +15,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
|
||||
import { FormModel, FormService } from 'ng2-activiti-form';
|
||||
import { DemoForm } from './demo-form';
|
||||
import { ActivitiForm } from 'ng2-activiti-form';
|
||||
|
||||
declare var componentHandler;
|
||||
|
||||
@Component({
|
||||
selector: 'form-demo',
|
||||
@@ -26,9 +29,17 @@ import { DemoForm } from './demo-form';
|
||||
'form-demo.component.css'
|
||||
]
|
||||
})
|
||||
export class FormDemoComponent implements OnInit {
|
||||
export class FormDemoComponent implements OnInit, AfterViewInit {
|
||||
|
||||
@ViewChild(ActivitiForm)
|
||||
activitiForm: ActivitiForm;
|
||||
|
||||
form: FormModel;
|
||||
activeTab: string = 'demo';
|
||||
storedData: any = {};
|
||||
restoredData: any = {};
|
||||
formToLoadName: string = null;
|
||||
showError: boolean = false;
|
||||
|
||||
constructor(private formService: FormService) {
|
||||
formService.executeOutcome.subscribe(e => {
|
||||
@@ -43,4 +54,69 @@ export class FormDemoComponent implements OnInit {
|
||||
console.log(form);
|
||||
this.form = form;
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
// workaround for MDL issues with dynamic components
|
||||
if (componentHandler) {
|
||||
componentHandler.upgradeAllRegistered();
|
||||
}
|
||||
}
|
||||
|
||||
changeToStoreForm() {
|
||||
this.activeTab = 'store';
|
||||
this.showError = false;
|
||||
}
|
||||
|
||||
changeToDemoForm() {
|
||||
this.activeTab = 'demo';
|
||||
let formDefinitionJSON: any = DemoForm.getDefinition();
|
||||
let demoForm = this.formService.parseForm(formDefinitionJSON);
|
||||
this.form = demoForm;
|
||||
}
|
||||
|
||||
store() {
|
||||
this.clone(this.activitiForm.form.values, this.storedData);
|
||||
console.log('DATA SAVED');
|
||||
console.log(this.storedData);
|
||||
console.log('DATA SAVED');
|
||||
this.restoredData = null;
|
||||
}
|
||||
|
||||
restore() {
|
||||
this.restoredData = this.storedData;
|
||||
this.storedData = {};
|
||||
}
|
||||
|
||||
clone(objToCopyFrom, objToCopyTo) {
|
||||
for (let attribute in objToCopyFrom) {
|
||||
if (objToCopyFrom.hasOwnProperty(attribute)) {
|
||||
objToCopyTo[attribute] = objToCopyFrom[attribute];
|
||||
}
|
||||
}
|
||||
return objToCopyTo;
|
||||
}
|
||||
|
||||
loadForm() {
|
||||
if (this.formToLoadName) {
|
||||
this.showError = false;
|
||||
this.formService
|
||||
.getFormDefinitionByName(this.formToLoadName)
|
||||
.debounceTime(7000)
|
||||
.subscribe(
|
||||
id => {
|
||||
this.formService.getFormDefinitionById(id).subscribe(
|
||||
form => {
|
||||
this.form = this.formService.parseForm((form);
|
||||
},
|
||||
(error) => {
|
||||
this.showError = true;
|
||||
}
|
||||
);
|
||||
},
|
||||
(error) => {
|
||||
this.showError = true;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user