crfHTML.js 4.1 KB

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