private initRecord(): Promise<any> {
+ const pc = this.idlDef.permacrud || {};
+ this.modePerms = {
+ view: pc.retrieve ? pc.retrieve.perms : [],
+ create: pc.create ? pc.create.perms : [],
+ update: pc.update ? pc.update.perms : [],
+ };
+
if (this.mode === 'update' || this.mode === 'view') {
return this.pcrud.retrieve(this.idlClass, this.recId)
.toPromise().then(rec => {
});
}
- const pc = this.idlDef.permacrud || {};
- this.modePerms = {
- view: pc.retrieve ? pc.retrieve.perms : [],
- create: pc.create ? pc.create.perms : [],
- update: pc.update ? pc.update.perms : [],
- };
-
// create a new record from scratch
this.pkeyIsEditable = !('pkey_sequence' in this.idlDef);
this.record = this.idl.create(this.idlClass);
@Input() label: string;
@Input() action: () => any;
+ @Input() set disabled(d: boolean) {
+ // Support asynchronous disabled values by appling directly
+ // to our button object as values arrive.
+ if (this.button) {
+ this.button.disabled = d;
+ }
+ }
+
+ button: GridToolbarButton;
+
// get a reference to our container grid.
- constructor(@Host() private grid: GridComponent) {}
+ constructor(@Host() private grid: GridComponent) {
+ this.button = new GridToolbarButton();
+ }
ngOnInit() {
return;
}
- const btn = new GridToolbarButton();
- btn.label = this.label;
- btn.action = this.action;
-
- this.grid.context.toolbarButtons.push(btn);
+ this.button.label = this.label;
+ this.button.action = this.action;
+ this.grid.context.toolbarButtons.push(this.button);
}
}
<!-- buttons -->
<div class="btn-grp" *ngIf="gridContext.toolbarButtons.length">
<button *ngFor="let btn of gridContext.toolbarButtons"
+ [disabled]="btn.disabled"
class="btn btn-outline-dark" (click)="btn.action()">
{{btn.label}}
</button>
export class GridToolbarButton {
label: string;
action: () => any;
+ disabled: boolean;
}
export class GridToolbarCheckbox {
<eg-grid #grid idlClass="{{idlClass}}" [dataSource]="dataSource"
[sortable]="true" persistKey="{{persistKey}}">
- <eg-grid-toolbar-button label="New {{idlClassDef.label}}" i18n-label [action]="createNew">
+ <eg-grid-toolbar-button [disabled]="!canCreate"
+ label="New {{idlClassDef.label}}" i18n-label [action]="createNew">
</eg-grid-toolbar-button>
<eg-grid-toolbar-action label="Delete Selected" i18n-label [action]="deleteSelected">
</eg-grid-toolbar-action>
import {Pager} from '@eg/share/util/pager';
import {PcrudService} from '@eg/core/pcrud.service';
import {OrgService} from '@eg/core/org.service';
+import {PermService} from '@eg/core/perm.service';
import {AuthService} from '@eg/core/auth.service';
import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
import {StringComponent} from '@eg/share/string/string.component';
contextOrg: IdlObject;
orgFieldLabel: string;
viewPerms: string;
+ canCreate: boolean;
constructor(
private idl: IdlService,
private org: OrgService,
private auth: AuthService,
private pcrud: PcrudService,
+ private perm: PermService,
private toast: ToastService
) {}
this.viewPerms = pc.retrieve.perms;
}
+ this.checkCreatePerms();
this.applyOrgValues();
// If the caller provides not data source, create a generic one.
};
}
+ checkCreatePerms() {
+ this.canCreate = false;
+ const pc = this.idlClassDef.permacrud || {};
+ const perms = pc.create ? pc.create.perms : [];
+ if (perms.length === 0) { return; }
+
+ this.perm.hasWorkPermAt(perms, true).then(permMap => {
+ Object.keys(permMap).forEach(key => {
+ if (permMap[key].length > 0) {
+ this.canCreate = true;
+ }
+ });
+ });
+ }
+
orgOnChange(org: IdlObject) {
this.contextOrg = org;
this.grid.reload();