taskform.ui.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. window.waitDom('#resolvePanel input[name=execution]', function(){loadAll()});
  2. window.loadAll = function()
  3. {
  4. const executionID = $('#resolvePanel input[name=execution]').val();
  5. if(!executionID) return;
  6. const moduleID = $('#resolvePanel input[name=module]').val();
  7. loadModules(executionID);
  8. loadExecutionMembers(executionID);
  9. }
  10. function loadModules(executionID)
  11. {
  12. if(executionID instanceof Event) executionID = $('#resolvePanel input[name=execution]').val();
  13. const extra = $('#resolvePanel input[name=showAllModule]').prop('checked') ? 'allModule' : '';
  14. const getModuleLink = $.createLink('tree', 'ajaxGetOptionMenu', 'rootID=' + executionID + '&viewtype=task&branch=0&rootModuleID=0&returnType=items&fieldID=&extra=' + extra);
  15. $.getJSON(getModuleLink, function(modules)
  16. {
  17. const $modulePicker = $('#resolvePanel input[name=module]').zui('picker');
  18. $modulePicker.render({items: modules});
  19. });
  20. }
  21. function loadExecutionMembers(executionID)
  22. {
  23. const getAssignedToLink = $.createLink('execution', 'ajaxGetMembers', 'executionID=' + executionID + '&assignedTo=' + $('#assignedTo').val());
  24. $.getJSON(getAssignedToLink, function(members)
  25. {
  26. const $assignedToPicker = $('input[name=assignedTo]').zui('picker');
  27. $assignedToPicker.render({items: members});
  28. $('#modalTeam [data-name=team] input[name^=team]').each(function()
  29. {
  30. let $memberPicker = $(this).zui('picker');
  31. $memberPicker.render({items: members});
  32. });
  33. });
  34. }
  35. window.renderRowData = function($row, index, row)
  36. {
  37. const mode = $('[name=mode]').val();
  38. $row.find('[data-name=id]').addClass('center').html("<span class='team-number'>" + $row.find('[data-name=id]').text() + "</span><i class='icon-angle-down " + (mode == 'linear' ? '' : 'hidden') + "'><i/>");
  39. const executionID = $('#resolvePanel input[name=execution]').val();
  40. const getAssignedToLink = $.createLink('execution', 'ajaxGetMembers', 'executionID=' + executionID + '&assignedTo=' + $('#assignedTo').val());
  41. $.getJSON(getAssignedToLink, function(members)
  42. {
  43. let $memberPicker = $row.find('[data-name=team] input[name^=team]').zui('picker');
  44. $memberPicker.render({items: members});
  45. });
  46. }
  47. /**
  48. * 根据多人任务是否勾选展示团队。
  49. * Show team menu box.
  50. *
  51. * @access public
  52. * @return void
  53. */
  54. function toggleTeam()
  55. {
  56. const $assignedToBox = $('.assignedToBox');
  57. if($('[name^=multiple]').prop('checked'))
  58. {
  59. $assignedToBox.find('.add-team').removeClass('hidden');
  60. $assignedToBox.find('.picker-box').addClass('hidden');
  61. $assignedToBox.find('.assignedToList').removeClass('hidden');
  62. $('input[name=estimate]').attr('disabled', true);
  63. }
  64. else
  65. {
  66. $assignedToBox.find('.add-team').addClass('hidden');
  67. $assignedToBox.find('.picker-box').removeClass('hidden');
  68. $assignedToBox.find('.assignedToList').addClass('hidden');
  69. $('input[name=estimate]').removeAttr('disabled');
  70. }
  71. }
  72. $('#teamTable .team-saveBtn').on('click.team', '.btn', function()
  73. {
  74. $('div.assignedToList').html('');
  75. let team = [];
  76. let totalEstimate = 0;
  77. let error = false;
  78. let mode = $('[name="mode"]').val();
  79. let assignedToList = '';
  80. $(this).closest('#teamTable').find('.picker-box').each(function(index)
  81. {
  82. if(!$(this).find('[name^=team]').val()) return;
  83. let realname = $(this).find('.picker-single-selection').text();
  84. let account = $(this).find('[name^=team]').val();
  85. if(!team.includes(realname)) team.push(realname);
  86. let estimate = parseFloat($(this).closest('tr').find('[name^=teamEstimate]').val());
  87. if(!isNaN(estimate) && estimate > 0) totalEstimate += estimate;
  88. if(realname != '' && (isNaN(estimate) || estimate <= 0))
  89. {
  90. zui.Modal.alert(realname + ' ' + estimateNotEmpty);
  91. error = true;
  92. return false;
  93. }
  94. assignedToList += `<div class='picker-multi-selection' data-index=${index}><span class='text'>${realname}</span><div class="picker-deselect-btn btn size-xs ghost"><span class="close"></span></div></div>`;
  95. if(mode == 'linear') assignedToList += '<i class="icon icon-arrow-right"></i>';
  96. })
  97. if(error) return false;
  98. if(team.length < 2)
  99. {
  100. zui.Modal.alert(teamMemberError);
  101. return false;
  102. }
  103. else
  104. {
  105. $('[data-name=estimate] input').val(totalEstimate);
  106. }
  107. /* 将选中的团队成员展示在指派给后面. */
  108. const regex = /<i class="icon icon-arrow-right"><\/i>(?!.*<i class="icon icon-arrow-right"><\/i>)/;
  109. assignedToList = assignedToList.replace(regex, '');
  110. $('div.assignedToList').prepend(assignedToList);
  111. zui.Modal.hide('#modalTeam');
  112. return false;
  113. })
  114. $('#resolveFrom').on('click', '.assignedToList .picker-multi-selection', function()
  115. {
  116. /* 团队成员必须大于1人. */
  117. if($(this).closest('.assignedToList').find('.picker-multi-selection').length == 2)
  118. {
  119. zui.Modal.alert(teamMemberError);
  120. return false;
  121. }
  122. /* 删除人员前后的箭头. */
  123. if($(this).next('.icon').length)
  124. {
  125. $(this).next('.icon').remove();
  126. }
  127. else if($(this).prev('.icon').length)
  128. {
  129. $(this).prev('.icon').remove();
  130. }
  131. $(this).remove();
  132. /* 删除团队中,已经选中的人. */
  133. let index = $(this).data('index');
  134. $('#teamTable').find('tr').eq(index).remove();
  135. let totalEstimate = 0;
  136. $('#teamTable').find('[name^=teamEstimate]').each(function(index)
  137. {
  138. let estimate = parseFloat($(this).val());
  139. if(!isNaN(estimate) && estimate > 0) totalEstimate += estimate;
  140. })
  141. $("[name='estimate']").val(totalEstimate);
  142. setLineIndex();
  143. })
  144. /**
  145. * Set line number.
  146. *
  147. * @access public
  148. * @return void
  149. */
  150. function setLineIndex()
  151. {
  152. let index = 1;
  153. $('.team-number').each(function()
  154. {
  155. $(this).text(index);
  156. $(this).closest('tr').find('[id^="line"]').attr('id', 'line' + index);
  157. index ++;
  158. });
  159. }
  160. /* 切换串行/并行 展示/隐藏工序图标. */
  161. $('#modalTeam').on('change.team', '[name="mode"]', function()
  162. {
  163. if($(this).val() == 'multi')
  164. {
  165. $('#teamTable td .icon-angle-down').addClass('hidden');
  166. }
  167. else
  168. {
  169. $('#teamTable td .icon-angle-down').removeClass('hidden');
  170. }
  171. });
  172. /**
  173. * 根据任务类型设置任务相关字段。
  174. * Set task-related fields based on the task type.
  175. *
  176. * @param object e
  177. * @access public
  178. * @return void
  179. */
  180. function typeChange()
  181. {
  182. const result = $('#resolveFrom [name=type]').val();
  183. /* Change assigned person to multiple selection, and hide multiple team box. */
  184. const $assignedToPicker = $('#resolveFrom [name^=assignedTo]').zui('picker');
  185. if(result == 'affair')
  186. {
  187. const $assignedToBox = $('.assignedToBox');
  188. $assignedToBox.find('.add-team').addClass('hidden');
  189. $assignedToBox.find('.picker-box').removeClass('hidden');
  190. $assignedToBox.find('.assignedToList').addClass('hidden');
  191. $('input[name=estimate]').removeAttr('disabled');
  192. $('[name=multiple]').prop("checked", false);
  193. $assignedToPicker.render({multiple: true, checkbox: true, toolbar: true});
  194. }
  195. /* If assigned selection is multiple, remove multiple and hide the selection of select all members. */
  196. else if($assignedToPicker.options.multiple)
  197. {
  198. $assignedToPicker.render({multiple: false, checkbox: false, toolbar: false});
  199. $assignedToPicker.$.setValue('');
  200. }
  201. $('#resolveFrom [name=multiple]').closest('.checkbox-primary').toggleClass('hidden', result == 'affair');
  202. }