browse.html.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * The browse view file of dept module of ZenTaoPMS.
  4. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  5. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  6. * @author Mengyi Liu <liumengyi@easycorp.ltd>
  7. * @package dept
  8. * @link https://www.zentao.net
  9. */
  10. namespace zin;
  11. $processTreeAction = function($tree) use (&$processTreeAction)
  12. {
  13. global $lang;
  14. $canEditDept = hasPriv('dept', 'edit');
  15. $canDeleteDept = hasPriv('dept', 'delete');
  16. $canSortDept = hasPriv('dept', 'updateOrder');
  17. foreach($tree as $node)
  18. {
  19. $actions = array();
  20. if($canSortDept) $actions[] = array('key' => 'sort', 'icon' => 'move', 'hint' => $lang->dept->order, 'onClick' => jsRaw('window.operateDept'));
  21. if($canEditDept) $actions[] = array('key' => 'edit', 'icon' => 'edit', 'hint' => $lang->dept->edit, 'onClick' => jsRaw('window.operateDept'));
  22. if(empty($node->items) && $canDeleteDept) $actions[] = array('key' => 'delete', 'icon' => 'trash', 'hint' => $lang->dept->delete, 'onClick' => jsRaw('window.operateDept'));
  23. if(!empty($node->items)) $node->items = $processTreeAction($node->items);
  24. $node->actions = $actions;
  25. }
  26. return $tree;
  27. };
  28. $tree = $processTreeAction($tree);
  29. $parentNames = array();
  30. foreach($parentDepts as $dept)
  31. {
  32. $parentNames[] = cell
  33. (
  34. setClass('flex items-center'),
  35. a
  36. (
  37. set::title($dept->name),
  38. set::href(common::isTutorialMode() ? null : createLink('dept', 'browse', "deptID={$dept->id}")),
  39. $dept->name
  40. ),
  41. icon
  42. (
  43. setClass('mx-2'),
  44. 'angle-right'
  45. )
  46. );
  47. }
  48. $maxOrder = 0;
  49. $deptInputs = array();
  50. foreach($sons as $dept)
  51. {
  52. if($dept->order > $maxOrder) $maxOrder = $dept->order;
  53. $deptInputs[] = formGroup
  54. (
  55. setClass('w-full my-1'),
  56. set::name("depts[id{$dept->id}]"),
  57. set::value($dept->name)
  58. );
  59. }
  60. $emptyInputs = array();
  61. for($i = 0; $i < $config->dept->newChildCount; $i ++)
  62. {
  63. $emptyInputs[] = formGroup
  64. (
  65. setClass('w-full my-1'),
  66. set::name("depts[]"),
  67. set::value('')
  68. );
  69. }
  70. jsVar('editLinkTemp', createLink('dept', 'edit', "deptID={id}"));
  71. jsVar('deleteLinkTemp', createLink('dept', 'delete', "deptID={id}"));
  72. jsVar('deleteTip', $lang->dept->confirmDelete);
  73. sidebar
  74. (
  75. set::width(360),
  76. set::showToggle(false),
  77. panel
  78. (
  79. set::title($title),
  80. tree
  81. (
  82. set::id('deptTree'),
  83. set::items($tree),
  84. set::hover(true),
  85. set::sortable(array('handle' => '.icon-move')),
  86. set::onSort(jsRaw('window.onSort'))
  87. )
  88. )
  89. );
  90. panel
  91. (
  92. set::title($lang->dept->manageChild),
  93. set::titleClass('text-base'),
  94. form
  95. (
  96. set('action', createLink('dept', 'manageChild')),
  97. cell
  98. (
  99. setClass('flex'),
  100. cell
  101. (
  102. setClass('flex flex-none flex-wrap px-2'),
  103. cell
  104. (
  105. setClass('flex items-center'),
  106. a
  107. (
  108. set::title($this->app->company->name),
  109. set::href(common::isTutorialMode() ? null : createLink('dept', 'browse')),
  110. $this->app->company->name
  111. ),
  112. icon('angle-right')
  113. ),
  114. $parentNames
  115. ),
  116. cell
  117. (
  118. setClass('flex flex-wrap p-2'),
  119. width('500px'),
  120. $deptInputs,
  121. $emptyInputs,
  122. formGroup
  123. (
  124. setClass('hidden'),
  125. set::name('maxOrder'),
  126. set::value($maxOrder)
  127. ),
  128. formGroup
  129. (
  130. setClass('hidden'),
  131. set::name('parentDeptID'),
  132. set::value($deptID)
  133. )
  134. )
  135. )
  136. )
  137. );
  138. render();