Item Support #69
3 changed files with 59 additions and 1 deletions
|
|
@ -58,6 +58,7 @@
|
||||||
"confirm-and-close": "Confirm and Close",
|
"confirm-and-close": "Confirm and Close",
|
||||||
"save-and-close": "Save and Close",
|
"save-and-close": "Save and Close",
|
||||||
"delete": "Delete",
|
"delete": "Delete",
|
||||||
|
"edit": "Edit",
|
||||||
"resizable": "Resizable",
|
"resizable": "Resizable",
|
||||||
"not-resizable": "Not Resizable",
|
"not-resizable": "Not Resizable",
|
||||||
"item": {
|
"item": {
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,12 @@ import { attributeSorter } from "../utils/attributeSort.mjs";
|
||||||
import { config } from "../config.mjs";
|
import { config } from "../config.mjs";
|
||||||
import { TAFDocumentSheetConfig } from "./TAFDocumentSheetConfig.mjs";
|
import { TAFDocumentSheetConfig } from "./TAFDocumentSheetConfig.mjs";
|
||||||
import { TAFDocumentSheetMixin } from "./mixins/TAFDocumentSheetMixin.mjs";
|
import { TAFDocumentSheetMixin } from "./mixins/TAFDocumentSheetMixin.mjs";
|
||||||
|
import { deleteItemFromElement, editItemFromElement } from "./utils.mjs";
|
||||||
|
|
||||||
const { HandlebarsApplicationMixin } = foundry.applications.api;
|
const { HandlebarsApplicationMixin } = foundry.applications.api;
|
||||||
const { ActorSheetV2 } = foundry.applications.sheets;
|
const { ActorSheetV2 } = foundry.applications.sheets;
|
||||||
const { getProperty } = foundry.utils;
|
const { getProperty } = foundry.utils;
|
||||||
const { TextEditor } = foundry.applications.ux;
|
const { ContextMenu, TextEditor } = foundry.applications.ux;
|
||||||
|
|
||||||
export class PlayerSheet extends
|
export class PlayerSheet extends
|
||||||
TAFDocumentSheetMixin(
|
TAFDocumentSheetMixin(
|
||||||
|
|
@ -146,6 +147,36 @@ export class PlayerSheet extends
|
||||||
return controls;
|
return controls;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async _onRender(ctx, options) {
|
||||||
|
await super._onRender(ctx, options);
|
||||||
|
|
||||||
|
new ContextMenu.implementation(
|
||||||
|
this.element,
|
||||||
|
`li.item`,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
label: _loc(`taf.misc.edit`),
|
||||||
|
condition: (el) => {
|
||||||
|
const itemUuid = el.dataset.itemUuid;
|
||||||
|
const itemExists = itemUuid != null && itemUuid !== "";
|
||||||
|
return this.isEditable && itemExists;
|
||||||
|
},
|
||||||
|
onClick: editItemFromElement,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: _loc(`taf.misc.delete`),
|
||||||
|
condition: (el) => {
|
||||||
|
const itemUuid = el.dataset.itemUuid;
|
||||||
|
const itemExists = itemUuid != null && itemUuid !== "";
|
||||||
|
return this.isEditable && itemExists;
|
||||||
|
},
|
||||||
|
onClick: deleteItemFromElement,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
{ jQuery: false, fixed: true, },
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
async close() {
|
async close() {
|
||||||
this.#attributeManager?.close();
|
this.#attributeManager?.close();
|
||||||
this.#attributeManager = null;
|
this.#attributeManager = null;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,32 @@ This file contains utility methods used by Applications in order to be
|
||||||
DRYer
|
DRYer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Event} _event The click event
|
||||||
|
* @param {HTMLElement} target The element to operate on
|
||||||
|
*/
|
||||||
|
export async function editItemFromElement(_event, target) {
|
||||||
|
const itemEl = target.closest(`[data-item-uuid]`);
|
||||||
|
if (!itemEl) { return };
|
||||||
|
const uuid = itemEl.dataset.itemUuid;
|
||||||
|
if (!uuid) { return };
|
||||||
|
const item = await fromUuid(uuid);
|
||||||
|
item.sheet.render({ force: true, orBringToFront: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Event} _event The click event
|
||||||
|
* @param {HTMLElement} target The element to operate on
|
||||||
|
*/
|
||||||
|
export async function deleteItemFromElement(_event, target) {
|
||||||
|
const itemEl = target.closest(`[data-item-uuid]`);
|
||||||
|
if (!itemEl) { return };
|
||||||
|
const uuid = itemEl.dataset.itemUuid;
|
||||||
|
if (!uuid) { return };
|
||||||
|
const item = await fromUuid(uuid);
|
||||||
|
item.deleteDialog();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a document using the UUID, this is most useful for editing
|
* Updates a document using the UUID, this is most useful for editing
|
||||||
* documents from a sheet of another document (e.g. an Item embedded
|
* documents from a sheet of another document (e.g. an Item embedded
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue