Spaces:
Sleeping
Sleeping
drakosfire
commited on
Commit
•
cf6d81c
1
Parent(s):
0034c2d
Almost to functional print maybe. Opening modal is working, reset has been refactored and works with print modal close. storeUI.html button ids updated for Event Delegation
Browse files- scripts.js +192 -189
- templates/storeUI.html +4 -4
scripts.js
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
-
|
|
|
|
|
2 |
let initialPositions = [];
|
|
|
|
|
3 |
document.addEventListener("DOMContentLoaded", function() {
|
4 |
-
|
|
|
5 |
let blockContainerPage = document.getElementById('block-page');
|
6 |
const pageContainer = document.getElementById('pages');
|
7 |
const trashArea = document.getElementById('trashArea');
|
8 |
-
const toggleButton = document.getElementById('toggle-text-block-button');
|
9 |
-
const autofillButton = document.getElementById('autofill-button');
|
10 |
-
const resetButton = document.getElementById('resetButton');
|
11 |
-
const addPageButton = document.getElementById('add-page-button');
|
12 |
-
const removePageButton = document.getElementById('remove-page-button');
|
13 |
let currentPage = pageContainer.querySelector('.block.monster.frame.wide');
|
14 |
const modal = document.getElementById('imageModal');
|
15 |
const modalImg = document.getElementById('modalImage');
|
@@ -40,61 +40,104 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
40 |
|
41 |
// Event delegation for image clicks
|
42 |
document.addEventListener('click', function(event) {
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
modal
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
});
|
92 |
-
storeInitialPositions();
|
93 |
-
})
|
94 |
-
.catch((error) => {
|
95 |
-
console.error('Error:', error);
|
96 |
-
});
|
97 |
-
});
|
98 |
|
99 |
|
100 |
function toggleAllTextBlocks() {
|
@@ -108,12 +151,11 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
108 |
// Hide all textareas and buttons
|
109 |
textareas.forEach(textarea => textarea.style.display = 'none');
|
110 |
generateButtons.forEach(btn => btn.style.display = 'none');
|
111 |
-
document.querySelector('.toggle-text-block-button').textContent = 'Show All Image Descriptions';
|
112 |
} else {
|
113 |
// Show all textareas and buttons
|
114 |
textareas.forEach(textarea => textarea.style.display = 'block');
|
115 |
generateButtons.forEach(btn => btn.style.display = 'inline-block');
|
116 |
-
|
117 |
}
|
118 |
}
|
119 |
function autofillBlocks() {
|
@@ -148,52 +190,13 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
148 |
console.log('Autofill complete, all blocks moved to page-container');
|
149 |
}
|
150 |
|
151 |
-
|
152 |
-
// Works great locally, not deployed to huggingface
|
153 |
-
// function printPDF() {
|
154 |
-
// // Capture the innerHTML of brewRenderer
|
155 |
-
// var brewRendererContent = document.getElementById('brewRenderer').innerHTML;
|
156 |
-
|
157 |
-
// // Open a new window immediately on user interaction
|
158 |
-
// var previewWindow = window.open('', 'pdf-preview', 'width=800,height=600');
|
159 |
-
|
160 |
-
// // Check if the window was blocked
|
161 |
-
// if (!previewWindow) {
|
162 |
-
// alert("Popup blocked! Please allow popups for this website to preview the PDF.");
|
163 |
-
// return;
|
164 |
-
// }
|
165 |
-
|
166 |
-
// // Create a form to send the content to the proxy
|
167 |
-
// var form = document.createElement("form");
|
168 |
-
// form.setAttribute("method", "post");
|
169 |
-
// form.setAttribute("action", "/proxy.html");
|
170 |
-
// form.setAttribute("target", "pdf-preview");
|
171 |
-
|
172 |
-
// // Create a hidden input to store the HTML content
|
173 |
-
// var hiddenField = document.createElement("input");
|
174 |
-
// hiddenField.setAttribute("type", "hidden");
|
175 |
-
// hiddenField.setAttribute("name", "htmlContent");
|
176 |
-
// hiddenField.setAttribute("value", brewRendererContent);
|
177 |
-
|
178 |
-
// form.appendChild(hiddenField);
|
179 |
-
// document.body.appendChild(form);
|
180 |
-
|
181 |
-
// // Submit the form, which will load the proxy.html in the new window
|
182 |
-
// form.submit();
|
183 |
-
|
184 |
-
// // Clean up the form after a short delay
|
185 |
-
// setTimeout(function() {
|
186 |
-
// form.remove();
|
187 |
-
// }, 1000);
|
188 |
-
// }
|
189 |
-
|
190 |
-
// document.getElementById('printButton').addEventListener('click', printPDF);
|
191 |
-
|
192 |
function openPrintModal() {
|
|
|
|
|
|
|
193 |
var brewRendererContent = document.getElementById('brewRenderer').innerHTML;
|
194 |
-
|
195 |
-
|
196 |
-
// Fetch proxy.html via AJAX
|
197 |
fetch('/proxy.html', {
|
198 |
method: 'POST',
|
199 |
headers: {
|
@@ -203,32 +206,42 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
203 |
})
|
204 |
.then(response => response.text())
|
205 |
.then(html => {
|
206 |
-
// Insert the fetched HTML into the modal
|
207 |
document.getElementById('modalPreviewContent').innerHTML = html;
|
208 |
-
|
209 |
-
// Display the modal
|
210 |
var modal = document.getElementById('printModal');
|
211 |
modal.style.display = "block";
|
212 |
-
|
213 |
-
// Attach event listeners to the print and cancel buttons
|
214 |
document.getElementById('print-button').onclick = function() {
|
215 |
-
window.print();
|
216 |
};
|
217 |
-
|
218 |
document.getElementById('cancel-button').onclick = function() {
|
219 |
-
|
220 |
};
|
221 |
-
|
222 |
document.getElementsByClassName('close')[0].onclick = function() {
|
223 |
-
|
224 |
};
|
225 |
})
|
226 |
.catch(error => {
|
227 |
console.error('Error loading the print preview:', error);
|
228 |
});
|
229 |
}
|
230 |
-
|
231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
|
233 |
|
234 |
// Store initial positions of the blocks
|
@@ -247,7 +260,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
247 |
console.log('Initial positions:', initialPositions);
|
248 |
}
|
249 |
|
250 |
-
function sortBlocksById() {
|
251 |
// Select all blocks inside the block-container
|
252 |
const blocks = Array.from(blockContainerPage.querySelectorAll('.block-item'));
|
253 |
console.log('Blocks in blockContainerPage:', blocks);
|
@@ -261,11 +274,14 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
261 |
|
262 |
// Clear the block-container before re-appending the sorted blocks
|
263 |
blockContainerPage.innerHTML = '';
|
|
|
264 |
|
265 |
// Re-append the blocks in the sorted order
|
|
|
266 |
blocks.forEach(block => blockContainerPage.appendChild(block));
|
267 |
|
268 |
console.log('Blocks have been sorted and re-appended based on block-id');
|
|
|
269 |
}
|
270 |
|
271 |
function reinsertBlock(blockContainerPage, blockId, innerHTML) {
|
@@ -341,8 +357,6 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
341 |
initializeTextareaResizing();
|
342 |
}
|
343 |
|
344 |
-
storeInitialPositions();
|
345 |
-
|
346 |
function adjustTextareaHeight(el, offset = 0) {
|
347 |
if (el.scrollHeight > 16){
|
348 |
el.style.height = 'auto';
|
@@ -441,15 +455,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
441 |
}
|
442 |
initializeTextareaResizing();
|
443 |
}
|
444 |
-
|
445 |
-
|
446 |
-
document.addEventListener('click', function(event) {
|
447 |
-
if (event.target && event.target.classList.contains('generate-image-button')) {
|
448 |
-
const blockId = event.target.getAttribute('data-block-id');
|
449 |
-
generateImage(blockId);
|
450 |
-
}
|
451 |
-
});
|
452 |
-
|
453 |
// Function to generate image
|
454 |
function generateImage(blockId) {
|
455 |
const sdPromptElement = document.getElementById(`sdprompt-${blockId}`);
|
@@ -913,7 +919,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
913 |
|
914 |
// Reinsert the block using the refactored function
|
915 |
reinsertBlock(blockContainerPage, blockId, innerHTML);
|
916 |
-
sortBlocksById();
|
917 |
} else {
|
918 |
console.log('No data transferred');
|
919 |
}
|
@@ -939,84 +945,81 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
939 |
}
|
940 |
|
941 |
function handleReset() {
|
942 |
-
|
943 |
-
|
944 |
-
// Collect all blocks from all pages
|
945 |
-
const allBlocks = [];
|
946 |
-
const pages = document.querySelectorAll('.page');
|
947 |
-
|
948 |
-
pages.forEach(page => {
|
949 |
-
console.log(`Processing page with ID: ${page.getAttribute('data-page-id')}`);
|
950 |
|
951 |
-
|
|
|
|
|
952 |
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
959 |
});
|
960 |
-
block.remove();
|
961 |
-
console.log(`Removed block with ID: ${blockId} from page ID: ${page.getAttribute('data-page-id')}`);
|
962 |
});
|
963 |
-
});
|
964 |
|
965 |
-
|
966 |
-
|
967 |
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
|
978 |
-
|
979 |
-
let blockContainerPage = document.getElementById('block-page');
|
980 |
-
if (!blockContainerPage) {
|
981 |
blockContainerPage = document.createElement('div');
|
982 |
blockContainerPage.classList.add('page');
|
983 |
blockContainerPage.setAttribute('id', 'block-page');
|
984 |
blockContainer.appendChild(blockContainerPage);
|
985 |
console.log('Created new blockContainerPage');
|
986 |
-
} else {
|
987 |
-
console.log('blockContainerPage already exists');
|
988 |
-
}
|
989 |
|
990 |
-
|
991 |
-
|
992 |
-
console.log('blockContainerPage reassigned to:', blockContainerPage);
|
993 |
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
|
1007 |
// Add a new page after reset
|
1008 |
-
|
1009 |
-
console.log('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1010 |
|
1011 |
console.log('Reset complete, all blocks moved back to block-container');
|
1012 |
initializeTextareaResizing();
|
1013 |
}
|
1014 |
|
1015 |
-
|
1016 |
-
addPageButton.addEventListener('click', addPage);
|
1017 |
-
removePageButton.addEventListener('click', removePage);
|
1018 |
-
toggleButton.addEventListener('click', toggleAllTextBlocks);
|
1019 |
-
autofillButton.addEventListener('click', autofillBlocks);
|
1020 |
|
1021 |
// Event listeners for drag and drop functionality
|
1022 |
blockContainer.addEventListener('dragover', handleDragOver);
|
@@ -1028,6 +1031,6 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
1028 |
trashArea.addEventListener('dragover', handleTrashOver);
|
1029 |
trashArea.addEventListener('dragleave', handleTrashLeave);
|
1030 |
trashArea.addEventListener('drop', handleTrashDrop);
|
1031 |
-
|
1032 |
extractBlocks();
|
1033 |
});
|
|
|
1 |
+
|
2 |
+
// Globals
|
3 |
+
let originalContent = null;
|
4 |
let initialPositions = [];
|
5 |
+
|
6 |
+
// Waits for DOM content to be fully loaded and assigns critical elements to variables.
|
7 |
document.addEventListener("DOMContentLoaded", function() {
|
8 |
+
// constants and variables.
|
9 |
+
let blockContainer = document.getElementById('blockContainer');
|
10 |
let blockContainerPage = document.getElementById('block-page');
|
11 |
const pageContainer = document.getElementById('pages');
|
12 |
const trashArea = document.getElementById('trashArea');
|
|
|
|
|
|
|
|
|
|
|
13 |
let currentPage = pageContainer.querySelector('.block.monster.frame.wide');
|
14 |
const modal = document.getElementById('imageModal');
|
15 |
const modalImg = document.getElementById('modalImage');
|
|
|
40 |
|
41 |
// Event delegation for image clicks
|
42 |
document.addEventListener('click', function(event) {
|
43 |
+
// Log the click event for debugging
|
44 |
+
console.log('Click detected:', event.target);
|
45 |
+
|
46 |
+
// Handle image clicks for modal display
|
47 |
+
if (event.target.tagName === 'IMG' && event.target.id.startsWith('generated-image-')) {
|
48 |
+
console.log('Image clicked for modal display. Image ID:', event.target.id);
|
49 |
+
modal.style.display = 'block';
|
50 |
+
modalImg.src = event.target.src;
|
51 |
+
captionText.innerHTML = event.target.alt;
|
52 |
+
}
|
53 |
+
|
54 |
+
// Handle modal close button
|
55 |
+
if (event.target.id === 'closeModal') {
|
56 |
+
console.log('Close button clicked for modal. Element ID:', event.target.id);
|
57 |
+
modal.style.display = "none";
|
58 |
+
}
|
59 |
+
|
60 |
+
// Handle modal close when clicking outside of the modal content
|
61 |
+
if (event.target === modal) {
|
62 |
+
console.log('Clicked outside of modal content, closing modal.');
|
63 |
+
modal.style.display = "none";
|
64 |
+
}
|
65 |
+
|
66 |
+
// Handle submission of the description
|
67 |
+
if (event.target.id === 'submitDescription') {
|
68 |
+
console.log('Submit description button clicked. Element ID:', event.target.id);
|
69 |
+
const userInput = document.getElementById('user-description').value;
|
70 |
+
blockContainerPage.innerHTML = ''; // Clear the block container before inserting new blocks
|
71 |
+
|
72 |
+
fetch('/process-description', {
|
73 |
+
method: 'POST',
|
74 |
+
headers: {
|
75 |
+
'Content-Type': 'application/json'
|
76 |
+
},
|
77 |
+
body: JSON.stringify({ user_input: userInput })
|
78 |
+
})
|
79 |
+
.then(response => response.json())
|
80 |
+
.then(data => {
|
81 |
+
console.log('Success:', data);
|
82 |
+
initialPositions.length = 0; // Clear the initialPositions array
|
83 |
+
insertHtmlBlocks(data.html_blocks);
|
84 |
+
const blocks = blockContainerPage.querySelectorAll('.block-item');
|
85 |
+
blocks.forEach(block => {
|
86 |
+
block.setAttribute('data-page-id', 'block-container');
|
87 |
+
block.setAttribute('draggable', true);
|
88 |
+
block.addEventListener('dragstart', handleDragStart);
|
89 |
+
block.addEventListener('dragend', handleDragEnd);
|
90 |
+
});
|
91 |
+
storeInitialPositions();
|
92 |
+
})
|
93 |
+
.catch((error) => {
|
94 |
+
console.error('Error:', error);
|
95 |
+
});
|
96 |
+
}
|
97 |
+
|
98 |
+
// Handle print button click
|
99 |
+
if (event.target.id === 'printButton') {
|
100 |
+
console.log('Print button clicked. Element ID:', event.target.id);
|
101 |
+
openPrintModal();
|
102 |
+
}
|
103 |
+
|
104 |
+
// Handle generate image button click
|
105 |
+
if (event.target.classList.contains('generate-image-button')) {
|
106 |
+
const blockId = event.target.getAttribute('data-block-id');
|
107 |
+
console.log('Generate image button clicked. Block ID:', blockId);
|
108 |
+
generateImage(blockId);
|
109 |
+
}
|
110 |
+
|
111 |
+
// Handle page add button
|
112 |
+
if (event.target.id === 'addPageButton') {
|
113 |
+
console.log('Add page button clicked. Element ID:', event.target.id);
|
114 |
+
addPage();
|
115 |
+
}
|
116 |
+
|
117 |
+
// Handle page remove button
|
118 |
+
if (event.target.id === 'removePageButton') {
|
119 |
+
console.log('Remove page button clicked. Element ID:', event.target.id);
|
120 |
+
removePage();
|
121 |
+
}
|
122 |
+
|
123 |
+
// Handle toggle button click
|
124 |
+
if (event.target.id === 'toggleButton') {
|
125 |
+
console.log('Toggle button clicked. Element ID:', event.target.id);
|
126 |
+
toggleAllTextBlocks();
|
127 |
+
}
|
128 |
+
|
129 |
+
// Handle autofill button click
|
130 |
+
if (event.target.id === 'autofillButton') {
|
131 |
+
console.log('Autofill button clicked. Element ID:', event.target.id);
|
132 |
+
autofillBlocks();
|
133 |
+
}
|
134 |
+
|
135 |
+
// Handle reset button click
|
136 |
+
if (event.target.id === 'resetButton') {
|
137 |
+
console.log('Reset button clicked. Element ID:', event.target.id);
|
138 |
+
handleReset();
|
139 |
+
}
|
140 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
|
143 |
function toggleAllTextBlocks() {
|
|
|
151 |
// Hide all textareas and buttons
|
152 |
textareas.forEach(textarea => textarea.style.display = 'none');
|
153 |
generateButtons.forEach(btn => btn.style.display = 'none');
|
|
|
154 |
} else {
|
155 |
// Show all textareas and buttons
|
156 |
textareas.forEach(textarea => textarea.style.display = 'block');
|
157 |
generateButtons.forEach(btn => btn.style.display = 'inline-block');
|
158 |
+
|
159 |
}
|
160 |
}
|
161 |
function autofillBlocks() {
|
|
|
190 |
console.log('Autofill complete, all blocks moved to page-container');
|
191 |
}
|
192 |
|
193 |
+
// This works in principal when deployed. It looks like shit but it does function.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
function openPrintModal() {
|
195 |
+
// Clone the original content before modifying
|
196 |
+
originalContent = document.body.cloneNode(true);
|
197 |
+
|
198 |
var brewRendererContent = document.getElementById('brewRenderer').innerHTML;
|
199 |
+
|
|
|
|
|
200 |
fetch('/proxy.html', {
|
201 |
method: 'POST',
|
202 |
headers: {
|
|
|
206 |
})
|
207 |
.then(response => response.text())
|
208 |
.then(html => {
|
|
|
209 |
document.getElementById('modalPreviewContent').innerHTML = html;
|
210 |
+
|
|
|
211 |
var modal = document.getElementById('printModal');
|
212 |
modal.style.display = "block";
|
213 |
+
|
|
|
214 |
document.getElementById('print-button').onclick = function() {
|
215 |
+
window.print();
|
216 |
};
|
217 |
+
|
218 |
document.getElementById('cancel-button').onclick = function() {
|
219 |
+
closePrintModal();
|
220 |
};
|
221 |
+
|
222 |
document.getElementsByClassName('close')[0].onclick = function() {
|
223 |
+
closePrintModal();
|
224 |
};
|
225 |
})
|
226 |
.catch(error => {
|
227 |
console.error('Error loading the print preview:', error);
|
228 |
});
|
229 |
}
|
230 |
+
|
231 |
+
function closePrintModal() {
|
232 |
+
var modal = document.getElementById('printModal');
|
233 |
+
modal.style.display = "none";
|
234 |
+
document.getElementById('modalPreviewContent').innerHTML = '';
|
235 |
+
|
236 |
+
// // Restore the original content or state
|
237 |
+
// if (originalContent) {
|
238 |
+
// document.body = originalContent.cloneNode(true);
|
239 |
+
// originalContent = null; // Clear the reference
|
240 |
+
// }
|
241 |
+
}
|
242 |
+
|
243 |
+
|
244 |
+
|
245 |
|
246 |
|
247 |
// Store initial positions of the blocks
|
|
|
260 |
console.log('Initial positions:', initialPositions);
|
261 |
}
|
262 |
|
263 |
+
function sortBlocksById(blockContainerPage) {
|
264 |
// Select all blocks inside the block-container
|
265 |
const blocks = Array.from(blockContainerPage.querySelectorAll('.block-item'));
|
266 |
console.log('Blocks in blockContainerPage:', blocks);
|
|
|
274 |
|
275 |
// Clear the block-container before re-appending the sorted blocks
|
276 |
blockContainerPage.innerHTML = '';
|
277 |
+
|
278 |
|
279 |
// Re-append the blocks in the sorted order
|
280 |
+
console.log('Contents of blocks', blocks);
|
281 |
blocks.forEach(block => blockContainerPage.appendChild(block));
|
282 |
|
283 |
console.log('Blocks have been sorted and re-appended based on block-id');
|
284 |
+
console.log('Contents of blockContainerPage', blockContainerPage);
|
285 |
}
|
286 |
|
287 |
function reinsertBlock(blockContainerPage, blockId, innerHTML) {
|
|
|
357 |
initializeTextareaResizing();
|
358 |
}
|
359 |
|
|
|
|
|
360 |
function adjustTextareaHeight(el, offset = 0) {
|
361 |
if (el.scrollHeight > 16){
|
362 |
el.style.height = 'auto';
|
|
|
455 |
}
|
456 |
initializeTextareaResizing();
|
457 |
}
|
458 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
459 |
// Function to generate image
|
460 |
function generateImage(blockId) {
|
461 |
const sdPromptElement = document.getElementById(`sdprompt-${blockId}`);
|
|
|
919 |
|
920 |
// Reinsert the block using the refactored function
|
921 |
reinsertBlock(blockContainerPage, blockId, innerHTML);
|
922 |
+
sortBlocksById(blockContainerPage);
|
923 |
} else {
|
924 |
console.log('No data transferred');
|
925 |
}
|
|
|
945 |
}
|
946 |
|
947 |
function handleReset() {
|
948 |
+
console.log('Reset button clicked');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
949 |
|
950 |
+
// Collect all blocks from all pages
|
951 |
+
const allBlocks = [];
|
952 |
+
const pages = document.querySelectorAll('.page');
|
953 |
|
954 |
+
pages.forEach(page => {
|
955 |
+
console.log(`Processing page with ID: ${page.getAttribute('data-page-id')}`);
|
956 |
+
|
957 |
+
const blocksOnPage = page.querySelectorAll('[data-block-id]');
|
958 |
+
|
959 |
+
blocksOnPage.forEach(block => {
|
960 |
+
block.setAttribute('display', 'block');
|
961 |
+
const blockId = block.getAttribute('data-block-id');
|
962 |
+
allBlocks.push({
|
963 |
+
id: blockId,
|
964 |
+
innerHTML: block.innerHTML
|
965 |
+
});
|
966 |
+
block.remove();
|
967 |
+
console.log(`Removed block with ID: ${blockId} from page ID: ${page.getAttribute('data-page-id')}`);
|
968 |
});
|
|
|
|
|
969 |
});
|
|
|
970 |
|
971 |
+
// Log blocks collected
|
972 |
+
console.log('All blocks collected:', allBlocks);
|
973 |
|
974 |
+
// Clear all pages
|
975 |
+
pages.forEach(page => {
|
976 |
+
console.log(`Removing page with ID: ${page.getAttribute('data-page-id')}`);
|
977 |
+
page.remove();
|
978 |
+
});
|
979 |
|
980 |
+
// Clear blockContainer before reinserting blocks
|
981 |
+
console.log('Clearing blockContainer...');
|
982 |
+
blockContainer.innerHTML = '';
|
983 |
|
984 |
+
// Create a new page inside the blockContainer
|
|
|
|
|
985 |
blockContainerPage = document.createElement('div');
|
986 |
blockContainerPage.classList.add('page');
|
987 |
blockContainerPage.setAttribute('id', 'block-page');
|
988 |
blockContainer.appendChild(blockContainerPage);
|
989 |
console.log('Created new blockContainerPage');
|
|
|
|
|
|
|
990 |
|
991 |
+
// Reassign blockContainerPage to the newly created block-page element
|
992 |
+
console.log('blockContainerPage reassigned to:', blockContainerPage);
|
|
|
993 |
|
994 |
+
// Reinsert blocks back into the blockContainer in their original order
|
995 |
+
initialPositions.forEach(pos => {
|
996 |
+
const blockData = allBlocks.find(block => block.id === pos.id);
|
997 |
+
|
998 |
+
if (blockData) {
|
999 |
+
console.log(`Reinserting block with ID: ${blockData.id} into blockContainerPage`);
|
1000 |
+
reinsertBlock(blockContainerPage, blockData.id, blockData.innerHTML);
|
1001 |
+
sortBlocksById(blockContainerPage);
|
1002 |
+
} else {
|
1003 |
+
console.log(`Block with ID: ${pos.id} not found in collected blocks.`);
|
1004 |
+
}
|
1005 |
+
});
|
1006 |
|
1007 |
// Add a new page after reset
|
1008 |
+
let currentPage = pageContainer.querySelector('.page');
|
1009 |
+
console.log('Current page:', currentPage);
|
1010 |
+
// If no existing page is found, create the first page
|
1011 |
+
if (!currentPage) {
|
1012 |
+
currentPage = addPage();
|
1013 |
+
currentPage.setAttribute('data-page-id', 'page-0');
|
1014 |
+
console.log('No existing pages found. Created the first page:', currentPage.id);
|
1015 |
+
}
|
1016 |
+
|
1017 |
|
1018 |
console.log('Reset complete, all blocks moved back to block-container');
|
1019 |
initializeTextareaResizing();
|
1020 |
}
|
1021 |
|
1022 |
+
|
|
|
|
|
|
|
|
|
1023 |
|
1024 |
// Event listeners for drag and drop functionality
|
1025 |
blockContainer.addEventListener('dragover', handleDragOver);
|
|
|
1031 |
trashArea.addEventListener('dragover', handleTrashOver);
|
1032 |
trashArea.addEventListener('dragleave', handleTrashLeave);
|
1033 |
trashArea.addEventListener('drop', handleTrashDrop);
|
1034 |
+
|
1035 |
extractBlocks();
|
1036 |
});
|
templates/storeUI.html
CHANGED
@@ -64,10 +64,10 @@
|
|
64 |
hx-target="#user-description" hx-swap="outerHTML"
|
65 |
title="As much or as little description as you want to provide. You can provide specific employees, inventory etc">A very standard gear store run by a fae potted plant named Gorgeous</textarea>
|
66 |
<button id="submitDescription">Submit</button>
|
67 |
-
<button id="
|
68 |
-
<button id="
|
69 |
-
<button id="
|
70 |
-
<button id="
|
71 |
<button id="resetButton">Reset</button>
|
72 |
<button id="printButton">Open Tab to print</button>
|
73 |
</div>
|
|
|
64 |
hx-target="#user-description" hx-swap="outerHTML"
|
65 |
title="As much or as little description as you want to provide. You can provide specific employees, inventory etc">A very standard gear store run by a fae potted plant named Gorgeous</textarea>
|
66 |
<button id="submitDescription">Submit</button>
|
67 |
+
<button id="autofillButton">Autofill Pages</button>
|
68 |
+
<button id="toggleButton">Toggle Image Descriptions</button>
|
69 |
+
<button id="addPageButton">Add New Page</button>
|
70 |
+
<button id="removePageButton">Remove Last Page</button>
|
71 |
<button id="resetButton">Reset</button>
|
72 |
<button id="printButton">Open Tab to print</button>
|
73 |
</div>
|