/
Sidebar.html
1711 lines (1480 loc) · 75.4 KB
/
Sidebar.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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<style>
.paddedV
{
min-height: 35px;
background-color: #242424;
}
.buttonPadding
{
min-height: 5px;
background-color: #242424;
margin-bottom: 15px;
}
.buttonPlaceholder
{
min-height: 70px;
}
.mainWrapper
{
margin-left: auto;
margin-right: auto;
}
.sectionWrapper
{
margin: 25px;
}
.centerWrapper
{
margin: auto;
max-width: 175px;
}
.scrollWrapper
{
max-height: 150px;
overflow: auto;
}
.buttonWrapper
{
background-color: #4d4d4d;
min-width: 100%;
position: fixed;
bottom: 0;
left: 0;
padding-bottom: 20px;
z-index: 2;
}
.dropdown
{
width: 200px;
}
.note
{
color: grey;
font-style: italic;
}
.option
{
position: relative;
display: inline-block;
}
.option .tooltip
{
visibility: hidden;
width: 200px;
background-color: rgba(0,0,0,0.975);
border-radius: 6px;
padding: 10px 10px;
position: absolute;
z-index: 1;
top: 100%;
left: 0%;
opacity: 0;
transition: opacity 0.5s;
}
.option .padded
{
margin-left: 20px;
}
.option:hover .tooltip
{
visibility: visible;
opacity: 1;
}
.disabled
{
color: grey;
}
.accordion
{
min-height: 20px;
background-color: #242424;
cursor: pointer;
width: 100%;
text-align: left;
border-bottom: 5px solid black;
outline: none;
transition: 0.4s;
}
.accordion:hover
{
background-color: #2a5266;
}
.accordion:before
{
content: '\002B';
color: white;
float: left;
margin: 16px 0px 0px 10px;
font-size: 36px;
}
.active:before
{
content: "\2212";
}
.accodionPanel
{
display: block;
overflow: hidden;
}
input[type=text]:enabled
{
background: #ffffff;
}
input[type=text]:disabled
{
background: #595959;
}
h1
{
color: white;
display: inline-block;
vertical-align: middle;
line-height: normal;
margin: 10px 0px 10px 5px;
}
</style>
<div class='mainWrapper'>
<div id="generalOptions">
</div>
<div id='xmlOptions'>
</div>
<div id='jsonOptions'>
</div>
<div id='advancedOptions'>
</div>
<div class='buttonPlaceholder'></div>
<div class='buttonWrapper'>
<div class='buttonPadding'></div>
<div class='centerWrapper'>
<button class="action" onclick="exportFile()">Export</button>
<button onclick="visualizeFile()">Visualize</button>
</div>
</div>
</div>
<script type="text/javascript">
//Consts
var EXP_SHEET_CUSTOM = "custom";
var EXP_SHEET_SINGLE = "currentSheet";
var EXP_TYPE_XML = "xmlFormat";
//General
var IGNORE_COLUMN_DEFAULT = "NOEX_";
var UNWRAP_SHEETS_DEFAULT = "US_";
var COLLAPSE_SHEET_DEFAULT = "CS_";
//XML
var XML_ROOT_DEFAULT = "data";
var XML_ATT_DEFAULT = "ATT_";
var XML_CE_DEFAULT = "CE_";
var XML_IT_DEFAULT = "IT_";
//JSON
var JSON_SEPARATOR_DEFAULT = ","; //TODO: Cannot be " or ' chars
var JSON_JA_DEFAULT = "JA_";
//Nesting Elements
var NEST_NA_DEFAULT = "NA_";
//Visualization
var visualizeData = false;
//General Options
//Replaces any export files that have the same name
var replaceExistingFiles = false;
//Don't wrap the contents of a sheet in a JSON object / XML element if the sheet only has one row
var unwrapSingleRows = false;
//Collapse the contents of a sheet in a JSON object / XML element if the sheet only has one row
var collapseSingleRows = false;
//Don't export cells that are empty (helps reduce file size)
var ignoreEmptyCells = false;
//Advanced Options
//Support complex nested elements by using special key formatting
var nestedElements = false;
//Export data without spaces or newlines
var minifyData = false;
//Don't export columns with the ignore prefix
var ignoreColumnsWithPrefix = false;
var ignoreColumnsPrefix = "NOEX_";
//Unwrap sheets with one row and this prefix
var unwrapSheetsWithPrefix = false;
var unwrapSheetsPrefix = "US_";
//Collapse sheets with one row and this prefix
var collapseSheetsWithPrefix = false;
var collapseSheetsPrefix = "CS_";
//XML Options
//Export values as child elements instead of attributes
var exportChildElementXml = false;
//Include the first column in the export in addition to using it as the name for the row element.
var includeFirstColumnXml = false;
//XML Advanced Options
//Root element of the XML document
var rootElementXml = "data";
//XML element name invalid char replacement
var nameReplacementCharXml = "_";
//XML declaration inclusion
var includeDeclarationXml = false;
//XML declaration version
var declarationVersionXml = "1.0";
//XML declaration encoding
var declarationEncodingXml = "none";
//XML declaration standalone
var declarationStandaloneXml = "none";
//Columns using keys starting with a specified string will always be exported as attributes
var forceAttributesXml = false;
var forceAttributesPrefixXml = "ATT_";
//Columns using keys starting with a specified string will always be exported as child elements
var forceChildElementsXml = false;
var forceChildElementsPrefixXml = "CE_";
//Columns using keys starting with a specified string will always be exported as inner text
var forceInnerTextXml = false;
var forceInnerTextPrefixXml = "IT_";
//JSON Options
//Export cell contents as a JSON array if the cell contains commas
var exportCellArrayJson = false;
//Export a sheet's contents as an array, with each row being one JSON object element in the array
var exportSheetArrayJson = false;
//Export a sheet's contents as an array of values if the sheet contains only one column
var exportValueArrayJson = false;
//Force every value to be a string instead of the default bool/int/float/etc.
var forceStringJson = false;
//JSON Advanced Options
//Export the spreadsheet's contents as a JSON array, instead of a regular JSON object
var exportContentsAsArrayJson = false;
//Export cell contents as a JSON object if the cell is wrapped with {}
var exportCellObjectJson = false;
//Export sheets as 2D JSON arrays
var export2dArrayJson = false;
//Separator char for JSON arrays
var arraySeparatorCharJson = ",";
//Sheets or columns using keys starting with a specified string will always be exported as JSON arrays
var forceArrayJson = false;
var forceArrayPrefixJson = "JA_";
//Sheets using the specified prefix will always be exported as nested arrays
var forceArrayNest = false;
var forceArrayPrefixNest = "NAR_";
var exportType = "jsonFormat";
var exportSheets = "allSheets";
var targetSheets = { };
var sheets = new Array();
//Get the properties for the sheet to automatically set values based on the user's last export for this document.
function getProperties(onSuccess)
{
return google.script.run.withSuccessHandler(onSuccess).getExportProperties();
}
//Saves the properties for the user's last export for this document so they are automatically set the next time the document opens..
function setProperties()
{
return google.script.run.setExportProperties(generateProperties());
}
//Actually sets the local properties based on stored settings.
function updateProperties(properties)
{
var settings;
if(properties == null || properties === "")
{
settings = {};
}
else
{
settings = JSON.parse(properties);
}
//General
exportType = settings["exportType"] != null ? settings["exportType"] : exportType;
exportSheets = settings["exportSheets"] != null ? (settings["exportSheets"] === "" ? exportSheets : settings["exportSheets"]) : exportSheets;
targetSheets = settings["targetSheets"] != null ? (settings["targetSheets"] === "" ? targetSheets : JSON.parse(settings["targetSheets"])) : targetSheets;
replaceExistingFiles = settings["replaceExistingFiles"] != null ? settings["replaceExistingFiles"] === true : false;
unwrapSingleRows = settings["unwrapSingleRows"] != null ? settings["unwrapSingleRows"] === true : false;
collapseSingleRows = settings["collapseSingleRows"] != null ? settings["collapseSingleRows"] === true : false;
ignoreEmptyCells = settings["ignoreEmptyCells"] != null ? settings["ignoreEmptyCells"] === true : false;
//Advanced
nestedElements = settings["nestedElements"] != null ? settings["nestedElements"] === true : false;
minifyData = settings["minifyData"] != null ? settings["minifyData"] === true : minifyData;
ignoreColumnsWithPrefix = settings["ignoreColumnsWithPrefix"] != null ? settings["ignoreColumnsWithPrefix"] === true : false;
ignoreColumnsPrefix = settings["ignorePrefix"] != null ? (settings["ignorePrefix"] === "" ? IGNORE_COLUMN_DEFAULT : settings["ignorePrefix"]) : IGNORE_COLUMN_DEFAULT;
unwrapSheetsWithPrefix = settings["unwrapSheetsWithPrefix"] != null ? settings["unwrapSheetsWithPrefix"] === true : false;
unwrapSheetsPrefix = settings["unwrapPrefix"] != null ? (settings["unwrapPrefix"] === "" ? UNWRAP_SHEETS_DEFAULT : settings["unwrapPrefix"]) : UNWRAP_SHEETS_DEFAULT;
collapseSheetsWithPrefix = settings["collapseSheetsWithPrefix"] != null ? settings["collapseSheetsWithPrefix"] === true : false;
collapseSheetsPrefix = settings["collapsePrefix"] != null ? (settings["collapsePrefix"] === "" ? COLLAPSE_SHEET_DEFAULT : settings["collapsePrefix"]) : COLLAPSE_SHEET_DEFAULT;
//JSON
exportContentsAsArrayJson = settings["exportContentsAsArray"] != null ? settings["exportContentsAsArray"] === true : exportContentsAsArrayJson;
exportCellObjectJson = settings["exportCellObject"] != null ? settings["exportCellObject"] === true : exportCellObjectJson;
exportCellArrayJson = settings["exportCellArray"] != null ? settings["exportCellArray"] === true : exportCellArrayJson;
exportSheetArrayJson = settings["exportSheetArray"] != null ? settings["exportSheetArray"] === true : exportSheetArrayJson;
exportValueArrayJson = settings["exportValueArray"] != null ? settings["exportValueArray"] === true : exportValueArrayJson;
forceStringJson = settings["forceString"] != null ? settings["forceString"] === true : forceStringJson;
arraySeparatorCharJson = settings["separatorChar"] != null ? (settings["separatorChar"] === "" ? "," : settings["separatorChar"]) : JSON_SEPARATOR_DEFAULT;
forceArrayJson = settings["forceArray"] != null ? settings["forceArray"] === true : forceArrayJson;
forceArrayPrefixJson = settings["forceArrayPrefix"] != null ? (settings["forceArrayPrefix"] === "" ? JSON_JA_DEFAULT : settings["forceArrayPrefix"]) : JSON_JA_DEFAULT;
forceArrayNest = settings["forceArrayNest"] != null ? settings["forceArrayNest"] === true : forceArrayNest;
forceArrayPrefixNest = settings["forceArrayPrefixNest"] != null ? (settings["forceArrayPrefixNest"] === "" ? NEST_NA_DEFAULT : settings["forceArrayPrefixNest"]) : NEST_NA_DEFAULT;
//XML
exportChildElementXml = settings["exportChildElements"] != null ? settings["exportChildElements"] === true : exportChildElementXml;
includeFirstColumnXml = settings["includeFirstColumn"] != null ? settings["includeFirstColumn"] === true : includeFirstColumnXml;
rootElementXml = settings["rootElement"] != null ? (settings["rootElement"] === "" ? rootElementXml : settings["rootElement"]) : rootElementXml;
nameReplacementCharXml = settings["nameReplacementChar"] != null ? (settings["nameReplacementChar"] === "" ? nameReplacementCharXml : settings["nameReplacementChar"]) : nameReplacementCharXml;
includeDeclarationXml = settings["includeDeclaration"] != null ? settings["includeDeclaration"] === true : includeDeclarationXml;
declarationVersionXml = settings["declarationVersion"] != null ? (settings["declarationVersion"] === "" ? declarationVersionXml : settings["declarationVersion"]) : declarationVersionXml;
declarationEncodingXml = settings["declarationEncoding"] != null ? (settings["declarationEncoding"] === "" ? declarationEncodingXml : settings["declarationEncoding"]) : declarationEncodingXml;
declarationStandaloneXml = settings["declarationStandalone"] != null ? (settings["declarationStandalone"] === "" ? declarationStandaloneXml : settings["declarationStandalone"]) : declarationStandaloneXml;
forceAttributesXml = settings["forceAttributes"] != null ? settings["forceAttributes"] === true : forceAttributesXml;
forceAttributesPrefixXml = settings["attributePrefix"] != null ? (settings["attributePrefix"] === "" ? forceAttributesPrefixXml : settings["attributePrefix"]) : forceAttributesPrefixXml;
forceChildElementsXml = settings["forceChildElements"] != null ? settings["forceChildElements"] === true : forceChildElementsXml;
forceChildElementsPrefixXml = settings["childElementPrefix"] != null ? (settings["childElementPrefix"] === "" ? forceChildElementsPrefixXml : settings["childElementPrefix"]) : forceChildElementsPrefixXml;
forceInnerTextXml = settings["forceInnerText"] != null ? settings["forceInnerText"] === true : forceInnerTextXml;
forceInnerTextPrefixXml = settings["innerTextPrefix"] != null ? (settings["innerTextPrefix"] === "" ? forceInnerTextPrefixXml : settings["innerTextPrefix"]) : forceInnerTextPrefixXml;
refreshSideBar();
}
//Generate the JSON blob representation of the document's settings.
function generateProperties()
{
var properties = {
//General settings
"exportType" : exportType,
"exportSheets" : exportSheets,
"targetSheets" : JSON.stringify(targetSheets),
"replaceExistingFiles" : replaceExistingFiles,
"unwrapSingleRows" : unwrapSingleRows,
"collapseSingleRows" : collapseSingleRows,
"ignoreEmptyCells" : ignoreEmptyCells,
//Advanced
"ignoreColumnsWithPrefix" : ignoreColumnsWithPrefix,
"minifyData" : minifyData,
"ignorePrefix" : (ignoreColumnsPrefix === "" ? IGNORE_COLUMN_DEFAULT : ignoreColumnsPrefix),
"unwrapSheetsWithPrefix" : unwrapSheetsWithPrefix,
"unwrapPrefix" : (unwrapSheetsPrefix === "" ? UNWRAP_SHEETS_DEFAULT : unwrapSheetsPrefix),
"collapseSheetsWithPrefix" : collapseSheetsWithPrefix,
"collapsePrefix" : (collapseSheetsPrefix === "" ? COLLAPSE_SHEET_DEFAULT : collapseSheetsPrefix),
//Nested Elements
"nestedElements" : nestedElements,
"forceArrayNest" : forceArrayNest,
"forceArrayPrefixNest" : (forceArrayPrefixNest === "" ? NEST_NA_DEFAULT : forceArrayPrefixNest),
//JSON
"exportContentsAsArray" : exportContentsAsArrayJson,
"exportCellObject" : exportCellObjectJson,
"exportCellArray" : exportCellArrayJson,
"exportSheetArray" : exportSheetArrayJson,
"exportValueArray" : exportValueArrayJson,
"forceString" : forceStringJson,
"separatorChar" : getSeparatorCharJson(),
"forceArray" : forceArrayJson,
"forceArrayPrefix" : (forceArrayPrefixJson === "" ? JSON_JA_DEFAULT : forceArrayPrefixJson),
//XML
"exportChildElements" : exportChildElementXml,
"includeFirstColumn" : includeFirstColumnXml,
"rootElement" : getRootElement(),
"nameReplacementChar" : nameReplacementCharXml,
"includeDeclaration" : includeDeclarationXml,
"declarationVersion" : declarationVersionXml,
"declarationEncoding" : declarationEncodingXml,
"declarationStandalone" : declarationStandaloneXml,
"forceAttributes" : forceAttributesXml,
"attributePrefix" : (forceAttributesPrefixXml === "" ? XML_ATT_DEFAULT : forceAttributesPrefixXml),
"forceChildElements" : forceChildElementsXml,
"childElementPrefix" : (forceChildElementsPrefixXml === "" ? XML_CE_DEFAULT : forceChildElementsPrefixXml),
"forceInnerText" : forceInnerTextXml,
"innerTextPrefix" : (forceInnerTextPrefixXml === "" ? XML_IT_DEFAULT : forceInnerTextPrefixXml)
};
return JSON.stringify(properties);
}
//Get the names of all sheets in the current document
function getNames(onSuccess)
{
return google.script.run.withSuccessHandler(onSuccess).getSheetNames();
}
//Get the name of the active sheet in the current document
function getActiveName(onSuccess)
{
return google.script.run.withSuccessHandler(onSuccess).getActiveSheetName();
}
//Checks if all the sheets are selected for export
function checkAllTogglesTrue()
{
for(var i=0; i < sheets.length; i++)
{
if(targetSheets[sheets[i]] === 'false') return false;
}
return true;
}
//General Options
function toggleReplace()
{
replaceExistingFiles = !replaceExistingFiles;
}
function toggleUnwrapSingleRows()
{
unwrapSingleRows = !unwrapSingleRows;
}
function toggleCollapseSingleRows()
{
collapseSingleRows = !collapseSingleRows;
}
function toggleIgnoreEmptyCells()
{
ignoreEmptyCells = !ignoreEmptyCells;
}
function toggleNestedElements()
{
nestedElements = !nestedElements;
//TODO: Should disable JSON/XML specific nested element fields when toggling.
}
function toggleMinifyData()
{
minifyData = !minifyData;
}
function getIgnorePrefix()
{
if(ignoreColumnsWithPrefix === false) return "";
return ignoreColumnsPrefix === "" ? IGNORE_COLUMN_DEFAULT : ignoreColumnsPrefix;
}
function updateIgnorePrefix()
{
ignoreColumnsPrefix = document.getElementById("ignoreColumnsPrefixTextField").value;
}
function toggleIgnoreColumnsWithPrefix()
{
ignoreColumnsWithPrefix = !ignoreColumnsWithPrefix;
var text = "<input id='ignoreColumnsPrefixTextField' type='text' value=";
text += "'" + ignoreColumnsPrefix + "'";
text += " placeholder='" + IGNORE_COLUMN_DEFAULT + "'";
if(ignoreColumnsWithPrefix === false) text += " disabled";
text += "/>";
document.getElementById("ignoreColumnsText").innerHTML = text;
if(ignoreColumnsWithPrefix === true) document.getElementById('ignoreColumnsPrefixTextField').addEventListener("change", updateIgnorePrefix);
}
function getUnwrapPrefix()
{
if(unwrapSheetsWithPrefix === false) return "";
return unwrapSheetsPrefix === "" ? UNWRAP_SHEETS_DEFAULT : unwrapSheetsPrefix;
}
function updateUnwrapPrefix()
{
unwrapSheetsPrefix = document.getElementById("unwrapSheetsPrefixTextField").value;
}
function toggleUnwrapSheetsWithPrefix()
{
unwrapSheetsWithPrefix = !unwrapSheetsWithPrefix;
var text = "<input id='unwrapSheetsPrefixTextField' type='text' value=";
text += "'" + unwrapSheetsPrefix + "'";
text += " placeholder='" + UNWRAP_SHEETS_DEFAULT + "'";
if(unwrapSheetsWithPrefix === false) text += " disabled";
text += "/>";
document.getElementById("unwrapSheetsText").innerHTML = text;
if(unwrapSheetsWithPrefix === true) document.getElementById('unwrapSheetsPrefixTextField').addEventListener("change", updateUnwrapPrefix);
}
function getCollapsePrefix()
{
if(collapseSheetsWithPrefix === false) return "";
return collapseSheetsPrefix === "" ? COLLAPSE_SHEET_DEFAULT : collapseSheetsPrefix;
}
function updateCollapsePrefix()
{
collapseSheetsPrefix = document.getElementById("collapseSheetsPrefixTextField").value;
}
function toggleCollapseSheetsWithPrefix()
{
collapseSheetsWithPrefix = !collapseSheetsWithPrefix;
var text = "<input id='collapseSheetsPrefixTextField' type='text' value=";
text += "'" + collapseSheetsPrefix + "'";
text += " placeholder='" + COLLAPSE_SHEET_DEFAULT + "'";
if(collapseSheetsWithPrefix === false) text += " disabled";
text += "/>";
document.getElementById("collapseSheetsText").innerHTML = text;
if(collapseSheetsWithPrefix === true) document.getElementById('collapseSheetsPrefixTextField').addEventListener("change", updateCollapsePrefix);
}
//XML Options
function toggleElement()
{
exportChildElementXml = !exportChildElementXml;
}
function toggleIncludeFirstColumnXml()
{
includeFirstColumnXml = !includeFirstColumnXml;
}
function getRootElement()
{
return rootElementXml === "" ? XML_ROOT_DEFAULT : rootElementXml;
}
function getDeclarationVersion()
{
if(includeDeclarationXml === false) return "";
return declarationVersionXml;
}
function getDeclarationEncoding()
{
if(includeDeclarationXml === false) return "";
return declarationEncodingXml === "none" ? "" : declarationEncodingXml;
}
function getDeclarationStandalone()
{
if(includeDeclarationXml === false) return "";
return declarationStandaloneXml === "none" ? "" : declarationStandaloneXml;
}
function getAttributePrefix()
{
if(forceAttributesXml === false) return "";
return forceAttributesPrefixXml === "" ? XML_ATT_DEFAULT : forceAttributesPrefixXml;
}
function getChildElementPrefix()
{
if(forceChildElementsXml === false) return "";
return forceChildElementsPrefixXml === "" ? XML_CE_DEFAULT : forceChildElementsPrefixXml;
}
function getInnerTextPrefix()
{
if(forceInnerTextXml === false) return "";
return forceInnerTextPrefixXml === "" ? XML_IT_DEFAULT : forceInnerTextPrefixXml;
}
function updateRootElementXml()
{
rootElementXml = document.getElementById("xmlRootField").value;
}
function updateAttributePrefixXml()
{
forceAttributesPrefixXml = document.getElementById("xmlForceAttributesTextField").value;
}
function updateChildElementPrefixXml()
{
forceChildElementsPrefixXml = document.getElementById("xmlForceChildElementsTextField").value;
}
function updateInnerTextPrefixXml()
{
forceInnerTextPrefixXml = document.getElementById("xmlForceInnerTextTextField").value;
}
//Changes replacement char used in XML elements with illegal characters
function changeNameReplacementCharXml()
{
nameReplacementCharXml = document.getElementById("xmlNameReplaceCharDropdown").value;
}
function toggleIncludeDeclarationXml()
{
includeDeclarationXml = !includeDeclarationXml;
if(document.getElementById('xmlIncludeDeclarationToggle') != null)
{
document.getElementById('xmlDeclarationVersionDropdown').removeEventListener("change", changeDeclarationVersionXml);
document.getElementById('xmlDeclarationEncodingDropdown').removeEventListener("change", changeDeclarationEncodingXml);
document.getElementById('xmlDeclarationStandaloneDropdown').removeEventListener("change", changeDeclarationStandaloneXml);
}
var advancedXmlText = "";
//Declaration Version
advancedXmlText += "<div class='sectionWrapper'><div class='option'><label for='select'>XML version</label><div class='tooltip note'>Version of the XML standard that the XML document conforms to.</div></div><select class='dropdown' id='xmlDeclarationVersionDropdown' onchange='changeDeclarationVersionXml()'";
if(includeDeclarationXml === false) advancedXmlText += " disabled";
advancedXmlText += "><option value='1.0'";
if(declarationVersionXml === "1.0") advancedXmlText += " selected";
advancedXmlText += ">1.0</option><option value='1.1'";
if(declarationVersionXml === "1.1") advancedXmlText += " selected";
advancedXmlText += ">1.1</option></select></div>";
//Declaration Encoding
advancedXmlText += "<div class='sectionWrapper'><div class='option'><label for='select'>XML encoding</label><div class='tooltip note'>Identifies which encoding is used to represent the characters in the document.</div></div><select class='dropdown' id='xmlDeclarationEncodingDropdown' onchange='changeDeclarationEncodingXml()'";
if(includeDeclarationXml === false) advancedXmlText += " disabled";
advancedXmlText += "><option value='none'";
if(declarationEncodingXml === "none") advancedXmlText += " selected";
advancedXmlText += ">None</option><option value='UTF-8'";
if(declarationEncodingXml === "UTF-8") advancedXmlText += " selected";
advancedXmlText += ">UTF-8</option><option value='UTF-16'";
if(declarationEncodingXml === "UTF-16") advancedXmlText += " selected";
advancedXmlText += ">UTF-16</option><option value='ISO-10646-UCS-2'";
if(declarationEncodingXml === "ISO-10646-UCS-2") advancedXmlText += " selected";
advancedXmlText += ">ISO-10646-UCS-2</option><option value='ISO-10646-UCS-4'";
if(declarationEncodingXml === "ISO-10646-UCS-4") advancedXmlText += " selected";
advancedXmlText += ">ISO-10646-UCS-4</option><option value='ISO-8859-1'";
if(declarationEncodingXml === "ISO-8859-1") advancedXmlText += " selected";
advancedXmlText += ">ISO-8859-1</option><option value='ISO-8859-2'";
if(declarationEncodingXml === "ISO-8859-2") advancedXmlText += " selected";
advancedXmlText += ">ISO-8859-2</option><option value='ISO-8859-3'";
if(declarationEncodingXml === "ISO-8859-3") advancedXmlText += " selected";
advancedXmlText += ">ISO-8859-3</option><option value='ISO-8859-4'";
if(declarationEncodingXml === "ISO-8859-4") advancedXmlText += " selected";
advancedXmlText += ">ISO-8859-4</option><option value='ISO-8859-5'";
if(declarationEncodingXml === "ISO-8859-5") advancedXmlText += " selected";
advancedXmlText += ">ISO-8859-5</option><option value='ISO-8859-6'";
if(declarationEncodingXml === "ISO-8859-6") advancedXmlText += " selected";
advancedXmlText += ">ISO-8859-6</option><option value='ISO-8859-7'";
if(declarationEncodingXml === "ISO-8859-7") advancedXmlText += " selected";
advancedXmlText += ">ISO-8859-7</option><option value='ISO-8859-8'";
if(declarationEncodingXml === "ISO-8859-8") advancedXmlText += " selected";
advancedXmlText += ">ISO-8859-8</option><option value='ISO-8859-9'";
if(declarationEncodingXml === "ISO-8859-9") advancedXmlText += " selected";
advancedXmlText += ">ISO-8859-9</option><option value='ISO-2022-JP'";
if(declarationEncodingXml === "ISO-2022-JP") advancedXmlText += " selected";
advancedXmlText += ">ISO-2022-JP</option><option value='Shift_JIS'";
if(declarationEncodingXml === "Shift_JIS") advancedXmlText += " selected";
advancedXmlText += ">Shift_JIS</option><option value='EUC-JP'";
if(declarationEncodingXml === "EUC-JP") advancedXmlText += " selected";
advancedXmlText += ">EUC-JP</option></select></div>";
//Declaration Standalone
advancedXmlText += "<div class='sectionWrapper'><div class='option'><label for='select'>Standalone</label><div class='tooltip note'>Indicates whether a document relies on information from an external source, such as external document type definition (DTD).</div></div><select class='dropdown' id='xmlDeclarationStandaloneDropdown' onchange='changeDeclarationStandaloneXml()'";
if(includeDeclarationXml === false) advancedXmlText += " disabled";
advancedXmlText += "><option value='none'";
if(declarationStandaloneXml === "none") advancedXmlText += " selected";
advancedXmlText += ">None</option><option value='yes'";
if(declarationStandaloneXml === "yes") advancedXmlText += " selected";
advancedXmlText += ">Yes</option><option value='no'";
if(declarationStandaloneXml === "no") advancedXmlText += " selected";
advancedXmlText += ">No</option></select></div>";
document.getElementById("xmlDeclarationSection").innerHTML = advancedXmlText;
if(includeDeclarationXml === true)
{
document.getElementById('xmlDeclarationVersionDropdown').addEventListener("change", changeDeclarationVersionXml);
document.getElementById('xmlDeclarationEncodingDropdown').addEventListener("change", changeDeclarationEncodingXml);
document.getElementById('xmlDeclarationStandaloneDropdown').addEventListener("change", changeDeclarationStandaloneXml);
}
}
function changeDeclarationVersionXml()
{
declarationVersionXml = document.getElementById("xmlDeclarationVersionDropdown").value;
}
function changeDeclarationEncodingXml()
{
declarationEncodingXml = document.getElementById("xmlDeclarationEncodingDropdown").value;
}
function changeDeclarationStandaloneXml()
{
declarationStandaloneXml = document.getElementById("xmlDeclarationStandaloneDropdown").value;
}
function toggleAttributePrefixXml()
{
forceAttributesXml = !forceAttributesXml;
var text = "<input id='xmlForceAttributesTextField' type='text' value=";
text += "'" + forceAttributesPrefixXml + "'";
text += " placeholder='" + XML_ATT_DEFAULT + "'";
if(forceAttributesXml === false) text += " disabled";
text += "/>";
document.getElementById("xmlForceAttributeText").innerHTML = text;
if(forceAttributesXml === true) document.getElementById('xmlForceAttributesTextField').addEventListener("change", updateAttributePrefixXml);
}
function toggleChildElementPrefixXml()
{
forceChildElementsXml = !forceChildElementsXml;
var text = "<input id='xmlForceChildElementsTextField' type='text' value=";
text += "'" + forceChildElementsPrefixXml + "'";
text += " placeholder='" + XML_CE_DEFAULT + "'";
if(forceChildElementsXml === false) text += " disabled";
text += "/>";
document.getElementById("xmlForceChildElementsText").innerHTML = text;
if(forceChildElementsXml === true) document.getElementById('xmlForceChildElementsTextField').addEventListener("change", updateChildElementPrefixXml);
}
function toggleInnerTextPrefixXml()
{
forceInnerTextXml = !forceInnerTextXml;
var text = "<input id='xmlForceInnerTextTextField' type='text' value=";
text += "'" + forceInnerTextPrefixXml + "'";
text += " placeholder='" + XML_IT_DEFAULT + "'";
if(forceInnerTextXml === false) text += " disabled";
text += "/>";
document.getElementById("xmlForceInnerTextText").innerHTML = text;
if(forceInnerTextXml === true) document.getElementById('xmlForceInnerTextTextField').addEventListener("change", updateInnerTextPrefixXml);
}
//JSON Options
function toggleContentArrayJson()
{
exportContentsAsArrayJson = !exportContentsAsArrayJson;
}
function toggleCellObjectJson()
{
exportCellObjectJson = !exportCellObjectJson;
}
function toggleArrayJson()
{
exportCellArrayJson = !exportCellArrayJson;
}
function toggleSheetArrayJson()
{
exportSheetArrayJson = !exportSheetArrayJson;
}
function toggleValueArrayJson()
{
exportValueArrayJson = !exportValueArrayJson;
}
function toggleForceStringJson()
{
forceStringJson = !forceStringJson;
}
function getSeparatorCharJson()
{
return (arraySeparatorCharJson === "" || arraySeparatorCharJson === "'" || arraySeparatorCharJson === '"') ? JSON_SEPARATOR_DEFAULT : arraySeparatorCharJson;
}
function getForceArrayPrefixJson()
{
if(forceArrayJson === false) return "";
return forceArrayPrefixJson === "" ? JSON_JA_DEFAULT : forceArrayPrefixJson;
}
function updateSeparatorCharJson()
{
arraySeparatorCharJson = document.getElementById("jsonArraySeparatorCharTextField").value;
}
function toggleArrayPrefixJson()
{
forceArrayJson = !forceArrayJson;
var text = "<input id='jsonForceArrayTextField' type='text' value=";
text += "'" + forceArrayPrefixJson + "'";
text += " placeholder='" + JSON_JA_DEFAULT + "'";
if(forceArrayJson === false) text += " disabled";
text += "/>";
document.getElementById("jsonForceArrayText").innerHTML = text;
if(forceArrayJson === true) document.getElementById('jsonForceArrayTextField').addEventListener("change", updateArrayPrefixJson);
}
function updateArrayPrefixJson()
{
forceArrayPrefixJson = document.getElementById("jsonForceArrayTextField").value;
}
//Nested Elements options
function toggleArrayPrefixNest()
{
forceArrayNest = !forceArrayNest;
var text = "<input id='nestForceArrayTextField' type='text' value=";
text += "'" + forceArrayPrefixNest + "'";
text += " placeholder='" + NEST_NA_DEFAULT + "'";
if(forceArrayNest === false) text += " disabled";
text += "/>";
document.getElementById("nestForceArrayText").innerHTML = text;
if(forceArrayNest === true) document.getElementById('nestForceArrayTextField').addEventListener("change", updateArrayPrefixNest);
}
function updateArrayPrefixNest()
{
forceArrayPrefixNest = document.getElementById("nestForceArrayTextField").value;
}
function getForceArrayPrefixNest()
{
if(forceArrayNest === false) return "";
return forceArrayPrefixNest === "" ? NEST_NA_DEFAULT : forceArrayPrefixNest;
}
//Toggles value for exporting all sheets
function toggleAllSheets()
{
var value = document.getElementById('allSheetsToggle').value;
if(value === 'false') generateSheetToggles(sheets, true);
else generateSheetToggles(sheets, false);
}
//Updates the toggle for all sheets so that it is only checked when all sheets are set for export
function updateAllSheetsToggle()
{
var value = checkAllTogglesTrue();
if(value === true)
{
document.getElementById('allToggleContainer').innerHTML = "<input id='allSheetsToggle' type='checkbox' value='true' onChange='toggleAllSheets()' checked /> All";
}
else
{
document.getElementById('allToggleContainer').innerHTML = "<input id='allSheetsToggle' type='checkbox' value='false' onChange='toggleAllSheets()' /> All";
}
}
//Sets all sheets to be exported
function selectAllSheets()
{
generateSheetToggles(sheets, true);
}
//Sets no sheets to be exported
function selectNoneSheets()
{
generateSheetToggles(sheets, false);
}
//Toggles a sheet for export
function toggleSheet(sheetName)
{
var value = document.getElementById(formatSheetName(sheetName) + 'Toggle').value;
if(value === 'false') value = 'true';
else value = 'false';
targetSheets[sheetName] = value;
document.getElementById(formatSheetName(sheetName) + 'Toggle').value = value;
updateAllSheetsToggle();
}
//Function to rebuild the sidebar after loading export parameters
function refreshSideBar()
{
removeGeneralListeners();
var generalText = "<div class='accordion active'><h1>Format</h1></div></div><div class='accordionPanel'>";
//Export Settings
//Format
generalText += "<p><div class='block form-group sectionWrapper'><div class='option'><label for='select'><b>Select Format</b></label></div><select class='dropdown' id='formatSelect'><option value='jsonFormat'";
if(exportType === "jsonFormat") generalText += " selected";
generalText += ">JSON</option><option value='xmlFormat'";
if(exportType !== "jsonFormat") generalText += " selected";
generalText += ">XML</option></select></p>";
//Sheets
generalText += "<p><div class='option'><label for='select'><b>Select Sheet(s)</b></label></div><select class='dropdown' id='sheetSelect'><option value='allSheets'";
if(exportSheets === "allSheets") generalText += " selected";
generalText += ">All sheets</option><option value='currentSheet'";
if(exportSheets === "currentSheet") generalText += " selected";
generalText += ">Current sheet only</option><option value='custom'";
if(exportSheets === "custom") generalText += " selected";
generalText += ">Custom</option></select></p>";
//Custom Sheets
generalText += "<div id='customSheetSelect'></div></div></div>"; //Sheet selection is filled automatically at end of refresh process.
//General Options
generalText += "<div class='accordion active'><h1>General</h1></div><div class='accordionPanel'>";
//Replace existing files
generalText += "<div class='sectionWrapper'><input id='replaceToggle' type='checkbox' value='Replace'";
if(replaceExistingFiles) generalText += " checked";
generalText += "/><div class='option'>Replace existing file(s)<div class='tooltip note'>Trash files in the export folder with the same name and extension as the exported file.</div></div></div>";
//Unwrap Single Rows
generalText += "<div class='sectionWrapper'><input id='unwrapSingleRowToggle' type='checkbox' value='false'";
if(unwrapSingleRows) generalText += " checked";
generalText += "/><div class='option'>Unwrap single row sheets<div class='tooltip note'>Don't wrap a sheet's contents with a JSON object / XML element if it contains only one row. (not counting keys)</div></div></div>";
//Collapse Single Rows
generalText += "<div class='sectionWrapper'><input id='collapseSingleRowToggle' type='checkbox' value='false'";
if(collapseSingleRows) generalText += " checked";
generalText += "/><div class='option'>Collapse single row sheets<div class='tooltip note'>Collapse a sheet's contents into a JSON object / XML element if it contains only one row. (not counting keys)</div></div></div>";
//Ignore empty cells
generalText += "<div class='sectionWrapper'><input id='ignoreEmptyCellsToggle' type='checkbox' value='false'";
if(ignoreEmptyCells) generalText += " checked";
generalText += "/><div class='option'>Ignore empty cells<div class='tooltip note'>Don't export cells that are empty.</div></div></div>";
generalText += "</div>";
//Advanced General Options
generalText += "<div class='accordion active'><h1>Advanced</h1></div><div class='accordionPanel'>";
//Nested Elements
generalText += "<div class='sectionWrapper'><input id='nestedElementsToggle' type='checkbox' value='false'";
if(nestedElements) generalText += " checked";
if(exportType != "jsonFormat") generalText += " disabled";
generalText += "/><div class='option'>Nested Elements<div class='tooltip note'>Export nested elements by using specific formatting in keys.";
if(exportType != "jsonFormat") generalText += " XML support in development!";
generalText += "</div></div></div>";
//Minify Data
generalText += "<div class='sectionWrapper'><input id='minifyDataToggle' type='checkbox' value='minifyData'";
if(minifyData) generalText += " checked";
generalText += "><div class='option'>Minify data<div class='tooltip note'>Remove human readability formatting from the exported data to produce a smaller file.</div></div></div>";
//Ignore columns prefix
generalText += "<div class='sectionWrapper'><input id='ignoreColumnsToggle' type='checkbox' value='false'";
if(ignoreColumnsWithPrefix) generalText += " checked";
generalText += "/><div class='option'>Ignore prefix<div class='tooltip note'>Don't export columns with keys using the specified prefix, or rows whose first value starts with the specified prefix.</div></div><p id='ignoreColumnsText'><input id='ignoreColumnsPrefixTextField' type='text' value='";
generalText += ignoreColumnsPrefix === "" ? IGNORE_COLUMN_DEFAULT : ignoreColumnsPrefix;
generalText += "' placeholder='NOEX_'";
if(ignoreColumnsWithPrefix === false) generalText += " disabled";
generalText += "/></p><p class='note'></p></div>";
//Unwrap sheets prefix
generalText += "<div class='sectionWrapper'><input id='unwrapSheetsToggle' type='checkbox' value='false'";
if(unwrapSheetsWithPrefix) generalText += " checked";
generalText += "/><div class='option'>Unwrap sheet prefix<div class='tooltip note'>Unwrap sheets with only one row that use the given prefix.</div></div><p id='unwrapSheetsText'><input id='unwrapSheetsPrefixTextField' type='text' value='";
generalText += unwrapSheetsPrefix === "" ? UNWRAP_SHEETS_DEFAULT : unwrapSheetsPrefix;
generalText += "' placeholder='US_'";
if(unwrapSheetsWithPrefix === false) generalText += " disabled";
generalText += "/></p><p class='note'></p></div>";