control.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <?php
  2. /**
  3. * The view file of datatable module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2014-2014 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license business(商业软件)
  7. * @author Hao sun <sunhao@cnezsoft.com>
  8. * @package datatable
  9. * @version $Id$
  10. * @link https://www.zentao.net
  11. */
  12. class datatable extends control
  13. {
  14. /**
  15. * 设置列表页是否显示模块名。
  16. * Set display.
  17. *
  18. * @param string $datatableID
  19. * @param string $moduleName
  20. * @param string $methodName
  21. * @param string $currentModule
  22. * @param string $currentMethod
  23. * @access public
  24. * @return void
  25. */
  26. public function ajaxDisplay($datatableID, $moduleName, $methodName, $currentModule, $currentMethod)
  27. {
  28. $this->loadModel($currentModule);
  29. if($moduleName == 'execution' && $methodName == 'task' && $this->config->vision != 'lite') $this->view->execution = $this->execution->getByID($this->session->execution);
  30. $this->view->datatableID = $datatableID;
  31. $this->view->moduleName = $moduleName;
  32. $this->view->methodName = $methodName;
  33. $this->view->currentModule = $currentModule;
  34. $this->view->currentMethod = $currentMethod;
  35. $this->render();
  36. }
  37. /**
  38. * 保存列表页是否显示模块名的配置项。
  39. * Save config
  40. *
  41. * @access public
  42. * @return void
  43. */
  44. public function ajaxSave()
  45. {
  46. if(!empty($_POST))
  47. {
  48. $account = $this->app->user->account;
  49. if($account == 'guest') return $this->send(array('result' => 'fail', 'message' => 'guest.'));
  50. $module = $this->post->currentModule;
  51. $method = $this->post->currentMethod;
  52. $this->app->checkModuleName($module);
  53. $this->app->checkMethodName($method);
  54. $this->loadModel('setting')->setItem($account . '.' . $module . '.' . $method . '.showModule', $this->post->value);
  55. if($this->post->allModule !== false) $this->setting->setItem("$account.execution.task.allModule", $this->post->allModule);
  56. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
  57. return $this->send(array('result' => 'success', 'closeModal' => true, 'load' => true));
  58. }
  59. }
  60. /**
  61. * 自定义列页面保存配置。
  62. * Ajax save fields.
  63. *
  64. * @param string $module
  65. * @param string $method
  66. * @param string $extra
  67. * @access public
  68. * @return void
  69. */
  70. public function ajaxSaveFields($module, $method, $extra = '')
  71. {
  72. if(!empty($_POST))
  73. {
  74. $account = $this->app->user->account;
  75. if($account == 'guest') return $this->send(array('result' => 'fail', 'message' => 'guest.'));
  76. $rawModule = zget($this->config->datatable->moduleAlias, "$module-$method", $module);
  77. if($rawModule == 'story' && $extra && $rawModule != $extra) $rawModule = $extra;
  78. $cols = $this->datatable->getSetting($module, $method, true, $extra);
  79. $postFields = json_decode($this->post->fields);
  80. /* 生成配置信息。 */
  81. $fields = array();
  82. $attrs = array('order', 'width', 'show', 'extraWidth', 'border'); // 需要保存的配置属性。
  83. foreach($cols as $id => $col)
  84. {
  85. $fields[$id] = array();
  86. foreach($attrs as $attr)
  87. {
  88. if($attr == 'show' && isset($col['required']) && $col['required']) $col['show'] = true;
  89. if(!isset($col[$attr])) continue;
  90. $fields[$id][$attr] = $col[$attr];
  91. }
  92. }
  93. foreach($postFields as $field)
  94. {
  95. $id = $field->id;
  96. if($module == 'testcase' && $id == 'caseID') $id = 'id';
  97. if(!isset($fields[$id])) continue;
  98. foreach($attrs as $attr)
  99. {
  100. if(!isset($field->$attr)) continue;
  101. if($attr == 'show') $field->$attr = $field->$attr ? true : false;
  102. $fields[$id][$attr] = $field->$attr;
  103. }
  104. }
  105. $name = 'datatable.' . $module . ucfirst($method) . '.cols';
  106. $value = json_encode($fields);
  107. /* Split story and requirement custom fields. */
  108. if(("$module-$method" == 'product-browse') && in_array($extra, array('story', 'requirement', 'epic'))) $name = 'datatable.' . $module . ucfirst($method) . ucfirst($extra) . '.cols';
  109. /* 保存个人配置信息。 */
  110. $this->loadModel('setting')->setItem($account . '.' . $name, $value);
  111. /* 保存全局配置信息。 */
  112. if($this->post->global) $this->setting->setItem('system.' . $name, $value);
  113. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => 'dao error.'));
  114. $load = "$module-$method" == 'my-effort' ? $this->createLink('my', 'effort') : true;
  115. return $this->send(array('result' => 'success', 'closeModal' => true, 'load' => $load));
  116. }
  117. }
  118. /**
  119. * 自定义列配置页面。
  120. * custom fields.
  121. *
  122. * @param string $module
  123. * @param string $method
  124. * @param string $extra
  125. * @access public
  126. * @return void
  127. */
  128. public function ajaxCustom($module, $method, $extra = '')
  129. {
  130. $cols = $this->datatable->getSetting($module, $method, true, $extra);
  131. if(!$method) $method = $this->app->getMethodName();
  132. if($module == 'testcase')
  133. {
  134. unset($cols['assignedTo']);
  135. unset($cols['product']);
  136. unset($cols['module']);
  137. }
  138. if($module == 'bug')
  139. {
  140. unset($cols['product']);
  141. unset($cols['module']);
  142. }
  143. if(zget($this->config->datatable->moduleAlias, "$module-$method", $module) == 'story')
  144. {
  145. unset($cols['product'], $cols['module']);
  146. if($extra != 'story')
  147. {
  148. foreach(array('taskCount', 'bugCount', 'caseCount') as $field) unset($cols[$field]);
  149. $cols['title']['title'] = $cols['title']['title'] = $this->lang->story->name;
  150. }
  151. if($this->app->tab != 'product') $cols['title']['title'] = $this->lang->story->name;
  152. }
  153. if(($module == 'productplan' && $method == 'browse') || ($module == 'project' && $method == 'bug'))
  154. {
  155. $branchField = $module == 'productplan' ? 'branchName' : 'branch';
  156. if($this->session->currentProductType == 'normal')
  157. {
  158. unset($cols[$branchField]);
  159. }
  160. else
  161. {
  162. $this->app->loadLang('product');
  163. $cols[$branchField]['title'] = sprintf($this->lang->product->branch, $this->lang->product->branchName[$this->session->currentProductType]);
  164. }
  165. }
  166. if($module == 'project' && $method == 'bug')
  167. {
  168. $project = $this->loadModel('project')->getByID($this->session->project);
  169. if(!$project->multiple) unset($cols['execution']);
  170. if(!$project->hasProduct && ($project->model != 'scrum' || !$project->multiple)) unset($cols['plan']);
  171. if(!$project->hasProduct) unset($cols['branch']);
  172. }
  173. if($module == 'execution' && $method == 'bug')
  174. {
  175. unset($cols['execution']);
  176. unset($cols['branch']);
  177. $execution = $this->loadModel('execution')->getByID($this->session->execution);
  178. $project = $this->loadModel('project')->getByID($execution->project);
  179. if(!$project->hasProduct && $project->model != 'scrum') unset($cols['plan']);
  180. if(!$project->hasProduct) unset($cols['branch']);
  181. }
  182. if($module == 'execution' && $method == 'story')
  183. {
  184. $execution = $this->loadModel('execution')->getByID($this->session->execution);
  185. if(!$execution->hasProduct && !$execution->multiple) unset($cols['plan']);
  186. if(!$execution->hasProduct) unset($cols['branch']);
  187. }
  188. if($module == 'project' && $method == 'execution')
  189. {
  190. $project = $this->datatable->fetchByID($this->session->project, 'project');
  191. if(!empty($project->isTpl)) unset($cols['deliverable']);
  192. }
  193. if($module == 'deliverable')
  194. {
  195. $hasProcess = $this->loadModel('workflowgroup')->hasFeature((int)$extra, 'process');
  196. if(!$hasProcess) unset($cols['activity'], $cols['trimmable'], $cols['trimRule']);
  197. }
  198. if($extra == 'unsetStory' && isset($cols['story'])) unset($cols['story']);
  199. if($this->config->edition == 'ipd' && $module == 'product' && $method == 'browse' && $extra == 'story') unset($cols['roadmap']);
  200. if($this->app->tab == 'project' && !$this->session->multiple && $module == 'meeting' && $method == 'browse') unset($cols['execution']);
  201. $this->view->module = $module;
  202. $this->view->method = $method;
  203. $this->view->cols = $cols;
  204. $this->view->extra = $extra;
  205. $this->display();
  206. }
  207. /**
  208. * Save config
  209. *
  210. * @access public
  211. * @return void
  212. */
  213. public function ajaxOldSave()
  214. {
  215. if(!empty($_POST))
  216. {
  217. $account = $this->app->user->account;
  218. if($account == 'guest') return $this->send(array('result' => 'fail', 'target' => $target, 'message' => 'guest.'));
  219. $name = 'datatable.' . $this->post->target . '.' . $this->post->name;
  220. $this->loadModel('setting')->setItem($account . '.' . $name, $this->post->value);
  221. if($this->post->allModule !== false) $this->setting->setItem("$account.execution.task.allModule", $this->post->allModule);
  222. if($this->post->showBranch !== false) $this->setting->setItem($account . '.' . $this->post->currentModule . '.' . $this->post->currentMethod . '.showBranch', $this->post->showBranch);
  223. if($this->post->global) $this->setting->setItem('system.' . $name, $this->post->value);
  224. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => 'dao error.'));
  225. return $this->send(array('result' => 'success'));
  226. }
  227. }
  228. /**
  229. * custom fields.
  230. *
  231. * @param string $module
  232. * @param string $method
  233. * @param string $extra
  234. * @access public
  235. * @return void
  236. */
  237. public function ajaxOldCustom($module, $method, $extra = '')
  238. {
  239. $moduleName = $module;
  240. $target = $module . ucfirst($method);
  241. $mode = isset($this->config->datatable->$target->mode) ? $this->config->datatable->$target->mode : 'table';
  242. $key = $mode == 'datatable' ? 'cols' : 'tablecols';
  243. if($module == 'testtask')
  244. {
  245. $this->loadModel('testcase');
  246. $this->app->loadConfig('testtask');
  247. $this->config->testcase->datatable->defaultField = $this->config->testtask->datatable->defaultField;
  248. $this->config->testcase->datatable->fieldList['actions']['width'] = '100';
  249. $this->config->testcase->datatable->fieldList['status']['width'] = '90';
  250. }
  251. if($module == 'testcase')
  252. {
  253. $this->loadModel('testcase');
  254. unset($this->config->testcase->datatable->fieldList['assignedTo']);
  255. }
  256. $this->view->module = $module;
  257. $this->view->method = $method;
  258. $this->view->mode = $mode;
  259. $module = zget($this->config->datatable->moduleAlias, "$module-$method", $module);
  260. $setting = '';
  261. if(isset($this->config->datatable->$target->$key)) $setting = $this->config->datatable->$target->$key;
  262. if(empty($setting))
  263. {
  264. $this->loadModel($module);
  265. $setting = json_encode($this->config->$module->datatable->defaultField);
  266. }
  267. $cols = $this->datatable->getOldFieldList($module);
  268. if($module == 'story' && $extra != 'requirement') unset($cols['SRS']);
  269. if($extra == 'requirement')
  270. {
  271. unset($cols['plan']);
  272. unset($cols['stage']);
  273. unset($cols['taskCount']);
  274. unset($cols['bugCount']);
  275. unset($cols['caseCount']);
  276. unset($cols['URS']);
  277. $cols['title']['title'] = str_replace($this->lang->SRCommon, $this->lang->URCommon, $this->lang->story->title);
  278. }
  279. if($moduleName == 'project' and $method == 'bug')
  280. {
  281. $project = $this->loadModel('project')->getByID($this->session->project);
  282. if(!$project->multiple) unset($cols['execution']);
  283. if(!$project->hasProduct and $project->model != 'scrum') unset($cols['plan']);
  284. if(!$project->hasProduct) unset($cols['branch']);
  285. }
  286. if($moduleName == 'execution' and $method == 'bug')
  287. {
  288. $execution = $this->loadModel('execution')->getByID($this->session->execution);
  289. $project = $this->loadModel('project')->getByID($execution->project);
  290. if(!$project->hasProduct and $project->model != 'scrum') unset($cols['plan']);
  291. if(!$project->hasProduct) unset($cols['branch']);
  292. }
  293. if($moduleName == 'execution' and $method == 'story')
  294. {
  295. $execution = $this->loadModel('execution')->getByID($this->session->execution);
  296. if(!$execution->hasProduct and !$execution->multiple) unset($cols['plan']);
  297. if(!$execution->hasProduct) unset($cols['branch']);
  298. }
  299. if($moduleName == 'auditplan' && $this->app->tab == 'project' && !$this->session->multiple) unset($cols['execution']);
  300. if($extra == 'unsetStory' and isset($cols['story'])) unset($cols['story']);
  301. $this->view->cols = $cols;
  302. $this->view->setting = $setting;
  303. $this->display();
  304. }
  305. /**
  306. * 恢复自定义项为默认配置。
  307. * Ajax reset cols.
  308. *
  309. * @param string $module
  310. * @param string $method
  311. * @param int $system
  312. * @param string $confirm
  313. * @param string $extra
  314. * @access public
  315. * @return void
  316. */
  317. public function ajaxReset($module, $method, $system = 0, $confirm = 'no', $extra = '')
  318. {
  319. if($confirm != 'yes')
  320. {
  321. $confirmURL = $this->createLink('datatable', 'ajaxreset', "module={$module}&method={$method}&system={$system}&confirm=yes&extra={$extra}");
  322. $tip = (int)$system ? $this->lang->datatable->confirmGlobalReset : $this->lang->datatable->confirmReset;
  323. return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.confirm({message: '{$tip}', icon: 'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) => {if(res) $.ajaxSubmit({url: '$confirmURL'});});"));
  324. }
  325. $account = !$system ? $this->app->user->account : "system,{$this->app->user->account}";
  326. $target = $module . ucfirst($method);
  327. $this->loadModel('setting')->deleteItems("owner={$account}&module=datatable&section={$target}&key=cols");
  328. /* Delete story and requirement custom fields. */
  329. if(strpos(',product-browse,execution-story,', ",$module-$method,") !== false)
  330. {
  331. $extra = in_array($extra, array('story', 'requirement', 'epic')) ? ucfirst($extra) : 'Story';
  332. $section = $module . ucfirst($method) . $extra;
  333. $this->loadModel('setting')->deleteItems("owner={$account}&module=datatable&section={$section}&key=cols");
  334. }
  335. return $this->send(array('result' => 'success', 'load' => true, 'callback' => "$('#table-$module-$method,[zui-create-dtable]').first().closest('[z-use-dtable]').attr('zui-create-dtable', '')"));
  336. }
  337. /**
  338. * Ajax reset old cols.
  339. *
  340. * @param string $module
  341. * @param string $method
  342. * @param int $system
  343. * @param string $confirm
  344. * @access public
  345. * @return void
  346. */
  347. public function ajaxOldReset($module, $method, $system = 0, $confirm = 'no')
  348. {
  349. if($confirm == 'no') return print(js::confirm($this->lang->datatable->confirmReset, inlink('ajaxOldReset', "module=$module&method=$method&system=$system&confirm=yes")));
  350. $account = $this->app->user->account;
  351. $target = $module . ucfirst($method);
  352. $mode = isset($this->config->datatable->$target->mode) ? $this->config->datatable->$target->mode : 'table';
  353. $key = $mode == 'datatable' ? 'cols' : 'tablecols';
  354. $this->loadModel('setting')->deleteItems("owner=$account&module=datatable&section=$target&key=$key");
  355. if($system) $this->setting->deleteItems("owner=system&module=datatable&section=$target&key=$key");
  356. return print(js::reload('parent'));
  357. }
  358. /**
  359. * 应用自定义列配置到全局。
  360. * Ajax save setting to global.
  361. *
  362. * @param string $module
  363. * @param string $method
  364. * @param string $extra
  365. * @param string $confirm
  366. * @access public
  367. * @return void
  368. */
  369. public function ajaxSaveGlobal($module, $method, $extra = '', $confirm = 'no')
  370. {
  371. if($confirm != 'yes')
  372. {
  373. $confirmURL = $this->createLink('datatable', 'ajaxsaveglobal', "module={$module}&method={$method}&extra={$extra}&confirm=yes");
  374. $tip = $this->lang->datatable->confirmSetGlobal;
  375. return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.confirm({message: '{$tip}', icon: 'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) => {if(res) $.ajaxSubmit({url: '$confirmURL'});});"));
  376. }
  377. $target = $module . ucfirst($method);
  378. if(strpos(',product-browse,execution-story,', ",$module-$method,") !== false && strpos(',story,requirement,epic,', ",$extra,") !== false) $target .= ucfirst($extra);
  379. $settings = isset($this->config->datatable->$target->cols) ? $this->config->datatable->$target->cols : '';
  380. if(!empty($settings)) $this->loadModel('setting')->setItem("system.datatable.{$target}.cols", $settings);
  381. return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess));
  382. }
  383. }