create.html.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?php
  2. /**
  3. * Create view of program plan 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 chen.tao <chentao@easycorp.ltd>
  8. * @package programplan
  9. * @link https://www.zentao.net
  10. */
  11. namespace zin;
  12. include($this->app->getModuleRoot() . 'ai/ui/inputinject.html.php');
  13. $fields = $this->config->programplan->form->create;
  14. $reviewedPoints = isset($reviewedPoints) ? $reviewedPoints : array();
  15. $canParallel = isset($canParallel) ? $canParallel : false;
  16. $customKey = 'createFields';
  17. $section = 'custom';
  18. unset($fields['level']);
  19. /* Generate custom config key by project model. */
  20. if(in_array($project->model, array('waterfallplus', 'ipd', 'waterfall'))) $customKey = 'create' . ucfirst($project->model) . 'Fields';
  21. if($executionType == 'agileplus')
  22. {
  23. $section = 'customAgilePlus';
  24. $customKey = 'createFields';
  25. }
  26. /* Generate title that is tailored to specific situation. */
  27. $title = $lang->programplan->create;
  28. if($planID)
  29. {
  30. $title = $programPlan->name . $lang->project->stage . '(' . $programPlan->begin . $lang->project->to . $programPlan->end . ')';
  31. }
  32. else
  33. {
  34. $project->end = $project->end == LONG_TIME ? $this->lang->project->longTime : $project->end;
  35. $title .= '(' . $project->name . '-' . $lang->execution->beginAndEnd . ' : ' . $project->begin . ' ~ ' . $project->end . ')';
  36. }
  37. /* Generate product list dropdown menu while stage by product. */
  38. $fnGenerateStageByProductList = function() use ($productID, $productList, $project, $planID, $syncData)
  39. {
  40. if(empty($productList) || $project->stageBy != 'product') return null;
  41. $defaultName = $productID != 0 ? zget($productList,$productID) : current($productList);
  42. $items = array();
  43. foreach($productList as $key => $product)
  44. {
  45. $items[] = array('text' => $product, 'active' => $productID == $key, 'url' => createLink('programplan', 'create', "projectID=$project->id&productID=$key&planID=$planID&executionType=stage&from=&syncData={$syncData}"));
  46. }
  47. return dropdown($defaultName, span(setClass('caret')), set::items($items));
  48. };
  49. /* Generate checkboxes for sub-stage management. */
  50. $fnGenerateSubPlanManageFields = function() use ($lang, $planID, $project, $canParallel)
  51. {
  52. if(!(empty($planID) && $project->model == 'ipd')) return div();
  53. foreach($lang->programplan->parallelList as $key => $value)
  54. {
  55. $items[] = div(setClass('px-1'), checkbox
  56. (
  57. set::type('radio'),
  58. set::name('parallel'),
  59. set::text($value),
  60. set::value($key),
  61. set::checked($key == $project->parallel),
  62. set::disabled($canParallel),
  63. on::change('window.onChangeParallel')
  64. ));
  65. }
  66. return div
  67. (
  68. setClass('flex w-1/2 items-center'),
  69. div(setClass('font-bold'), $lang->programplan->parallel . ':'),
  70. $items,
  71. html($lang->programplan->parallelTip)
  72. );
  73. };
  74. /* Generate form fields. */
  75. $fnGenerateFields = function() use ($lang, $requiredFields, $showFields, $fields, $PMUsers, $enableOptionalAttr, $programPlan, $planID, $project, $syncData, $app)
  76. {
  77. $items = array();
  78. $isEn = $app->getClientLang() == 'en';
  79. $fields['attribute']['required'] = $fields['acl']['required'] = true;
  80. if(isset($requiredFields['code'])) $fields['code']['required'] = true;
  81. $renderFields = implode(',', array_keys($requiredFields));
  82. $renderFields = ",$renderFields,$showFields,";
  83. foreach($fields as $name => $field)
  84. {
  85. $field['name'] = $name;
  86. if($name == 'id')
  87. {
  88. $field['control'] = 'hidden';
  89. $field['hidden'] = true;
  90. }
  91. if(!empty($field['default'])) $field['value'] = $field['default'];
  92. /* Convert 'options' to 'items'. */
  93. if(!empty($field['options'])) $field['items'] = $field['options'];
  94. unset($field['options']);
  95. /* Assgn item data to PM field. */
  96. if($name == 'PM') $field['items'] = $PMUsers;
  97. if($name == 'syncData') $field['value'] = $syncData;
  98. /* Set hidden attribute. */
  99. if(strpos($renderFields, ",$name,") === false) $field['hidden'] = true;
  100. /* Sub-stage. */
  101. if($name == 'attribute')
  102. {
  103. if(!$enableOptionalAttr) $field['disabled'] = true;
  104. if($programPlan) $field['value'] = $programPlan->attribute;
  105. if($isEn) $field['width'] = '150px';
  106. }
  107. if($name == 'acl' && $planID)
  108. {
  109. $field['disabled'] = true;
  110. $field['value'] = empty($programPlan) ? 'open' : $programPlan->acl;
  111. }
  112. /* Field for agileplus. */
  113. if($name == 'type' && in_array($project->model, array('waterfallplus', 'ipd')))
  114. {
  115. $field['hidden'] = false;
  116. $field['items'] = $lang->execution->typeList;
  117. if($project->model == 'waterfallplus')
  118. {
  119. $field['tipIcon'] = 'help';
  120. $field['tip'] = $lang->programplan->typeTip;
  121. $field['tipProps'] = array
  122. (
  123. 'id' => 'tooltipHover',
  124. 'data-toggle' => 'tooltip',
  125. 'data-placement' => 'right',
  126. 'data-type' => 'white',
  127. 'data-class-name' => 'text-gray border border-gray-300'
  128. );
  129. }
  130. }
  131. if($name == 'attribute' && in_array($project->model, array('waterfall', 'waterfallplus')))
  132. {
  133. $field['tipIcon'] = 'help';
  134. $field['tip'] = $lang->execution->typeTip;
  135. $field['tipProps'] = array
  136. (
  137. 'id' => 'tooltipHover',
  138. 'data-toggle' => 'tooltip',
  139. 'data-placement' => 'right',
  140. 'data-type' => 'white',
  141. 'data-class-name' => 'text-gray border border-gray-300'
  142. );
  143. }
  144. if($name == 'milestone') $field['width'] = '100px';
  145. if($name == 'enabled') $field['width'] = '80px';
  146. if($name == 'point')
  147. {
  148. $field['width'] = '200px';
  149. $field['tipIcon'] = 'help';
  150. $field['tip'] = zget($lang->programplan, 'pointTip', '');
  151. $field['tipProps'] = array
  152. (
  153. 'id' => 'tooltipHover',
  154. 'data-toggle' => 'tooltip',
  155. 'data-placement' => 'right',
  156. 'data-type' => 'white',
  157. 'data-class-name' => 'text-gray border border-gray-300'
  158. );
  159. }
  160. if($name == 'defaultPoint') $field['hidden'] = true;
  161. if($name == 'name') $field['width'] = '240px';
  162. if(!isset($field['width'])) $field['width'] = '120px';
  163. $items[] = $field;
  164. }
  165. return $items;
  166. };
  167. /* Generate default rendering data. */
  168. $fnGenerateDefaultData = function() use ($config, $plans, $planID, $stages, $executionType, $project)
  169. {
  170. $items = array();
  171. /* Created a new project with no stages. */
  172. if(empty($plans) && $planID == 0)
  173. {
  174. foreach($stages as $stage)
  175. {
  176. $TRpoints = isset($stage->pointList['TR']) ? array_keys($stage->pointList['TR']) : array();
  177. $DCPpoints = isset($stage->pointList['DCP']) ? array_keys($stage->pointList['DCP']) : array();
  178. $points = array_merge($TRpoints, $DCPpoints);
  179. $item = new stdClass();
  180. $item->name = $stage->name;
  181. $item->code = isset($stage->code) ? $stage->code : '';
  182. $item->percent = $stage->percent ?: 0;
  183. $item->attribute = $stage->type;
  184. $item->acl = 'open';
  185. $item->milestone = 0;
  186. $item->point = implode(',', $points);
  187. $item->defaultPoint = implode(',', $points);
  188. $item->parallel = 0;
  189. $item->stageID = $stage->id;
  190. $items[] = $item;
  191. }
  192. }
  193. /* Create stages for exist project. */
  194. foreach($plans as $plan)
  195. {
  196. $points = isset($plan->enabledPoints) ? array_keys($plan->enabledPoints) : array();
  197. $item = new stdClass();
  198. $item->disabled = $plan->type != 'stage';
  199. $item->enabled = $plan->enabled;
  200. $item->id = $plan->id;
  201. $item->type = $plan->type;
  202. $item->name = $plan->name;
  203. $item->code = $plan->code;
  204. $item->PM = $plan->PM;
  205. $item->status = $plan->status;
  206. $item->percent = $plan->percent ?: 0;
  207. $item->attribute = $plan->attribute;
  208. $item->acl = $plan->acl;
  209. $item->milestone = $plan->milestone;
  210. $item->begin = $plan->begin;
  211. $item->end = $plan->end;
  212. $item->realBegan = $plan->realBegan;
  213. $item->realEnd = $plan->realEnd;
  214. $item->desc = $plan->desc;
  215. $item->setMilestone = isset($plan->setMilestone) ? $plan->setMilestone : false;
  216. $item->order = $plan->order;
  217. $item->parallel = $plan->parallel;
  218. $item->point = implode(',', $points);
  219. $plan->stageID = $plan->id;
  220. $plan->disabled = !isset($plan->setMilestone);
  221. $plan->setMilestone = isset($plan->setMilestone) ? $plan->setMilestone : false;
  222. $plan->point = implode(',', $points);
  223. if(in_array($config->edition, array('max', 'ipd')) && $executionType == 'stage')
  224. {
  225. $plan->output = empty($plan->output) ? 0 : explode(',', $plan->output);
  226. }
  227. $items[] = $plan;
  228. }
  229. if($project->model != 'ipd' || $planID) $items[] = array();
  230. return $items;
  231. };
  232. /* ZIN: layout. */
  233. jsVar('projectID', $project->id);
  234. jsVar('productID', $productID);
  235. jsVar('planID', $planID);
  236. jsVar('type', $executionType);
  237. jsVar('project', $project);
  238. jsVar('plans', $plans);
  239. jsVar('initType', ($planID && $plans) ? reset($plans)->type : 'stage');
  240. jsVar('planGrade', $programPlan ? $programPlan->grade + 1 : 1);
  241. jsVar('syncData', $syncData);
  242. jsVar('cropStageTip', $lang->programplan->cropStageTip);
  243. jsVar('childEnabledTip', $lang->programplan->childEnabledTip);
  244. jsVar('typeList', $lang->execution->typeList);
  245. jsVar('confirmCreateTip', $lang->project->confirmCreateStage);
  246. jsVar('errorLang', $lang->programplan->error);
  247. jsVar('ipdStagePoint', $project->model == 'ipd' ? $ipdStagePoint : array());
  248. jsVar('attributeList', $project->model == 'ipd' ? $lang->stage->ipdTypeList : $lang->stage->typeList);
  249. jsVar('reviewedPoints', $project->model == 'ipd' ? $reviewedPoints : array());
  250. jsVar('reviewedPointTip', $project->model == 'ipd' ? $lang->programplan->reviewedPointTip : '');
  251. jsVar('addSubTip', $lang->programplan->error->notStage);
  252. jsVar('addSiblingTip', zget($lang->programplan, 'addSiblingTip', ''));
  253. jsVar('sortableTip', zget($lang->programplan, 'sortableTip', ''));
  254. featureBar(li
  255. (
  256. setClass('nav-item'),
  257. a(setClass('active'), $title),
  258. empty($project->isTpl) ? $fnGenerateStageByProductList() : null
  259. ));
  260. toolbar(backBtn(set::icon('back'), setClass('primary'), $lang->goback));
  261. if($project->model == 'ipd' && empty($stages) && empty($plans) && empty($planID))
  262. {
  263. div
  264. (
  265. setClass('dtable-empty-tip bg-white'),
  266. div
  267. (
  268. setClass('row gap-4 items-center'),
  269. div
  270. (
  271. setClass('text-gray'),
  272. $lang->programplan->emptyStageTip
  273. )
  274. )
  275. );
  276. return;
  277. }
  278. $batchFormOptions = array();
  279. $batchFormOptions['fixedActions'] = true; // 滚动时固定操作列。
  280. $batchFormOptions['actions'] = array('sort', array('type' => 'addSibling', 'icon' => 'icon-plus', 'text' => $lang->task->addSibling), array('type' => 'addSub', 'icon' => 'icon-split', 'text' => $lang->task->addSub), 'delete');
  281. $batchFormOptions['onClickAction'] = jsRaw('window.handleClickBatchFormAction'); // 定义操作列按钮点击事件处理函数。
  282. $batchFormOptions['onRenderRow'] = jsRaw('window.handleRenderRow'); // 定义行渲染事件处理函数。
  283. formBatchPanel(setID('dataform'), set::idKey('index'), set::batchFormOptions($batchFormOptions), to::headingActions(array($fnGenerateSubPlanManageFields())), set::customFields(array('list' => $customFields, 'show' => explode(',', $showFields), 'key' => 'createFields')), set::customUrlParams("module=programplan&section=$section&key=$customKey"), set::items($fnGenerateFields()), set::sortable(array('onMove' => jsRaw('window.onMove'), 'onSort' => jsRaw('window.onSort'))), set::data($fnGenerateDefaultData()), $app->session->projectPlanList ? set::actions(array('submit', array('text' => $lang->cancel, 'url' => $app->session->projectPlanList))) : null, on::change('[name^="enabled"]', 'changeEnabled(e.target)'), on::change('[name^="attribute"]', 'changeAttribute(e.target)'), on::change('[name^="type"]', 'changeType(e.target)'), ($project->model == 'ipd' && !$planID) ? set::maxRows(count($fnGenerateDefaultData())) : null);