diff --git a/src/interaction/policies/policies.js b/src/interaction/policies/policies.js index 628f22b148b741920e3f124df09c47d9815e65e7..00c862863c41dfbdf8b9f138386c6a1c18abf0b3 100644 --- a/src/interaction/policies/policies.js +++ b/src/interaction/policies/policies.js @@ -122,22 +122,63 @@ globalThis.policy = function(category) { let div; let span; let link; + let policyValue = _.get(V.policies, selectedPolicy[0].policy); + if (policyValue === 0) { + // apply + for (let i = 0; i < selectedPolicy.length; i++) { + const p = selectedPolicy[i]; + policyValue = _.get(V.policies, p.policy); - for (let i = 0; i < selectedPolicy.length; i++) { - const p = selectedPolicy[i]; - const policyValue = _.get(V.policies, p.policy); + testArray(p); + div = document.createElement("div"); + span = document.createElement("span"); + + // title + span.style.fontWeight = "bold"; + span.textContent = p.title; + div.append(span); + div.append(`: `); - // If we can repeal any policy, hide the others. - if (policyValue !== 0) { - if (selectedPolicy.length === 2) { // If it's length of two, we just need to hide the wrong one. Also, it uses -1. - if ((i === 0 && policyValue === -1) || (i === 1 && policyValue === 1)) { - continue; + // Description text + div.append(p.text); + div.append(` `); + //console.log(`selectedPolicy is `, p.policy, `and policyValue is: `, policyValue, `i: `, i); + // link + if (policyValue === 0) { + let enable; + if (i === 1 && selectedPolicy.length === 2) { + enable = -1; + } else { + enable = i + 1; + } + if (p.hasOwnProperty("requirements")) { + if (p.requirements()) { + implement(p, enable); + } else { + link = App.UI.DOM.disabledLink("Implement", [`You do not meet the requirments, or passed a conflicting policy already`]); + link.style.color = "white"; + div.append(link); + el.append(div); + } + } else { + implement(p, enable); } - } else if (i !== policyValue - 1) { // Otherwise, the policyValue should be the place in the array, starting from 1 since 0 represents off, so we offset. - continue; } } - + } else { + // repeal + let i; + if (selectedPolicy.length === 2) { // Tall vs short, -1 vs 1. + if (policyValue === 1) { + i = 0; // first element of array + } else if (policyValue === -1) { + i = 1; + } + } else { + i = policyValue - 1; + } + const p = selectedPolicy[i]; + policyValue = _.get(V.policies, p.policy); testArray(p); div = document.createElement("div"); span = document.createElement("span"); @@ -149,34 +190,19 @@ globalThis.policy = function(category) { div.append(`: `); // Description text - div.append(p.text); // TODO: "activatedText" if available + if (p.hasOwnProperty("activatedText")) { + div.append(p.activatedText); + } else { + div.append(p.text); + } div.append(` `); //console.log(`selectedPolicy is `, p.policy, `and policyValue is: `, policyValue, `i: `, i); // link - if (policyValue === 0) { - let enable; - if (i === 1 && selectedPolicy.length === 2) { - enable = -1; - } else { - enable = i + 1; - } - if (p.hasOwnProperty("requirements")) { - if (p.requirements()) { - implement(p, enable); - } else { - link = App.UI.DOM.disabledLink("Implement", [`You do not meet the requirments, or passed a conflicting policy already`]); - link.style.color = "white"; - div.append(link); - el.append(div); - } - } else { - implement(p, enable); - } - } else { - repeal(p); - } + repeal(p); } + + return el; function testArray(p) {