2020-04-17 21:23:57 +00:00
|
|
|
/**
|
2020-04-21 16:06:33 +00:00
|
|
|
* Extend the basic ItemSheet
|
2020-04-17 21:23:57 +00:00
|
|
|
* @extends {ItemSheet}
|
|
|
|
*/
|
2020-04-21 16:06:33 +00:00
|
|
|
export class BladesItemSheet extends ItemSheet {
|
2020-04-17 21:23:57 +00:00
|
|
|
|
|
|
|
/** @override */
|
|
|
|
static get defaultOptions() {
|
|
|
|
return mergeObject(super.defaultOptions, {
|
2020-04-21 16:06:33 +00:00
|
|
|
classes: ["blades-in-the-dark", "sheet", "item"],
|
2020-04-24 15:30:51 +00:00
|
|
|
width: 900,
|
|
|
|
height: 900,
|
2020-04-17 21:23:57 +00:00
|
|
|
tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
2020-04-21 16:06:33 +00:00
|
|
|
/** @override */
|
|
|
|
get template() {
|
2020-04-22 07:57:36 +00:00
|
|
|
const path = "systems/blades-in-the-dark/templates/items";
|
2020-04-23 16:11:04 +00:00
|
|
|
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`;
|
2020-04-21 16:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
2020-04-17 21:23:57 +00:00
|
|
|
/** @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
|
2020-04-23 16:11:04 +00:00
|
|
|
// html.find(".attributes").on("click", ".attribute-control", this._onClickAttributeControl.bind(this));
|
2020-04-17 21:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 = `<input type="text" name="data.attributes.attr${nk}.key" value="attr${nk}"/>`;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
2020-04-24 15:30:51 +00:00
|
|
|
|
|
|
|
/** override */
|
|
|
|
_getFormData(form) {
|
|
|
|
const FD = BladesHelpers.getFormDataHelper(form, this.editors);
|
|
|
|
return FD;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-04-17 21:23:57 +00:00
|
|
|
}
|