v1.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace zin;
  3. require_once dirname(__DIR__) . DS . 'prilabel' . DS . 'v1.php';
  4. require_once dirname(__DIR__) . DS . 'severitylabel' . DS . 'v1.php';
  5. require_once dirname(__DIR__) . DS . 'risklabel' . DS . 'v1.php';
  6. require_once dirname(__DIR__) . DS . 'collapsebtn' . DS . 'v1.php';
  7. class tableData extends wg
  8. {
  9. /**
  10. * @var mixed[]
  11. */
  12. protected static $defineProps = array(
  13. 'title?: string',
  14. 'useTable?: bool=true',
  15. 'class?: string',
  16. 'required?: bool=false'
  17. );
  18. public static function getPageCSS()
  19. {
  20. return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
  21. }
  22. private function buildItemWithTr($item)
  23. {
  24. global $app;
  25. $required = $item->prop('required');
  26. return h::tr
  27. (
  28. setClass($item->prop('trClass')),
  29. h::th
  30. (
  31. setClass('py-1.5 pr-2 font-normal nowrap text-right' . ($required ? ' required' : ''), $item->prop('thClass')),
  32. $item->prop('name'),
  33. $item->block('suffixName')
  34. ),
  35. h::td
  36. (
  37. setClass('py-1.5 pl-2 w-full', $item->prop('tdClass')),
  38. $item->children()
  39. )
  40. );
  41. }
  42. private function buildItemWithDiv($item)
  43. {
  44. if($item->prop('collapse'))
  45. {
  46. return div
  47. (
  48. setClass('col', 'table-data-tr', $item->prop('trClass')),
  49. div
  50. (
  51. setClass('py-1.5 pr-2 font-normal nowrap table-data-th', $item->prop('thClass')),
  52. $item->prop('name'),
  53. new collapseBtn
  54. (
  55. setClass('w-5 h-5 ml-1'),
  56. set::target('.table-data-td'),
  57. set::parent('.table-data-tr')
  58. )
  59. ),
  60. div
  61. (
  62. setClass('py-1.5 pl-2 table-data-td', $item->prop('tdClass')),
  63. $item->children()
  64. )
  65. );
  66. }
  67. return div
  68. (
  69. setClass('flex table-data-tr', $item->prop('trClass')),
  70. div
  71. (
  72. setClass('py-1.5 pr-2 font-normal nowrap table-data-th', $item->prop('thClass')),
  73. $item->prop('name')
  74. ),
  75. div
  76. (
  77. setClass('py-1.5 pl-2 table-data-td', $item->prop('tdClass')),
  78. $item->children()
  79. )
  80. );
  81. }
  82. public function onBuildItem($item)
  83. {
  84. $item->setProp(array('thClass' => $this->prop('thClass'), 'tdClass' => $this->prop('tdClass')));
  85. $useTable = $this->prop('useTable');
  86. if($useTable) return $this->buildItemWithTr($item);
  87. return $this->buildItemWithDiv($item);
  88. }
  89. private function caption()
  90. {
  91. $title = $this->prop('title');
  92. if(empty($title)) return null;
  93. return h::caption
  94. (
  95. setClass('text-lg font-bold text-left mb-2'),
  96. $title
  97. );
  98. }
  99. protected function build()
  100. {
  101. $useTable = $this->prop('useTable');
  102. $tableClass = $this->prop('class');
  103. if($useTable)
  104. {
  105. return h::table
  106. (
  107. setClass('table-data'),
  108. $tableClass ? setClass($tableClass) : null,
  109. $this->caption(),
  110. h::tbody($this->children())
  111. );
  112. }
  113. return div
  114. (
  115. setClass('table-data'),
  116. $tableClass ? setClass($tableClass) : null,
  117. div
  118. (
  119. setClass('table-data-body'),
  120. $this->children()
  121. )
  122. );
  123. }
  124. }