common.ui.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. $(document).on('click', '.time-input', function()
  2. {
  3. $('.time-input').removeClass('focus');
  4. $(this).addClass('focus');
  5. })
  6. let nameDefaultHtml = $('#nameInputBox').html();
  7. /**
  8. * 切换周期类型。
  9. * Toggle cycle type.
  10. *
  11. * @return void
  12. */
  13. function changeCycleType()
  14. {
  15. var cycleType = $('#cycleType input[type=radio]:checked').val();
  16. toggleCycleConfig(cycleType);
  17. $('.type-day .input-group, .config-day .input-control').removeClass('has-error');
  18. }
  19. /**
  20. * 切换周期设置的展示。
  21. * Toggle cycle setting display.
  22. *
  23. * @param string cycleType Type of cycle.
  24. * @return void
  25. */
  26. function toggleCycleConfig(cycleType)
  27. {
  28. $('.cycle-type-detail:not(.type-' + cycleType + ')').addClass('hidden');
  29. $('.cycle-type-detail.type-' + cycleType).removeClass('hidden');
  30. }
  31. /**
  32. * 切换私人事务,用于切换指派给的禁用状态。
  33. * Toggle private transactions for switching the disabled state assigned to.
  34. *
  35. * @param object switcher
  36. * @return void
  37. */
  38. function togglePrivate(switcher)
  39. {
  40. $assignedTo = $("[name='assignedTo']").zui('picker');
  41. $assignedTo.options.disabled = false;
  42. if($(switcher).prop('checked')) $assignedTo.options.disabled = true;
  43. $assignedTo.render($assignedTo.options);
  44. }
  45. /**
  46. * 更改指派给时。
  47. * change assignedTo.
  48. *
  49. * @return void
  50. */
  51. function changeAssignedTo()
  52. {
  53. var assignedTo = $('[name=assignedTo]').val();
  54. if(assignedTo != userAccount || todoAccount != userAccount)
  55. {
  56. $('#private').prop('disabled', true);
  57. $('#private').closest('.checkbox-primary').addClass('disabled');
  58. $('#private')[0].value = '0';
  59. }
  60. else
  61. {
  62. $('#private').prop('disabled', false);
  63. $('#private').closest('.checkbox-primary').removeClass('disabled');
  64. $('#private')[0].value = 'on';
  65. }
  66. }
  67. /**
  68. * 切换日期待定复选框。
  69. * Toggle date pending checkbox.
  70. *
  71. * @param object switcher
  72. * @return void
  73. */
  74. function togglePending()
  75. {
  76. $date = $("[name='date']").zui('datePicker');
  77. options = $date.options;
  78. options.disabled = false;
  79. if($('#switchDate').prop('checked')) options.disabled = true;
  80. $date.render(options);
  81. }
  82. /**
  83. * 加载不同类型数据列表,从而更改待办名称控件。
  84. * Load different types of list to change the name control.
  85. *
  86. * @param string type Type of selected todo.
  87. * @param string id ID of selected todo.
  88. * @param string defaultType Default type of selected todo.
  89. * @param int objectID ID of the closed todo type.
  90. * @return void
  91. */
  92. function loadList(type, id, todoDefaultType, objectID)
  93. {
  94. let nameBoxClass = '.name-box';
  95. let nameBoxID = '#nameBox';
  96. if(id)
  97. {
  98. nameBoxClass = '.name-box' + id;
  99. nameBoxID = '#nameBox' + id;
  100. }
  101. id = id ? id : '';
  102. var param = 'userID=' + userID + '&id=' + id;
  103. if(type == 'task') param += '&status=wait,doing';
  104. if(type == 'risk') param += '&status=active,hangup';
  105. if(todoDefaultType && type == todoDefaultType && objectID != 0) param += '&objectID=' + objectID;
  106. if(moduleList.indexOf(type) !== -1)
  107. {
  108. let link = $.createLink(type, objectsMethod[type], param);
  109. $.get(link, function(data)
  110. {
  111. data = JSON.parse(data);
  112. if(todoDefaultType && type == todoDefaultType && objectID != 0) data.defaultValue = objectID;
  113. $(nameBoxClass).find('#nameInputBox').html("<div class='picker-box' id='" + type + "'></div>");
  114. const $typePicker = $('#nameInputBox #' + type).picker(data);
  115. });
  116. }
  117. else
  118. {
  119. $(nameBoxClass).find('#nameInputBox').html(nameDefaultHtml);
  120. }
  121. if(nameBoxLabel) return;
  122. var formLabel = type == 'custom' || (vision && vision == 'rnd') ? nameBoxLabel.custom : nameBoxLabel.objectID;
  123. $('#nameBox .form-label').text(formLabel);
  124. }
  125. /**
  126. * 选择开始时间后,自动给出默认终止时间。
  127. * After selecting the start time, the default end time is automatically given.
  128. *
  129. * @return void
  130. */
  131. function selectNext()
  132. {
  133. if($('#begin').length == 0 || $('#end').length == 0) return;
  134. $begin = $("[name='begin']").zui('picker');
  135. $end = $("[name='end']").zui('picker');
  136. beginValue = $begin.$.value;
  137. endValue = $end.$.value;
  138. $end.options.items.forEach(function(item, index)
  139. {
  140. if(item.value == beginValue)
  141. {
  142. endValue = $end.options.items[index + 3].value;
  143. return;
  144. }
  145. })
  146. $end.$.setValue(endValue);
  147. }
  148. /**
  149. * 切换起止时间的禁用状态。
  150. * Switch the disabled state of start and end time.
  151. *
  152. * @param object switcher
  153. * @return void
  154. */
  155. function switchDateFeature(e)
  156. {
  157. $begin = $("[name='begin']").zui('picker');
  158. $end = $("[name='end']").zui('picker');
  159. $begin.options.disabled = false;
  160. $end.options.disabled = false;
  161. if($(e.target).prop('checked'))
  162. {
  163. $begin.options.disabled = true;
  164. $end.options.disabled = true;
  165. }
  166. $begin.render($begin.options);
  167. $end.render($end.options);
  168. }
  169. /**
  170. * 切换周期复选框的回调函数,用于页面交互展示。
  171. * Switch the cycle checkbox for page interactive display.
  172. *
  173. * @param object switcher
  174. * @return void
  175. */
  176. function showEvery(switcher)
  177. {
  178. if(switcher.checked)
  179. {
  180. $('#spaceDay').removeAttr('disabled');
  181. $('.specify').addClass('hidden');
  182. $('.every').removeClass('hidden');
  183. $('#cycleYear').removeAttr('checked');
  184. $('#configSpecify, #configEvery').prop('checked', false);
  185. }
  186. }
  187. /**
  188. * 周期设置为天并为指定时,更改月份时获取天数。
  189. * When the cycle is set to days and specified, obtain the number of days when changing the month.
  190. *
  191. * @param int specifiedMonth
  192. * @return void
  193. */
  194. function setDays(e)
  195. {
  196. var specifiedMonth = $(e.target).val()
  197. /* Get last day in specified month. */
  198. var date = new Date();
  199. date.setMonth(specifiedMonth);
  200. var month = date.getMonth() + 1;
  201. date.setMonth(month);
  202. date.setDate(0);
  203. var specifiedMonthLastDay = date.getDate();
  204. const dayPicker = $('#specifiedDay').zui('picker');
  205. let dayItems = [];
  206. for(var i = 1; i <= specifiedMonthLastDay; i++) dayItems.push({'text': i + dayLang, 'value': i});
  207. dayPicker.render({items: dayItems});
  208. }
  209. /**
  210. * 更改日期。
  211. * Change date.
  212. *
  213. * @param object dateInput
  214. * @return void
  215. */
  216. function changeDate(event)
  217. {
  218. $('#switchDate').prop('checked', !event.target.value);
  219. }
  220. /**
  221. * 验证间隔天数是否为空。
  222. * Verify if the sapceDay value is empty.
  223. *
  224. * @return void
  225. */
  226. function verifySpaceDay()
  227. {
  228. if($('#spaceDay').length > 0 && !$('#spaceDay').val()) $(this).closest('.input-control').addClass('has-error');
  229. }
  230. /**
  231. * 验证周期类型为天的日期是否为空。
  232. * Verify if the date with a cycle type of days is empty.
  233. *
  234. * @param object dateInput
  235. * @return void
  236. */
  237. function verifyCycleDate(event)
  238. {
  239. if(!event.target.value) $(event.target).closest('.input-group').addClass('has-error');
  240. }
  241. /**
  242. * 验证结束时间是否正确。
  243. * Verify if the end time is correct.
  244. *
  245. * @param object time
  246. * @return void
  247. */
  248. function verifyEndTime(event)
  249. {
  250. let end = $(event.target).zui('picker').$.value;
  251. if(end < $('#begin').zui('picker').$.value) $(event.target).closest('.picker-box').addClass('has-error');
  252. }