|
1 | 1 | import { getI18n } from "@/util/i18n"; |
| 2 | +import { createElementFromHtml } from "@/util/dom"; |
2 | 3 |
|
| 4 | +const enableHeadings = false; |
3 | 5 | const nameInput = document.querySelector(`#createItem input[name="name"]`); |
4 | 6 | const copyFromInput = document.querySelector(`#createItem input[name="from"]`); |
5 | 7 | const copyRadio = document.querySelector(`#createItem input[value="copy"]`); |
@@ -116,6 +118,29 @@ document.addEventListener("DOMContentLoaded", () => { |
116 | 118 | ////////////////////////////////// |
117 | 119 | // Draw functions |
118 | 120 |
|
| 121 | + function drawCategory(category) { |
| 122 | + const heading = createElementFromHtml( |
| 123 | + "<div class='jenkins-choice-list__heading'></div>", |
| 124 | + ); |
| 125 | + const title = createElementFromHtml("<h2>" + category.name + "</h2>"); |
| 126 | + const description = createElementFromHtml( |
| 127 | + "<p>" + category.description + "</p>", |
| 128 | + ); |
| 129 | + heading.appendChild(title); |
| 130 | + heading.appendChild(description); |
| 131 | + const response = []; |
| 132 | + |
| 133 | + if (enableHeadings) { |
| 134 | + response.push(heading); |
| 135 | + } |
| 136 | + |
| 137 | + category.items.forEach((elem) => { |
| 138 | + response.push(drawItem(elem)); |
| 139 | + }); |
| 140 | + |
| 141 | + return response; |
| 142 | + } |
| 143 | + |
119 | 144 | function drawItem(elem) { |
120 | 145 | var item = document.createElement("div"); |
121 | 146 | item.className = |
@@ -209,9 +234,7 @@ document.addEventListener("DOMContentLoaded", () => { |
209 | 234 | // Render all categories |
210 | 235 | var $categories = document.querySelector(".categories template"); |
211 | 236 | data.categories.forEach((elem) => { |
212 | | - elem.items.forEach((elem) => { |
213 | | - $categories.before(drawItem(elem)); |
214 | | - }); |
| 237 | + drawCategory(elem).forEach((e) => $categories.before(e)); |
215 | 238 | }); |
216 | 239 |
|
217 | 240 | // Init NameField |
|
0 commit comments