Add confirm on item deletion
This commit is contained in:
@@ -25,10 +25,9 @@
|
|||||||
},
|
},
|
||||||
"l5r5e": {
|
"l5r5e": {
|
||||||
"global": {
|
"global": {
|
||||||
"ok": "OK",
|
|
||||||
"add": "Add",
|
"add": "Add",
|
||||||
"edit": "Edit",
|
"edit": "Edit",
|
||||||
"delete": "Delete",
|
"delete_confirm": "Are you sure you want to delete '{name}' ?",
|
||||||
"drop_here": "Drop here",
|
"drop_here": "Drop here",
|
||||||
"edge_translation_disclaimer": ""
|
"edge_translation_disclaimer": ""
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -25,10 +25,9 @@
|
|||||||
},
|
},
|
||||||
"l5r5e": {
|
"l5r5e": {
|
||||||
"global": {
|
"global": {
|
||||||
"ok": "OK",
|
|
||||||
"add": "Añadir",
|
"add": "Añadir",
|
||||||
"edit": "Editar",
|
"edit": "Editar",
|
||||||
"delete": "Borrar",
|
"delete_confirm": "Are you sure you want to delete '{name}' ?",
|
||||||
"drop_here": "Dejar caer aquí",
|
"drop_here": "Dejar caer aquí",
|
||||||
"edge_translation_disclaimer": "Edge Studio nos da su permiso para ofrecer este módulo a la comunidad, pero tanto los textos así como los códigos que lo constituyen no tienen su aprobación explícita."
|
"edge_translation_disclaimer": "Edge Studio nos da su permiso para ofrecer este módulo a la comunidad, pero tanto los textos así como los códigos que lo constituyen no tienen su aprobación explícita."
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -25,10 +25,9 @@
|
|||||||
},
|
},
|
||||||
"l5r5e": {
|
"l5r5e": {
|
||||||
"global": {
|
"global": {
|
||||||
"ok": "OK",
|
|
||||||
"add": "Ajouter",
|
"add": "Ajouter",
|
||||||
"edit": "Modifier",
|
"edit": "Modifier",
|
||||||
"delete": "Supprimer",
|
"delete_confirm": "Etes-vous sûr de vouloir supprimer '{name}' ?",
|
||||||
"drop_here": "Déposez ici",
|
"drop_here": "Déposez ici",
|
||||||
"edge_translation_disclaimer": ""
|
"edge_translation_disclaimer": ""
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ export class BaseSheetL5r5e extends ActorSheet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle dropped data on the Actor sheet
|
* Handle dropped data on the Actor sheet
|
||||||
|
* @param {Event} event
|
||||||
*/
|
*/
|
||||||
async _onDrop(event) {
|
async _onDrop(event) {
|
||||||
// *** Everything below here is only needed if the sheet is editable ***
|
// *** Everything below here is only needed if the sheet is editable ***
|
||||||
@@ -208,28 +209,12 @@ export class BaseSheetL5r5e extends ActorSheet {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Equipped / Readied
|
// Equipped / Readied
|
||||||
html.find(".equip-readied-control").on("click", (event) => {
|
html.find(".equip-readied-control").on("click", this._switchEquipReadied.bind(this));
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
this._switchEquipReadied(event);
|
|
||||||
});
|
|
||||||
|
|
||||||
// *** Items : add, edit, delete ***
|
// *** Items : add, edit, delete ***
|
||||||
html.find(".item-add").on("click", (event) => {
|
html.find(".item-add").on("click", this._addSubItem.bind(this));
|
||||||
event.preventDefault();
|
html.find(`.item-edit`).on("click", this._editSubItem.bind(this));
|
||||||
event.stopPropagation();
|
html.find(`.item-delete`).on("click", this._deleteSubItem.bind(this));
|
||||||
this._addSubItem(event);
|
|
||||||
});
|
|
||||||
html.find(`.item-edit`).on("click", (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
this._editSubItem(event);
|
|
||||||
});
|
|
||||||
html.find(`.item-delete`).on("click", (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
this._deleteSubItem(event);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -248,9 +233,13 @@ export class BaseSheetL5r5e extends ActorSheet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a generic item with sub type
|
* Add a generic item with sub type
|
||||||
|
* @param {Event} event
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
async _addSubItem(event) {
|
async _addSubItem(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
const type = $(event.currentTarget).data("item-type");
|
const type = $(event.currentTarget).data("item-type");
|
||||||
const titles = {
|
const titles = {
|
||||||
item: "l5r5e.items.title_new",
|
item: "l5r5e.items.title_new",
|
||||||
@@ -278,9 +267,13 @@ export class BaseSheetL5r5e extends ActorSheet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit a generic item with sub type
|
* Edit a generic item with sub type
|
||||||
|
* @param {Event} event
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_editSubItem(event) {
|
_editSubItem(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
const itemId = $(event.currentTarget).data("item-id");
|
const itemId = $(event.currentTarget).data("item-id");
|
||||||
const item = this.actor.getOwnedItem(itemId);
|
const item = this.actor.getOwnedItem(itemId);
|
||||||
item.sheet.render(true);
|
item.sheet.render(true);
|
||||||
@@ -288,9 +281,13 @@ export class BaseSheetL5r5e extends ActorSheet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a generic item with sub type
|
* Delete a generic item with sub type
|
||||||
|
* @param {Event} event
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_deleteSubItem(event) {
|
_deleteSubItem(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
const itemId = $(event.currentTarget).data("item-id");
|
const itemId = $(event.currentTarget).data("item-id");
|
||||||
|
|
||||||
// Remove 1 qty if possible
|
// Remove 1 qty if possible
|
||||||
@@ -299,32 +296,48 @@ export class BaseSheetL5r5e extends ActorSheet {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Specific advancements, remove 1 to selected ring/skill
|
const callback = async () => {
|
||||||
if (tmpItem.type === "advancement") {
|
// Specific advancements, remove 1 to selected ring/skill
|
||||||
const actor = duplicate(this.actor.data.data);
|
if (tmpItem.type === "advancement") {
|
||||||
const itmData = tmpItem.data.data;
|
const actor = duplicate(this.actor.data.data);
|
||||||
if (itmData.advancement_type === "ring") {
|
const itmData = tmpItem.data.data;
|
||||||
// Ring
|
if (itmData.advancement_type === "ring") {
|
||||||
actor.rings[itmData.ring] = Math.max(1, actor.rings[itmData.ring] - 1);
|
// Ring
|
||||||
} else {
|
actor.rings[itmData.ring] = Math.max(1, actor.rings[itmData.ring] - 1);
|
||||||
// Skill
|
} else {
|
||||||
const skillCatId = CONFIG.l5r5e.skills.get(itmData.skill);
|
// Skill
|
||||||
if (skillCatId) {
|
const skillCatId = CONFIG.l5r5e.skills.get(itmData.skill);
|
||||||
actor.skills[skillCatId][itmData.skill] = Math.max(0, actor.skills[skillCatId][itmData.skill] - 1);
|
if (skillCatId) {
|
||||||
|
actor.skills[skillCatId][itmData.skill] = Math.max(
|
||||||
|
0,
|
||||||
|
actor.skills[skillCatId][itmData.skill] - 1
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update Actor
|
||||||
|
this.actor.update({
|
||||||
|
data: diffObject(this.actor.data.data, actor),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Actor
|
return this.actor.deleteOwnedItem(itemId);
|
||||||
this.actor.update({
|
};
|
||||||
data: diffObject(this.actor.data.data, actor),
|
|
||||||
});
|
// Holing Ctrl = without confirm
|
||||||
|
if (event.ctrlKey) {
|
||||||
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.actor.deleteOwnedItem(itemId);
|
game.l5r5e.HelpersL5r5e.confirmDeleteDialog(
|
||||||
|
game.i18n.format("l5r5e.global.delete_confirm", { name: tmpItem.name }),
|
||||||
|
callback
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switch "in_curriculum"
|
* Switch "in_curriculum"
|
||||||
|
* @param {Event} event
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_switchSubItemCurriculum(event) {
|
_switchSubItemCurriculum(event) {
|
||||||
@@ -359,9 +372,13 @@ export class BaseSheetL5r5e extends ActorSheet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Switch Readied state on a weapon
|
* Switch Readied state on a weapon
|
||||||
|
* @param {Event} event
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_switchEquipReadied(event) {
|
_switchEquipReadied(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
const type = $(event.currentTarget).data("type");
|
const type = $(event.currentTarget).data("type");
|
||||||
if (!["equipped", "readied"].includes(type)) {
|
if (!["equipped", "readied"].includes(type)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -215,4 +215,27 @@ export class HelpersL5r5e {
|
|||||||
core.set("Anx", "l5r5e.core-peculiarities-anxieties");
|
core.set("Anx", "l5r5e.core-peculiarities-anxieties");
|
||||||
return core.get(itemId.replace(/L5RCore(\w{3})\d+/gi, "$1"));
|
return core.get(itemId.replace(/L5RCore(\w{3})\d+/gi, "$1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show a confirm dialog before a deletion
|
||||||
|
* @param {string} content
|
||||||
|
* @param {function} callback The callback function for confirmed action
|
||||||
|
*/
|
||||||
|
static confirmDeleteDialog(content, callback) {
|
||||||
|
new Dialog({
|
||||||
|
title: game.i18n.localize("Delete"),
|
||||||
|
content,
|
||||||
|
buttons: {
|
||||||
|
confirm: {
|
||||||
|
icon: '<i class="fas fa-trash"></i>',
|
||||||
|
label: game.i18n.localize("Yes"),
|
||||||
|
callback,
|
||||||
|
},
|
||||||
|
cancel: {
|
||||||
|
icon: '<i class="fas fa-times"></i>',
|
||||||
|
label: game.i18n.localize("No"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}).render(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,12 +105,7 @@ export class ItemSheetL5r5e extends ItemSheet {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Delete a property
|
// Delete a property
|
||||||
html.find(`.property-delete`).on("click", (event) => {
|
html.find(`.property-delete`).on("click", this._deleteProperty.bind(this));
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
const li = $(event.currentTarget).parents(".property");
|
|
||||||
this._deleteProperty(li.data("propertyId"));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -174,20 +169,37 @@ export class ItemSheetL5r5e extends ItemSheet {
|
|||||||
* Delete a property from the current item
|
* Delete a property from the current item
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_deleteProperty(id) {
|
_deleteProperty(event) {
|
||||||
if (
|
event.preventDefault();
|
||||||
!Array.isArray(this.entity.data.data.properties) ||
|
event.stopPropagation();
|
||||||
this.entity.data.data.properties.findIndex((p) => p.id === id) === -1
|
|
||||||
) {
|
if (!Array.isArray(this.entity.data.data.properties)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.entity.data.data.properties = this.entity.data.data.properties.filter((p) => p.id !== id);
|
const id = $(event.currentTarget).parents(".property").data("propertyId");
|
||||||
|
const tmpProps = this.entity.data.data.properties.find((p) => p.id === id);
|
||||||
|
if (!tmpProps) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.entity.update({
|
const callback = async () => {
|
||||||
data: {
|
this.entity.data.data.properties = this.entity.data.data.properties.filter((p) => p.id !== id);
|
||||||
properties: this.entity.data.data.properties,
|
this.entity.update({
|
||||||
},
|
data: {
|
||||||
});
|
properties: this.entity.data.data.properties,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Holing Ctrl = without confirm
|
||||||
|
if (event.ctrlKey) {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
game.l5r5e.HelpersL5r5e.confirmDeleteDialog(
|
||||||
|
game.i18n.format("l5r5e.global.delete_confirm", { name: tmpProps.name }),
|
||||||
|
callback
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<li class="item-name">{{ advancement.name }}</li>
|
<li class="item-name">{{ advancement.name }}</li>
|
||||||
{{#if editable}}
|
{{#if editable}}
|
||||||
<li data-item-id="{{advancement._id}}" class="item-control item-edit" title="{{localize 'l5r5e.global.edit'}}"><i class="fas fa-edit"></i></li>
|
<li data-item-id="{{advancement._id}}" class="item-control item-edit" title="{{localize 'l5r5e.global.edit'}}"><i class="fas fa-edit"></i></li>
|
||||||
<li data-item-id="{{advancement._id}}" class="item-control item-delete" title="{{localize 'l5r5e.global.delete'}}"><i class="fas fa-trash"></i></li>
|
<li data-item-id="{{advancement._id}}" class="item-control item-delete" title="{{localize 'Delete'}}"><i class="fas fa-trash"></i></li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</ul>
|
</ul>
|
||||||
{{#if advancement.data.description}}
|
{{#if advancement.data.description}}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
</li>
|
</li>
|
||||||
{{#if editable}}
|
{{#if editable}}
|
||||||
<li data-item-id="{{item._id}}" class="item-edit" title="{{localize 'l5r5e.global.edit'}}"><i class="fas fa-edit"></i></li>
|
<li data-item-id="{{item._id}}" class="item-edit" title="{{localize 'l5r5e.global.edit'}}"><i class="fas fa-edit"></i></li>
|
||||||
<li data-item-id="{{item._id}}" class="item-delete" title="{{localize 'l5r5e.global.delete'}}"><i class="fas fa-trash"></i></li>
|
<li data-item-id="{{item._id}}" class="item-delete" title="{{localize 'Delete'}}"><i class="fas fa-trash"></i></li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="item-properties">
|
<ul class="item-properties">
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
{{#if editable}}
|
{{#if editable}}
|
||||||
<li data-item-id="{{item._id}}" data-type="equipped" class="item-equip equip-readied-control" title="{{localize 'l5r5e.armors.equipped'}}"><i class="fas {{#if item.data.equipped}}fa-tshirt{{else}}fa-weight-hanging{{/if}}"></i></li>
|
<li data-item-id="{{item._id}}" data-type="equipped" class="item-equip equip-readied-control" title="{{localize 'l5r5e.armors.equipped'}}"><i class="fas {{#if item.data.equipped}}fa-tshirt{{else}}fa-weight-hanging{{/if}}"></i></li>
|
||||||
<li data-item-id="{{item._id}}" class="item-edit" title="{{localize 'l5r5e.global.edit'}}"><i class="fas fa-edit"></i></li>
|
<li data-item-id="{{item._id}}" class="item-edit" title="{{localize 'l5r5e.global.edit'}}"><i class="fas fa-edit"></i></li>
|
||||||
<li data-item-id="{{item._id}}" class="item-delete" title="{{localize 'l5r5e.global.delete'}}"><i class="fas fa-trash"></i></li>
|
<li data-item-id="{{item._id}}" class="item-delete" title="{{localize 'Delete'}}"><i class="fas fa-trash"></i></li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="item-properties">
|
<ul class="item-properties">
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<li class="item-name">{{ peculiarity.name }}</li>
|
<li class="item-name">{{ peculiarity.name }}</li>
|
||||||
{{#if editable}}
|
{{#if editable}}
|
||||||
<li data-item-id="{{peculiarity._id}}" class="item-control item-edit" title="{{localize 'l5r5e.global.edit'}}"><i class="fas fa-edit"></i></li>
|
<li data-item-id="{{peculiarity._id}}" class="item-control item-edit" title="{{localize 'l5r5e.global.edit'}}"><i class="fas fa-edit"></i></li>
|
||||||
<li data-item-id="{{peculiarity._id}}" class="item-control item-delete" title="{{localize 'l5r5e.global.delete'}}"><i class="fas fa-trash"></i></li>
|
<li data-item-id="{{peculiarity._id}}" class="item-control item-delete" title="{{localize 'Delete'}}"><i class="fas fa-trash"></i></li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</ul>
|
</ul>
|
||||||
{{#if peculiarity.data.types}}
|
{{#if peculiarity.data.types}}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<li class="item-img"><img src="{{item.img}}" title="{{item.name}}" width="32px" height="32px"/></li>
|
<li class="item-img"><img src="{{item.img}}" title="{{item.name}}" width="32px" height="32px"/></li>
|
||||||
<li class="item-name">{{ item.name }}</li>
|
<li class="item-name">{{ item.name }}</li>
|
||||||
{{#if editable}}
|
{{#if editable}}
|
||||||
<li class="property-delete" title="{{localize 'l5r5e.global.delete'}}"><i class="fas fa-trash"></i></li>
|
<li class="property-delete" title="{{localize 'Delete'}}"><i class="fas fa-trash"></i></li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</ul>
|
</ul>
|
||||||
{{#if item.data.data.description}}
|
{{#if item.data.data.description}}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<li class="item-name">{{ technique.name }}</li>
|
<li class="item-name">{{ technique.name }}</li>
|
||||||
{{#if editable}}
|
{{#if editable}}
|
||||||
<li data-item-id="{{technique._id}}" class="item-control item-edit" title="{{localize 'l5r5e.global.edit'}}"><i class="fas fa-edit"></i></li>
|
<li data-item-id="{{technique._id}}" class="item-control item-edit" title="{{localize 'l5r5e.global.edit'}}"><i class="fas fa-edit"></i></li>
|
||||||
<li data-item-id="{{technique._id}}" class="item-control item-delete" title="{{localize 'l5r5e.global.delete'}}"><i class="fas fa-trash"></i></li>
|
<li data-item-id="{{technique._id}}" class="item-control item-delete" title="{{localize 'Delete'}}"><i class="fas fa-trash"></i></li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</ul>
|
</ul>
|
||||||
{{#if technique.data.description}}
|
{{#if technique.data.description}}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
</li>
|
</li>
|
||||||
{{#if editable}}
|
{{#if editable}}
|
||||||
<li data-item-id="{{item._id}}" class="item-edit" title="{{localize 'l5r5e.global.edit'}}"><i class="fas fa-edit"></i></li>
|
<li data-item-id="{{item._id}}" class="item-edit" title="{{localize 'l5r5e.global.edit'}}"><i class="fas fa-edit"></i></li>
|
||||||
<li data-item-id="{{item._id}}" class="item-delete" title="{{localize 'l5r5e.global.delete'}}"><i class="fas fa-trash"></i></li>
|
<li data-item-id="{{item._id}}" class="item-delete" title="{{localize 'Delete'}}"><i class="fas fa-trash"></i></li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="item-properties">
|
<ul class="item-properties">
|
||||||
|
|||||||
Reference in New Issue
Block a user