-
Notifications
You must be signed in to change notification settings - Fork 0
/
fill_out_form.html
1203 lines (1069 loc) · 47.9 KB
/
fill_out_form.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
<!DOCTYPE html>
<!--
A quick-and-dirty HTML5 form for filling in Schedule 3 metadata and
exporting to the RIF-CS compliant XML data form.
Code author: Russell A. Edson, Biometry Hub
Date last modified: 09/05/2022
-->
<html>
<head>
<title>Schedule 3 Metadata Form</title>
<meta name="description" content="Form for filling out Sch.3 metadata.">
<meta name="author" content="Biometry Hub">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<style>
div { padding-top: 8px; padding-bottom: 8px; }
textarea { overflow-y: scroll; height: 100px; width: 100%; }
#dataset_name { width: 100%; }
#dataset_contracttitle { width: 100%; }
#dataset_contractcode { width: 100%; }
#dataset_location { width: 100%; }
#dataset_subject { width: 100%; }
#dataset_organisation { width: 100%; }
#dataset_saginode { width: 100%; }
#dataset_treatments { width: 100%; }
#dataset_variables { width: 100%; }
#dataset_design { width: 100%; }
#dataset_files { width: 100%; }
#dataset_rights { width: 100%; }
#dataset_datefrom { width: 100%; }
#dataset_dateto { width: 100%; }
#dataset_datetext { width: 100%; }
#xml_export_filename {width: 50%; }
</style>
</head>
<body>
<h1>Schedule 3 Metadata Form</h1>
<!-- XML import functionality (for checking) -->
<div>
<p>
(Optionally) upload an existing XML file to check:
</p>
<input type="file" id="xml_import">
</div>
<!-- Name of the dataset -->
<div>
<label for="dataset_name">Dataset Name:</label>
<input type="text" id="dataset_name">
</div>
<!-- Project details -->
<div>
<h3>
GRDC project details (i.e. the project that generated this dataset)
</h3>
<!-- GRDC contract title -->
<div>
<label for="dataset_contracttitle">GRDC contract title:</label>
<input type="text" id="dataset_contracttitle">
</div>
<!-- GRDC project code -->
<div>
<label for="dataset_contractcode">GRDC contract code:</label>
<input type="text" id="dataset_contractcode">
</div>
<!-- Location email address -->
<div>
<label for="dataset_location">Project point-of-contact email:</label>
<input type="text" id="dataset_location">
</div>
<!-- Keywords -->
<div>
<label for="dataset_subject">Subject keywords:</label>
<input type="text" id="dataset_subject">
</div>
<!-- Parties -->
<div>
<h4>Parties involved in the project</h4>
<!-- Research organisation -->
<div>
<label for="dataset_organisation">
(Primary) Research organisation / Project Partner:
</label>
<input type="text" id="dataset_organisation">
</div>
<!-- SAGI node -->
<div>
<label for="dataset_saginode">SAGI node:</label>
<input type="text" id="dataset_saginode">
</div>
<!-- Additional parties -->
<div>
<p>
Add details for as many organisational or individual parties
as you like:
</p>
<div id="dataset_party"></div>
<input type="button" id="add_party" value="Add new party">
</div>
</div>
</div>
<!-- Description -->
<div>
<h3>Dataset description (plain-text)</h3>
<!-- General information -->
<div>
<label for="dataset_geninfo">
General information about the dataset (where available):
</label>
<textarea id="dataset_geninfo"></textarea>
</div>
<!-- Treatment factors -->
<div>
<label for="dataset_treatments">
Treatment factors (delimited by commas):
</label>
<input type="text" id="dataset_treatments">
</div>
<!-- Observed variables -->
<div>
<label for="dataset_variables">
Observed variables (delimited by commas):
</label>
<input type="text" id="dataset_variables">
</div>
<div>
<label for="dataset_design">
Experimental design elements (delimited by commas):
</label>
<input type="text" id="dataset_design">
</div>
<div>
<label for="dataset_files">
Files associated with this dataset (delimited by commas):
</label>
<input type="text" id="dataset_files">
</div>
</div>
<!-- Rights (auto-filled, shouldn't need to change) -->
<div>
<label for="dataset_rights">
Dataset rights (modify if necessary):
</label>
<input type="text" id="dataset_rights"
value="By agreement from GRDC and dataset co-owners">
</div>
<!-- Coverage -->
<div>
<h3>Dataset coverage (temporal/spatial)</h3>
<!-- Temporal coverage -->
<div>
<p>Temporal coverage with dates in W3CDTF format (e.g. YYYY-MM-DD):</p>
<!-- Start date (From...) -->
<label for="dataset_datefrom">Start date: </label>
<input type="text" id="dataset_datefrom">
<!-- End date (To...) -->
<label for="dataset_dateto">End date: </label>
<input type="text" id="dataset_dateto">
<!-- Otherwise, descriptive date instead -->
<label for="dataset_datetext">
(If unknown or overly vague, enter a text description here instead):
</label>
<input type="text" id="dataset_datetext">
</div>
<!-- Spatial coverage -->
<div>
<p>
Spatial coverage (in KML lat/long coordinates or plaintext names).
Add as many locations as needed:
</p>
<div id="dataset_spatial"></div>
<input type="button" id="add_spatial" value="Add new location">
</div>
</div>
<!-- Finally, click the button to export XML. -->
<div>
<p>
Done. Export to RIF-CS standard XML:
</p>
<input type="text" id="xml_export_filename" value="output.xml">
<input type="button" id="xml_export" value="Export to XML...">
</div>
</body>
<script>
/* For user-friendliness, disable the start/end date boxes if they
* have provided a text description instead. If there is anything
* in the text description box then entered dates are ignored during
* the XML export.
*/
var ignoreDates = false;
document.getElementById("dataset_datetext").addEventListener(
"input",
function (evt) {
const dateFrom = document.getElementById("dataset_datefrom");
const dateTo = document.getElementById("dataset_dateto");
const text = document.getElementById("dataset_datetext").value;
if (text.length > 0) {
ignoreDates = true;
dateFrom.setAttribute("disabled", true);
dateTo.setAttribute("disabled", true);
} else {
ignoreDates = false;
dateFrom.removeAttribute("disabled");
dateTo.removeAttribute("disabled");
}
}
);
/* Spatial location textboxes are auto-generated, and we keep track
* of the ids for the XML export.
*/
const spatialLocations = [ ];
function addSpatialLocation() {
const nextId = "dataset_spatial_" + (spatialLocations.length + 1);
spatialLocations.push(nextId);
const nextSpatial = document.createElement("input");
nextSpatial.setAttribute("type", "text");
nextSpatial.setAttribute("id", nextId);
nextSpatial.setAttribute("style", "width: 100%");
document.getElementById("dataset_spatial").appendChild(nextSpatial);
}
addSpatialLocation();
document.getElementById("add_spatial").addEventListener(
"click",
addSpatialLocation
);
/* Parties are also auto-generated, and we keep track of the ids for
* the XML export. Parties can be either organisational or
* individual, and the user can freely swap between both.
* (By default, a new Organisational-type party is created.)
*/
const parties = [ ];
function addParty() {
const nextId = "dataset_party_" + (parties.length + 1);
parties.push(nextId);
const nextParty = document.createElement("span");
nextParty.setAttribute("id", nextId);
const partyType = document.createElement("div");
const partyType1 = document.createElement("input");
partyType1.setAttribute("type", "radio");
partyType1.setAttribute("id", nextId + "_type_organisation");
partyType1.setAttribute("name", nextId + "_type");
partyType1.setAttribute("value", "Organisation");
partyType1.checked = true;
const partyType1Label = document.createElement("label");
partyType1Label.setAttribute("for", nextId + "_type_organisation");
partyType1Label.innerText = "Organisation";
const partyType2 = document.createElement("input");
partyType2.setAttribute("type", "radio");
partyType2.setAttribute("id", nextId + "_type_individual");
partyType2.setAttribute("name", nextId + "_type");
partyType2.setAttribute("value", "Individual");
const partyType2Label = document.createElement("label");
partyType2Label.setAttribute("for", nextId + "_type_individual");
partyType2Label.innerText = "Individual";
partyType.appendChild(partyType1);
partyType.appendChild(partyType1Label);
partyType.appendChild(partyType2);
partyType.appendChild(partyType2Label);
const partyOrgTitle = document.createElement("input");
partyOrgTitle.setAttribute("type", "text");
partyOrgTitle.setAttribute("id", nextId + "_org_title");
partyOrgTitle.setAttribute("style", "width: 100%");
const partyOrgTitleLabel = document.createElement("label");
partyOrgTitleLabel.setAttribute("for", nextId + "_org_title");
partyOrgTitleLabel.setAttribute("id", nextId + "_org_title_label");
partyOrgTitleLabel.innerText =
"Title (e.g. 'Research Organisation', 'Project Partner'):";
const partyOrgName = document.createElement("input");
partyOrgName.setAttribute("type", "text");
partyOrgName.setAttribute("id", nextId + "_org_name");
partyOrgName.setAttribute("style", "width: 100%; margin-bottom: 20px");
const partyOrgNameLabel = document.createElement("label");
partyOrgNameLabel.setAttribute("for", nextId + "_org_name");
partyOrgNameLabel.setAttribute("id", nextId + "_org_name_label");
partyOrgNameLabel.innerText = "Name:";
const partyIndTitle = document.createElement("input");
partyIndTitle.setAttribute("type", "text");
partyIndTitle.setAttribute("id", nextId + "_ind_title");
partyIndTitle.setAttribute("style", "width: 100%; display: none");
const partyIndTitleLabel = document.createElement("label");
partyIndTitleLabel.setAttribute("for", nextId + "_ind_title");
partyIndTitleLabel.setAttribute("id", nextId + "_ind_title_label");
partyIndTitleLabel.setAttribute("style", "display: none");
partyIndTitleLabel.innerText =
"Title (e.g.'Research Contact', 'SAGI Contact'):";
const partyIndName = document.createElement("input");
partyIndName.setAttribute("type", "text");
partyIndName.setAttribute("id", nextId + "_ind_name");
partyIndName.setAttribute("style", "width: 100%; display: none");
const partyIndNameLabel = document.createElement("label");
partyIndNameLabel.setAttribute("for", nextId + "_ind_name");
partyIndNameLabel.setAttribute("id", nextId + "_ind_name_label");
partyIndNameLabel.setAttribute("style", "display: none");
partyIndNameLabel.innerText = "Name:";
const partyIndPosition = document.createElement("input");
partyIndPosition.setAttribute("type", "text");
partyIndPosition.setAttribute("id", nextId + "_ind_position");
partyIndPosition.setAttribute("style", "width: 100%; display: none");
const partyIndPositionLabel = document.createElement("label");
partyIndPositionLabel.setAttribute("for", nextId + "_ind_position");
partyIndPositionLabel.setAttribute("id", nextId + "_ind_position_label");
partyIndPositionLabel.setAttribute("style", "display: none");
partyIndPositionLabel.innerText = "Position:";
const partyIndEmail = document.createElement("input");
partyIndEmail.setAttribute("type", "text");
partyIndEmail.setAttribute("id", nextId + "_ind_email");
partyIndEmail.setAttribute(
"style",
"width: 100%; margin-bottom: 20px; display: none"
);
const partyIndEmailLabel = document.createElement("label");
partyIndEmailLabel.setAttribute("for", nextId + "_ind_email");
partyIndEmailLabel.setAttribute("id", nextId + "_ind_email_label");
partyIndEmailLabel.setAttribute("style", "display: none");
partyIndEmailLabel.innerText = "Contact email:";
nextParty.appendChild(partyType);
nextParty.appendChild(partyOrgTitleLabel)
nextParty.appendChild(partyOrgTitle);
nextParty.appendChild(partyOrgNameLabel);
nextParty.appendChild(partyOrgName);
nextParty.appendChild(partyIndTitleLabel);
nextParty.appendChild(partyIndTitle);
nextParty.appendChild(partyIndNameLabel);
nextParty.appendChild(partyIndName);
nextParty.appendChild(partyIndPositionLabel);
nextParty.appendChild(partyIndPosition);
nextParty.appendChild(partyIndEmailLabel);
nextParty.appendChild(partyIndEmail);
/* Add an event listener for the radio buttons that lets us toggle
* between Organisation and Individual-type parties.
*/
partyType1.addEventListener(
"change",
function () { toggleParty(nextId, true) }
);
partyType2.addEventListener(
"change",
function () { toggleParty(nextId, false) }
);
document.getElementById("dataset_party").appendChild(nextParty);
}
addParty();
document.getElementById("add_party").addEventListener("click", addParty);
/* Toggle the party as an organisation or individual. */
function toggleParty(partyId, organisation) {
var orgDisplay = "";
var indDisplay = "none";
if (!organisation) {
orgDisplay = "none";
indDisplay = "";
}
document.getElementById(partyId + "_org_title")
.style.display = orgDisplay;
document.getElementById(partyId + "_org_title_label")
.style.display = orgDisplay;
document.getElementById(partyId + "_org_name")
.style.display = orgDisplay;
document.getElementById(partyId + "_org_name_label")
.style.display = orgDisplay;
document.getElementById(partyId + "_ind_title")
.style.display = indDisplay;
document.getElementById(partyId + "_ind_title_label")
.style.display = indDisplay;
document.getElementById(partyId + "_ind_name")
.style.display = indDisplay;
document.getElementById(partyId + "_ind_name_label")
.style.display = indDisplay;
document.getElementById(partyId + "_ind_position")
.style.display = indDisplay;
document.getElementById(partyId + "_ind_position_label")
.style.display = indDisplay;
document.getElementById(partyId + "_ind_email")
.style.display = indDisplay;
document.getElementById(partyId + "_ind_email_label")
.style.display = indDisplay;
}
/* For both the import and export, we set/check that the
* registryObject group and originatingSource are "Grains
* Research and Development Corporation - Statistics for the
* Australian Grains Industry 3"
*/
const grdcSagi = "Grains Research and Development Corporation" +
" - Statistics for the Australian Grains Industry 3";
/* Helper function: trim whitespace from a given string. */
function trimws(string) {
return string.replace(/[\n|\t| ]+/g, " ").replace(/^\s+|\s+$/gm, "");
}
/* An XML file can be uploaded to populate the fields in the form
* (and serve as a double-check that everything appears properly).
*/
function xmlImport(evt) {
/* Load the XML file selected by the user. */
var file = evt.target.files[0];
var reader = new FileReader();
reader.onload = (function (reader) {
return function () { xmlParse(reader.result); }
})(reader);
reader.readAsText(file);
}
/* Parse the XML, double-checking that everything exists according
* to GRDC guidelines. We explicitly step through the XML
* structure: monitor the console for any errors, which will mean
* that the XML structure does not match expectations.
*
* We also populate the HTML form fields as we go.
*/
function xmlParse(xmlString) {
const parser = new DOMParser();
const xml = parser.parseFromString(xmlString, "text/xml");
var traverse = xml;
traverse = traverse.getElementsByTagName("registryObjects")[0];
traverse = traverse.getElementsByTagName("registryObject")[0];
/* registryObject group and originatingSource should be "Grains
* Research and Development Corporation - Statistics for the
* Australian Grains Industry 3".
*/
const registryObjectGroup = traverse.attributes["group"].textContent;
traverse = traverse.getElementsByTagName("originatingSource")[0];
const originatingSource = traverse.childNodes[0].nodeValue;
traverse = traverse.parentNode;
if (registryObjectGroup != grdcSagi && originatingSource != grdcSagi) {
console.error("registryObject group or originatingSource incorrect.");
}
/* The collection type should be "dataset". */
traverse = traverse.getElementsByTagName("collection")[0];
if (traverse.attributes["type"].textContent != "dataset") {
console.error("collection type=... mismatch (should be 'dataset').");
}
/* Get the name of the dataset. */
traverse = traverse.getElementsByTagName("name")[0];
if (traverse.attributes["type"].textContent != "primary") {
console.error("name type=... mismatch (should be 'primary').");
}
traverse = traverse.getElementsByTagName("namePart")[0];
const datasetName = traverse.childNodes[0].textContent;
document.getElementById("dataset_name").value = datasetName;
traverse = traverse.parentNode.parentNode;
/* Get the location of the dataset. */
traverse = traverse.getElementsByTagName("location")[0];
traverse = traverse.getElementsByTagName("address")[0];
traverse = traverse.getElementsByTagName("electronic")[0];
if (traverse.attributes["type"].textContent != "email") {
console.error("electronic type=... mismatch (should be 'email').");
}
traverse = traverse.getElementsByTagName("value")[0];
const datasetLocation = traverse.childNodes[0].textContent;
document.getElementById("dataset_location").value = datasetLocation;
traverse = traverse.parentNode.parentNode.parentNode.parentNode;
/* Get and parse the description of the dataset. (Assume that
* everything is in the order: general description, treatments,
* variables, design elements, filenames.)
*/
traverse = traverse.getElementsByTagName("description")[0];
if (traverse.attributes["type"].textContent != "full") {
console.error("description type=... mismatch (should be 'full').");
}
const description = traverse.getElementsByTagName("p");
const datasetGeninfo = trimws(description[0].childNodes[0].textContent);
document.getElementById("dataset_geninfo").value = datasetGeninfo;
const datasetTreatments = trimws(
trimws(description[1].childNodes[0].textContent)
.match(/(?<=:).*/g)[0]
.replace(/,[ ]*/g, ",")
);
document.getElementById("dataset_treatments").value = datasetTreatments;
const datasetVariables = trimws(
trimws(description[2].childNodes[0].textContent)
.match(/(?<=:).*/g)[0]
.replace(/,[ ]*/g, ",")
);
document.getElementById("dataset_variables").value = datasetVariables;
const datasetDesign = trimws(
trimws(description[3].childNodes[0].textContent)
.match(/(?<=:).*/g)[0]
.replace(/,[ ]*/g, ",")
);
document.getElementById("dataset_design").value = datasetDesign;
const datasetFiles = trimws(
trimws(description[4].childNodes[0].textContent)
.match(/(?<=:).*/g)[0]
.replace(/,[ ]*/g, ",")
);
document.getElementById("dataset_files").value = datasetFiles;
traverse = traverse.parentNode;
/* Get the access rights for the dataset. */
traverse = traverse.getElementsByTagName("rights")[0];
if (traverse.attributes["type"].textContent != "accessRights") {
console.error("rights type=... mismatch (should be 'accessRights').");
}
traverse = traverse.getElementsByTagName("p")[0];
const datasetRights = traverse.childNodes[0].textContent;
document.getElementById("dataset_rights").value = datasetRights;
traverse = traverse.parentNode.parentNode;
/* Get the temporal coverage for the dataset. Here we check to
* see whether dateFrom and dateTo exist: if they don't assume
* that a (vague) description exists instead.
*/
traverse = traverse.getElementsByTagName("coverage")[0];
traverse = traverse.getElementsByTagName("temporal")[0];
if (traverse.getElementsByTagName("date").length > 0) {
const dateFrom = traverse.querySelector("date[type='dateFrom']");
if (dateFrom.attributes["dateFormat"].value != "W3CDTF") {
console.error("dateFrom format=... mismatch (should be 'W3CDTF').");
}
const datasetDateFrom = dateFrom.textContent;
document.getElementById("dataset_datefrom").value = datasetDateFrom;
const dateTo = traverse.querySelector("date[type='dateTo']");
if (dateTo.attributes["dateFormat"].value != "W3CDTF") {
console.error("dateTo format=... mismatch (should be 'W3CDTF').");
}
const datasetDateTo = dateTo.textContent;
document.getElementById("dataset_dateto").value = datasetDateTo;
} else {
/* Assume a description instead. */
const datasetDateText = traverse.childNodes[0].textContent;
document.getElementById("dataset_datetext").value = datasetDateText;
ignoreDates = true;
document.getElementById("dataset_datefrom")
.setAttribute("disabled", true);
document.getElementById("dataset_dateto")
.setAttribute("disabled", true);
}
traverse = traverse.parentNode;
/* Get the spatial coverage for the dataset (generate as many
* rows as necessary.)
*/
const spatial = traverse.getElementsByTagName("spatial");
for (i = 0; i < spatial.length; i++) {
if (i >= spatialLocations.length) {
addSpatialLocation();
}
var datasetSpatial = spatial[i].textContent;
document.getElementById(spatialLocations[i]).value = datasetSpatial;
}
traverse = traverse.parentNode;
/* Get the subject keywords for the dataset. */
//TODO: Are these comma-separated? At the moment we just treat it
// as a text string, but this might need to be changed later.
traverse = traverse.getElementsByTagName("subject")[0];
if (traverse.attributes["type"].textContent != "local") {
console.error("subject type=... mismatch (should be 'local').");
}
const datasetSubject = traverse.childNodes[0].textContent;
document.getElementById("dataset_subject").value = datasetSubject;
traverse = traverse.parentNode;
/* Get the contract title and contract code (in the 'activity'
* relatedInfo tag), and confirm the XML structure.
*/
traverse = traverse.querySelector("relatedInfo[type='activity']");
traverse = traverse.getElementsByTagName("title")[0];
const datasetContractCode = traverse.childNodes[0].textContent;
document.getElementById("dataset_contractcode").value =
datasetContractCode;
traverse = traverse.parentNode;
traverse = traverse.getElementsByTagName("notes")[0];
const datasetContractTitle = traverse.childNodes[0].textContent;
document.getElementById("dataset_contracttitle").value =
datasetContractTitle;
traverse = traverse.parentNode;
traverse = traverse.getElementsByTagName("identifier")[0];
if (traverse.attributes["type"].textContent != "local") {
console.error("identifier type=... mismatch (should be 'local').");
}
if (traverse.childNodes[0].textContent != datasetContractCode) {
console.error("identifier != title in relatedInfo['activity'].");
}
traverse = traverse.parentNode.parentNode;
/* Get the listed parties (including the primary Research
* Organisation and SAGI Node, which we handle specifically).
* Here we assume that the primary research organisation is the
* first listed party that explicitly has 'Project Partner'
* (or 'Research Organisation' for previous version compatibility)
* as its title, and the SAGI node is the first party that has
* 'SAGI Node' in its title, both case-sensitive. The other
* parties are toggled as organisations or individuals depending
* on how the XML looks: if the identifier text matches the notes
* text, we assume an organisation, otherwise assume a party.
*/
const partyElements =
traverse.querySelectorAll("relatedInfo[type='party']");
/* Research Organisation / Project Partner */
var i = 0;
while (i < partyElements.length &&
partyElements[i].getElementsByTagName("title")[0].textContent !=
"Research Organisation" &&
partyElements[i].getElementsByTagName("title")[0].textContent !=
"Project Partner") {
i++;
}
if (i == partyElements.length) {
console.error("No 'Research Organisation/Project Partner' found.");
} else {
traverse = partyElements[i];
const organisation =
traverse.getElementsByTagName("notes")[0].textContent;
document.getElementById("dataset_organisation").value = organisation;
traverse = traverse.getElementsByTagName("identifier")[0];
if (traverse.attributes["type"].textContent != "local") {
console.error("identifier type=... mismatch (should be 'local').");
}
if (traverse.childNodes[0].textContent != organisation) {
console.error("identifier != notes in Research Organisation party.");
}
traverse = traverse.parentNode.parentNode;
}
/* SAGI Node */
var j = 0;
while (j < partyElements.length &&
partyElements[j].getElementsByTagName("title")[0].textContent !=
"SAGI Node") {
j++;
}
if (j == partyElements.length) {
console.error("No 'SAGI Node' party found.");
} else {
traverse = partyElements[j];
const sagiNode = traverse.getElementsByTagName("notes")[0].textContent;
document.getElementById("dataset_saginode").value = sagiNode;
traverse = traverse.getElementsByTagName("identifier")[0];
if (traverse.attributes["type"].textContent != "local") {
console.error("identifier type=... mismatch (should be 'local').");
}
if (traverse.childNodes[0].textContent != sagiNode) {
console.error("identifier != notes in SAGI Node party.");
}
traverse = traverse.parentNode.parentNode;
}
/* Other parties are populated as either organisations or
* individuals depending on whether their identifier text matches
* with the notes text.
*/
for (k = 0, count = 0; k < partyElements.length; k++) {
if (k != i && k != j) {
if (count >= parties.length) {
addParty();
}
traverse = partyElements[k];
traverse = traverse.getElementsByTagName("title")[0];
var partyTitle = trimws(traverse.childNodes[0].textContent);
traverse = traverse.parentNode;
traverse = traverse.getElementsByTagName("notes")[0];
var partyNotes = trimws(traverse.childNodes[0].textContent);
traverse = traverse.parentNode;
traverse = traverse.getElementsByTagName("identifier")[0];
if (traverse.attributes["type"].textContent != "local") {
console.error("identifier type=... mismatch (should be 'local').");
}
var partyIdentifier = trimws(traverse.childNodes[0].textContent);
traverse = traverse.parentNode;
if (partyNotes == partyIdentifier) {
/* Assume an organisation in this case. */
document.getElementById(parties[count] + "_type_organisation")
.checked = true;
toggleParty(parties[count], true);
document.getElementById(parties[count] + "_org_title").value =
partyTitle;
var partyName = trimws(partyNotes);
document.getElementById(parties[count] + "_org_name").value =
partyName;
} else {
/* Assume an individual in this case. */
document.getElementById(parties[count] + "_type_individual")
.checked = true;
toggleParty(parties[count], false);
document.getElementById(parties[count] + "_ind_title").value =
partyTitle;
partyNotes = partyNotes.split(",");
var partyName = trimws(partyNotes[0]);
document.getElementById(parties[count] + "_ind_name").value =
partyName;
var partyPosition = trimws(partyNotes[1]);
document.getElementById(parties[count] + "_ind_position").value =
partyPosition;
var partyEmail = trimws(partyIdentifier);
document.getElementById(parties[count] + "_ind_email").value =
partyEmail;
}
count++;
}
}
/* By default, the export filename is the input filename (so that
* changes can be overwritten, which is presumably the typical
* use-case).
*/
var cleaned = datasetName.match(/\w+/g);
if (cleaned == null) {
cleaned = [ "output" ];
}
const filename = cleaned.join("_") + ".xml";
document.getElementById("xml_export_filename").value = filename;
}
document.getElementById("xml_import").addEventListener(
"change",
xmlImport,
false
);
/* Finally, the fields are all exported to RIF-CS compliant XML. */
function xmlExport(evt) {
const filename = document.getElementById("xml_export_filename").value;
/* Create the XML string and populate the fields as we go,
* extracting the relevant bits from the HTML form fields.
*/
var xmlString = "<registryObjects></registryObjects>";
const parser = new DOMParser();
const xml = parser.parseFromString(xmlString, "text/xml");
var traverse = xml.getElementsByTagName("registryObjects")[0];
/* The registryObject has group="Grains Research and Development
* Corporation - Statistics for the Australian Grains Industry 3".
*/
var registryObject = xml.createElement("registryObject");
registryObject.setAttribute("group", grdcSagi);
traverse.appendChild(registryObject);
traverse = registryObject;
/* The originatingSource has type="" and text content
* "Grains Research and Development Corporation - Statistics for
* the Australian Grains Industry 3".
*/
var originatingSource = xml.createElement("originatingSource");
originatingSource.setAttribute("type", "");
originatingSource.textContent = grdcSagi;
traverse.appendChild(originatingSource);
/* The collection has type="dataset" and contains all of the
* dataset metadata.
*/
var collection = xml.createElement("collection");
collection.setAttribute("type", "dataset");
traverse.appendChild(collection);
traverse = collection;
/* The name has type="primary" and contains a sub-element namePart
* that holds the text name for the dataset.
*/
const datasetName = trimws(document.getElementById("dataset_name").value);
var name_ = xml.createElement("name");
name_.setAttribute("type", "primary");
traverse.appendChild(name_);
traverse = name_;
var namePart = xml.createElement("namePart");
namePart.textContent = datasetName;
traverse.appendChild(namePart);
traverse = traverse.parentNode;
/* The location holds an address tag, which in turn holds an
* electronic tag with type="email", which in turn holds a value
* tag with the text of the point of contact email.
*/
const datasetLocation =
trimws(document.getElementById("dataset_location").value);
var location_ = xml.createElement("location");
traverse.appendChild(location_);
traverse = location_;
var address_ = xml.createElement("address");
traverse.appendChild(address_);
traverse = address_;
var electronic = xml.createElement("electronic");
electronic.setAttribute("type", "email");
traverse.appendChild(electronic);
traverse = electronic;
var value_ = xml.createElement("value");
value_.textContent = datasetLocation;
traverse.appendChild(value_);
traverse = traverse.parentNode.parentNode.parentNode;
/* The description has type="full" and contains separate p
* paragraphs for the general info, treatment factors,
* observed variables, experimental design elements and filenames
* in that order.
*/
const datasetGenInfo =
trimws(document.getElementById("dataset_geninfo").value);
const datasetTreatments =
trimws(document.getElementById("dataset_treatments").value);
const datasetVariables =
trimws(document.getElementById("dataset_variables").value);
const datasetDesign =
trimws(document.getElementById("dataset_design").value);
const datasetFiles =
trimws(document.getElementById("dataset_files").value);
var description = xml.createElement("description");
description.setAttribute("type", "full");
traverse.appendChild(description);
traverse = description;
var p_ = xml.createElement("p");
p_.textContent = datasetGenInfo;
traverse.appendChild(p_);
var p_ = xml.createElement("p");
p_.textContent = "Treatment factors: " +
datasetTreatments.replaceAll(",", ", ");
traverse.appendChild(p_);
var p_ = xml.createElement("p");
p_.textContent = "Variables: " +
datasetVariables.replaceAll(",", ", ");
traverse.appendChild(p_);
var p_ = xml.createElement("p");
p_.textContent = "Experimental design elements: " +
datasetDesign.replaceAll(",", ", ");
traverse.appendChild(p_);
var p_ = xml.createElement("p");
p_.textContent = "Filenames: " + datasetFiles.replaceAll(",", ", ");
traverse.appendChild(p_);
traverse = traverse.parentNode;
/* The rights tag has type="accessRights" and contains a p tag
* that holds the access rights text.
*/
const datasetRights =
trimws(document.getElementById("dataset_rights").value);
var rights = xml.createElement("rights");
rights.setAttribute("type", "accessRights");
traverse.appendChild(rights);
traverse = rights;
var p_ = xml.createElement("p");
p_.textContent = datasetRights;
traverse.appendChild(p_);
traverse = traverse.parentNode;
/* The coverage tag contains both temporal and spatial tags. */
var coverage = xml.createElement("coverage");
traverse.appendChild(coverage);
traverse = coverage;
/* The temporal tag will either:
* 1/ have type="text" and contain the textual description of
* the tempoarl coverage, if only a vague description was
* given in the HTML form, or:
* 2/ have no type or other attributes, but contain date tags
* with type="dateFrom" and "dateTo", and
* dateFormat="W3CDTF", which contain the dates as text.
*/
const datasetDateFrom =
trimws(document.getElementById("dataset_datefrom").value);
const datasetDateTo =
trimws(document.getElementById("dataset_dateto").value);
const datasetDateText =
trimws(document.getElementById("dataset_datetext").value);
var temporal = xml.createElement("temporal");
if (ignoreDates) {
temporal.setAttribute("type", "text");
temporal.textContent = datasetDateText;
} else {
var dateFrom = xml.createElement("date");
dateFrom.setAttribute("type", "dateFrom");
dateFrom.setAttribute("dateFormat", "W3CDTF");
dateFrom.textContent = datasetDateFrom;
temporal.appendChild(dateFrom);
var dateTo = xml.createElement("date");
dateTo.setAttribute("type", "dateTo");
dateTo.setAttribute("dateFormat", "W3CDTF");
dateTo.textContent = datasetDateTo;
temporal.appendChild(dateTo);
}
traverse.appendChild(temporal);
/* There will be multiple spatial tags for each spatial location
* specified in the form, and they each have type="text" and
* contain the text for the locations (which may or may not be
* GPS coordinates).
*/
for (i = 0; i < spatialLocations.length; i++) {
var spatialLocation =
trimws(document.getElementById(spatialLocations[i]).value);
if (spatialLocation.length > 0) {
var spatial = xml.createElement("spatial");
spatial.setAttribute("type", "text");
spatial.textContent = spatialLocation;
traverse.appendChild(spatial);
}
}
traverse = traverse.parentNode;
/* The subject has type="local" and contains the subject keywords
* for the project.
*/
const datasetSubject =
trimws(document.getElementById("dataset_subject").value);
var subject = xml.createElement("subject");
subject.setAttribute("type", "local");
subject.textContent = datasetSubject;
traverse.appendChild(subject);
/* The first relatedInfo tag has type="activity" and contains
* a title tag which has the text for the GRDC contract code,
* a notes tag that has the GRDC contract title text, and an
* identifier tag with type="local" that also contains the
* GRDC contract code.
*/
const datasetContractTitle =
trimws(document.getElementById("dataset_contracttitle").value);