common.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. window.ignoreTips = {
  2. 'beyondBudgetTip' : false,
  3. 'dateTip' : false
  4. };
  5. var batchEditDateTips = new Array();
  6. function addNewMarket()
  7. {
  8. $('#marketBox .picker').toggle();
  9. $('#marketBox input').css('border-left-color', '');
  10. $('#marketBox input').toggle();
  11. }
  12. /**
  13. * Access rights are equal to private, and the white list settings are displayed.
  14. *
  15. * @param string acl
  16. * @access public
  17. * @return void
  18. */
  19. function setWhite(acl)
  20. {
  21. acl != 'open' ? $('#whitelistBox').removeClass('hidden') : $('#whitelistBox').addClass('hidden');
  22. }
  23. /**
  24. * Compute work days.
  25. *
  26. * @param string currentID
  27. * @access public
  28. * @return void
  29. */
  30. function computeWorkDays(currentID)
  31. {
  32. isBactchEdit = false;
  33. if(currentID)
  34. {
  35. index = currentID.replace('begins[', '');
  36. index = index.replace('ends[', '');
  37. index = index.replace(']', '');
  38. if(!isNaN(index)) isBactchEdit = true;
  39. }
  40. if(isBactchEdit)
  41. {
  42. beginDate = $('#begins\\[' + index + '\\]').val();
  43. endDate = $('#ends\\[' + index + '\\]').val();
  44. }
  45. else
  46. {
  47. beginDate = $('#begin').val();
  48. endDate = $('#end').val();
  49. var begin = new Date(beginDate.replace(/-/g,"/"));
  50. var end = new Date(endDate.replace(/-/g,"/"));
  51. var time = end.getTime() - begin.getTime();
  52. var days = parseInt(time / (1000 * 60 * 60 * 24)) + 1;
  53. if(days != $("input:radio[name='delta']:checked").val()) $("input:radio[name='delta']:checked").attr('checked', false);
  54. if(endDate == longTime) $("#delta999").prop('checked', true);
  55. }
  56. if(beginDate && endDate)
  57. {
  58. if(isBactchEdit) $('#dayses\\[' + index + '\\]').val(computeDaysDelta(beginDate, endDate));
  59. if(!isBactchEdit) $('#days').val(computeDaysDelta(beginDate, endDate));
  60. }
  61. else if($('input[checked="true"]').val())
  62. {
  63. computeEndDate();
  64. }
  65. outOfDateTip(isBactchEdit ? index : 0);
  66. }
  67. /**
  68. * Compute the end date for project.
  69. *
  70. * @param int $delta
  71. * @access public
  72. * @return void
  73. */
  74. function computeEndDate(delta)
  75. {
  76. beginDate = $('#begin').val();
  77. if(!beginDate) return;
  78. delta = parseInt(delta);
  79. if(delta == 999)
  80. {
  81. $('#end').val(longTime).trigger('mousedown');
  82. $('#daysBox').addClass('hidden');
  83. $('#days').val(0).trigger('mousedown');
  84. outOfDateTip();
  85. return false;
  86. }
  87. $('#daysBox').removeClass('hidden');
  88. beginDate = convertStringToDate(beginDate);
  89. if((delta == 7 || delta == 14) && (beginDate.getDay() == 1))
  90. {
  91. delta = (weekend == 2) ? (delta - 2) : (delta - 1);
  92. }
  93. endDate = $.zui.formatDate(beginDate.addDays(delta - 1), 'yyyy-MM-dd');
  94. $('#end').val(endDate).datetimepicker('update').trigger('mousedown');
  95. computeWorkDays();
  96. $('#days').trigger('mousedown');
  97. }
  98. /**
  99. * Convert a date string like 2011-11-11 to date object in js.
  100. *
  101. * @param string dateString
  102. * @access public
  103. * @return date
  104. */
  105. function convertStringToDate(dateString)
  106. {
  107. dateString = dateString.split('-');
  108. return new Date(dateString[0], dateString[1] - 1, dateString[2]);
  109. }
  110. /**
  111. * Compute delta of two days.
  112. *
  113. * @param string date1
  114. * @param string date2
  115. * @access public
  116. * @return int
  117. */
  118. function computeDaysDelta(date1, date2)
  119. {
  120. date1 = convertStringToDate(date1);
  121. date2 = convertStringToDate(date2);
  122. delta = (date2 - date1) / (1000 * 60 * 60 * 24) + 1;
  123. if(isNaN(delta)) return;
  124. weekEnds = 0;
  125. for(i = 0; i < delta; i++)
  126. {
  127. if((weekend == 2 && date1.getDay() == 6) || date1.getDay() == 0) weekEnds ++;
  128. date1 = date1.valueOf();
  129. date1 += 1000 * 60 * 60 * 24;
  130. date1 = new Date(date1);
  131. }
  132. return delta - weekEnds;
  133. }
  134. /**
  135. *The date is out of the range of the parent project set, and a prompt is given.
  136. *
  137. * @param string $currentID
  138. * @access public
  139. * @return void
  140. */
  141. function outOfDateTip(currentID)
  142. {
  143. if(window.ignoreTips['dateTip']) return;
  144. if(typeof(systemMode) != 'undefined' && systemMode == 'light') return;
  145. if(batchEditDateTips.includes(Number(currentID))) return;
  146. var end = currentID ? $('#ends\\[' + currentID + '\\]').val() : $('#end').val();
  147. var begin = currentID ? $('#begins\\[' + currentID + '\\]').val() : $('#begin').val();
  148. if($('#dateTip.text-remind').length > 0) $('#dateTip').parent().parent().remove();
  149. if(currentID) $('#dateTip\\[' + currentID + '\\]').remove();
  150. if(end == longTime) end = LONG_TIME;
  151. if(end.length > 0 && begin.length > 0)
  152. {
  153. var selectedProgramID = currentID ? $("select[name='parents\[" + currentID + "\]']").val() : $('#parent').val();
  154. if(selectedProgramID == 0 || selectedProgramID == undefined) return;
  155. if(typeof(projectID) == 'undefined') projectID = 0;
  156. projectID = currentID ? $('#projectIdList\\['+ currentID + '\\]').val() : projectID;
  157. $.get(createLink('project', 'ajaxGetObjectInfo', 'objectType=project&objectID=' + projectID + '&selectedProgramID=' + selectedProgramID), function(data)
  158. {
  159. var data = JSON.parse(data);
  160. var parentEnd = new Date(data.selectedProgramEnd);
  161. var parentBegin = new Date(data.selectedProgramBegin);
  162. var projectEnd = new Date(end);
  163. var projectBegin = new Date(begin);
  164. var beginLetterParentTip = beginLetterParent + data.selectedProgramBegin;
  165. var endGreaterParentTip = endGreaterParent + data.selectedProgramEnd;
  166. if(projectBegin >= parentBegin && projectEnd <= parentEnd) return;
  167. var dateTip = "";
  168. if(projectBegin < parentBegin)
  169. {
  170. dateTip = currentID ? beginLetterParentTip + "'><p>" + beginLetterParentTip : beginLetterParentTip;
  171. }
  172. else if(projectEnd > parentEnd)
  173. {
  174. dateTip = currentID ? endGreaterParentTip + "'><p>" + endGreaterParentTip : endGreaterParentTip;
  175. }
  176. if(currentID)
  177. {
  178. $("#projects\\[" + currentID + "\\]").after("<tr><td colspan='5'></td><td class='c-name' colspan='3'><span id='dateTip" + currentID + "' class='text-remind' title='" + dateTip + "</p><p id='ignore' onclick='ignoreTip(this," + currentID + ")'>" + ignore + "</p></span></td></tr>");
  179. $('#dateTip'+ currentID).parent().css('line-height', '0')
  180. }
  181. else
  182. {
  183. $('#dateRange').parent().after("<tr><td></td><td colspan='2'><span id='dateTip' class='text-remind'><p>" + dateTip + "</p><p id='ignore' onclick='ignoreTip(this)'>" + ignore + "</p></span></td><tr>");
  184. $('#dateTip').parent().css('line-height', '0')
  185. }
  186. });
  187. }
  188. }
  189. // init pri selector
  190. $('#pri').on('change', function()
  191. {
  192. var $select = $(this);
  193. var $selector = $select.closest('.pri-selector');
  194. var value = $select.val();
  195. $selector.find('.pri-text').html('<span class="label-pri label-pri-' + value + '" title="' + value + '">' + value + '</span>');
  196. });