disable save and publish button when not allowed

This commit is contained in:
Mads Rasmussen
2024-04-09 19:50:00 +02:00
parent b6fb7363eb
commit e30fcacf4e

View File

@@ -1,13 +1,29 @@
import { UMB_DOCUMENT_WORKSPACE_CONTEXT } from '../document-workspace.context-token.js';
import { UmbDocumentUserPermissionCondition } from '../../user-permissions/document-user-permission.condition.js';
import { UMB_USER_PERMISSION_DOCUMENT_UPDATE } from '../../user-permissions/index.js';
import { UmbWorkspaceActionBase } from '@umbraco-cms/backoffice/workspace';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
export class UmbDocumentSaveAndPreviewWorkspaceAction extends UmbWorkspaceActionBase {
constructor(host: UmbControllerHost, args: any) {
super(host, args);
/* The action is disabled by default because the onChange callback
will first be triggered when the condition is changed to permitted */
this.disable();
const condition = new UmbDocumentUserPermissionCondition(host, {
host,
config: {
alias: 'Umb.Condition.UserPermission.Document',
allOf: [UMB_USER_PERMISSION_DOCUMENT_UPDATE],
},
onChange: () => {
condition.permitted ? this.enable() : this.disable();
},
});
}
async execute() {
const workspaceContext = await this.getContext(UMB_DOCUMENT_WORKSPACE_CONTEXT);
//const document = workspaceContext.getData();
// TODO: handle errors
//if (!document) return;
//this.workspaceContext.repository?.saveAndPreview();
//Remember to return a promise.
alert('Save and preview');
}
}