Skip to content
Snippets Groups Projects
Commit cb86fb41 authored by lowercasedonkey's avatar lowercasedonkey
Browse files

move repeal out of the main loop

parent b40f8e72
No related branches found
No related tags found
No related merge requests found
...@@ -122,22 +122,63 @@ globalThis.policy = function(category) { ...@@ -122,22 +122,63 @@ globalThis.policy = function(category) {
let div; let div;
let span; let span;
let link; 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++) { testArray(p);
const p = selectedPolicy[i]; div = document.createElement("div");
const policyValue = _.get(V.policies, p.policy); 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. // Description text
if (policyValue !== 0) { div.append(p.text);
if (selectedPolicy.length === 2) { // If it's length of two, we just need to hide the wrong one. Also, it uses -1. div.append(` `);
if ((i === 0 && policyValue === -1) || (i === 1 && policyValue === 1)) { //console.log(`selectedPolicy is `, p.policy, `and policyValue is: `, policyValue, `i: `, i);
continue; // 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); testArray(p);
div = document.createElement("div"); div = document.createElement("div");
span = document.createElement("span"); span = document.createElement("span");
...@@ -149,34 +190,19 @@ globalThis.policy = function(category) { ...@@ -149,34 +190,19 @@ globalThis.policy = function(category) {
div.append(`: `); div.append(`: `);
// Description text // 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(` `); div.append(` `);
//console.log(`selectedPolicy is `, p.policy, `and policyValue is: `, policyValue, `i: `, i); //console.log(`selectedPolicy is `, p.policy, `and policyValue is: `, policyValue, `i: `, i);
// link // link
if (policyValue === 0) { repeal(p);
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);
}
} }
return el; return el;
function testArray(p) { function testArray(p) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment