ajaxcustom.html.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * The ajaxcustom view file of datatable module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author sunhao<sunhao@easycorp.ltd>
  8. * @package zin
  9. * @link https://www.zentao.net
  10. */
  11. namespace zin;
  12. global $lang, $app;
  13. $app->loadLang('datatable');
  14. jsVar('ajaxSaveUrl', $this->createLink('datatable', 'ajaxSaveFields', "module={$module}&method={$method}&extra={$extra}"));
  15. function buildItem($item)
  16. {
  17. global $lang;
  18. $isRequired = $item['required'];
  19. $isPercent = $item['width'] < 1;
  20. $unitTypes = array('px' => 'px', '%' => '%');
  21. $value = $isPercent ? strval(round((float)$item['width'] * 100)) : $item['width'];
  22. return li
  23. (
  24. setClass('row items-center ring px-5 h-9 cursor-move mt-px'),
  25. set('data-key', $item['name']),
  26. set('data-value', $item['width']),
  27. $isRequired ? setClass('required-col') : null,
  28. checkbox
  29. (
  30. set::disabled($isRequired),
  31. set::name($item['name']),
  32. set::checked($item['show'] || $isRequired)
  33. ),
  34. h::label
  35. (
  36. setClass('flex-auto cursor-move'),
  37. set('for', $item['name'] . '_'),
  38. $item['title']
  39. ),
  40. div
  41. (
  42. setClass('hidden row items-center gap-1'),
  43. span($lang->datatable->width, setClass('muted')),
  44. inputGroup
  45. (
  46. input
  47. (
  48. setClass('size-sm text-center w-14'),
  49. set::value($value === '0' ? '' : $value)
  50. ),
  51. select
  52. (
  53. set::name('width'),
  54. setClass('size-sm w-12'),
  55. set::name('width'),
  56. set::required(true),
  57. set::items($unitTypes),
  58. set::value($isPercent ? '%' : 'px')
  59. )
  60. )
  61. )
  62. );
  63. }
  64. function getDefaultConfig($name)
  65. {
  66. global $config;
  67. $defaultConfig = $config->datatable->defaultColConfig;
  68. if(isset($defaultConfig[$name])) return $defaultConfig[$name];
  69. return array();
  70. }
  71. function buildBody($cols)
  72. {
  73. $itemsList = array(
  74. 'left' => array(),
  75. 'no' => array(),
  76. 'right' => array()
  77. );
  78. foreach($cols as $col)
  79. {
  80. if(zget($_SESSION, 'currentProductType', '') == 'normal' && $col['name'] == 'branch') continue;
  81. if(isset($col['type'])) $col = array_merge(getDefaultConfig($col['type']), $col);
  82. if(!isset($col['fixed']) || empty($col['fixed'])) $col['fixed'] = 'no';
  83. $itemsList[$col['fixed']][] = array(
  84. 'required' => isset($col['required']) && $col['required'] === true,
  85. 'title' => zget($col, 'title', ''),
  86. 'width' => zget($col, 'width', ''),
  87. 'name' => zget($col, 'name', ''),
  88. 'show' => !empty($col['show'])
  89. );
  90. }
  91. $body = form
  92. (
  93. setClass('col', 'gap-0.5'),
  94. set::grid(false),
  95. set::actions(array())
  96. );
  97. foreach($itemsList as $key => $items)
  98. {
  99. if(empty($items)) continue;
  100. $ul = zui::sortable
  101. (
  102. set::_tag('ul'),
  103. set::_class("{$key}-cols pl-0")
  104. );
  105. foreach($items as $item) $ul->add(buildItem($item));
  106. $body->add($ul);
  107. }
  108. $body->setProp('data-zin-gid', $body->gid);
  109. jsVar('formGID', $body->gid);
  110. return $body;
  111. }
  112. setClass('edit-cols');
  113. set::title($lang->datatable->custom);
  114. to::header(span($lang->datatable->customTip, setClass('text-gray', 'text-md')));
  115. set::footerClass('justify-center');
  116. buildBody($cols);
  117. to::footer
  118. (
  119. toolbar
  120. (
  121. btn
  122. (
  123. setClass('toolbar-item w-28'),
  124. set::type('primary'),
  125. on::click('handleEditColsSubmit'),
  126. $lang->save
  127. )
  128. )
  129. );
  130. render();