-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsdctemplate.xslt
4552 lines (3624 loc) · 132 KB
/
sdctemplate.xslt
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
<?xml version="1.0" encoding="us-ascii"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2018_08_17" xmlns:sr="http://www.cap.org/pert/2009/01/"
xmlns:x="urn:ihe:qrph:sdc:2016">
<xsl:output encoding="us-ascii" method="html" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:variable name="show-toc" select="'false'"/>
<xsl:variable name="debug" select="'false'"/>
<!-- new code -->
<xsl:variable name="metadata-display" select="'true'"/>
<xsl:variable name="change-display" select="'true'"/>
<xsl:template match="/">
<xsl:variable name ="required" select="string(//Header/Property[@type='web_posting_date meta']/@val)"/>
<html>
<head>
<!-- <h3>HELLO</h3> -->
<!-- <div> HELLO </div> -->
<title><xsl:value-of select="//x:Header/@title"/></title>
<!--<link rel="stylesheet" href="Transforms/working/sdctemplate.css" type="text/css" />-->
<!--<link rel="stylesheet" href="sdctemplate.css" type="text/css" />-->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<!--<script type="text/javascript" src="sdctemplate.js"></script>-->
<script type="text/javascript">
$(document).ready(function () {
$('.mustImplement').parent().toggle();
var toggle_all = true;
$(".collapse_all_control").click(function(){
$(".collapsable_q").each(function(){
if ($(this).siblings().is( ":visible" ) && toggle_all === true) {
$(this).siblings().toggle(false);
$(this).toggleClass("Question collapsed_q");
} else if (!$(this).siblings().is( ":visible" ) && toggle_all === false) {
$(this).siblings().toggle(true);
$(this).toggleClass("Question collapsed_q");
}
});
$(".collapsable").each(function(){
if ($(this).siblings().is( ":visible" ) && toggle_all === true) {
$(this).siblings().toggle(false);
$(this).toggleClass("HeaderGroup collapsed");
} else if (!$(this).siblings().is( ":visible" ) && toggle_all === false) {
$(this).siblings().toggle(true);
$(this).toggleClass("HeaderGroup collapsed");
}
});
if (toggle_all) {
toggle_all = false;
} else {
toggle_all = true;
}
});
$(".collapsable").click(function(){
$(this).siblings().toggle();
$(this).toggleClass("HeaderGroup collapsed");
});
var toggle_section = true;
$(".collapse_control").click(function(){
$(".collapsable").each(function(){
if ($(this).siblings().is( ":visible" ) && toggle_section === true) {
$(this).siblings().toggle(false);
$(this).toggleClass("HeaderGroup collapsed");
} else if (!$(this).siblings().is( ":visible" ) && toggle_section === false) {
$(this).siblings().toggle(true);
$(this).toggleClass("HeaderGroup collapsed");
}
});
if (toggle_section) {
toggle_section = false;
} else {
toggle_section = true;
}
});
var toggle_question = true;
$(".collapse_q_control").click(function(){
$(".collapsable_q").each(function(){
if ($(this).siblings().is( ":visible" ) && toggle_question === true) {
$(this).siblings().toggle(false);
$(this).toggleClass("Question collapsed_q");
} else if (!$(this).siblings().is( ":visible" ) && toggle_question === false) {
$(this).siblings().toggle(true);
$(this).toggleClass("Question collapsed_q");
}
});
if (toggle_question)
toggle_question = false;
else
toggle_question = true;
});
//support toggle - sections
$(".collapsable").click(function(){
$(this).siblings().toggle();
$(this).toggleClass("HeaderGroup collapsed");
});
// support toggle - questions
$(".collapsable_q").click(function(){
$(this).siblings().toggle();
$(this).toggleClass("Question collapsed_q");
});
});
<xsl:text disable-output-escaping="yes" >
<![CDATA[
$(document).ready(function () {
//link CSS based on whether runing from disk or from server
if (window.location.protocol=='file:')
{
//$('<script type="text/javascript" src="sdctemplate.js"/>').appendTo('head');
$('<link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"/>').appendTo('head');
$("<link rel='stylesheet' href='sdctemplate.css' type='text/css' />").appendTo('head');
}
else{
//$('<script type="text/javascript" src="Transforms/working/sdctemplate.js"/>').appendTo('head');
$("<link rel='stylesheet' href='Transforms/working/sdctemplate.css' type='text/css' />").appendTo('head');
}
})
var xmlDoc;
var repeatIndex = 0; //used to generate unique ids, names in repeated elements
var _debug = true;
$(document).ready(function () {
// 2018-08-02
// alert($('#checklist').length);
//hide all notRequired
//toggle_notRequired();
toggle_mustImplement();
jQuery.support.cors = true; //not sure if needed because cors setting is on the server
$("#btnParameters").click(function(){
$("#options").toggle();
});
$("#btnParameters").click();
//support toggle
$(".collapsable").click(function(){
$(this).siblings().toggle();
$(this).toggleClass("HeaderGroup collapsed");
});
var endpoints;
var successIndex = 0;
/*
save original xml in jquery variable
server or xslt puts original xml in #rawxml, issue with xslt putting in xml is copy-of function decodes special characters, thus
making xml invalid
*/
var xmlstring = $("#rawxml").val();
// 2018-08-02
// alert($("#rawxml").length);
//load into xml dom
try{
xmlDoc = $.parseXML(xmlstring);
$xml = $(xmlDoc);
//allow submit
if($("#allowsubmit").val()=='no')
{
$("#send").css("display","none");
}
}
catch(err){
alert('Error loading xml: ' + err.message);
}
//disable all fill-in boxes
/*
var $fillins = $xml.find("ListItemResponseField")
$fillins.each(function(){
var answerid = $(this).parent().attr("ID");
var $answerElement = getAnswerItemByID(answerid, $("html"))
if(!$answerElement.prop('checked'))
$answerElement.parent().find('.AnswerTextBox').prop('disabled',true);
})
*/
});
function validateDate(value)
{
//2015-1-11 13:57:24
var pattern = /^\d\d\d\d-(0?[1-9]|1[0-2])-(0?[1-9]|[12][0-9]|3[01]) (00|[0-9]|1[0-9]|2[0-3]):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9])$/g;
}
function doConfirm(msg, yesFn, noFn)
{
var confirmBox = $("#confirmBox");
confirmBox.find(".message").text(msg);
confirmBox.find(".yes,.no").unbind().click(function()
{
confirmBox.hide();
});
confirmBox.find(".yes").click(yesFn);
confirmBox.find(".no").click(noFn);
confirmBox.show();
}
function isLocalMode()
{
if (window.location.protocol=='file:')
{
return true;
}
else
{
return false;
}
}
function loadXml(){
if (isLocalMode())
{
// 2018-08-02 change:
// alert('local');
$('#rawxml').remove();
$('<textarea id="rawxml" rows="20" style="-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;width: 100%;"/>').appendTo('body');
readTextFile(window.location.href);
if(_debug)
{
$('#rawxml').show();
}
else{
$('#rawxml').hide();
}
}
}
function readTextFile(file)
{
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
var allText = rawFile.responseText;
$('#rawxml').val(allText);
}
}
}
rawFile.send(null);
}
function sayHello(name) {
alert("sayHello function in javascripts says - hello, " + name);
return window.external.ShowMessage("If you can see this message sayHello successfully called ShowMessage function in this desktop client app.");
}
function toggle_metadata() {
var divsMD = document.getElementsByClassName('MetadataDisplay')
var divsMDH = document.getElementsByClassName('MetadataDisplayHeader')
var display = 'none'
if (divsMD[0].style.display)
{
if (divsMD[0].style.display == 'inline' )
{ display = 'none' }
else
{ display = 'inline' }
}
for (var i = 0; i < divsMD.length; i++)
{ divsMD[i].style.display = display }
for (var i = 0; i < divsMDH.length; i++)
{ divsMDH[i].style.display = display }
//Toggle ids too
var divs = document.getElementsByClassName('idDisplay')
for (var i = 0; i < divs.length; i++)
{
divs[i].style.display = display
}
//Toggle deprecated items
var dis = document.getElementsByClassName('TopHeader')
var searchText = "(Deprecated Items)"
for (var i = 0; i < dis.length; i++)
{
if (dis[i].textContent.indexOf(searchText) >=0)
{
var divHeader = dis[i].parentElement.parentElement.parentElement //the tbody element
if (display == 'inline') {display = ''}
divHeader.style.display = display
break;
}
}
}
function toggle_name()
{
var nameDiv = document.getElementsByClassName('nameDiv');
var display = 'none'
if (nameDiv[0].style.display)
{
if (nameDiv[0].style.display == 'inline' )
{ display = 'none' }
else
{ display = 'inline' }
}
for (var i = 0; i < nameDiv.length; i++)
{ nameDiv[i].style.display = display }
}
function toggle_mustImplement()
{
//alert('here');
// $('.mustImplement').parent().toggle();
if($('.mustImplement').parent().is(":visible")){
$('#mnuRequired').text('Toggle optional items');
$('.mustImplement').parent().toggle();
}
else{
$('#mnuRequired').text('Hide optional items');
$('.mustImplement').parent().toggle();
}
}
function toggle_id() {
var divs = document.getElementsByClassName('idDisplay');
var display = 'none';
if (divs[0].style.display)
{
if (divs[0].style.display == 'inline' )
{ display = 'none'; }
else
{ display = 'inline'; }
}
for (var i = 0; i < divs.length; i++)
{ divs[i].style.display = display; }
}
function resetAnswer(questionId, event) {
/*will it work with repeated sections?*/
var answers = document.getElementsByName(questionId);
//alert(questionId.split("..")[0]);
for (var i = 0; i < answers.length; i++) {
var selecttype = $(answers[i]).attr('type');
if(selecttype=="checkbox" || selecttype=="radio")
{
answers[i].checked = false;
// fire onchange on this answer choice
//answers[i].onchange();
}
}
return false;
}
function ShowHideDemo() {
$('#divdemo').toggle();
if (($('#divdemo')).css("display")=='none')
$('#demshowhide').text('+ Demographics');
else
$('#demshowhide').text('- Demographics');
}
//adds a new repeat of a section
function addSection(obj) {
//obj is btnAdd
/*
UI: Clone the block
Get new guid for block (section)
Change names of each element (textbox, hiddenbox, checkbox, radio) in the block to original id + ":" + blockguid
XML:
Clone the current section in xml
Add new attribute called Guid = blockguid to the top level element
Add new attribute called ParentGuid and set it equal to blockguid
Change Id of each child to original id + ":" + blockguid
Each question and answer choices in repeated block will have their ids changed to their original id + ": " + blockguid
*/
//we need to clone table, so get table
var td = obj.parentElement;
var table = td.parentElement //tr
.parentElement //tbody
.parentElement //table
/*if current section is the first occurrence, it's ID is from the xml
if current section is a repeat it's ID = ID from the xml + Guid*/
var currentSectionId = table.id;
var blockGuid = generateShortUid(); // generateGuid(); //to distinguish each repeat of parent element which is section for now
repeatIndex++;
var max = table.parentElement.firstChild.value; //maxcardinality
try{
var parentTable = table.parentElement.
parentElement.
parentElement.
parentElement.
parentElement;
}
catch(err)
{
alert("Error when getting parent table: " + err);
return;
}
if(countSectionRepeats(parentTable,currentSectionId.split("..")[0])==max)
{
alert("max repeat = " + max + " reached ");
return;
}
var newtable = table.cloneNode(true);
//newtable.id = currentSectionId.split(":")[0] + ":" + blockGuid; //each repeated section id has the same ID from xml + blockGuid
newtable.id = currentSectionId.split("..")[0] + ".." + repeatIndex
//set new ids to each nested table
var newtableitems = newtable.getElementsByTagName('*');
for(i=0; i< newtableitems.length; i++)
if(newtableitems[i].tagName=="TABLE")
//newtableitems[i].id = newtableitems[i].id.split(":")[0] + ":" + blockGuid;
newtableitems[i].id = newtableitems[i].id.split("..")[0] + ".." + repeatIndex;
var trace = 0;
var newname;
var i;
var ID;
//add the new repeat
try {
/*find section in xml corresponding to this block (ID=currentSectionId.substring(1)) and clone it, then assign new ID*/
//alert(currentSectionId.substring(1));
var $sectionCurrent = $xml.find('Section[ID="' + currentSectionId.substring(1) + '"]:first'); //first is redundant since there is only one section with this ID
if($sectionCurrent.length==0)
{
alert("Section ID = " + currentSectionId.substring(1) + " not found");
return;
}
var $sectionNew = $sectionCurrent.clone(true);
//$sectionNew.attr('ID',currentSectionId.split(":")[0].substring(1)+":" + blockGuid);
$sectionNew.attr('ID',currentSectionId.split("..")[0].substring(1)+".." + repeatIndex);
//xml: set IDs of all children sections
$sectionNew.find('Section').each(function(index){
//var secid = $(this).attr("ID").split(":")[0] + ":" + blockGuid;
var secid = $(this).attr("ID").split("..")[0] + ".." + repeatIndex;
$(this).attr("ID",secid);
});
var oldtableitems = td.getElementsByTagName("input"); //get hidden input, radio buttons, checkboxes and input text boxes
//iterate through oldtableitems and assign new unique ids to them
for (i = 0; i < oldtableitems.length; i++) {
if (oldtableitems[i].type == "hidden" || oldtableitems[i].type == "text" || oldtableitems[i].type=="radio") {
oldname = oldtableitems[i].name; //name of the first instance is ID from xml, repeats have ID + ":" + Guid
if(oldtableitems[i].id=="maxcardinality")
continue;
if(oldtableitems[i].name=="")
{
alert("error: a " + oldtableitems[i].type + " box without name is found at " + i);
continue;
}
//newname = oldtableitems[i].name.split(":")[0] + ':' + blockGuid;
newname = oldtableitems[i].name.split("..")[0] + '..' + repeatIndex;
//find the element in the new table
newtableitems = newtable.getElementsByTagName('*');
for(k=0;k<newtableitems.length;k++)
{
if(newtableitems[k].name == oldtableitems[i].name)
{
newtableitems[k].name = newname;
if(newtableitems[k].type=="hidden") //question will have Q as the first letter
{
//find question in xml fragment and change ID
$question = $sectionNew.find('Question[ID="' + oldtableitems[i].name.substring(1) + '"]');
if($question.length==0)
{
alert("Qusetion ID = " + oldtableitems[i].name.substring(1) + " not found.");
$sectionNew.find('Question').each(function(index){
alert($(this).attr("ID"));
})
return;
}
else{
//$question.attr("ID", newtableitems[k].name.split(":")[0].substring(1) + ':' + blockGuid);
$question.attr("ID", newtableitems[k].name.split("..")[0].substring(1) + '..' + repeatIndex);
}
/* 12/18/2016
New constraints
Property name, ResponseField name and Value name have to be unique
*/
if (typeof $question.find("Property").attr("name") != 'undefined')
{
//new property name
//var propname = $question.find("Property").attr("name") + "_" + blockGuid; // repeat;
var propname = $question.find("Property").attr("name").split('..')[0] + ".." + repeatIndex;
$question.find("Property").attr("name",propname);
}
if (typeof $question.find("ResponseField").attr("name") != 'undefined')
{
//new response name
//propname = $question.find("ResponseField").attr("name") + "_" + blockGuid; // repeat;
propname = $question.find("ResponseField").attr("name").split('..')[0] + ".." + repeatIndex; // repeat;
$question.find("ResponseField").attr("name",propname);
}
if (typeof $question.find("Response").children(0).attr("name") != 'undefined')
{
//new name on value field
//propname = $question.find("Response").children(0).attr("name") + "_" + blockGuid; // repeat;
propname = $question.find("Response").children(0).attr("name").split('..')[0] + ".." + repeatIndex; // repeat;
$question.find("Response").children(0).attr("name", propname);
}
}
else { //answers do not have Q
if(newtableitems[k].type=="radio" || newtableitems[k].type == "checkbox")
{
newtableitems[k].checked = false;
}
else
{
newtableitems[k].value = "";
}
}
}
}
}
}
//better to append new table after setting properties of individual controls
table.parentElement.appendChild(newtable);
//insert newsec after last section
//$xml.find('Section[ID="' + table.id.substring(1) + '"]').after($sectionNew);
var $orgsecid = table.id.substring(1).split('..')[0];
var $lastindex = $xml.find('Section[ID*="' + $orgsecid + '"]').length - 1;
if($lastindex>=0)
{
$xml.find('Section[ID*="' + $orgsecid + '"]').last().after($sectionNew);
}
else
{
alert("error adding section repeat");
return;
}
//remove all nested repeats
newtable = removeNestedTableRepeats(newtable);
//update rawxml for view
$('#rawxml').val(xmlToString(xmlDoc));
repeat = countSectionRepeats(parentTable, currentSectionId.split("..")[0])
showHideButtons(newtable);
//make sure + is visible on the first repeat of nested section
nestedtables = getChildTables(newtable);
for(i=0;i<nestedtables.length;i++)
{
elements = nestedtables[i].getElementsByTagName('*');
for(j=0;j<elements.length;j++)
{
if(elements[j].className=="btnAdd")
elements[j].style.visibility="visible";
}
}
}
catch (err) {
alert(err.message + "\n" + trace + "\n" + newname + "n" + i);
}
}
//adds a new repeat of a question
function addQuestion(obj) {
//obj is btnAdd inside command div
/*
UI: Clone .question div, update id of this div to original id + '..' + repeatIndex
change names of children to name + '..' + repeatIndex
XML:
Clone the current question node in xml
Change Id of the question and its children to original id + ":" + blockguid
Each question and answer choices in repeated block will have their ids changed to their original id + ": " + blockguid
*/
try{
var button = $(obj);
//find question div
var questionToRepeat = button.closest('.question'); //closest parent div with class='question'
//alert(questionToRepeat.html())
var currentQuestionId = questionToRepeat.attr('id');
currentQuestionId = currentQuestionId.substring(1).split('.')[0];
var max = questionToRepeat.find("input[id='maxcardinality']").first().val(); //maxcardinality
//alert(max);
var repeats = countQuestionRepeats(currentQuestionId);
repeatIndex++;
if(repeats> max)
{
alert('max value ' + max + ' reached.');
return;
}
var clonedBlock = questionToRepeat.clone();
//alert(currentQuestionId);
clonedBlock.attr("id", 'q' + currentQuestionId + '..' + repeatIndex);
//alert(clonedBlock.html());
//find the top level question node in xml and clone it
var elementToClone = $xml.find("Question[ID='" + currentQuestionId + "']");
var clonedXml = elementToClone.clone();
//change name attributes
clonedXml.find("Property").each(function(){
var prop = $(this);
if(typeof prop.attr("name") != "undefined")
prop.attr("name",prop.attr("name").split('..')[0] + ".." + repeatIndex);
});
clonedXml.find("ResponseField").each(function(){
var temp = $(this);
if(typeof temp.attr("name") != "undefined")
temp.attr("name",temp.attr("name").split('..')[0] + ".." + repeatIndex);
});
clonedXml.find("Response").each(function(){
var temp = $(this).children(0);
if(typeof temp.attr("name") != "undefined")
temp.attr("name",temp.attr("name").split('..')[0] + ".." + repeatIndex);
});
clonedXml.find("ListItemResponseField").each(function(){
var temp = $(this);
if(typeof temp.attr("name") != "undefined")
temp.attr("name",temp.attr("name").split('..')[0] + ".." + repeatIndex);
});
//update names of cloned elements
var clonedItems = clonedBlock.find("input"); //get hidden input, radio buttons, checkboxes and input text boxes
//iterate through clonedItems and assign new unique ids to them
clonedItems.each(function(){
var item = $(this);
var name = item.attr('name');
if(typeof name != 'undefined')
{
if(name.substring(0,1)=='q')
{
var questionId = name.substring(1).split('..')[0];
item.attr('name','q' + questionId + '..' + repeatIndex);
//alert(questionId + ':' + clonedXml.find("Question[ID='" + questionId + "']").length);
if(clonedXml.attr("ID")==questionId)
{
//alert('here')
clonedXml.attr("ID",questionId + '..' + repeatIndex);
}
else{
clonedXml.find("Question[ID='" + name.substring(1) + "']").attr('ID',questionId + '..' + repeatIndex);
//alert(questionId + '..' + repeatIndex);
}
}
else{
//answer choices do not have 'q'
var questionId = name.split('..')[0];
item.attr('name',questionId + '..' + repeatIndex);
//alert(item.attr('type'));
if(item.attr('type')=='text')
{
item.val('');
}
item.attr('checked',false);
}
}
});
//append cloned node to xml
clonedXml.appendTo(elementToClone.parent());
//append cloned UI block in display
clonedBlock.find('.btnRemove').css('visibility', 'visible'); //show does not work
//clonedBlock.appendTo(questionToRepeat.after());
questionToRepeat.after( clonedBlock);
}
catch (err) {
alert(err.message );
}
}
function removeQuestion(obj)
{
try {
var button = $(obj);
//find question div
var questionToRemove = button.closest('.question'); //closest parent div with class='question'
var currentQuestionId = questionToRemove.attr('id').substring(1);
//remove
questionToRemove.remove();
//alert('now removing ' + currentQuestionId);
//alert(countQuestionRepeats(currentQuestionId));
if($xml.find("Question [ID='" + currentQuestionId + "']").length==0)
{
alert("ID = " + currentQuestionId + " not found");
}
$xml.find("Question [ID='" + currentQuestionId + "']").remove();
}
catch(err)
{
alert(err.message);
}
}
function getRepeats(id)
{
var id = id.split('_')[0];
var count = 0;
$('input').each(function(){
var name = $(this).attr('name');
if(name==id)
{
count++;
}
});
return count;
}
function generateShortUid() {
return ("0000" + (Math.random()*Math.pow(36,4) << 0).toString(36)).slice(-4)
}
function generateGuid() {
var result, i, j;
result = '';
for (j = 0; j < 32; j++) {
if (j == 8 || j == 12 || j == 16 || j == 20)
result = result + '-';
i = Math.floor(Math.random() * 16).toString(16).toUpperCase();
result = result + i;
}
return result;
}
/*
Counts the number of repeats of a block (table)
Each repeated block (table) has id that has two parts
1. id that is the same for each repeat.
2. a guid that is different for each repeat
*/
function countSectionRepeats(parentT, sectionid) {
var tables = parentT.getElementsByTagName('TABLE');
var count = 0;
for(i=0; i<tables.length; i++)
{
checkid = tables[i].id.split("..")[0];
if(checkid == sectionid) count++;
}
return count;
}
/*
count question repeats
*/
function countQuestionRepeats(questionid) {
questionid = questionid.split('.')[0];
//alert(questionid + ':' + $xml.find('Question[ID^="' + questionid + '"]').length);
return $xml.find('Question[ID^="' + questionid + '"]').length;
}
function getMaxCount(sectionid)
{
alert(document.getElementById(sectionid).length);
}
function getSiblingTables(parentT) {
return tables = parentT.getElementsByTagName('TABLE');
}
function getChildTables(table)
{
return table = table.getElementsByTagName('TABLE');
}
function getLastRepeat(sectionid) {
var section = document.getElementById(sectionid);
var tables = section.parentElement.getElementsByTagName('TABLE');
var ret = null;
for(i=0;i<tables.length;i++)
{
if(tables[i].id.split("..")[0]==sectionid)
ret = tables[i];
}
return ret;
}
function getFirstRepeat(sectionid) {
var section = document.getElementById(sectionid);
var tables = section.parentElement.getElementsByTagName('TABLE');
var ret = null;
for(i=0;i<tables.length;i++)
{
if(tables[i].id.split("..")[0]==sectionid)
{
ret = tables[i];
break;
}
}
return ret;
}
function removeNestedTableRepeats(table)
{
var all = table.getElementsByTagName("*");
for(i=0; i<all.length-1; i++)
{
if(all[i].id.indexOf("s")==0 & all[i].tagName=="TABLE") //nested table
{
var id = all[i].id;
//alert("delete id = " + id);
for(j=i+1; j<all.length-1; j++)
{
if(all[j].id.split("..")[0]==id.split("..")[0])
{
v = all[j].id;
//remove table
all[j].parentElement.removeChild(all[j]);