fix: remove duplicate action handlers and improve template action generation
- Remove duplicate action handlers (edititem, deleteitem, createitem, etc.) from DS4ActorSheet and DS4ItemSheet - Fix editImage method reference from static to prototype in DS4ActorSheet - Add capitalize helper to handlebars-helpers.ts for dynamic action name generation - Update control-button-group.hbs and add-button.hbs templates to use concat and capitalize helpers - Ensure consistent camelCase naming for all action handlers (editItem, deleteItem, createItem, etc.) This resolves action handler conflicts and improves maintainability by using dynamic template generation instead of hardcoded conditional logic.
This commit is contained in:
parent
1358bfad93
commit
3eaf69f558
5 changed files with 9 additions and 14 deletions
|
@ -41,14 +41,7 @@ export class DS4ActorSheet extends foundry.applications.api.HandlebarsApplicatio
|
|||
changeEffect: DS4ActorSheet.prototype._onChangeEffect,
|
||||
sortItems: DS4ActorSheet.prototype._onSortItems,
|
||||
changeTab: DS4ActorSheet.prototype._onChangeTab,
|
||||
edititem: DS4ActorSheet.prototype._onEditItem,
|
||||
deleteitem: DS4ActorSheet.prototype._onDeleteItem,
|
||||
createitem: DS4ActorSheet.prototype._onCreateItem,
|
||||
editeffect: DS4ActorSheet.prototype._onEditEffect,
|
||||
deleteeffect: DS4ActorSheet.prototype._onDeleteEffect,
|
||||
createeffect: DS4ActorSheet.prototype._onCreateEffect,
|
||||
editImage: DS4ActorSheet._onEditImage,
|
||||
|
||||
editImage: DS4ActorSheet.prototype._onEditImage,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -26,11 +26,8 @@ export class DS4ItemSheet extends foundry.applications.api.HandlebarsApplication
|
|||
actions: {
|
||||
controlEffect: DS4ItemSheet.prototype._onControlEffect,
|
||||
createEffect: DS4ItemSheet.prototype._onCreateEffect,
|
||||
createeffect: DS4ItemSheet.prototype._onCreateEffect,
|
||||
editEffect: DS4ItemSheet.prototype._onEditEffect,
|
||||
editeffect: DS4ItemSheet.prototype._onEditEffect,
|
||||
deleteEffect: DS4ItemSheet.prototype._onDeleteEffect,
|
||||
deleteeffect: DS4ItemSheet.prototype._onDeleteEffect,
|
||||
changeTab: DS4ItemSheet.prototype._onChangeTab,
|
||||
editImage: DS4ItemSheet.prototype._onEditImage,
|
||||
},
|
||||
|
|
|
@ -14,6 +14,11 @@ const helpers = {
|
|||
|
||||
isEmpty: (input: Array<unknown> | null | undefined): boolean => (input?.length ?? 0) === 0,
|
||||
|
||||
capitalize: (str: string): string => {
|
||||
if (typeof str !== 'string') return '';
|
||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||
},
|
||||
|
||||
toRomanNumerals,
|
||||
};
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ SPDX-License-Identifier: MIT
|
|||
}}
|
||||
{{#if @root/editable}}
|
||||
<div class="ds4-add-button">
|
||||
<a class="ds4-add-button__link" title="{{localize title}}" data-action="create{{documentType}}" {{#if type}}data-type="{{type}}"
|
||||
<a class="ds4-add-button__link" title="{{localize title}}" data-action="{{concat 'create' (capitalize documentType)}}" {{#if type}}data-type="{{type}}"
|
||||
{{/if}}>
|
||||
<i class="fas fa-plus"></i>
|
||||
{{localize "DS4.UserInteractionAdd"}}
|
||||
|
|
|
@ -14,9 +14,9 @@ SPDX-License-Identifier: MIT
|
|||
--}}
|
||||
<div class="ds4-control-button-group">
|
||||
{{#if @root/editable}}
|
||||
<a class="ds4-control-button-group__button" data-action="edit{{documentType}}" data-document-type="{{documentType}}"
|
||||
<a class="ds4-control-button-group__button" data-action="{{concat 'edit' (capitalize documentType)}}" data-document-type="{{documentType}}"
|
||||
title="{{localize editTitle}}"><i class="fas fa-edit"></i></a>
|
||||
<a class="ds4-control-button-group__button" data-action="delete{{documentType}}" data-document-type="{{documentType}}"
|
||||
<a class="ds4-control-button-group__button" data-action="{{concat 'delete' (capitalize documentType)}}" data-document-type="{{documentType}}"
|
||||
title="{{localize deleteTitle}}"><i class="fas fa-trash"></i></a>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue