back_ui.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. function toggleEnable(id)
  2. {
  3. var sw = $("#"+id+"_cb");
  4. var r = $('#'+id);
  5. r.prop('disabled', !sw.is(':checked'));
  6. }
  7. function findPathInObject(obj, path, modifier={})
  8. {
  9. var list = path.split("/");
  10. if(list.length==1)
  11. {
  12. var o = obj[list[0]];
  13. if(o instanceof Array)
  14. {
  15. return o;
  16. }else if(o instanceof Object){
  17. var x = {};
  18. Object.assign(x, o, modifier);
  19. return x;
  20. }else if(typeof o == "string"){
  21. if(o[0]=='@' && o[1]=='/')
  22. return findPathInObject(obj, o, modifier);
  23. else
  24. return o;
  25. }else{
  26. return o;
  27. }
  28. }
  29. return findPathInObject(obj[list[0]], list.slice(1).join("/"), modifier)
  30. }
  31. class UIManager
  32. {
  33. constructor()
  34. {
  35. this.list={}
  36. this.uiClasses={};
  37. this.idIndex=0;
  38. }
  39. registerUiClass(type, classname){
  40. this.uiClasses[type]=classname;
  41. }
  42. newUi(type, a, b, c, d)
  43. {
  44. return new this.uiClasses[type](a, b, c, d);
  45. }
  46. registerElement(obj)
  47. {
  48. this.idIndex++;
  49. this.list[this.idIndex]=obj;
  50. return this.idIndex;
  51. }
  52. deleteElement(obj)
  53. {
  54. var id = obj.uiId;
  55. delete this.list[id];
  56. }
  57. getElementById(id)
  58. {
  59. return this.list[id];
  60. }
  61. }
  62. var __uiManager = new UIManager();
  63. function newUiClass(type, a, b, c)
  64. {
  65. return __uiManager.newUi(type, a, b, c);
  66. }
  67. function registerUiClass(type, classe)
  68. {
  69. return __uiManager.registerUiClass(type, classe);
  70. }
  71. function getUI(uiId)
  72. {
  73. return __uiManager.getElementById(uiId);
  74. }
  75. function getUIFromDom(id)
  76. {
  77. var root = $("#"+id);
  78. var uiId = root.data().id;
  79. return __uiManager.getElementById(uiId);
  80. }
  81. function registerUI(obj)
  82. {
  83. return __uiManager.registerElement(obj);
  84. }
  85. function deleteUI(obj)
  86. {
  87. return __uiManager.deleteElement(obj);
  88. }