/src/main/resources/static/page/gantt/ganttZoom.js

https://github.com/xiweicheng/tms · JavaScript · 248 lines · 185 code · 28 blank · 35 comment · 8 complexity · 813e8683ee332f6144e90ad768cccdab MD5 · raw file

  1. /*
  2. Copyright (c) 2012-2018 Open Lab
  3. Written by Roberto Bicchierai and Silvia Chelazzi http://roberto.open-lab.com
  4. Permission is hereby granted, free of charge, to any person obtaining
  5. a copy of this software and associated documentation files (the
  6. "Software"), to deal in the Software without restriction, including
  7. without limitation the rights to use, copy, modify, merge, publish,
  8. distribute, sublicense, and/or sell copies of the Software, and to
  9. permit persons to whom the Software is furnished to do so, subject to
  10. the following conditions:
  11. The above copyright notice and this permission notice shall be
  12. included in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  17. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  18. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  19. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. Ganttalendar.prototype.initZoomlevels = function () {
  22. //console.debug("Ganttalendar.prototype.initZoomlevels");
  23. var self = this;
  24. // define the zoom level arrays
  25. this.zoomLevels = [];
  26. this.zoomDrawers = {};
  27. function _addZoom(zoom,zoomDrawer){
  28. self.zoomLevels.push(zoom);
  29. self.zoomDrawers[zoom] = zoomDrawer;
  30. //compute the scale
  31. self.zoomDrawers[zoom].computedScaleX=600/millisFromString(zoom);
  32. }
  33. //----------------------------- 3 DAYS 600px-----------------------------
  34. _addZoom("3d", {
  35. adjustDates: function (start, end) {
  36. start.setFirstDayOfThisWeek();
  37. end.setFirstDayOfThisWeek();
  38. end.setDate(end.getDate() + 6);
  39. },
  40. row1: function (date, ctxHead) {
  41. var start = new Date(date.getTime());
  42. date.setDate(date.getDate() + 6);
  43. self.createHeadCell(1,this,ctxHead,start.format("MMMM d") + " - " + date.format("MMMM d yyyy")+ " ("+start.format("w")+")",7,"", start,date);
  44. date.setDate(date.getDate() + 1);
  45. },
  46. row2: function (date, ctxHead, ctxBody) {
  47. var start = new Date(date.getTime());
  48. date.setDate(date.getDate() + 1);
  49. var holyClass = isHoliday(start) ? "holy" : "";
  50. self.createHeadCell(2,this,ctxHead,start.format("EEE d"), 1, "headSmall "+holyClass, start,date);
  51. self.createBodyCell(this,ctxBody,1, start.getDay() % 7 == (self.master.firstDayOfWeek + 6) % 7, holyClass);
  52. }
  53. });
  54. //----------------------------- 1 WEEK 600px -----------------------------
  55. _addZoom("1w", {
  56. adjustDates: function (start, end) {
  57. //reset day of week
  58. start.setFirstDayOfThisWeek();
  59. start.setDate(start.getDate() - 7);
  60. end.setFirstDayOfThisWeek();
  61. end.setDate(end.getDate() + 13);
  62. },
  63. row1: function (date, ctxHead) {
  64. var start = new Date(date.getTime());
  65. date.setDate(date.getDate() + 6);
  66. self.createHeadCell(1,this,ctxHead,start.format("MMM d") + " - " + date.format("MMM d 'yy")+" (" + GanttMaster.messages["GANTT_WEEK_SHORT"]+date.format("w")+")", 7,"",start,date);
  67. date.setDate(date.getDate() + 1);
  68. },
  69. row2: function (date, ctxHead, ctxBody) {
  70. var start = new Date(date.getTime());
  71. date.setDate(date.getDate() + 1);
  72. var holyClass = isHoliday(start) ? "holy" : "";
  73. self.createHeadCell(2,this,ctxHead,start.format("EEEE").substr(0, 1)+" ("+start.format("dd")+")", 1, "headSmall "+holyClass, start,date);
  74. self.createBodyCell(this,ctxBody,1, start.getDay() % 7 == (self.master.firstDayOfWeek + 6) % 7, holyClass);
  75. }
  76. });
  77. //----------------------------- 2 WEEKS 600px -----------------------------
  78. _addZoom( "2w",{
  79. adjustDates: function (start, end) {
  80. start.setFirstDayOfThisWeek();
  81. start.setDate(start.getDate() - 7);
  82. end.setFirstDayOfThisWeek();
  83. end.setDate(end.getDate() + 20);
  84. },
  85. row1: function (date, tr1) {
  86. var start = new Date(date.getTime());
  87. date.setDate(date.getDate() + 6);
  88. self.createHeadCell(1,this,tr1,start.format("MMM d") + " - " + date.format("MMM d 'yy")+" (" + GanttMaster.messages["GANTT_WEEK_SHORT"]+date.format("w")+")", 7,"",start,date);
  89. date.setDate(date.getDate() + 1);
  90. },
  91. row2: function (date, tr2, trBody) {
  92. var start = new Date(date.getTime());
  93. date.setDate(date.getDate() + 1);
  94. var holyClass = isHoliday(start) ? "holy" : "";
  95. self.createHeadCell(2,this,tr2,start.format("EEEE").substr(0, 1), 1, "headSmall "+holyClass, start,date);
  96. self.createBodyCell(this,trBody,1, start.getDay() % 7 == (self.master.firstDayOfWeek + 6) % 7, holyClass);
  97. }
  98. });
  99. //----------------------------- 1 MONTH 600px -----------------------------
  100. _addZoom( "1M",{
  101. adjustDates: function (start, end) {
  102. start.setMonth(start.getMonth()-1);
  103. start.setDate(15);
  104. end.setDate(1);
  105. end.setMonth(end.getMonth() + 1);
  106. end.setDate(end.getDate() + 14);
  107. },
  108. row1: function (date, tr1) {
  109. var start = new Date(date.getTime());
  110. date.setDate(1);
  111. date.setMonth(date.getMonth() + 1);
  112. date.setDate(date.getDate() - 1);
  113. var inc=date.getDate()-start.getDate()+1;
  114. date.setDate(date.getDate() + 1);
  115. self.createHeadCell(1,this,tr1,start.format("MMMM yyyy"), inc,"",start,date); //spans mumber of dayn in the month
  116. },
  117. row2: function (date, tr2, trBody) {
  118. var start = new Date(date.getTime());
  119. date.setDate(date.getDate() + 1);
  120. var holyClass = isHoliday(start) ? "holy" : "";
  121. self.createHeadCell(2,this,tr2,start.format("d"), 1, "headSmall "+holyClass, start,date);
  122. var nd = new Date(start.getTime());
  123. nd.setDate(start.getDate() + 1);
  124. self.createBodyCell(this,trBody,1, nd.getDate() == 1, holyClass);
  125. }
  126. });
  127. //----------------------------- 1 QUARTERS -----------------------------
  128. _addZoom( "1Q", {
  129. adjustDates: function (start, end) {
  130. start.setDate(1);
  131. start.setMonth(Math.floor(start.getMonth() / 3) * 3 -1 );
  132. end.setDate(1);
  133. end.setMonth(Math.floor(end.getMonth() / 3) * 3 + 4);
  134. end.setDate(end.getDate() - 1);
  135. },
  136. row1: function (date, tr1) {
  137. var start = new Date(date.getTime());
  138. date.setMonth(Math.floor(date.getMonth() / 3) * 3 + 3);
  139. var inc=(date.getMonth()-start.getMonth());
  140. var q = (Math.floor(start.getMonth() / 3) + 1);
  141. self.createHeadCell(1,this,tr1,GanttMaster.messages["GANTT_QUARTER"]+" "+q+" "+start.format("yyyy"), inc,"",start,date);
  142. },
  143. row2: function (date, tr2, trBody) {
  144. var start = new Date(date.getTime());
  145. date.setMonth(date.getMonth() + 1);
  146. self.createHeadCell(2,this,tr2,start.format("MMMM"), 1, "headSmall", start,date);
  147. self.createBodyCell(this,trBody,1, start.getMonth() % 3 == 2);
  148. }
  149. });
  150. //----------------------------- 2 QUARTERS -----------------------------
  151. _addZoom( "2Q", {
  152. adjustDates: function (start, end) {
  153. start.setDate(1);
  154. start.setMonth(Math.floor(start.getMonth() / 3) * 3 -3);
  155. end.setDate(1);
  156. end.setMonth(Math.floor(end.getMonth() / 3) * 3 + 6);
  157. end.setDate(end.getDate() - 1);
  158. },
  159. row1: function (date, tr1) {
  160. var start = new Date(date.getTime());
  161. date.setMonth(date.getMonth() + 3);
  162. var q = (Math.floor(start.getMonth() / 3) + 1);
  163. self.createHeadCell(1,this,tr1,GanttMaster.messages["GANTT_QUARTER"]+" "+q+" "+start.format("yyyy"), 3,"",start,date);
  164. },
  165. row2: function (date, tr2, trBody) {
  166. var start = new Date(date.getTime());
  167. date.setMonth(date.getMonth() + 1);
  168. var lbl = start.format("MMMM");
  169. self.createHeadCell(2,this,tr2,lbl, 1, "headSmall", start,date);
  170. self.createBodyCell(this,trBody,1, start.getMonth() % 3 == 2);
  171. }
  172. });
  173. //----------------------------- 1 YEAR -----------------------------
  174. _addZoom( "1y", {
  175. adjustDates: function (start, end) {
  176. start.setDate(1);
  177. start.setMonth(Math.floor(start.getMonth() / 6) * 6 -6);
  178. end.setDate(1);
  179. end.setMonth(Math.floor(end.getMonth() / 6) * 6 + 12);
  180. end.setDate(end.getDate() - 1);
  181. },
  182. row1: function (date, tr1) {
  183. var start = new Date(date.getTime());
  184. date.setMonth(date.getMonth() + 6);
  185. var sem = (Math.floor(start.getMonth() / 6) + 1);
  186. self.createHeadCell(1,this,tr1,GanttMaster.messages["GANTT_SEMESTER"]+" "+sem+"-"+start.format("yyyy") , 6,"",start,date);
  187. },
  188. row2: function (date, tr2, trBody) {
  189. var start = new Date(date.getTime());
  190. date.setMonth(date.getMonth() + 1);
  191. self.createHeadCell(2,this,tr2,start.format("MMM"), 1, "headSmall", start,date);
  192. self.createBodyCell(this,trBody,1, (start.getMonth() + 1) % 6 == 0);
  193. }
  194. });
  195. //----------------------------- 2 YEAR -----------------------------
  196. _addZoom( "2y", {
  197. adjustDates: function (start, end) {
  198. start.setDate(1);
  199. start.setMonth(-6);
  200. end.setDate(30);
  201. end.setMonth(17);
  202. },
  203. row1: function (date, tr1) {
  204. var start = new Date(date.getTime());
  205. var inc=12-start.getMonth();
  206. date.setMonth(date.getMonth() + inc);
  207. self.createHeadCell(1,this,tr1,start.format("yyyy"), inc/6,"",start,date);
  208. },
  209. row2: function (date, tr2, trBody) {
  210. var start = new Date(date.getTime());
  211. date.setMonth(date.getMonth() + 6);
  212. var sem = (Math.floor(start.getMonth() / 6) + 1);
  213. self.createHeadCell(2,this,tr2,GanttMaster.messages["GANTT_SEMESTER"] +" "+ sem, 1, "headSmall", start,date);
  214. self.createBodyCell(this,trBody,1, sem == 2);
  215. }
  216. });
  217. };