-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
525 lines (452 loc) · 26.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Generator Version 0.1</title>
<!-- bootstrap css 5.3 -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<!-- w3 animate -->
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<!-- jquery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- base.css styles -->
<link rel="stylesheet" href="css/base.css">
<!-- object-styles.css styles -->
<link rel="stylesheet" href="css/object-styles.css">
<!-- code_editing.css style -->
<link rel="stylesheet" href="css/code_editing.css">
<!-- Include Prism CSS -->
<!-- <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism.min.css" rel="stylesheet" /> -->
<link href="./node_modules/prismjs/themes/prism.css" rel="stylesheet" />
</head>
<body>
<div id="snackbar" class="snackbar"></div>
<div id="root" class="container-fluid">
<div class="row">
<div class="col-md-4">
<!-- design pallete window -->
<h5 class="fs-1">Tools</h5>
<div class="design-tools-panel mb-4" style="max-height: 209px;" id="design-pallete-container">
<div class="row">
<div class="col-sm">
<p class="fs-5">Database Config.</p>
</div>
<div class="col-sm">
<p class="fs-5">Form Style.</p>
<!-- select the form style -->
<div class="input-group">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="formStyleOptions"
id="inlineRadiobtn" value="inline">
<label class="form-check-label" for="inlineRadiobtn">inline</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="formStyleOptions"
id="gridRadiobtn" value="grid">
<label class="form-check-label" for="gridRadiobtn">grid</label>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm">
<p class="fs-5">CSS Styling</p>
</div>
<div class="col-sm">
<p class="fs-5">Elements</p>
</div>
</div>
<div class="row">
<div class="col-sm">
<p class="fs-5">Reorder</p>
</div>
<div class="col-sm">
<p class="fs-5">Reload</p>
</div>
</div>
</div>
<!-- db table list -->
<div class="material-rounded-panel mb-4" style="max-height: 66vh;" id="dbtables-list-container">
<div class="text-center">
<div class="spinner-border" style="width: 3rem; height: 3rem;" role="status">
<span class="visually-hidden">Waiting for list...</span>
</div>
</div>
</div>
</div>
<div class="col-md-8">
<!-- review output window -->
<h5 class="fs-1">Preview</h5>
<div class="material-rounded-panel" id="preview-output-container">
<!-- bootstrap tabs -->
<ul class="nav nav-tabs sticky-top m-0 bg-white rounded-2" style="overflow: hidden;" id="myTab"
role="tablist">
<li class="nav-item" role="presentation" id="tabDesign">
<a class="nav-link fs-bold active" id="design-tab" data-bs-toggle="tab"
data-bs-target="#design-panel" role="tab" aria-controls="design-panel"
aria-selected="true">Form view.</a>
</li>
<li class="nav-item" role="presentation" id="tabHTML">
<a class="nav-link fs-bold" id="html-tab" data-bs-toggle="tab" data-bs-target="#html-panel"
role="tab" aria-controls="html-panel" aria-selected="false">HTML.</a>
</li>
<li class="nav-item" role="presentation" id="tabJS">
<a class="nav-link fs-bold" id="js-tab" data-bs-toggle="tab" data-bs-target="#js-panel"
role="tab" aria-controls="js-panel" aria-selected="false">Javascript.</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<!-- design tab -->
<div class="tab-pane fade show active" id="design-panel" role="tabpanel"
aria-labelledby="home-tab">
<span class="visually-hidden">Design</span>
<div class="design-preview w3-animate-left" id="design-output">
<p class="text-center py-5">No preview available</p>
</div>
</div>
<!-- html tab -->
<div class="tab-pane fade" id="html-panel" role="tabpanel" aria-labelledby="profile-tab">
<span class="visually-hidden">HTML</span>
<!-- function seperator accordion -->
<div class="accordion accordion-flush" id="accordionFlushHTML">
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button btn btn-primary fw-bold fs-5" type="button"
data-bs-toggle="collapse" data-bs-target="#flush-collapseOne"
aria-expanded="true" aria-controls="flush-collapseOne">
View form code.
</button>
</h2>
<div id="flush-collapseOne" class="accordion-collapse collapse show"
data-bs-parent="#accordionFlushExample">
<div class="accordion-body">
<!-- html output text container -->
<div class="code-block">
<pre><code id="html-preview" class="language-html">
<p> Select a table. </p>
</code></pre>
</div>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button btn btn-primary fw-bold fs-5 collapsed"
type="button" data-bs-toggle="collapse" data-bs-target="#flush-collapseTwo"
aria-expanded="false" aria-controls="flush-collapseTwo">
Edit form code.
</button>
</h2>
<div id="flush-collapseTwo" class="accordion-collapse collapse"
data-bs-parent="#accordionFlushExample">
<div class="accordion-body">
<div class="d-grid" style="height: 400px;position: relative;">
<!-- html code editor -->
<pre id="html-editing" class="highlighting" aria-hidden="true">
<code id="html-editing-highlighting" class="language-html"></code>
</pre>
<textarea class="editing" id="html-output" spellcheck="false"
oninput="sync_scroll(this,'#html-editing');"
onscroll="sync_scroll(this,'#html-editing');"></textarea>
<!-- oninput="editorUpdate(this.value);" -->
<!-- ./ html code editor -->
</div>
</div>
</div>
</div>
</div>
</div>
<!-- js tab -->
<div class="tab-pane fade" id="js-panel" role="tabpanel" aria-labelledby="contact-tab">
<span class="visually-hidden">Javascript</span>
<!-- function seperator accordion -->
<div class="accordion accordion-flush" id="accordionFlushJS">
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button btn btn-primary fw-bold fs-5" type="button"
data-bs-toggle="collapse" data-bs-target="#flush-collapseOne"
aria-expanded="true" aria-controls="flush-collapseOne">
View form code.
</button>
</h2>
<div id="flush-collapseOne" class="accordion-collapse collapse show"
data-bs-parent="#accordionFlushExample">
<div class="accordion-body">
<!-- js output text container -->
<div class="code-block">
<pre><code id="js-preview" class="language-javascript"></code></pre>
</div>
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header">
<button class="accordion-button btn btn-primary fw-bold fs-5 collapsed"
type="button" data-bs-toggle="collapse" data-bs-target="#flush-collapseTwo"
aria-expanded="false" aria-controls="flush-collapseTwo">
Edit form code.
</button>
</h2>
<div id="flush-collapseTwo" class="accordion-collapse collapse"
data-bs-parent="#accordionFlushExample">
<div class="accordion-body">
<div class="d-grid" style="height: 400px;position: relative;">
<!-- js code editor -->
<pre id="js-editing" class="highlighting" aria-hidden="true">
<code id="js-editing-highlighting" class="language-javascript"></code>
</pre>
<textarea class="editing" id="js-output" spellcheck="false"
oninput="sync_scroll(this,'#js-editing');"
onscroll="sync_scroll(this,'#js-editing');"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- ./ bootstrap tabs -->
</div>
</div>
</div>
</div>
<script>
function sync_scroll(element, scrollElement) {
/* Scroll result to scroll coords of event - sync with textarea */
let result_element = document.querySelector(scrollElement);
// Get and set x and y
result_element.scrollTop = element.scrollTop;
result_element.scrollLeft = element.scrollLeft;
}
// jquery
$(document).ready(function () {
// load design pallete
// $("#design-pallete-container").load("design-pallete.php");
// load preview output
// $("#preview-output-container").load("preview-output.php");
// PREVIEW_FORM_STYLE is used to determine what the default form structure is: inline or grid (input labels and input form are placed in a row object) style
// check if PREVIEW_FORM_STYLE is set in localstorage
var previewFormStyle = localStorage.getItem("PREVIEW_FORM_STYLE");
if (previewFormStyle == null) {
// set it to the default structure: inline
localStorage.setItem("PREVIEW_FORM_STYLE", "inline");
previewFormStyle = "inline";
} else {
previewFormStyle = localStorage.getItem("PREVIEW_FORM_STYLE");
}
if (previewFormStyle == "inline") {
document.getElementById("inlineRadiobtn").checked = true;
document.getElementById("gridRadiobtn").checked = false;
} else {
document.getElementById("inlineRadiobtn").checked = false;
document.getElementById("gridRadiobtn").checked = true;
}
// show snackbar
$.showSnackbar = function (message) {
// Get the snackbar DIV
var x = document.getElementById("snackbar");
// Add the "show" class to DIV
x.className = "show";
x.innerHTML = message;
// After 5 seconds, remove the show class from DIV
setTimeout(function () {
x.className = x.className.replace("show", "");
}, 5000);
}
$.compileDesignPallete = function () {
// 1. get function call get_db_table_names.php and output to #design-pallete-container
$.get("scripts/php/form_generation/get_db_table_names.php", function (data) {
if (data == "error" || data == "") {
alert("Error: " + data);
console.log(
"get request has failed calling [get_db_table_names.php]: \n[Status]: " +
status + "\n[Data]: " + data
);
$("#dbtables-list-container").html("<p class='text-center'>Error loading design pallete</p>");
} else {
$("#dbtables-list-container").html(data);
}
});
}
$.compileFormPreview = function (tableName) {
// set the table name in localstorage
let previewFormStyle = localStorage.setItem("DB_TABLE_NAME", tableName);
// get the initial form design preview
$.get("scripts/php/form_generation/generate_form_from_dbtable.php?tblname=" + tableName + "&style=" + previewFormStyle, function (data) {
if (data == "error" || data == "") {
alert("Error: " + data);
console.log(
"get request has failed calling [generate_form_from_dbtable.php]: \n[Status]: " +
status + "\n[Data]: " + data
);
// push error message to #design-output
$("#design-output").html("<p class='text-center'>Error loading design preview</p>");
// push error message to #html-output
$("#html-output").val("Error loading design preview");
// call Prism to highlight the code
$.compilePrismOutputHTML("Error loading design preview");
} else {
// to see the form design output
$("#design-output").html(data);
// to see the html output
$("#html-output").val(data);
// call Prism to highlight the code
$.compilePrismOutputHTML(data);
}
});
// 3. get function call generate_form_jquery_from_dbtable.php.php?req=js and output to #js-preview
$.get("scripts/php/form_generation/generate_form_jquery_from_dbtable.php?tblname=" + tableName, function (data) {
if (data == "error" || data == "") {
alert("Error: " + data);
console.log(
"get request has failed calling [generate_form_jquery_from_dbtable.php.php]: \n[Status]: " +
status + "\n[Data]: " + data
);
$("#js-output").val("Error loading form jquery");
// $("#js-preview").text("<p class='text-center'>Error loading form jquery</p>");
$.compilePrismOutputJavascript("Error loading form jquery");
} else {
$("#js-output").val(data);
// $("#js-preview").text(data);
$.compilePrismOutputJavascript(data);
}
});
// show snackbar with message
$.showSnackbar("Form preview generated for table: " + tableName + "");
}
function editorUpdate(input, language, outputid) {
// Handle final newlines (see article)
if (input[input.length - 1] == "\n") { // If the last character is a newline character
input += " "; // Add a placeholder space character to the final line
}
// Get the HTML code
var htmlCode = input //document.getElementById('html-editing-input').value;
var indentedHtmlCode;
result_element = document.getElementById(outputid);
switch (language) {
case "html":
// Indent and add syntax highlighting
indentedHtmlCode = Prism.highlight(htmlCode, Prism.languages.markup, 'markup');
break;
case "js":
// Indent and add syntax highlighting
indentedHtmlCode = Prism.highlight(htmlCode, Prism.languages.javascript, 'javascript');
break;
default:
// Indent and add syntax highlighting
indentedHtmlCode = Prism.highlight(htmlCode, Prism.languages.markup, 'markup');
break;
}
// Add the indented and highlighted code to the preview container
// result_element.innerHTML = indentedHtmlCode;
result_element.innerHTML = indentedHtmlCode.replace(new RegExp("&", "g"), "&").replace(new RegExp("<", "g"), "<"); /* Global RegExp */
// Syntax Highlight
Prism.highlightElement(result_element);
}
$.compilePrismOutputHTML = function (input) {
//*** copilot chat:
// Get the HTML code
var htmlCode = input //document.getElementById('html-output').value;
// Indent and add syntax highlighting
var indentedHtmlCode = Prism.highlight(htmlCode, Prism.languages.markup, 'markup');
// Add the indented and highlighted code to the preview container
document.getElementById('html-preview').innerHTML = indentedHtmlCode;
// Add the indented and highlighted code to the text editing container
editorUpdate(htmlCode, "html", "html-editing-highlighting");
}
$.compilePrismOutputJavascript = function (input) {
//*** copilot chat:
// Get the HTML code
var jsCode = input //document.getElementById('js-output').value;
// Indent and add syntax highlighting
var indentedHtmlCode = Prism.highlight(jsCode, Prism.languages.javascript, 'javascript');
// Add the indented and highlighted code to the preview container
document.getElementById('js-preview').innerHTML = indentedHtmlCode;
}
// jquery event listener for #html-output on keyup
$("#html-output").keyup(function () {
// get the html output
var htmlOutput = $("#html-output").val();
// set the html preview
$("#html-preview").text(htmlOutput);
// update html text editor inputs content
editorUpdate(htmlOutput, "html", "html-editing-highlighting");
// compile prism
Prism.highlightAll();
// update #design-utput with the html output
$("#design-output").html(htmlOutput);
});
// jquery event listener for #js-output on keyup
$("#js-output").keyup(function () {
// get the js output
var jsOutput = $("#js-output").val();
// set the js preview
$("#js-preview").text(jsOutput);
// update html text editor inputs content
// editorUpdate(htmlOutput, "js", "js-editing-highlighting");
$('#html-editing-highlighting').text(jsOutput);
// compile prism
Prism.highlightAll();
});
// jquery event listener for #inlineRadiobtn radio button
$("#inlineRadiobtn").click(function () {
// set the preview form style to inline
localStorage.setItem("PREVIEW_FORM_STYLE", "inline");
// get the table name from localstorage
var tableName = localStorage.getItem("DB_TABLE_NAME");
if (tableName == null) {
// error: table name is not set in localstorage
alert("Error: table name is not set in localstorage");
} else {
// compile the table preview
$.compileFormPreview(tableName);
}
});
// jquery event listener for #gridRadiobtn radio button
$("#gridRadiobtn").click(function () {
// set the preview form style to grid
localStorage.setItem("PREVIEW_FORM_STYLE", "grid");
// get the table name from localstorage
var tableName = localStorage.getItem("DB_TABLE_NAME");
if (tableName == null) {
// error: table name is not set in localstorage
alert("Error: table name is not set in localstorage");
} else {
// compile the table preview
$.compileFormPreview(tableName);
}
});
// jquery event listener for #html-output change
// $("#html-output").change(function () {
// // get the html output
// var htmlOutput = $("#html-output").val();
// // set the html preview
// $("#html-preview").text(htmlOutput);
// // compile prism
// Prism.highlightAll();
// });
// jquery event listener for #js-output change
// $("#js-output").change(function () {
// // get the js output
// var jsOutput = $("#js-output").val();
// // set the js preview
// $("#js-preview").text(jsOutput);
// // compile prism
// Prism.highlightAll();
// });
// initialize the design pallete
$.compileDesignPallete();
});
</script>
<!-- bootstrap js 5.3 -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
<!-- Include Prism JS -->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/components/prism-markup.min.js"></script> -->
<script src="./node_modules/prismjs/prism.js"></script>
</body>
</html>