crfHTML.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. var crfHTML={};
  2. crfHTML.print=
  3. function(msg){
  4. console.log(msg);
  5. }
  6. crfHTML.init=
  7. function(cb=null){
  8. LABKEY.requiresCss("crf/crfHTML.css");
  9. this.print('CSS loaded');
  10. if (cb) cb();
  11. }
  12. crfHTML.getElement=
  13. function(id){
  14. return document.getElementById(id);
  15. }
  16. crfHTML.append=
  17. function(element,id=null,el=null){
  18. if (id) document.getElementById(id).appendChild(element);
  19. if (el) el.appendChild(element);
  20. }
  21. crfHTML.addStyle=
  22. function(el,style){
  23. el.classList.add(style);
  24. }
  25. crfHTML.createSelect=
  26. function(qMap,id=null,el=null){
  27. let fName='[makeSelect]';
  28. let input=document.createElement('select');
  29. this.addSelectOptions(input,qMap);
  30. this.append(input,id,el);
  31. return input;
  32. }
  33. crfHTML.createTable=
  34. function(id=null,el=null,style=null){
  35. let table=document.createElement('table');
  36. this.append(table,id,el);
  37. if (style) this.addStyle(style);
  38. return table;
  39. }
  40. crfHTML.createBox=
  41. function(id=null,el=null){
  42. let fbox=document.createElement('div');
  43. fbox.classList.add("box");
  44. this.append(fbox,id,el);
  45. return fbox;
  46. }
  47. crfHTML.createParagraph=
  48. function(text,id=null,el=null){
  49. let fp=document.createElement("p");
  50. fp.innerHTML=text;
  51. fp.classList.add("center");
  52. this.append(fp,id,el);
  53. return fp;
  54. }
  55. crfHTML.createTblHeader=
  56. function(id=null,el=null){
  57. let element=document.createElement('th');
  58. this.append(element,id,el);
  59. return element;
  60. }
  61. crfHTML.createButton=
  62. function(id=null,el=null){
  63. let button=document.createElement('input');
  64. button.type='button';
  65. this.append(button,id,el);
  66. return button;
  67. }
  68. crfHTML.createTextNode=
  69. function(text,id=null,el=null){
  70. let tNode=document.createTextNode(text);
  71. this.append(tNode,id,el);
  72. return tNode;
  73. }
  74. crfHTML.setTextNode=
  75. function(el,text){
  76. el.nodeValue=text;
  77. }
  78. crfHTML.createDiv=
  79. function(divId=null,id=null,el=null){
  80. let div=document.createElement('div');
  81. if (divId) div.id=divId;
  82. this.append(div,id,el);
  83. return div;
  84. }
  85. crfHTML.createTextArea=
  86. function(id=null,el=null){
  87. let area=document.createElement('textarea');
  88. this.append(area,id,el);
  89. return area;
  90. }
  91. crfHTML.createLabel=
  92. function(label,id=null,el=null){
  93. let x=document.createElement('label');
  94. x.innerText=label;
  95. this.append(x,id,el);
  96. return x;
  97. }
  98. crfHTML.createDate=
  99. function(id=null,el=null){
  100. let x=document.createElement('input');
  101. x.type='date';
  102. this.append(x,id,el);
  103. return x;
  104. }
  105. crfHTML.createTextInput=
  106. function(id=null,el=null){
  107. let x=document.createElement('input');
  108. x.type='text';
  109. this.append(x,id,el);
  110. return x;
  111. }
  112. crfHTML.createFileInput=
  113. function(id=null,el=null){
  114. let x=document.createElement('input');
  115. x.type='file';
  116. this.append(x,id,el);
  117. return x;
  118. }
  119. crfHTML.createCheckbox=
  120. function(id=null,el=null){
  121. let x=document.createElement('input');
  122. x.type='checkbox';
  123. this.append(x,id,el);
  124. return x;
  125. }
  126. crfHTML.clear=
  127. function(el){
  128. while (el.hasChildNodes()){
  129. el.removeChild(el.lastChild);
  130. }
  131. }
  132. crfHTML.clearOptions=
  133. function(input){
  134. while(input.options.length) input.remove(0);
  135. }
  136. crfHTML.addSelectOptions=
  137. function(input,qMap){
  138. let fName='[addSelectOptions]';
  139. this.clearOptions(input);
  140. let opt = document.createElement("option");
  141. opt.text = "<Select>";
  142. opt.value = -1;
  143. input.options[0] = opt;
  144. this.print(fName+": Adding <Select>");
  145. //add other, label them with LUT
  146. for (let v in qMap) {
  147. this.print(fName+': populating '+v+': '+qMap[v]);
  148. let opt = document.createElement("option");
  149. opt.text = qMap[v];
  150. opt.value = v;
  151. input.options[input.options.length] = opt;
  152. }
  153. input.selectedIndex=0;
  154. }