mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-10-01 14:41:32 +00:00
#440 basic saving of forms, debug mode
This commit is contained in:
@@ -11,3 +11,17 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.activiti-form-debug-container {
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.activiti-form-debug-container .debug-toggle-text {
|
||||||
|
padding-left: 15px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.activiti-form-debug-container .debug-toggle-text:hover {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
@@ -35,10 +35,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="form.hasOutcomes()" class="mdl-card__actions mdl-card--border">
|
<div *ngIf="form.hasOutcomes()" class="mdl-card__actions mdl-card--border">
|
||||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect activiti-form-outcomes__item"
|
<button *ngFor="let outcome of form.outcomes"
|
||||||
[class.mdl-button--colored]="!action.isSystem"
|
alfresco-mdl-button
|
||||||
*ngFor="let action of form.outcomes">
|
[class.mdl-button--colored]="!outcome.isSystem"
|
||||||
{{action.name}}
|
(click)="onOutcomeClicked(outcome, $event)">
|
||||||
|
{{outcome.name}}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -47,3 +48,22 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="activiti-form-debug-container">
|
||||||
|
|
||||||
|
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="switch-1" [class.is-checked]="debugMode">
|
||||||
|
<input type="checkbox" id="switch-1" class="mdl-switch__input" [(ngModel)]="debugMode">
|
||||||
|
<span class="mdl-switch__label"></span>
|
||||||
|
<span class="debug-toggle-text">Debug mode</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div *ngIf="debugMode && hasForm()">
|
||||||
|
<h4>Values</h4>
|
||||||
|
<pre>{{form.values | json}}</pre>
|
||||||
|
|
||||||
|
<h4>Form</h4>
|
||||||
|
<pre>{{form.json | json}}</pre>
|
||||||
|
|
||||||
|
<h4>Task</h4>
|
||||||
|
<pre>{{task | json}}</pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@@ -20,8 +20,10 @@ import {
|
|||||||
OnInit,
|
OnInit,
|
||||||
AfterViewChecked
|
AfterViewChecked
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
import { MATERIAL_DESIGN_DIRECTIVES } from 'ng2-alfresco-core';
|
||||||
|
|
||||||
import { FormService } from './../services/form.service';
|
import { FormService } from './../services/form.service';
|
||||||
import { FormModel } from './widgets/widget.model';
|
import { FormModel, FormOutcomeModel } from './widgets/widget.model';
|
||||||
|
|
||||||
import { TabsWidget } from './widgets/tabs/tabs.widget';
|
import { TabsWidget } from './widgets/tabs/tabs.widget';
|
||||||
import { ContainerWidget } from './widgets/container/container.widget';
|
import { ContainerWidget } from './widgets/container/container.widget';
|
||||||
@@ -34,10 +36,8 @@ declare var componentHandler;
|
|||||||
selector: 'activiti-form',
|
selector: 'activiti-form',
|
||||||
templateUrl: './activiti-form.component.html',
|
templateUrl: './activiti-form.component.html',
|
||||||
styleUrls: ['./activiti-form.component.css'],
|
styleUrls: ['./activiti-form.component.css'],
|
||||||
directives: [ContainerWidget, TabsWidget],
|
directives: [MATERIAL_DESIGN_DIRECTIVES, ContainerWidget, TabsWidget],
|
||||||
providers: [
|
providers: [FormService]
|
||||||
FormService
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
export class ActivitiForm implements OnInit, AfterViewChecked {
|
export class ActivitiForm implements OnInit, AfterViewChecked {
|
||||||
|
|
||||||
@@ -45,6 +45,8 @@ export class ActivitiForm implements OnInit, AfterViewChecked {
|
|||||||
form: FormModel;
|
form: FormModel;
|
||||||
tasks: any[] = [];
|
tasks: any[] = [];
|
||||||
|
|
||||||
|
debugMode: boolean = false;
|
||||||
|
|
||||||
hasForm(): boolean {
|
hasForm(): boolean {
|
||||||
return this.form ? true : false;
|
return this.form ? true : false;
|
||||||
}
|
}
|
||||||
@@ -74,4 +76,28 @@ export class ActivitiForm implements OnInit, AfterViewChecked {
|
|||||||
.subscribe(form => this.form = new FormModel(form));
|
.subscribe(form => this.form = new FormModel(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onOutcomeClicked(outcome: FormOutcomeModel, event?: Event) {
|
||||||
|
if (outcome) {
|
||||||
|
if (outcome.isSystem) {
|
||||||
|
if (outcome.id === '$save') {
|
||||||
|
return this.saveTaskForm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
alert(`Outcome clicked: ${outcome.name}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,10 @@ export interface FormFieldMetadata {
|
|||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FormValues {
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
export class FormWidgetModel {
|
export class FormWidgetModel {
|
||||||
|
|
||||||
private _form: FormModel;
|
private _form: FormModel;
|
||||||
@@ -40,25 +44,56 @@ export class FormWidgetModel {
|
|||||||
|
|
||||||
export class FormFieldModel extends FormWidgetModel {
|
export class FormFieldModel extends FormWidgetModel {
|
||||||
|
|
||||||
id: string;
|
private _id: string;
|
||||||
name: string;
|
private _name: string;
|
||||||
type: string;
|
private _type: string;
|
||||||
value: any;
|
private _value: string;
|
||||||
tab: string;
|
private _tab: string;
|
||||||
|
|
||||||
|
get id(): string {
|
||||||
|
return this._id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get name(): string {
|
||||||
|
return this._name;
|
||||||
|
}
|
||||||
|
|
||||||
|
get type(): string {
|
||||||
|
return this._type;
|
||||||
|
}
|
||||||
|
|
||||||
|
get value(): any {
|
||||||
|
return this._value;
|
||||||
|
}
|
||||||
|
|
||||||
|
set value(v: any) {
|
||||||
|
this._value = v;
|
||||||
|
this.form.values[this._id] = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
get tab(): string {
|
||||||
|
return this._tab;
|
||||||
|
}
|
||||||
|
|
||||||
colspan: number = 1;
|
colspan: number = 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
metadata: FormFieldMetadata = {};
|
metadata: FormFieldMetadata = {};
|
||||||
|
|
||||||
constructor(form: FormModel, json?: any) {
|
constructor(form: FormModel, json?: any) {
|
||||||
super(form, json);
|
super(form, json);
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
this.id = json.id;
|
this._id = json.id;
|
||||||
this.name = json.name;
|
this._name = json.name;
|
||||||
this.type = json.type;
|
this._type = json.type;
|
||||||
this.value = json.value;
|
this._value = json.value;
|
||||||
this.tab = json.tab;
|
this._tab = json.tab;
|
||||||
this.colspan = <number> json.colspan;
|
this.colspan = <number> json.colspan;
|
||||||
|
|
||||||
|
// update form values
|
||||||
|
form.values[json.id] = json.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,10 +204,33 @@ export class FormOutcomeModel extends FormWidgetModel {
|
|||||||
|
|
||||||
export class FormModel {
|
export class FormModel {
|
||||||
|
|
||||||
|
private _id: string;
|
||||||
|
private _name: string;
|
||||||
|
private _taskId: string;
|
||||||
|
private _taskName: string;
|
||||||
|
|
||||||
|
get id(): string {
|
||||||
|
return this._id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get name(): string {
|
||||||
|
return this._name;
|
||||||
|
}
|
||||||
|
|
||||||
|
get taskId(): string {
|
||||||
|
return this._taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
get taskName(): string{
|
||||||
|
return this._taskName;
|
||||||
|
}
|
||||||
|
|
||||||
tabs: TabModel[] = [];
|
tabs: TabModel[] = [];
|
||||||
fields: ContainerModel[] = [];
|
fields: ContainerModel[] = [];
|
||||||
outcomes: FormOutcomeModel[] = [];
|
outcomes: FormOutcomeModel[] = [];
|
||||||
|
|
||||||
|
values: FormValues = {};
|
||||||
|
|
||||||
private _json: any;
|
private _json: any;
|
||||||
|
|
||||||
get json() {
|
get json() {
|
||||||
@@ -194,6 +252,12 @@ export class FormModel {
|
|||||||
constructor(json?: any) {
|
constructor(json?: any) {
|
||||||
if (json) {
|
if (json) {
|
||||||
this._json = json;
|
this._json = json;
|
||||||
|
|
||||||
|
this._id = json.id;
|
||||||
|
this._name = json.name;
|
||||||
|
this._taskId = json.taskId;
|
||||||
|
this._taskName = json.taskName;
|
||||||
|
|
||||||
let tabCache: WidgetModelCache<TabModel> = {};
|
let tabCache: WidgetModelCache<TabModel> = {};
|
||||||
|
|
||||||
// this.tabs = (json.tabs || []).map(t => new TabModel(this, t));
|
// this.tabs = (json.tabs || []).map(t => new TabModel(this, t));
|
||||||
|
@@ -32,7 +32,8 @@ export class FormService {
|
|||||||
let body = JSON.stringify({});
|
let body = JSON.stringify({});
|
||||||
let options = this.getRequestOptions();
|
let options = this.getRequestOptions();
|
||||||
|
|
||||||
return this.http.post(url, body, options)
|
return this.http
|
||||||
|
.post(url, body, options)
|
||||||
.map(this.toJsonArray)
|
.map(this.toJsonArray)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
@@ -41,16 +42,28 @@ export class FormService {
|
|||||||
let url = `${this.basePath}/api/enterprise/tasks/${id}`;
|
let url = `${this.basePath}/api/enterprise/tasks/${id}`;
|
||||||
let options = this.getRequestOptions();
|
let options = this.getRequestOptions();
|
||||||
|
|
||||||
return this.http.get(url, options)
|
return this.http
|
||||||
|
.get(url, options)
|
||||||
.map(this.toJson)
|
.map(this.toJson)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveTaskForm(id: string, form: { values: { [key: string]: any }}): Observable<Response> {
|
||||||
|
let url = `${this.basePath}/api/enterprise/task-forms/${id}/save-form`;
|
||||||
|
let body = JSON.stringify(form);
|
||||||
|
let options = this.getRequestOptions();
|
||||||
|
|
||||||
|
return this.http
|
||||||
|
.post(url, body, options)
|
||||||
|
.catch(this.handleError);
|
||||||
|
}
|
||||||
|
|
||||||
getTaskForm(id: string): Observable<any> {
|
getTaskForm(id: string): Observable<any> {
|
||||||
let url = `${this.basePath}/api/enterprise/task-forms/${id}`;
|
let url = `${this.basePath}/api/enterprise/task-forms/${id}`;
|
||||||
let options = this.getRequestOptions();
|
let options = this.getRequestOptions();
|
||||||
|
|
||||||
return this.http.get(url, options)
|
return this.http
|
||||||
|
.get(url, options)
|
||||||
.map(this.toJson)
|
.map(this.toJson)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user