TableAjax.php.p5UI__TableAjax.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. var DBG = DBG || false;
  2. var DBG1 = true;
  3. if (!global.p5VendorJs) throw "Missing p5 Vendor js libs";
  4. if (!global.p5VendorJs.Redux) throw "Missing p5 Vendor js lib: Redux";
  5. var createReactClass = global.p5VendorJs.createReactClass;
  6. var h = global.p5VendorJs.React.createElement;
  7. var ReactDOM = global.p5VendorJs.ReactDOM;
  8. var Redux = global.p5VendorJs.Redux;
  9. var ReduxThunk = global.p5VendorJs.ReduxThunk;
  10. var createStoreWithThunkMiddleware = Redux.applyMiddleware(ReduxThunk)(Redux.createStore); // TODO: to vendor.js
  11. var cellFontSize = 12;
  12. var cellLineHeight = 18;
  13. var p5UI__TableAjax = createReactClass({
  14. getInitialState: function () {
  15. var cols = Array.apply(null, { length: 13 }).map(function (undefinedValue, cellIdx) {
  16. var label = "Col("+cellIdx+")" + ( cellIdx % 2 ? "<br>Col line 2..." : "" );
  17. return label;
  18. });
  19. return {
  20. isLoading: false,
  21. cols: cols,
  22. data: [],
  23. rowsPerPage: 10,
  24. };
  25. },
  26. getTheadCellHeight: function () {
  27. var maxLines = this.state.cols.reduce(function (ret, cell) {
  28. var label = cell;
  29. return Math.max(ret, label.replace('<br>', '###').replace('<br/>', '###').split("###").length);
  30. }, 1)
  31. return 2 * 2 + maxLines * cellLineHeight;
  32. },
  33. renderRowCell: function (rowIdx) {
  34. var _rowIdx = rowIdx;
  35. return function (value, cellIdx) {
  36. return h('td', {}, "("+_rowIdx+"/"+cellIdx+")");
  37. }
  38. },
  39. renderTheadColNameRowCell: function (value, cellIdx) {
  40. var label = this.state.cols[cellIdx];
  41. return h('th', {
  42. style: {
  43. padding: "2px 120px",
  44. 'white-space': 'nowrap',
  45. 'line-height': cellLineHeight+"px",
  46. 'font-size': cellFontSize+"px",
  47. 'border-bottom-width': "1px"
  48. }
  49. }, label.replace('<br>', '###<br>###').replace('<br/>', '###<br>###').split("###").map(function (txtOrBr) {
  50. return ('<br>' === txtOrBr) ? h('br') : txtOrBr;
  51. }));
  52. },
  53. renderTheadFilterRowCell: function (value, cellIdx) {
  54. return h('td', { style: { padding: 0 } }, [
  55. // <input class="filter" placeholder="%" type="text" value="" style="box-sizing: border-box; width: 100%; height: 21px; border-top: 0px; border-bottom: 2px solid transparent;">
  56. h('input', {
  57. type: "text",
  58. placeholder: "%",
  59. style: {
  60. 'box-sizing': "border-box",
  61. padding: "0 5px",
  62. width: "100%",
  63. height: "21px",
  64. 'border': "0px",
  65. 'border-bottom': "2px solid transparent",
  66. 'background-color': "#eee"
  67. }
  68. })
  69. ]);
  70. },
  71. renderRow: function (value, rowIdx) {
  72. var allColsCount = 13; // TODO: (this.state.cols.length || 0) + 3;
  73. var renderRowCell = this.renderRowCell(rowIdx);
  74. return h('tr', {}, Array.apply(null, { length: allColsCount }).map(renderRowCell));
  75. },
  76. render: function () {
  77. var baseStyle = { 'border-top': "1px solid red", 'border-bottom': "1px solid red", 'min-height': "100px" } // TODO: DBG
  78. var allColsCount = 13; // TODO: (this.state.cols.length || 0) + 3;
  79. return h('div', {
  80. className: "p5UI__TableAjax",
  81. style: Object.assign(baseStyle, {
  82. })
  83. }, [
  84. h('div', { style: { 'background-color': "#f00", color: "#fff", padding: "3px 12px" } }, "namespace: '" + this.props.namespace + "' getTheadCellHeight("+this.getTheadCellHeight()+")"),
  85. h('div', {
  86. style: {
  87. 'margin-left': "163px",
  88. 'min-height': "360px",
  89. 'overflow': "scroll visible",
  90. 'padding-bottom': "1px",
  91. 'clear': "both",
  92. 'width': "1187px",
  93. }
  94. }, [
  95. h('table', {
  96. className: "table table-bordered table-condensed",
  97. }, [
  98. h('thead', {}, [
  99. h('tr', {}, Array.apply(null, { length: allColsCount }).map(this.renderTheadColNameRowCell)),
  100. h('tr', {}, Array.apply(null, { length: allColsCount }).map(this.renderTheadFilterRowCell))
  101. ]),
  102. h('tbody', {}, [
  103. Array.apply(null, { length: this.state.rowsPerPage }).map(this.renderRow)
  104. ])
  105. ])
  106. ])
  107. ]);
  108. }
  109. });
  110. global.p5VendorJs['p5UI__TableAjax'] = p5UI__TableAjax;