jquery_gantt_rails 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +74 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/jquery_gantt_rails.iml +9 -0
- data/.idea/misc.xml +22 -0
- data/.idea/modules.xml +9 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/.ruby-version.rb +1 -0
- data/Gemfile +3 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/jquery_gantt_rails.gemspec +20 -0
- data/lib/jquery_gantt_rails/version.rb +3 -0
- data/lib/jquery_gantt_rails/version.rb~ +3 -0
- data/lib/jquery_gantt_rails.rb +9 -0
- data/vendor/assets/javascripts/jquery_gantt/README.md +28 -0
- data/vendor/assets/javascripts/jquery_gantt/add.gif +0 -0
- data/vendor/assets/javascripts/jquery_gantt/alert.gif +0 -0
- data/vendor/assets/javascripts/jquery_gantt/closeBig.png +0 -0
- data/vendor/assets/javascripts/jquery_gantt/del.gif +0 -0
- data/vendor/assets/javascripts/jquery_gantt/edit.gif +0 -0
- data/vendor/assets/javascripts/jquery_gantt/gantt.css +323 -0
- data/vendor/assets/javascripts/jquery_gantt/gantt.html +547 -0
- data/vendor/assets/javascripts/jquery_gantt/ganttDrawer.js +752 -0
- data/vendor/assets/javascripts/jquery_gantt/ganttGridEditor.js +518 -0
- data/vendor/assets/javascripts/jquery_gantt/ganttMaster.js +702 -0
- data/vendor/assets/javascripts/jquery_gantt/ganttTask.js +947 -0
- data/vendor/assets/javascripts/jquery_gantt/ganttUtilities.js +237 -0
- data/vendor/assets/javascripts/jquery_gantt/gantt_compact.css +323 -0
- data/vendor/assets/javascripts/jquery_gantt/hasExternalDeps.png +0 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/JST/jquery.JST.js +167 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/date.js +584 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/dateField/images/next.png +0 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/dateField/images/prev.png +0 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/dateField/jquery.dateField.css +88 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/dateField/jquery.dateField.js +212 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/i18nJs.js +140 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/jquery.livequery.min.js +11 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/jquery.timers.js +142 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/platform.js +954 -0
- data/vendor/assets/javascripts/jquery_gantt/linkArrow.png +0 -0
- data/vendor/assets/javascripts/jquery_gantt/milestone.png +0 -0
- data/vendor/assets/javascripts/jquery_gantt/platform.css +346 -0
- data/vendor/assets/javascripts/jquery_gantt/teamwork-regular-webfont.eot +0 -0
- data/vendor/assets/javascripts/jquery_gantt/teamwork-regular-webfont.otf +0 -0
- data/vendor/assets/javascripts/jquery_gantt/teamwork-regular-webfont.svg +152 -0
- data/vendor/assets/javascripts/jquery_gantt/teamwork-regular-webfont.ttf +0 -0
- data/vendor/assets/javascripts/jquery_gantt/teamwork-regular-webfont.woff +0 -0
- data/vendor/assets/javascripts/jquery_gantt/teamworkFont.css +16 -0
- data/vendor/assets/javascripts/jquery_gantt/twGanttSmall.png +0 -0
- metadata +107 -0
@@ -0,0 +1,752 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2012-2013 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
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
*/
|
23
|
+
function Ganttalendar(zoom, startmillis, endMillis, master, minGanttSize) {
|
24
|
+
this.master = master; // is the a GantEditor instance
|
25
|
+
this.element; // is the jquery element containing gantt
|
26
|
+
this.highlightBar;
|
27
|
+
this.zoom = zoom;
|
28
|
+
this.minGanttSize = minGanttSize;
|
29
|
+
this.includeToday=true; //when true today is always visible. If false boundaries comes from tasks periods
|
30
|
+
|
31
|
+
//this.zoomLevels = ["d","w","m","q","s","y"];
|
32
|
+
this.zoomLevels = ["w","m","q","s","y"];
|
33
|
+
|
34
|
+
this.element = this.create(zoom, startmillis, endMillis);
|
35
|
+
|
36
|
+
}
|
37
|
+
|
38
|
+
Ganttalendar.prototype.zoomGantt = function(isPlus) {
|
39
|
+
var curLevel = this.zoom;
|
40
|
+
var pos = this.zoomLevels.indexOf(curLevel + "");
|
41
|
+
|
42
|
+
var newPos = pos;
|
43
|
+
if (isPlus) {
|
44
|
+
newPos = pos <= 0 ? 0 : pos - 1;
|
45
|
+
} else {
|
46
|
+
newPos = pos >= this.zoomLevels.length - 1 ? this.zoomLevels.length - 1 : pos + 1;
|
47
|
+
}
|
48
|
+
if (newPos != pos) {
|
49
|
+
curLevel = this.zoomLevels[newPos];
|
50
|
+
this.zoom = curLevel;
|
51
|
+
this.refreshGantt();
|
52
|
+
}
|
53
|
+
};
|
54
|
+
|
55
|
+
|
56
|
+
Ganttalendar.prototype.create = function(zoom, originalStartmillis, originalEndMillis) {
|
57
|
+
//console.debug("Gantt.create " + new Date(originalStartmillis) + " - " + new Date(originalEndMillis));
|
58
|
+
|
59
|
+
var self = this;
|
60
|
+
|
61
|
+
function getPeriod(zoomLevel, stMil, endMillis) {
|
62
|
+
var start = new Date(stMil);
|
63
|
+
var end = new Date(endMillis);
|
64
|
+
|
65
|
+
|
66
|
+
//reset hours
|
67
|
+
if (zoomLevel == "d") {
|
68
|
+
start.setHours(0, 0, 0, 0);
|
69
|
+
end.setHours(23, 59, 59, 999);
|
70
|
+
|
71
|
+
//reset day of week
|
72
|
+
} else if (zoomLevel == "w") {
|
73
|
+
start.setHours(0, 0, 0, 0);
|
74
|
+
end.setHours(23, 59, 59, 999);
|
75
|
+
|
76
|
+
start.setFirstDayOfThisWeek();
|
77
|
+
end.setFirstDayOfThisWeek();
|
78
|
+
end.setDate(end.getDate() + 6);
|
79
|
+
|
80
|
+
//reset day of month
|
81
|
+
} else if (zoomLevel == "m") {
|
82
|
+
start.setHours(0, 0, 0, 0);
|
83
|
+
end.setHours(23, 59, 59, 999);
|
84
|
+
|
85
|
+
start.setDate(1);
|
86
|
+
end.setDate(1);
|
87
|
+
end.setMonth(end.getMonth() + 1);
|
88
|
+
end.setDate(end.getDate() - 1);
|
89
|
+
|
90
|
+
//reset to quarter
|
91
|
+
} else if (zoomLevel == "q") {
|
92
|
+
start.setHours(0, 0, 0, 0);
|
93
|
+
end.setHours(23, 59, 59, 999);
|
94
|
+
start.setDate(1);
|
95
|
+
start.setMonth(Math.floor(start.getMonth() / 3) * 3);
|
96
|
+
end.setDate(1);
|
97
|
+
end.setMonth(Math.floor(end.getMonth() / 3) * 3 + 3);
|
98
|
+
end.setDate(end.getDate() - 1);
|
99
|
+
|
100
|
+
//reset to semester
|
101
|
+
} else if (zoomLevel == "s") {
|
102
|
+
start.setHours(0, 0, 0, 0);
|
103
|
+
end.setHours(23, 59, 59, 999);
|
104
|
+
start.setDate(1);
|
105
|
+
|
106
|
+
start.setMonth(Math.floor(start.getMonth() / 6) * 6);
|
107
|
+
end.setDate(1);
|
108
|
+
end.setMonth(Math.floor(end.getMonth() / 6) * 6 + 6);
|
109
|
+
end.setDate(end.getDate() - 1);
|
110
|
+
|
111
|
+
//reset to year - > gen
|
112
|
+
} else if (zoomLevel == "y") {
|
113
|
+
start.setHours(0, 0, 0, 0);
|
114
|
+
end.setHours(23, 59, 59, 999);
|
115
|
+
|
116
|
+
start.setDate(1);
|
117
|
+
start.setMonth(0);
|
118
|
+
|
119
|
+
end.setDate(1);
|
120
|
+
end.setMonth(12);
|
121
|
+
end.setDate(end.getDate() - 1);
|
122
|
+
}
|
123
|
+
return {start:start.getTime(),end:end.getTime()};
|
124
|
+
}
|
125
|
+
|
126
|
+
function createHeadCell(lbl, span, additionalClass) {
|
127
|
+
var th = $("<th>").html(lbl).attr("colSpan", span);
|
128
|
+
if (additionalClass)
|
129
|
+
th.addClass(additionalClass);
|
130
|
+
return th;
|
131
|
+
}
|
132
|
+
|
133
|
+
function createBodyCell(span, isEnd, additionalClass) {
|
134
|
+
var ret = $("<td>").html(" ").attr("colSpan", span).addClass("ganttBodyCell");
|
135
|
+
if (isEnd)
|
136
|
+
ret.addClass("end");
|
137
|
+
if (additionalClass)
|
138
|
+
ret.addClass(additionalClass);
|
139
|
+
return ret;
|
140
|
+
}
|
141
|
+
|
142
|
+
function createGantt(zoom, startPeriod, endPeriod) {
|
143
|
+
var tr1 = $("<tr>").addClass("ganttHead1");
|
144
|
+
var tr2 = $("<tr>").addClass("ganttHead2");
|
145
|
+
var trBody = $("<tr>").addClass("ganttBody");
|
146
|
+
|
147
|
+
function iterate(renderFunction1, renderFunction2) {
|
148
|
+
var start = new Date(startPeriod);
|
149
|
+
//loop for header1
|
150
|
+
while (start.getTime() <= endPeriod) {
|
151
|
+
renderFunction1(start);
|
152
|
+
}
|
153
|
+
|
154
|
+
//loop for header2
|
155
|
+
start = new Date(startPeriod);
|
156
|
+
while (start.getTime() <= endPeriod) {
|
157
|
+
renderFunction2(start);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
//this is computed by hand in order to optimize cell size
|
162
|
+
var computedTableWidth;
|
163
|
+
|
164
|
+
// year
|
165
|
+
if (zoom == "y") {
|
166
|
+
computedTableWidth = Math.floor(((endPeriod - startPeriod) / (3600000 * 24 * 180)) * 100); //180gg = 1 sem = 100px
|
167
|
+
iterate(function(date) {
|
168
|
+
tr1.append(createHeadCell(date.format("yyyy"), 2));
|
169
|
+
date.setFullYear(date.getFullYear() + 1);
|
170
|
+
}, function(date) {
|
171
|
+
var sem = (Math.floor(date.getMonth() / 6) + 1);
|
172
|
+
tr2.append(createHeadCell(GanttMaster.messages["GANT_SEMESTER_SHORT"] + sem, 1));
|
173
|
+
trBody.append(createBodyCell(1, sem == 2));
|
174
|
+
date.setMonth(date.getMonth() + 6);
|
175
|
+
});
|
176
|
+
|
177
|
+
//semester
|
178
|
+
} else if (zoom == "s") {
|
179
|
+
computedTableWidth = Math.floor(((endPeriod - startPeriod) / (3600000 * 24 * 90)) * 100); //90gg = 1 quarter = 100px
|
180
|
+
iterate(function(date) {
|
181
|
+
var end = new Date(date.getTime());
|
182
|
+
end.setMonth(end.getMonth() + 6);
|
183
|
+
end.setDate(end.getDate() - 1);
|
184
|
+
tr1.append(createHeadCell(date.format("MMM") + " - " + end.format("MMM yyyy"), 2));
|
185
|
+
date.setMonth(date.getMonth() + 6);
|
186
|
+
}, function(date) {
|
187
|
+
var quarter = ( Math.floor(date.getMonth() / 3) + 1);
|
188
|
+
tr2.append(createHeadCell(GanttMaster.messages["GANT_QUARTER_SHORT"] + quarter, 1));
|
189
|
+
trBody.append(createBodyCell(1, quarter % 2 == 0));
|
190
|
+
date.setMonth(date.getMonth() + 3);
|
191
|
+
});
|
192
|
+
|
193
|
+
//quarter
|
194
|
+
} else if (zoom == "q") {
|
195
|
+
computedTableWidth = Math.floor(((endPeriod - startPeriod) / (3600000 * 24 * 30)) * 300); //1 month= 300px
|
196
|
+
iterate(function(date) {
|
197
|
+
var end = new Date(date.getTime());
|
198
|
+
end.setMonth(end.getMonth() + 3);
|
199
|
+
end.setDate(end.getDate() - 1);
|
200
|
+
tr1.append(createHeadCell(date.format("MMM") + " - " + end.format("MMM yyyy"), 3));
|
201
|
+
date.setMonth(date.getMonth() + 3);
|
202
|
+
}, function(date) {
|
203
|
+
var lbl = date.format("MMM");
|
204
|
+
tr2.append(createHeadCell(lbl, 1));
|
205
|
+
trBody.append(createBodyCell(1, date.getMonth() % 3 == 2));
|
206
|
+
date.setMonth(date.getMonth() + 1);
|
207
|
+
});
|
208
|
+
|
209
|
+
//month
|
210
|
+
} else if (zoom == "m") {
|
211
|
+
computedTableWidth = Math.floor(((endPeriod - startPeriod) / (3600000 * 24 * 1)) * 20); //1 day= 20px
|
212
|
+
iterate(function(date) {
|
213
|
+
var sm = date.getTime();
|
214
|
+
date.setMonth(date.getMonth() + 1);
|
215
|
+
var daysInMonth = parseInt((date.getTime() - sm) / (3600000 * 24));
|
216
|
+
tr1.append(createHeadCell(new Date(sm).format("MMMM yyyy"), daysInMonth)); //spans mumber of dayn in the month
|
217
|
+
}, function(date) {
|
218
|
+
tr2.append(createHeadCell(date.format("d"), 1, isHoliday(date) ? "holyH" : null));
|
219
|
+
var nd = new Date(date.getTime());
|
220
|
+
nd.setDate(date.getDate() + 1);
|
221
|
+
trBody.append(createBodyCell(1, nd.getDate() == 1, isHoliday(date) ? "holy" : null));
|
222
|
+
date.setDate(date.getDate() + 1);
|
223
|
+
});
|
224
|
+
|
225
|
+
//week
|
226
|
+
} else if (zoom == "w") {
|
227
|
+
computedTableWidth = Math.floor(((endPeriod - startPeriod) / (3600000 * 24)) * 30); //1 day= 30px
|
228
|
+
iterate(function(date) {
|
229
|
+
var end = new Date(date.getTime());
|
230
|
+
end.setDate(end.getDate() + 6);
|
231
|
+
tr1.append(createHeadCell(date.format("MMM d") + " - " + end.format("MMM d'yy"), 7));
|
232
|
+
date.setDate(date.getDate() + 7);
|
233
|
+
}, function(date) {
|
234
|
+
tr2.append(createHeadCell(date.format("EEEE").substr(0, 1), 1, isHoliday(date) ? "holyH" : null));
|
235
|
+
trBody.append(createBodyCell(1, date.getDay() % 7 == (self.master.firstDayOfWeek + 6) % 7, isHoliday(date) ? "holy" : null));
|
236
|
+
date.setDate(date.getDate() + 1);
|
237
|
+
});
|
238
|
+
|
239
|
+
//days
|
240
|
+
} else if (zoom == "d") {
|
241
|
+
computedTableWidth = Math.floor(((endPeriod - startPeriod) / (3600000 * 24)) * 200); //1 day= 200px
|
242
|
+
iterate(function(date) {
|
243
|
+
tr1.append(createHeadCell(date.format("EEEE d MMMM yyyy"), 4, isHoliday(date) ? "holyH" : null));
|
244
|
+
date.setDate(date.getDate() + 1);
|
245
|
+
}, function(date) {
|
246
|
+
tr2.append(createHeadCell(date.format("HH"), 1, isHoliday(date) ? "holyH" : null));
|
247
|
+
trBody.append(createBodyCell(1, date.getHours() > 17, isHoliday(date) ? "holy" : null));
|
248
|
+
date.setHours(date.getHours() + 6);
|
249
|
+
});
|
250
|
+
|
251
|
+
} else {
|
252
|
+
console.error("Wrong level " + zoom);
|
253
|
+
}
|
254
|
+
|
255
|
+
//set a minimal width
|
256
|
+
computedTableWidth = Math.max(computedTableWidth, self.minGanttSize);
|
257
|
+
|
258
|
+
var table = $("<table cellspacing=0 cellpadding=0>");
|
259
|
+
table.append(tr1).append(tr2).append(trBody).addClass("ganttTable").css({width:computedTableWidth});
|
260
|
+
table.height(self.master.editor.element.height());
|
261
|
+
|
262
|
+
var box = $("<div>");
|
263
|
+
box.addClass("gantt unselectable").attr("unselectable","true").css({position:"relative",width:computedTableWidth});
|
264
|
+
box.append(table);
|
265
|
+
|
266
|
+
//highlightBar
|
267
|
+
var hlb = $("<div>").addClass("ganttHighLight");
|
268
|
+
box.append(hlb);
|
269
|
+
self.highlightBar = hlb;
|
270
|
+
|
271
|
+
//create link container
|
272
|
+
var links = $("<div>");
|
273
|
+
links.addClass("ganttLinks").css({position:"absolute",top:0,width:computedTableWidth,height:"100%"});
|
274
|
+
box.append(links);
|
275
|
+
|
276
|
+
|
277
|
+
//compute scalefactor fx
|
278
|
+
self.fx = computedTableWidth / (endPeriod - startPeriod);
|
279
|
+
|
280
|
+
// drawTodayLine
|
281
|
+
if (new Date().getTime() > self.startMillis && new Date().getTime() < self.endMillis) {
|
282
|
+
var x = Math.round(((new Date().getTime()) - self.startMillis) * self.fx);
|
283
|
+
var today = $("<div>").addClass("ganttToday").css("left", x);
|
284
|
+
box.append(today);
|
285
|
+
}
|
286
|
+
|
287
|
+
return box;
|
288
|
+
}
|
289
|
+
|
290
|
+
//if include today synch extremes
|
291
|
+
if (this.includeToday){
|
292
|
+
var today=new Date().getTime();
|
293
|
+
originalStartmillis=originalStartmillis>today ? today:originalStartmillis;
|
294
|
+
originalEndMillis=originalEndMillis<today ? today:originalEndMillis;
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
//get best dimension fo gantt
|
299
|
+
var period = getPeriod(zoom, originalStartmillis, originalEndMillis); //this is enlarged to match complete periods basing on zoom level
|
300
|
+
|
301
|
+
//console.debug(new Date(period.start) + " " + new Date(period.end));
|
302
|
+
self.startMillis = period.start; //real dimension of gantt
|
303
|
+
self.endMillis = period.end;
|
304
|
+
self.originalStartMillis = originalStartmillis; //minimal dimension required by user or by task duration
|
305
|
+
self.originalEndMillis = originalEndMillis;
|
306
|
+
|
307
|
+
var table = createGantt(zoom, period.start, period.end);
|
308
|
+
|
309
|
+
return table;
|
310
|
+
};
|
311
|
+
|
312
|
+
|
313
|
+
//<%-------------------------------------- GANT TASK GRAPHIC ELEMENT --------------------------------------%>
|
314
|
+
Ganttalendar.prototype.drawTask = function (task) {
|
315
|
+
//console.debug("drawTask", task.name,new Date(task.start));
|
316
|
+
var self = this;
|
317
|
+
//var prof = new Profiler("ganttDrawTask");
|
318
|
+
//var editorRow = self.master.editor.element.find("tr[taskId=" + task.id + "]");
|
319
|
+
editorRow = task.rowElement;
|
320
|
+
var top = editorRow.position().top+self.master.editor.element.parent().scrollTop();
|
321
|
+
var x = Math.round((task.start - self.startMillis) * self.fx);
|
322
|
+
var taskBox = $.JST.createFromTemplate(task, "TASKBAR");
|
323
|
+
|
324
|
+
|
325
|
+
|
326
|
+
//save row element on task
|
327
|
+
task.ganttElement = taskBox;
|
328
|
+
|
329
|
+
//if I'm parent
|
330
|
+
if (task.isParent())
|
331
|
+
taskBox.addClass("hasChild");
|
332
|
+
|
333
|
+
|
334
|
+
taskBox.css({top:top,left:x,width:Math.round((task.end - task.start) * self.fx)});
|
335
|
+
|
336
|
+
if (this.master.canWrite) {
|
337
|
+
taskBox.resizable({
|
338
|
+
handles: 'e' + ( task.depends ? "" : ",w"), //if depends cannot move start
|
339
|
+
//helper: "ui-resizable-helper",
|
340
|
+
//grid:[oneDaySize,oneDaySize],
|
341
|
+
|
342
|
+
resize:function(event, ui) {
|
343
|
+
//console.debug(ui)
|
344
|
+
$(".taskLabel[taskId=" + ui.helper.attr("taskId") + "]").css("width", ui.position.left);
|
345
|
+
event.stopImmediatePropagation();
|
346
|
+
event.stopPropagation();
|
347
|
+
},
|
348
|
+
stop:function(event, ui) {
|
349
|
+
//console.debug(ui)
|
350
|
+
var task = self.master.getTask(ui.element.attr("taskId"));
|
351
|
+
var s = Math.round((ui.position.left / self.fx) + self.startMillis);
|
352
|
+
var e = Math.round(((ui.position.left + ui.size.width) / self.fx) + self.startMillis);
|
353
|
+
|
354
|
+
self.master.beginTransaction();
|
355
|
+
self.master.changeTaskDates(task, new Date(s), new Date(e));
|
356
|
+
self.master.endTransaction();
|
357
|
+
}
|
358
|
+
|
359
|
+
});
|
360
|
+
|
361
|
+
}
|
362
|
+
|
363
|
+
taskBox.dblclick(function() {
|
364
|
+
self.master.showTaskEditor($(this).closest("[taskId]").attr("taskId"));
|
365
|
+
|
366
|
+
}).mousedown(function() {
|
367
|
+
var task = self.master.getTask($(this).attr("taskId"));
|
368
|
+
task.rowElement.click();
|
369
|
+
});
|
370
|
+
|
371
|
+
//panning only in no depends
|
372
|
+
if (!task.depends && this.master.canWrite) {
|
373
|
+
|
374
|
+
taskBox.css("position", "absolute").draggable({
|
375
|
+
axis:'x',
|
376
|
+
drag:function (event, ui) {
|
377
|
+
$(".taskLabel[taskId=" + $(this).attr("taskId") + "]").css("width", ui.position.left);
|
378
|
+
},
|
379
|
+
stop:function(event, ui) {
|
380
|
+
//console.debug(ui,$(this))
|
381
|
+
var task = self.master.getTask($(this).attr("taskId"));
|
382
|
+
var s = Math.round((ui.position.left / self.fx) + self.startMillis);
|
383
|
+
|
384
|
+
self.master.beginTransaction();
|
385
|
+
self.master.moveTask(task, new Date(s));
|
386
|
+
self.master.endTransaction();
|
387
|
+
}/*,
|
388
|
+
start:function(event, ui) {
|
389
|
+
var task = self.master.getTask($(this).attr("taskId"));
|
390
|
+
var s = Math.round((ui.position.left / self.fx) + self.startMillis);
|
391
|
+
console.debug("start",new Date(s));
|
392
|
+
}*/
|
393
|
+
});
|
394
|
+
}
|
395
|
+
|
396
|
+
|
397
|
+
var taskBoxSeparator=$("<div class='ganttLines'></div>");
|
398
|
+
taskBoxSeparator.css({top:top+taskBoxSeparator.height()});
|
399
|
+
// taskBoxSeparator.css({top:top+18});
|
400
|
+
|
401
|
+
|
402
|
+
self.element.append(taskBox);
|
403
|
+
self.element.append(taskBoxSeparator);
|
404
|
+
|
405
|
+
//ask for redraw link
|
406
|
+
self.redrawLinks();
|
407
|
+
|
408
|
+
//prof.stop();
|
409
|
+
};
|
410
|
+
|
411
|
+
|
412
|
+
Ganttalendar.prototype.addTask = function (task) {
|
413
|
+
//set new boundaries for gantt
|
414
|
+
this.originalEndMillis = this.originalEndMillis > task.end ? this.originalEndMillis : task.end;
|
415
|
+
this.originalStartMillis = this.originalStartMillis < task.start ? this.originalStartMillis : task.start;
|
416
|
+
};
|
417
|
+
|
418
|
+
|
419
|
+
//<%-------------------------------------- GANT DRAW LINK ELEMENT --------------------------------------%>
|
420
|
+
//'from' and 'to' are tasks already drawn
|
421
|
+
Ganttalendar.prototype.drawLink = function (from, to, type) {
|
422
|
+
var peduncolusSize = 10;
|
423
|
+
var lineSize = 2;
|
424
|
+
|
425
|
+
/**
|
426
|
+
* A representation of a Horizontal line
|
427
|
+
*/
|
428
|
+
HLine = function(width, top, left) {
|
429
|
+
var hl = $("<div>").addClass("taskDepLine");
|
430
|
+
hl.css({
|
431
|
+
height: lineSize,
|
432
|
+
left: left,
|
433
|
+
width: width,
|
434
|
+
top: top - lineSize / 2
|
435
|
+
});
|
436
|
+
return hl;
|
437
|
+
};
|
438
|
+
|
439
|
+
/**
|
440
|
+
* A representation of a Vertical line
|
441
|
+
*/
|
442
|
+
VLine = function(height, top, left) {
|
443
|
+
var vl = $("<div>").addClass("taskDepLine");
|
444
|
+
vl.css({
|
445
|
+
height: height,
|
446
|
+
left:left - lineSize / 2,
|
447
|
+
width: lineSize,
|
448
|
+
top: top
|
449
|
+
});
|
450
|
+
return vl;
|
451
|
+
};
|
452
|
+
|
453
|
+
/**
|
454
|
+
* Given an item, extract its rendered position
|
455
|
+
* width and height into a structure.
|
456
|
+
*/
|
457
|
+
function buildRect(item) {
|
458
|
+
var rect = item.ganttElement.position();
|
459
|
+
rect.width = item.ganttElement.width();
|
460
|
+
rect.height = item.ganttElement.height();
|
461
|
+
|
462
|
+
return rect;
|
463
|
+
}
|
464
|
+
|
465
|
+
/**
|
466
|
+
* The default rendering method, which paints a start to end dependency.
|
467
|
+
*
|
468
|
+
* @see buildRect
|
469
|
+
*/
|
470
|
+
function drawStartToEnd(rectFrom, rectTo, peduncolusSize) {
|
471
|
+
var left, top;
|
472
|
+
|
473
|
+
var ndo = $("<div>").attr({
|
474
|
+
from: from.id,
|
475
|
+
to: to.id
|
476
|
+
});
|
477
|
+
|
478
|
+
var currentX = rectFrom.left + rectFrom.width;
|
479
|
+
var currentY = rectFrom.height / 2 + rectFrom.top;
|
480
|
+
|
481
|
+
var useThreeLine = (currentX + 2 * peduncolusSize) < rectTo.left;
|
482
|
+
|
483
|
+
if (!useThreeLine) {
|
484
|
+
// L1
|
485
|
+
if (peduncolusSize > 0) {
|
486
|
+
var l1 = new HLine(peduncolusSize, currentY, currentX);
|
487
|
+
currentX = currentX + peduncolusSize;
|
488
|
+
ndo.append(l1);
|
489
|
+
}
|
490
|
+
|
491
|
+
// L2
|
492
|
+
var l2_4size = ((rectTo.top + rectTo.height / 2) - (rectFrom.top + rectFrom.height / 2)) / 2;
|
493
|
+
var l2;
|
494
|
+
if (l2_4size < 0) {
|
495
|
+
l2 = new VLine(-l2_4size, currentY + l2_4size, currentX);
|
496
|
+
} else {
|
497
|
+
l2 = new VLine(l2_4size, currentY, currentX);
|
498
|
+
}
|
499
|
+
currentY = currentY + l2_4size;
|
500
|
+
|
501
|
+
ndo.append(l2);
|
502
|
+
|
503
|
+
// L3
|
504
|
+
var l3size = rectFrom.left + rectFrom.width + peduncolusSize - (rectTo.left - peduncolusSize);
|
505
|
+
currentX = currentX - l3size;
|
506
|
+
var l3 = new HLine(l3size, currentY, currentX);
|
507
|
+
ndo.append(l3);
|
508
|
+
|
509
|
+
// L4
|
510
|
+
var l4;
|
511
|
+
if (l2_4size < 0) {
|
512
|
+
l4 = new VLine(-l2_4size, currentY + l2_4size, currentX);
|
513
|
+
} else {
|
514
|
+
l4 = new VLine(l2_4size, currentY, currentX);
|
515
|
+
}
|
516
|
+
ndo.append(l4);
|
517
|
+
|
518
|
+
currentY = currentY + l2_4size;
|
519
|
+
|
520
|
+
// L5
|
521
|
+
if (peduncolusSize > 0) {
|
522
|
+
var l5 = new HLine(peduncolusSize, currentY, currentX);
|
523
|
+
currentX = currentX + peduncolusSize;
|
524
|
+
ndo.append(l5);
|
525
|
+
|
526
|
+
}
|
527
|
+
} else {
|
528
|
+
//L1
|
529
|
+
var l1_3Size = (rectTo.left - currentX) / 2;
|
530
|
+
var l1 = new HLine(l1_3Size, currentY, currentX);
|
531
|
+
currentX = currentX + l1_3Size;
|
532
|
+
ndo.append(l1);
|
533
|
+
|
534
|
+
//L2
|
535
|
+
var l2Size = ((rectTo.top + rectTo.height / 2) - (rectFrom.top + rectFrom.height / 2));
|
536
|
+
var l2;
|
537
|
+
if (l2Size < 0) {
|
538
|
+
l2 = new VLine(-l2Size, currentY + l2Size, currentX);
|
539
|
+
} else {
|
540
|
+
l2 = new VLine(l2Size, currentY, currentX);
|
541
|
+
}
|
542
|
+
ndo.append(l2);
|
543
|
+
|
544
|
+
currentY = currentY + l2Size;
|
545
|
+
|
546
|
+
//L3
|
547
|
+
var l3 = new HLine(l1_3Size, currentY, currentX);
|
548
|
+
currentX = currentX + l1_3Size;
|
549
|
+
ndo.append(l3);
|
550
|
+
}
|
551
|
+
|
552
|
+
//arrow
|
553
|
+
var arr = $("<img src='linkArrow.png'>").css({
|
554
|
+
position: 'absolute',
|
555
|
+
top: rectTo.top + rectTo.height / 2 - 5,
|
556
|
+
left: rectTo.left - 5
|
557
|
+
});
|
558
|
+
|
559
|
+
ndo.append(arr);
|
560
|
+
|
561
|
+
return ndo;
|
562
|
+
}
|
563
|
+
|
564
|
+
/**
|
565
|
+
* A rendering method which paints a start to start dependency.
|
566
|
+
*
|
567
|
+
* @see buildRect
|
568
|
+
*/
|
569
|
+
function drawStartToStart(rectFrom, rectTo, peduncolusSize) {
|
570
|
+
var left, top;
|
571
|
+
|
572
|
+
var ndo = $("<div>").attr({
|
573
|
+
from: from.id,
|
574
|
+
to: to.id
|
575
|
+
});
|
576
|
+
|
577
|
+
var currentX = rectFrom.left;
|
578
|
+
var currentY = rectFrom.height / 2 + rectFrom.top;
|
579
|
+
|
580
|
+
var useThreeLine = (currentX + 2 * peduncolusSize) < rectTo.left;
|
581
|
+
|
582
|
+
if (!useThreeLine) {
|
583
|
+
// L1
|
584
|
+
if (peduncolusSize > 0) {
|
585
|
+
var l1 = new HLine(peduncolusSize, currentY, currentX - peduncolusSize);
|
586
|
+
currentX = currentX - peduncolusSize;
|
587
|
+
ndo.append(l1);
|
588
|
+
}
|
589
|
+
|
590
|
+
// L2
|
591
|
+
var l2_4size = ((rectTo.top + rectTo.height / 2) - (rectFrom.top + rectFrom.height / 2)) / 2;
|
592
|
+
var l2;
|
593
|
+
if (l2_4size < 0) {
|
594
|
+
l2 = new VLine(-l2_4size, currentY + l2_4size, currentX);
|
595
|
+
} else {
|
596
|
+
l2 = new VLine(l2_4size, currentY, currentX);
|
597
|
+
}
|
598
|
+
currentY = currentY + l2_4size;
|
599
|
+
|
600
|
+
ndo.append(l2);
|
601
|
+
|
602
|
+
// L3
|
603
|
+
var l3size = (rectFrom.left - peduncolusSize) - (rectTo.left - peduncolusSize);
|
604
|
+
currentX = currentX - l3size;
|
605
|
+
var l3 = new HLine(l3size, currentY, currentX);
|
606
|
+
ndo.append(l3);
|
607
|
+
|
608
|
+
// L4
|
609
|
+
var l4;
|
610
|
+
if (l2_4size < 0) {
|
611
|
+
l4 = new VLine(-l2_4size, currentY + l2_4size, currentX);
|
612
|
+
} else {
|
613
|
+
l4 = new VLine(l2_4size, currentY, currentX);
|
614
|
+
}
|
615
|
+
ndo.append(l4);
|
616
|
+
|
617
|
+
currentY = currentY + l2_4size;
|
618
|
+
|
619
|
+
// L5
|
620
|
+
if (peduncolusSize > 0) {
|
621
|
+
var l5 = new HLine(peduncolusSize, currentY, currentX);
|
622
|
+
currentX = currentX + peduncolusSize;
|
623
|
+
ndo.append(l5);
|
624
|
+
}
|
625
|
+
} else {
|
626
|
+
//L1
|
627
|
+
|
628
|
+
var l1 = new HLine(peduncolusSize, currentY, currentX - peduncolusSize);
|
629
|
+
currentX = currentX - peduncolusSize;
|
630
|
+
ndo.append(l1);
|
631
|
+
|
632
|
+
//L2
|
633
|
+
var l2Size = ((rectTo.top + rectTo.height / 2) - (rectFrom.top + rectFrom.height / 2));
|
634
|
+
var l2;
|
635
|
+
if (l2Size < 0) {
|
636
|
+
l2 = new VLine(-l2Size, currentY + l2Size, currentX);
|
637
|
+
} else {
|
638
|
+
l2 = new VLine(l2Size, currentY, currentX);
|
639
|
+
}
|
640
|
+
ndo.append(l2);
|
641
|
+
|
642
|
+
currentY = currentY + l2Size;
|
643
|
+
|
644
|
+
//L3
|
645
|
+
|
646
|
+
var l3 = new HLine(peduncolusSize + (rectTo.left - rectFrom.left), currentY, currentX);
|
647
|
+
currentX = currentX + peduncolusSize + (rectTo.left - rectFrom.left);
|
648
|
+
ndo.append(l3);
|
649
|
+
}
|
650
|
+
|
651
|
+
//arrow
|
652
|
+
var arr = $("<img src='linkArrow.png'>").css({
|
653
|
+
position: 'absolute',
|
654
|
+
top: rectTo.top + rectTo.height / 2 - 5,
|
655
|
+
left: rectTo.left - 5
|
656
|
+
});
|
657
|
+
|
658
|
+
ndo.append(arr);
|
659
|
+
|
660
|
+
return ndo;
|
661
|
+
}
|
662
|
+
|
663
|
+
var rectFrom = buildRect(from);
|
664
|
+
var rectTo = buildRect(to);
|
665
|
+
|
666
|
+
// Dispatch to the correct renderer
|
667
|
+
if (type == 'start-to-start') {
|
668
|
+
this.element.find(".ganttLinks").append(
|
669
|
+
drawStartToStart(rectFrom, rectTo, peduncolusSize)
|
670
|
+
);
|
671
|
+
} else {
|
672
|
+
this.element.find(".ganttLinks").append(
|
673
|
+
drawStartToEnd(rectFrom, rectTo, peduncolusSize)
|
674
|
+
);
|
675
|
+
}
|
676
|
+
};
|
677
|
+
|
678
|
+
|
679
|
+
Ganttalendar.prototype.redrawLinks = function() {
|
680
|
+
//console.debug("redrawLinks ");
|
681
|
+
var self = this;
|
682
|
+
this.element.stopTime("ganttlnksredr");
|
683
|
+
this.element.oneTime(60, "ganttlnksredr", function() {
|
684
|
+
//var prof=new Profiler("gd_drawLink_real");
|
685
|
+
self.element.find(".ganttLinks").empty();
|
686
|
+
for (var i=0;i<self.master.links.length;i++) {
|
687
|
+
var link = self.master.links[i];
|
688
|
+
self.drawLink(link.from, link.to);
|
689
|
+
}
|
690
|
+
//prof.stop();
|
691
|
+
});
|
692
|
+
};
|
693
|
+
|
694
|
+
|
695
|
+
Ganttalendar.prototype.reset = function() {
|
696
|
+
this.element.find(".ganttLinks").empty();
|
697
|
+
this.element.find("[taskId]").remove();
|
698
|
+
};
|
699
|
+
|
700
|
+
|
701
|
+
Ganttalendar.prototype.redrawTasks = function() {
|
702
|
+
for (var i=0;i<this.master.tasks.length;i++) {
|
703
|
+
var task = this.master.tasks[i];
|
704
|
+
this.drawTask(task);
|
705
|
+
}
|
706
|
+
};
|
707
|
+
|
708
|
+
|
709
|
+
Ganttalendar.prototype.refreshGantt = function() {
|
710
|
+
//console.debug("refreshGantt")
|
711
|
+
var par = this.element.parent();
|
712
|
+
|
713
|
+
//try to maintain last scroll
|
714
|
+
var scrollY=par.scrollTop();
|
715
|
+
var scrollX=par.scrollLeft();
|
716
|
+
|
717
|
+
this.element.remove();
|
718
|
+
//guess the zoom level in base of period
|
719
|
+
if (!this.zoom ){
|
720
|
+
var days = (this.originalEndMillis - this.originalStartMillis) / (3600000 * 24);
|
721
|
+
this.zoom = this.zoomLevels[days < 2 ? 0 : (days < 15 ? 1 : (days < 60 ? 2 : (days < 150 ? 3 : (days < 400 ? 4 : 5 ) ) ) )];
|
722
|
+
}
|
723
|
+
var domEl = this.create(this.zoom, this.originalStartMillis, this.originalEndMillis);
|
724
|
+
this.element = domEl;
|
725
|
+
par.append(domEl);
|
726
|
+
this.redrawTasks();
|
727
|
+
|
728
|
+
//set old scroll
|
729
|
+
//console.debug("old scroll:",scrollX,scrollY)
|
730
|
+
par.scrollTop(scrollY);
|
731
|
+
par.scrollLeft(scrollX);
|
732
|
+
|
733
|
+
//set current task
|
734
|
+
if (this.master.currentTask) {
|
735
|
+
this.highlightBar.css("top", this.master.currentTask.ganttElement.position().top);
|
736
|
+
}
|
737
|
+
};
|
738
|
+
|
739
|
+
|
740
|
+
Ganttalendar.prototype.fitGantt = function() {
|
741
|
+
delete this.zoom;
|
742
|
+
this.refreshGantt();
|
743
|
+
};
|
744
|
+
|
745
|
+
Ganttalendar.prototype.centerOnToday = function() {
|
746
|
+
//console.debug("centerOnToday");
|
747
|
+
var x = Math.round(((new Date().getTime()) - this.startMillis) * this.fx);
|
748
|
+
this.element.parent().scrollLeft(x);
|
749
|
+
};
|
750
|
+
|
751
|
+
|
752
|
+
|