|
1 | | -import { $$, ajaxForm } from "./utils.js"; |
| 1 | +import { $$, ajaxForm, replaceToolbarState } from "./utils.js"; |
2 | 2 |
|
3 | 3 | const djDebug = document.getElementById("djDebug"); |
4 | 4 |
|
5 | | -$$.on(djDebug, "click", ".switchHistory", function (event) { |
6 | | - event.preventDefault(); |
7 | | - const newStoreId = this.dataset.storeId; |
8 | | - const tbody = this.closest("tbody"); |
| 5 | +function switchHistory(newStoreId) { |
| 6 | + const formTarget = djDebug.querySelector( |
| 7 | + ".switchHistory[data-store-id='" + newStoreId + "']" |
| 8 | + ); |
| 9 | + const tbody = formTarget.closest("tbody"); |
9 | 10 |
|
10 | 11 | const highlighted = tbody.querySelector(".djdt-highlighted"); |
11 | 12 | if (highlighted) { |
12 | 13 | highlighted.classList.remove("djdt-highlighted"); |
13 | 14 | } |
14 | | - this.closest("tr").classList.add("djdt-highlighted"); |
| 15 | + formTarget.closest("tr").classList.add("djdt-highlighted"); |
15 | 16 |
|
16 | | - ajaxForm(this).then(function (data) { |
17 | | - djDebug.setAttribute("data-store-id", newStoreId); |
18 | | - // Check if response is empty, it could be due to an expired store_id. |
| 17 | + ajaxForm(formTarget).then(function (data) { |
19 | 18 | if (Object.keys(data).length === 0) { |
20 | 19 | const container = document.getElementById("djdtHistoryRequests"); |
21 | 20 | container.querySelector( |
22 | 21 | 'button[data-store-id="' + newStoreId + '"]' |
23 | 22 | ).innerHTML = "Switch [EXPIRED]"; |
24 | | - } else { |
25 | | - Object.keys(data).forEach(function (panelId) { |
26 | | - const panel = document.getElementById(panelId); |
27 | | - if (panel) { |
28 | | - panel.outerHTML = data[panelId].content; |
29 | | - document.getElementById("djdt-" + panelId).outerHTML = |
30 | | - data[panelId].button; |
31 | | - } |
32 | | - }); |
33 | 23 | } |
| 24 | + //we're already in history panel, so handle locally vs replacing active html |
| 25 | + delete data.HistoryPanel; |
| 26 | + replaceToolbarState(newStoreId, data); |
34 | 27 | }); |
| 28 | +} |
| 29 | + |
| 30 | +$$.on(djDebug, "click", ".switchHistory", function (event) { |
| 31 | + event.preventDefault(); |
| 32 | + switchHistory(this.dataset.storeId); |
35 | 33 | }); |
36 | 34 |
|
37 | 35 | $$.on(djDebug, "click", ".refreshHistory", function (event) { |
|
0 commit comments