crfHTML.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. var crfHTML={};
  2. crfHTML.print=
  3. function(msg){
  4. console.log(msg);
  5. }
  6. crfHTML.init=
  7. function(cb=null){
  8. LABKEY.requiresCss("crfTecant/crfHTML.css");
  9. this.print('CSS loaded');
  10. if (cb) cb();
  11. }
  12. crfHTML.makeSelect=
  13. function(qMap,id=null,el=null){
  14. let fName='[makeSelect]';
  15. let input=document.createElement('select');
  16. let opt = document.createElement("option");
  17. opt.text = "<Select>";
  18. opt.value = -1;
  19. input.options[0] = opt;
  20. this.print(fName+": Adding <Select>");
  21. //add other, label them with LUT
  22. for (let v in qMap) {
  23. this.print(fName+': populating '+v+': '+qMap[v]);
  24. let opt = document.createElement("option");
  25. opt.text = qMap[v];
  26. opt.value = v;
  27. input.options[input.options.length] = opt;
  28. }
  29. input.selectedIndex=0;
  30. this.append(input,id,el);
  31. return input;
  32. }
  33. crfHTML.append=
  34. function(element,id=null,el=null){
  35. if (id) document.getElementById(id).appendChild(element);
  36. if (el) el.appendChild(element);
  37. }
  38. crfHTML.clear=
  39. function(el){
  40. while (el.hasChildNodes()){
  41. el.removeChild(el.lastChild);
  42. }
  43. }
  44. crfHTML.createTable=
  45. function(id=null,el=null,style=null){
  46. let table=document.createElement('table');
  47. this.append(table,id,el);
  48. if (style) this.addStyle(style);
  49. return table;
  50. }
  51. crfHTML.addStyle=
  52. function(el,style){
  53. el.classList.add(style);
  54. }
  55. crfHTML.createBox=
  56. function(id=null,el=null){
  57. let fbox=document.createElement('div');
  58. fbox.classList.add("box");
  59. this.append(fbox,id,el);
  60. return fbox;
  61. }
  62. crfHTML.createParagraph=
  63. function(text,id=null,el=null){
  64. let fp=document.createElement("p");
  65. fp.innerHTML=text;
  66. fp.classList.add("center");
  67. this.append(fp,id,el);
  68. }