/** * Extend the basic ItemSheet * @extends {ItemSheet} */ export class BladesItemSheet extends ItemSheet { /** @override */ static get defaultOptions() { return mergeObject(super.defaultOptions, { classes: ["blades-in-the-dark", "sheet", "item"], width: 900, height: 900, tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}] }); } /* -------------------------------------------- */ /** @override */ get template() { const path = "systems/blades-in-the-dark/templates/items"; let simple_item_types = ["background", "heritage", "vice"]; let template_name = `${this.item.data.type}`; if (simple_item_types.indexOf(this.item.data.type) >= 0) { template_name = "simple"; } return `${path}/${template_name}.html`; } /* -------------------------------------------- */ /** @override */ getData() { const data = super.getData(); return data; } /* -------------------------------------------- */ /** @override */ activateListeners(html) { super.activateListeners(html); // Everything below here is only needed if the sheet is editable if (!this.options.editable) return; // Add or Remove Attribute // html.find(".attributes").on("click", ".attribute-control", this._onClickAttributeControl.bind(this)); } /* -------------------------------------------- */ /** * Listen for click events on an attribute control to modify the composition of attributes in the sheet * @param {MouseEvent} event The originating left click event * @private */ async _onClickAttributeControl(event) { event.preventDefault(); const a = event.currentTarget; const action = a.dataset.action; const attrs = this.object.data.data.attributes; const form = this.form; // Add new attribute if ( action === "create" ) { const nk = Object.keys(attrs).length + 1; let newKey = document.createElement("div"); newKey.innerHTML = ``; newKey = newKey.children[0]; form.appendChild(newKey); await this._onSubmit(event); } // Remove existing attribute else if ( action === "delete" ) { const li = a.closest(".attribute"); li.parentElement.removeChild(li); await this._onSubmit(event); } } /* -------------------------------------------- */ /** override */ _getFormData(form) { const FD = BladesHelpers.getFormDataHelper(form, this.editors); return FD; } /* -------------------------------------------- */ }