diff --git a/src/packages/templating/templates/conditions/allow-delete/const.ts b/src/packages/templating/templates/conditions/allow-delete/const.ts new file mode 100644 index 0000000000..b986c98f18 --- /dev/null +++ b/src/packages/templating/templates/conditions/allow-delete/const.ts @@ -0,0 +1 @@ +export const UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS = 'Umb.Condition.Template.AllowDeleteAction'; diff --git a/src/packages/templating/templates/conditions/allow-delete/manifest.ts b/src/packages/templating/templates/conditions/allow-delete/manifest.ts new file mode 100644 index 0000000000..37a4793a92 --- /dev/null +++ b/src/packages/templating/templates/conditions/allow-delete/manifest.ts @@ -0,0 +1,8 @@ +import { UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS } from './const.js'; + +export const manifest: UmbExtensionManifest = { + type: 'condition', + name: 'Template Allow Delete Action Condition', + alias: UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS, + api: () => import('./template-allow-delete-action.condition.js'), +}; diff --git a/src/packages/templating/templates/conditions/allow-delete/template-allow-delete-action.condition.ts b/src/packages/templating/templates/conditions/allow-delete/template-allow-delete-action.condition.ts new file mode 100644 index 0000000000..c1550dab72 --- /dev/null +++ b/src/packages/templating/templates/conditions/allow-delete/template-allow-delete-action.condition.ts @@ -0,0 +1,22 @@ +import { UmbConditionBase } from '@umbraco-cms/backoffice/extension-registry'; +import { UMB_TREE_ITEM_CONTEXT } from '@umbraco-cms/backoffice/tree'; +import type { UmbConditionControllerArguments, UmbExtensionCondition } from '@umbraco-cms/backoffice/extension-api'; +import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; + +export class UmbTemplateAllowDeleteActionCondition extends UmbConditionBase implements UmbExtensionCondition { + constructor(host: UmbControllerHost, args: UmbConditionControllerArguments) { + super(host, args); + + this.consumeContext(UMB_TREE_ITEM_CONTEXT, (context) => { + this.observe( + context.hasChildren, + (hasChildren) => { + this.permitted = hasChildren === false; + }, + '_templateAllowDeleteActionCondition', + ); + }); + } +} + +export { UmbTemplateAllowDeleteActionCondition as api }; diff --git a/src/packages/templating/templates/conditions/manifests.ts b/src/packages/templating/templates/conditions/manifests.ts new file mode 100644 index 0000000000..731fde0ccd --- /dev/null +++ b/src/packages/templating/templates/conditions/manifests.ts @@ -0,0 +1,3 @@ +import { manifest as templateAllowDeleteActionCondition } from './allow-delete/manifest.js'; + +export const manifests: Array = [templateAllowDeleteActionCondition]; diff --git a/src/packages/templating/templates/entity-actions/manifests.ts b/src/packages/templating/templates/entity-actions/manifests.ts index fb548f4166..7912a433e2 100644 --- a/src/packages/templating/templates/entity-actions/manifests.ts +++ b/src/packages/templating/templates/entity-actions/manifests.ts @@ -1,5 +1,6 @@ import { UMB_TEMPLATE_DETAIL_REPOSITORY_ALIAS, UMB_TEMPLATE_ITEM_REPOSITORY_ALIAS } from '../repository/index.js'; import { UMB_TEMPLATE_ENTITY_TYPE, UMB_TEMPLATE_ROOT_ENTITY_TYPE } from '../entity.js'; +import { UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS } from '../conditions/allow-delete/const.js'; export const manifests: Array = [ { @@ -26,5 +27,6 @@ export const manifests: Array = [ detailRepositoryAlias: UMB_TEMPLATE_DETAIL_REPOSITORY_ALIAS, itemRepositoryAlias: UMB_TEMPLATE_ITEM_REPOSITORY_ALIAS, }, + conditions: [{ alias: UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS }], }, ]; diff --git a/src/packages/templating/templates/manifests.ts b/src/packages/templating/templates/manifests.ts index eb8a2594d5..da057a5daa 100644 --- a/src/packages/templating/templates/manifests.ts +++ b/src/packages/templating/templates/manifests.ts @@ -1,3 +1,4 @@ +import { manifests as conditionsManifests } from './conditions/manifests.js'; import { manifests as entityActionsManifests } from './entity-actions/manifests.js'; import { manifests as menuManifests } from './menu/manifests.js'; import { manifests as modalManifests } from './modals/manifests.js'; @@ -7,6 +8,7 @@ import { manifests as treeManifests } from './tree/manifests.js'; import { manifests as workspaceManifests } from './workspace/manifests.js'; export const manifests: Array = [ + ...conditionsManifests, ...entityActionsManifests, ...menuManifests, ...modalManifests,