nm-worklist-create-dialog
src/app/shared/widgets/worklist-select/worklist-create-dialog/create-folder-entry-dialog.component.ts
changeDetection | ChangeDetectionStrategy.OnPush |
selector | nm-worklist-create-dialog |
styleUrls | create-folder-entry-dialog.component.scss |
templateUrl | ./create-folder-entry-dialog.component.html |
Widget inputs |
Widget outputs |
Properties |
|
Methods |
|
constructor(dialogRef: MatDialogRef
|
||||||||||||
Parameters :
|
cancel |
cancel()
|
Returns :
void
|
create |
create()
|
Returns :
void
|
Public createAndContinue |
createAndContinue()
|
Returns :
void
|
folderSelected | ||||
folderSelected(event: )
|
||||
Parameters :
Returns :
void
|
Public formatInput |
formatInput()
|
Returns :
void
|
Private initTree | ||||
initTree(listFolderType: )
|
||||
Parameters :
Returns :
void
|
Public loadFolders | ||||
loadFolders(event: )
|
||||
Parameters :
Returns :
void
|
Public setFolderActions | ||||
setFolderActions(actions: )
|
||||
Parameters :
Returns :
void
|
Public availableActions |
availableActions:
|
Type : any[]
|
Default value : []
|
Public dialogRef |
dialogRef:
|
Type : MatDialogRef<CreateFolderEntryDialogComponent>
|
Public fixedActionName |
fixedActionName:
|
Public folder |
folder:
|
Private folderActionsInitialized |
folderActionsInitialized:
|
Default value : false
|
Public folderUrl |
folderUrl:
|
Type : string
|
Public listFolderSelect |
listFolderSelect:
|
Type : ListfolderSelectComponent
|
Decorators : ViewChild
|
Public listFolderType |
listFolderType:
|
Type : string
|
Public localesUrl |
localesUrl:
|
Type : string
|
Public name |
name:
|
Type : string
|
Default value : ""
|
Public productNumbers |
productNumbers:
|
Public selectedAction |
selectedAction:
|
Public title |
title:
|
Type : string
|
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
OnInit,
ViewChild,
} from "@angular/core";
import { MatDialogRef } from "@angular/material/dialog";
import { HalService } from "../../../components/hal/hal.service";
import { ListfolderSelectComponent } from "../../../components/listfolder-select/listfolder-select.component";
@Component({
selector: "nm-worklist-create-dialog",
templateUrl: "./create-folder-entry-dialog.component.html",
styleUrls: ["./create-folder-entry-dialog.component.scss"],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CreateFolderEntryDialogComponent {
public title: string;
public listFolderType: string;
public folderUrl: string;
public localesUrl: string;
public name: string = "";
public folder;
public availableActions: any[] = [];
public selectedAction;
public fixedActionName;
public productNumbers;
private folderActionsInitialized = false;
@ViewChild(ListfolderSelectComponent, { static: true })
public listFolderSelect: ListfolderSelectComponent;
constructor(
public dialogRef: MatDialogRef<CreateFolderEntryDialogComponent>,
private halService: HalService,
private cd: ChangeDetectorRef
) {}
cancel() {
this.dialogRef.close();
}
public createAndContinue() {
const action = this.selectedAction.actions.create;
action.payload = {
name: this.name,
parent: this.folder,
productNumbers: this.productNumbers,
};
this.halService.executeAndShowMessage("create", action).subscribe(() => {
this.initTree(this.selectedAction.listFolderType);
});
this.name = "";
this.cd.markForCheck();
}
create() {
const action = this.selectedAction.actions.create;
action.payload = {
name: this.name,
parent: this.folder,
productNumbers: this.productNumbers,
};
this.halService
.executeAndShowMessage("create", action)
.subscribe(() => this.dialogRef.close(true));
}
folderSelected(event) {
if (event) {
this.folder = event.id;
} else {
this.folder = null;
}
}
public loadFolders(event) {
if (this.selectedAction && this.selectedAction.listFolderType) {
this.initTree(this.selectedAction.listFolderType);
}
}
public setFolderActions(actions) {
if (this.folderActionsInitialized) {
//We already added the actions
return;
}
this.folderActionsInitialized = true;
if (this.fixedActionName) {
this.selectedAction = this.availableActions.find(
(entry) => entry.description === this.fixedActionName
);
if (!this.selectedAction.actions) {
console.error(
`Unable to find action with description ${this.fixedActionName}, available actions are`,
this.availableActions
);
}
} else {
this.selectedAction = this.availableActions[0];
}
}
public formatInput() {
//let compareString = this.name.replace(/\s+/g,"");
this.name = this.name.trim();
}
private initTree(listFolderType) {
this.listFolderType = listFolderType;
this.listFolderSelect.initTree(this.listFolderType);
}
}
<nm-dialog [dialogRef]="dialogRef" class="nm-dialog" [localesUrl]="localesUrl">
<ng-container slot="title">
{{ title | translate }}
</ng-container>
<ng-container slot="content">
<mat-form-field *ngIf="!fixedActionName">
<mat-label>{{ "placeholder.select.element" | translate }}</mat-label>
<mat-select
[(ngModel)]="selectedAction"
#selectedActionField="ngModel"
(ngModelChange)="loadFolders($event)"
>
<mat-option *ngFor="let option of availableActions" [value]="option">
{{ option.description | translate }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field (keydown.enter)="name && selectedAction ? create() : null">
<input
matInput
[(ngModel)]="name"
placeholder="Name"
(blur)="formatInput()"
[nmAutofocus]="true"
/>
</mat-form-field>
<div>
<br />
{{ "placeholder.select.folder" | translate }}
</div>
<nm-listfolder-select
[listFolderType]="listFolderType"
[folderUrl]="folderUrl"
(folderSelected)="folderSelected($event)"
(folderActions)="setFolderActions($event)"
>
</nm-listfolder-select>
</ng-container>
<ng-container slot="actions">
<button mat-button (click)="cancel()">
{{ "button.cancel" | translate }}
</button>
<button
mat-raised-button
color="primary"
[disabled]="!name || !selectedAction || name.trim().length === 0"
(click)="createAndContinue()"
>
{{ "button.create.and.continue" | translate }}
</button>
<button
mat-raised-button
color="primary"
[disabled]="!name || !selectedAction || name.trim().length === 0"
(click)="create()"
>
{{ "button.create" | translate }}
</button>
</ng-container>
</nm-dialog>