deactivate_aaw_items();
/**
* Deactivates #AAW (Automotive Assessment Workflow) items so that only the set of items
* on the first page is generated (duplicate sets on subsequent pages are skipped).
*/
function deactivate_aaw_items() {
let templ = Template.GetCurrent();
/* We will search for items with names beginning with an identifiable string */
let aaw_item_str = `#AAW`;
let aaw_deactivate_items_str = `#AAW REPORTER deactivate items`;
/* Loop through all pages in the template, searching for relevant items */
let pages = templ.GetAllPages();
let skip_reactivate = false;
let aaw_item_count = 0;
let first_aaw_page = -1;
let last_aaw_page = -1;
for (let p = 0; p < pages.length; p++) {
let items = pages[p].GetAllItems();
for (let item of items) {
if (item.name.substring(0, aaw_item_str.length) == aaw_item_str) {
aaw_item_count++;
/* We assume that the first item is `#AAW REPORTER on load script`, which makes
* itself inactive to prevent an infinite loop.
* If the second item is active, this means that we are still generating the first
* page, so we want to skip reactivating the items at the end. */
if (aaw_item_count == 2) {
first_aaw_page = p;
if (item.active) skip_reactivate = true;
}
/* Deactivate all #AAW items */
item.active = false;
/* Keep track of last page */
last_aaw_page = p;
}
}
}
if (first_aaw_page == last_aaw_page) skip_reactivate = false;
/* Loop through the items on the last #AAW page to activate this item on
* that page, so that we can reactivate all the items again before the
* template finishes generating.
*/
let items = pages[last_aaw_page].GetAllItems();
for (let item of items) {
if (item.name.substring(0, aaw_deactivate_items_str.length) == aaw_deactivate_items_str) {
item.active = true;
}
}
/* We only reactivate items if either the first #AAW page is also the last
* #AAW page, or if the second #AAW item we encountered was already inactive
*/
if (skip_reactivate) return;
for (let page of pages) {
let items = page.GetAllItems();
for (let item of items) {
if (item.name.substring(0, aaw_item_str.length) == aaw_item_str) {
item.active = true;
}
}
}
}