Bug 1487557 - Make all rows of active policies to have the same number of columns. r=felipe
authorSoeren Hentzschel <cadeyrn@ymail.com>
Thu, 30 Aug 2018 20:49:01 -0300
changeset 491935 bfe71056fd0f2f81a824a1b05132c80083eaa754
parent 491934 cd82664c5a141ff4b30f0bd0300f754adee3e262
child 491936 6b5dfb276159213aed3f93f6dac6d8ad85fec86e
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe
bugs1487557
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1487557 - Make all rows of active policies to have the same number of columns. r=felipe
browser/components/enterprisepolicies/content/aboutPolicies.js
--- a/browser/components/enterprisepolicies/content/aboutPolicies.js
+++ b/browser/components/enterprisepolicies/content/aboutPolicies.js
@@ -28,16 +28,42 @@ function machine_only_col(text) {
   icon.title = "Machine-only";
   let column = document.createElement("td");
   let content = document.createTextNode(text);
   column.appendChild(content);
   column.appendChild(icon);
   return column;
 }
 
+function addMissingColumns() {
+  const table = document.getElementById("activeContent");
+  let maxColumns = 0;
+
+  // count the number of columns per row and set the max number of columns
+  for (let i = 0, length = table.rows.length; i < length; i++) {
+    if (maxColumns < table.rows[i].cells.length) {
+      maxColumns = table.rows[i].cells.length;
+    }
+  }
+
+  // add the missing columns
+  for (let i = 0, length = table.rows.length; i < length; i++) {
+    const rowLength = table.rows[i].cells.length;
+
+    if (rowLength < maxColumns) {
+      let missingColumns = maxColumns - rowLength;
+
+      while (missingColumns > 0) {
+        table.rows[i].insertCell();
+        missingColumns--;
+      }
+    }
+  }
+}
+
 /*
  * This function generates the Active Policies content to be displayed by calling
  * a recursive function called generatePolicy() according to the policy schema.
  */
 
 function generateActivePolicies(data) {
 
   let new_cont = document.getElementById("activeContent");
@@ -68,21 +94,22 @@ function generateActivePolicies(data) {
         row.appendChild(col(obj));
         generatePolicy(data[policyName][obj], row, 2, new_cont, isLastRow, true);
         count++;
       }
     } else {
       let row = document.createElement("tr");
       row.appendChild(col(policyName));
       row.appendChild(col(JSON.stringify(data[policyName])));
-      row.appendChild(col(""));
       row.classList.add(color_class, "last_row");
       new_cont.appendChild(row);
     }
   }
+
+  addMissingColumns();
 }
 
 /*
  * This is a helper recursive function that iterates levels of each
  * policy and formats the content to be displayed accordingly.
  */
 
 function generatePolicy(data, row, depth, new_cont, islast, arr_sep = false) {