Final v0.0.2
This commit is contained in:
54
module/helpers/actor-helper.js
Normal file
54
module/helpers/actor-helper.js
Normal file
@@ -0,0 +1,54 @@
|
||||
export default class ActorHelpers {
|
||||
static async actorUpdate(event, formData) {
|
||||
formData = expandObject(formData);
|
||||
|
||||
// Handle the free-form relationship list
|
||||
const formAttrs = expandObject(formData)?.data?.relationships || {};
|
||||
|
||||
const relationships = Object.values(formAttrs).reduce((obj, v) => {
|
||||
let k = v["key"].trim();
|
||||
delete v["key"];
|
||||
obj[k] = v;
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
// Remove modifications which are no longer used
|
||||
if (this.object.data?.data?.relationships) {
|
||||
for (let k of Object.keys(this.object.data.data.relationships)) {
|
||||
if (!relationships.hasOwnProperty(k)) relationships[`-=${k}`] = null;
|
||||
}
|
||||
}
|
||||
|
||||
// recombine modifications to formData
|
||||
if (Object.keys(relationships).length > 0) {
|
||||
setProperty(formData, `data.relationships`, relationships);
|
||||
}
|
||||
|
||||
|
||||
// Handle the free-form learnign list
|
||||
const formAttrsLearning = expandObject(formData)?.data?.learning || {};
|
||||
|
||||
const learning = Object.values(formAttrsLearning).reduce((obj, v) => {
|
||||
let k = v["key"].trim();
|
||||
delete v["key"];
|
||||
obj[k] = v;
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
// Remove modifications which are no longer used
|
||||
if (this.object.data?.data?.learning) {
|
||||
for (let k of Object.keys(this.object.data.data.learning)) {
|
||||
if (!learning.hasOwnProperty(k)) learning[`-=${k}`] = null;
|
||||
}
|
||||
}
|
||||
|
||||
// recombine modifications to formData
|
||||
if (Object.keys(learning).length > 0) {
|
||||
setProperty(formData, `data.learning`, learning);
|
||||
}
|
||||
|
||||
// Update the Item
|
||||
this.actor.data.flags.loaded = false;
|
||||
this.object.update(formData);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user