browsetask.html.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php
  2. /**
  3. * The browse view file of tree module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2015 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Chunsheng Wang <chunsheng@cnezsoft.com>
  8. * @package tree
  9. * @version $Id: browse.html.php 4796 2013-06-06 02:21:59Z zhujinyonging@gmail.com $
  10. * @link http://www.zentao.net
  11. */
  12. ?>
  13. <?php include $this->app->getModuleRoot() . 'common/view/header.html.php';?>
  14. <?php js::set('tab', $app->tab);?>
  15. <style>
  16. li.story-item > .tree-actions .tree-action[data-type=sort] {display: none;}
  17. li.story-item > .tree-actions .tree-action[data-type=edit] {display: none;}
  18. li.story-item > .tree-actions .tree-action[data-type=delete] {display: none;}
  19. #modulesTree li.dragging {opacity: .3;}
  20. </style>
  21. <div id="mainMenu" class="clearfix">
  22. <div class="btn-toolbar pull-left">
  23. <?php $backLink = $this->session->taskList ? $this->session->taskList : 'javascript:history.go(-1)';?>
  24. <a href="<?php echo $backLink;?>" class="btn btn-secondary">
  25. <i class="icon icon-back icon-sm"></i> <?php echo $lang->goback;?>
  26. </a>
  27. <div class="divider"></div>
  28. <div class="page-title">
  29. <span class='text' title='<?php echo $root->name;?>'><?php echo $lang->tree->common . $lang->hyphen . $root->name;?></span>
  30. </div>
  31. </div>
  32. </div>
  33. <div id="mainContent" class="main-row">
  34. <div class="side-col col-4">
  35. <div class='panel'>
  36. <div class='panel-heading'>
  37. <div class='panel-title'><?php echo $title;?></div>
  38. </div>
  39. <div class='panel-body'>
  40. <ul id='modulesTree' data-name='tree-task'></ul>
  41. </div>
  42. </div>
  43. </div>
  44. <div class="main-col col-8">
  45. <form id='childrenForm' method='post' target='hiddenwin' action='<?php echo $this->createLink('tree', 'manageChild', "root={$root->id}&viewType=task");?>'>
  46. <div class='panel'>
  47. <div class='panel-heading'>
  48. <div class='panel-title'><?php echo $lang->tree->manageTaskChild;?></div>
  49. </div>
  50. <div class='panel-body'>
  51. <table class='table table-form table-auto'>
  52. <tr>
  53. <td class="text-middle text-right with-padding">
  54. <?php
  55. echo "<span>" . html::a($this->createLink('tree', 'browsetask', "root={$root->id}&productID=$productID&viewType=task"), $root->name, '', "data-app='{$app->tab}'") . "<i class='icon icon-angle-right muted'></i></span>";
  56. foreach($parentModules as $module)
  57. {
  58. echo "<span>" . html::a($this->createLink('tree', 'browsetask', "root={$root->id}&productID=$productID&moduleID=$module->id"), $module->name, '', "data-app='{$app->tab}'") . " <i class='icon icon-angle-right muted'></i></span>";
  59. }
  60. ?>
  61. </td>
  62. <td>
  63. <div id='sonModule'>
  64. <?php $maxOrder = 0;?>
  65. <?php if($newModule and !$productID):?>
  66. <?php foreach($products as $product):?>
  67. <div class="table-row row-module">
  68. <div class="table-col col-module"><?php echo html::input("products[id$product->id]", $product->name, 'class=form-control disabled="true"')?></div>
  69. </div>
  70. <?php endforeach;?>
  71. <?php endif;?>
  72. <?php foreach($sons as $sonModule):?>
  73. <?php
  74. if($sonModule->order > $maxOrder) $maxOrder = $sonModule->order;
  75. $disabled = $sonModule->type == 'task' ? '' : 'disabled';
  76. ?>
  77. <div class='table-row row-module'>
  78. <div class='table-col col-module'><?php echo html::input("modules[id$sonModule->id]", $sonModule->name, "class='form-control' placeholder='{$lang->tree->name}' $disabled")?></div>
  79. <div class='table-col col-shorts'>
  80. <?php
  81. echo html::input("shorts[id$sonModule->id]", $sonModule->short, "class='form-control' placeholder='{$lang->tree->short}' $disabled");
  82. echo html::hidden("order[id$sonModule->id]", $sonModule->order);
  83. ?>
  84. </div>
  85. <div class="table-col col-actions"> </div>
  86. </div>
  87. <?php endforeach;?>
  88. <?php for($i = 0; $i < TREE::NEW_CHILD_COUNT ; $i ++):?>
  89. <div class="table-row row-module row-module-new">
  90. <div class='table-col col-module'><?php echo html::input("modules[]", '', "class='form-control' placeholder='{$lang->tree->name}'")?></div>
  91. <div class='table-col col-shorts'><?php echo html::input("shorts[]", '', "class='form-control' placeholder='{$lang->tree->short}'")?></div>
  92. <div class="table-col col-actions">
  93. <button type="button" class="btn btn-link btn-icon btn-add" onclick="addItem(this)"><i class="icon icon-plus"></i></button>
  94. <button type="button" class="btn btn-link btn-icon btn-delete" onclick="deleteItem(this)"><i class="icon icon-close"></i></button>
  95. </div>
  96. <?php echo html::hidden('branch[]', empty($module) ? 0 : $module->branch);?>
  97. </div>
  98. <?php endfor;?>
  99. </div>
  100. <div id="insertItemBox" class="template">
  101. <div class="table-row row-module row-module-new">
  102. <div class="table-col col-module"><?php echo html::input("modules[]", '', "class='form-control' placeholder='{$lang->tree->name}'");?></div>
  103. <div class="table-col col-shorts"><?php echo html::input("shorts[]", '', "class='form-control' placeholder='{$lang->tree->short}'");?></div>
  104. <div class="table-col col-actions">
  105. <button type="button" class="btn btn-link btn-icon btn-add" onclick="addItem(this)"><i class="icon icon-plus"></i></button>
  106. <button type="button" class="btn btn-link btn-icon btn-delete" onclick="deleteItem(this)"><i class="icon icon-close"></i></button>
  107. </div>
  108. <?php echo html::hidden('branch[]', empty($module) ? 0 : (int)$module->branch);?>
  109. </div>
  110. </div>
  111. </td>
  112. </tr>
  113. <tr>
  114. <td></td>
  115. <td colspan='2' class="form-actions">
  116. <?php
  117. if($canBeChanged) echo html::submitButton();
  118. echo html::a($backLink, $lang->goback, '', "class='btn btn-wide'");
  119. echo html::hidden('parentModuleID', $currentModuleID);
  120. echo html::hidden('maxOrder', $maxOrder);
  121. ?>
  122. <input type='hidden' value='<?php echo $currentModuleID;?>' name='parentModuleID' />
  123. </td>
  124. </tr>
  125. </table>
  126. </div>
  127. </div>
  128. </form>
  129. </div>
  130. </div>
  131. <script>
  132. function getTree(data)
  133. {
  134. var tree = [];
  135. $.each(data,function(index, value){
  136. if(value.type === 'product')
  137. {
  138. for (var child of value.children) tree.push(child);
  139. }
  140. else
  141. {
  142. tree.push(value);
  143. }
  144. });
  145. return tree;
  146. }
  147. $(function()
  148. {
  149. var data = $.parseJSON('<?php echo helper::jsonEncode4Parse($tree);?>');
  150. data = getTree(data);
  151. var options = {
  152. initialState: 'preserve',
  153. data: data,
  154. itemCreator: function($li, item)
  155. {
  156. var $toggle = $('<span class="module-name" data-id="' + item.id + '">' + link + '</span>');
  157. var title = (item.type === 'product' ? '<i class="icon icon-product text-muted"></i> ' : '') + item.name;
  158. var link = item.id !== undefined ? ('<a data-app=' + tab + ' href="' + createLink('tree', 'browsetask', 'rootID=<?php echo $rootID ?>&viewType=task&moduleID={0}'.format(item.id)) + '">' + title + '</a>') : ('<span class="tree-toggle">' + title + '</span>');
  159. var $toggle = $('<span class="module-name" data-id="' + item.id + '">' + link + '</span>');
  160. if(item.type === 'task')
  161. {
  162. $li.addClass('task-item');
  163. }
  164. if(item.type === 'story') $li.addClass('story-item');
  165. $li.append($toggle);
  166. if(item.nodeType) $li.addClass('tree-item-' + item.nodeType);
  167. return true;
  168. },
  169. actions:
  170. {
  171. sort:
  172. {
  173. title: '<?php echo $lang->tree->dragAndSort ?>',
  174. template: '<a class="sort-handler" href="javascript:;"><i class="icon icon-move"></i></a>'
  175. },
  176. edit:
  177. {
  178. linkTemplate: '<?php echo helper::createLink('tree', 'edit', "moduleID={0}&type=task"); ?>',
  179. title: '<?php echo $lang->tree->edit ?>',
  180. template: '<a href="javascript:;"><i class="icon icon-edit"></i></a>'
  181. },
  182. "delete":
  183. {
  184. linkTemplate: '<?php echo helper::createLink('tree', 'delete', "rootID=$rootID&moduleID={0}"); ?>',
  185. title: '<?php echo $lang->tree->delete ?>',
  186. template: '<a href="javascript:;"><i class="icon icon-trash"></i></a>'
  187. },
  188. subModules:
  189. {
  190. linkTemplate: '<?php echo helper::createLink('tree', 'browsetask', "rootID=$rootID&viewType=task&moduleID={0}"); ?>',
  191. title: '<?php echo $lang->tree->child ?>',
  192. template: '<a href="javascript:;"><i class="icon icon-split"></i></a>'
  193. }
  194. },
  195. action: function(event)
  196. {
  197. var action = event.action, $target = $(event.target), item = event.item;
  198. if(action.type === 'edit')
  199. {
  200. new $.zui.ModalTrigger({
  201. type: 'ajax',
  202. url: action.linkTemplate.format(item.id),
  203. keyboard: true
  204. }).show();
  205. }
  206. else if(action.type === 'delete')
  207. {
  208. hiddenwin.location.href = action.linkTemplate.format(item.id);
  209. }
  210. else if(action.type === 'add')
  211. {
  212. window.location.href = action.linkTemplate.format(item.id);
  213. }
  214. else if(action.type === 'sort')
  215. {
  216. var orders = {};
  217. $('#modulesTree').find('li:not(.tree-action-item)').each(function()
  218. {
  219. var $li = $(this);
  220. var item = $li.data();
  221. orders['orders[' + item.id + ']'] = $li.attr('data-order') || item.order;
  222. });
  223. $.post('<?php echo $this->createLink('tree', 'updateOrder', "root={$root->id}&viewType=task");?>', orders, function(data)
  224. {
  225. $('.main-col').load(location.href + ' .main-col .panel');
  226. }).error(function()
  227. {
  228. bootbox.alert(lang.timeout);
  229. });
  230. }
  231. else if(action.type === 'subModules')
  232. {
  233. window.location.href = action.linkTemplate.format(item.id, item.branch);
  234. }
  235. }
  236. };
  237. if(<?php echo (common::hasPriv('tree', 'updateorder') and $canBeChanged) ? 'false' : 'true' ?>) options.actions["sort"] = false;
  238. if(<?php echo (common::hasPriv('tree', 'edit') and $canBeChanged) ? 'false' : 'true' ?>) options.actions["edit"] = false;
  239. if(<?php echo (common::hasPriv('tree', 'delete') and $canBeChanged) ? 'false' : 'true' ?>) options.actions["delete"] = false;
  240. if(<?php echo $canBeChanged ? 'false' : 'true' ?>) options.actions["subModules"] = false;
  241. var $tree = $('#modulesTree').tree(options);
  242. var tree = $tree.data('zui.tree');
  243. if(!tree.store.time) tree.expand($tree.find('li:not(.tree-action-item)').first());
  244. <?php if($currentModuleID): ?>
  245. var $currentLi = $tree.find('.module-name[data-id=' + <?php echo $currentModuleID ?> + ']').closest('li');
  246. if($currentLi.length) tree.show($currentLi);
  247. <?php endif; ?>
  248. $tree.on('mouseenter', 'li:not(.tree-action-item)', function(e)
  249. {
  250. $('#modulesTree').find('li.hover').removeClass('hover');
  251. $(this).addClass('hover');
  252. e.stopPropagation();
  253. });
  254. $tree.find('[data-toggle="tooltip"]').tooltip();
  255. });
  256. </script>
  257. <?php include $this->app->getModuleRoot() . 'common/view/footer.html.php';?>