81
|
1 |
/* |
|
2 |
* Main Timeline code |
|
3 |
*/ |
|
4 |
|
|
5 |
window.Tlns = { |
|
6 |
Utils : {}, |
|
7 |
Defaults : {}, |
|
8 |
Templates : {}, |
|
9 |
Classes : {} |
|
10 |
}; |
|
11 |
|
|
12 |
/* Utility Functions */ |
|
13 |
|
|
14 |
Tlns.Utils.zeroPad = function(_n) { |
|
15 |
return (_n < 10 ? "0" : "") + _n; |
|
16 |
} |
|
17 |
|
|
18 |
Tlns.Utils.SetDefaults = function(_object, _defaults, _options) { |
|
19 |
var _options = _options || {}; |
|
20 |
_(_defaults).each(function(_v, _k) { |
|
21 |
if(/^m(in|ax)_/.test(_k)) { |
|
22 |
var _tab = _k.split('_') |
|
23 |
if( typeof _object[_tab[1]] !== "undefined") { |
|
24 |
var _fn = (_tab[0] === "min" ? Math.max : Math.min); |
|
25 |
_object[_tab[1]] = _fn(_object[_tab[1]], _v); |
|
26 |
} |
|
27 |
} else { |
|
28 |
if( typeof _options[_k] !== "undefined") { |
|
29 |
_object[_k] = _options[_k]; |
|
30 |
} else { |
|
31 |
_object[_k] = _v; |
|
32 |
} |
|
33 |
} |
|
34 |
}); |
|
35 |
} |
|
36 |
|
|
37 |
Tlns.Utils.dateFormat = function(_date, _template) { |
|
38 |
if (typeof _date !== "object") { |
|
39 |
_date = new Date(parseInt(_date)); |
|
40 |
} |
|
41 |
var _params = { |
|
42 |
hours: _date.getHours(), |
|
43 |
"0hours": Tlns.Utils.zeroPad(_date.getHours()), |
|
44 |
minutes: _date.getMinutes(), |
|
45 |
"0minutes": Tlns.Utils.zeroPad(_date.getMinutes()), |
|
46 |
seconds: _date.getSeconds(), |
|
47 |
"0seconds": Tlns.Utils.zeroPad(_date.getSeconds()), |
|
48 |
dayOfWeek: ["dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi"][_date.getDay()], |
|
49 |
shortDayOfWeek: ["Dim","Lun","Mar","Mer","Jeu","Ven","Sam"][_date.getDay()], |
|
50 |
dayOfMonth: _date.getDate(), |
|
51 |
"0dayOfMonth": Tlns.Utils.zeroPad(_date.getDate()), |
|
52 |
monthNumber: 1+_date.getMonth(), |
|
53 |
"0monthNumber": Tlns.Utils.zeroPad(1+_date.getMonth()), |
|
54 |
monthName: ["janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"][_date.getMonth()], |
|
55 |
shortMonthName: ["jan","fev","mar","avr","mai","jun","jul","aou","sep","oct","nov","dec"][_date.getMonth()], |
|
56 |
year: _date.getFullYear() |
|
57 |
} |
|
58 |
return Mustache.to_html(_template, _params); |
|
59 |
} |
|
60 |
|
|
61 |
Tlns.Utils.guid = function() { |
|
62 |
return 'xxxx-xxxx-xxxx-xxxx'.replace(/x/g,function() { |
|
63 |
return Math.floor(Math.random()*16).toString(16); |
|
64 |
}); |
|
65 |
} |
|
66 |
|
|
67 |
Tlns.Utils.drawArrow = function(_ctx, _color, _x1, _y1, _x2, _y2) { |
|
68 |
_ctx.strokeStyle = _color; |
|
69 |
_ctx.fillStyle = _color; |
|
70 |
_ctx.beginPath(); |
|
71 |
_ctx.moveTo(_x1,_y1); |
|
72 |
_ctx.lineTo(_x2,_y2); |
|
73 |
_ctx.stroke(); |
|
74 |
var _mod = Math.sqrt(Math.pow(_x2 - _x1, 2) + Math.pow(_y2 - _y1, 2)), |
|
75 |
_xu = (_x2 - _x1) / _mod, |
|
76 |
_yu = (_y2 - _y1) / _mod, |
|
77 |
_xm = (_x1 + _x2) / 2, |
|
78 |
_ym = (_y1 + _y2) / 2, |
|
79 |
_arrowWidth = 4, |
|
80 |
_arrowLength = 8, |
|
81 |
_x3 = _xm - _arrowLength * _xu + _arrowWidth * _yu, |
|
82 |
_y3 = _ym - _arrowLength * _yu - _arrowWidth * _xu, |
|
83 |
_x4 = _xm - _arrowLength * _xu - _arrowWidth * _yu, |
|
84 |
_y4 = _ym - _arrowLength * _yu + _arrowWidth * _xu; |
|
85 |
_ctx.beginPath(); |
|
86 |
_ctx.moveTo(_x3, _y3); |
|
87 |
_ctx.lineTo(_xm, _ym); |
|
88 |
_ctx.lineTo(_x4, _y4); |
|
89 |
_ctx.fill(); |
|
90 |
_ctx.stroke(); |
|
91 |
} |
|
92 |
|
|
93 |
Tlns.Utils.timeFieldProcess = function(_val) { |
|
94 |
var _h = 0, |
|
95 |
_m = 0, |
|
96 |
_matches = _val.match(/(\d+)/g); |
|
97 |
if (_matches && _matches.length) { |
|
98 |
_h = Math.min(23, +(_matches[0])); |
|
99 |
if (_matches.length > 1) { |
|
100 |
_m = Math.min(59, +(_matches[1])); |
|
101 |
} |
|
102 |
} |
|
103 |
return { |
|
104 |
hours: _h, |
|
105 |
minutes: _m, |
|
106 |
text: Tlns.Utils.zeroPad(_h) + ':' + Tlns.Utils.zeroPad(_m) |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
Tlns.Utils.dateFieldProcess = function(_val) { |
|
111 |
var _now = new Date(), |
|
112 |
_y = _now.getFullYear(), |
|
113 |
_m = 1 + _now.getMonth(), |
|
114 |
_d = _now.getDate(), |
|
115 |
_matches = _val.match(/(\d+)/g); |
|
116 |
if (_matches && _matches.length) { |
|
117 |
_d = Math.min(31, +(_matches[0])); |
|
118 |
if (_matches.length > 1) { |
|
119 |
_m = Math.min(12, +(_matches[1])); |
|
120 |
} |
|
121 |
if (_matches.length > 2) { |
|
122 |
_y = parseInt(_matches[2]); |
|
123 |
if (_y < 2000) { |
|
124 |
_y += 2000; |
|
125 |
} |
|
126 |
_y = Math.min(2020, Math.max(2000, _y)); |
|
127 |
} |
|
128 |
} |
|
129 |
return { |
|
130 |
year: _y, |
|
131 |
month: _m, |
|
132 |
date: _d, |
|
133 |
text: Tlns.Utils.zeroPad(_d) + '/' + Tlns.Utils.zeroPad(_m) + '/' + _y |
|
134 |
} |
|
135 |
} |
|
136 |
|
|
137 |
/* Defaults */ |
|
138 |
|
|
139 |
Tlns.Defaults.Timeline = { |
|
140 |
container : "timeline", |
|
141 |
width : 950, |
|
142 |
height : 200, |
|
143 |
url_univers : '', |
|
144 |
min_width : 400, |
|
145 |
min_height : 100, |
|
146 |
main_width : 800, |
|
147 |
timescales : [{ |
|
148 |
label : "Mois", |
|
149 |
span : 32 * 86400 * 1000, |
|
150 |
grid_interval : 5 * 86400 * 1000, |
|
151 |
grid_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
152 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
153 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}} {{year}}' |
|
154 |
}, { |
|
155 |
label : "Semaine", |
|
156 |
span : 8 * 86400 * 1000, |
|
157 |
grid_interval : 86400 * 1000, |
|
158 |
grid_date_format : '{{shortDayOfWeek}} {{0dayOfMonth}}/{{0monthNumber}}', |
|
159 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
160 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}}' |
|
161 |
}, { |
|
162 |
label : "2 jours", |
|
163 |
span : 2 * 86400 * 1000, |
|
164 |
grid_interval : 8 * 3600 * 1000, |
|
165 |
grid_date_format : '{{shortDayOfWeek}} {{0dayOfMonth}}/{{0monthNumber}} {{hours}}h', |
|
166 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
167 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}}' |
|
168 |
}, { |
|
169 |
label : "Demi-Journée", |
|
170 |
span : 12 * 3600 * 1000, |
|
171 |
grid_interval : 2 * 3600 * 1000, |
|
172 |
grid_date_format : '{{hours}}h', |
|
173 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}} {{hours}}h', |
|
174 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}} {{hours}}h' |
|
175 |
}, { |
|
176 |
label : "3 Heures", |
|
177 |
span : 3 * 3600 * 1000, |
|
178 |
grid_interval : 30 * 60 * 1000, |
|
179 |
grid_date_format : '{{0hours}}:{{0minutes}}', |
|
180 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}} {{0hours}}:{{0minutes}}', |
|
181 |
end_date_format : '{{0hours}}:{{0minutes}}' |
|
182 |
}, { |
|
183 |
label : "1 Heure", |
|
184 |
span : 60 * 60 * 1000, |
|
185 |
grid_interval : 15 * 60 * 1000, |
|
186 |
grid_date_format : '{{0hours}}:{{0minutes}}', |
|
187 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}} {{0hours}}:{{0minutes}}', |
|
188 |
end_date_format : '{{0hours}}:{{0minutes}}' |
|
189 |
}], |
|
190 |
level: 0, |
|
191 |
central_time: 0, |
|
192 |
sync_now: true, |
|
193 |
urls_occurrences: [], |
|
194 |
occurrences: [], |
|
195 |
cluster_spacing: 12, |
|
196 |
tooltip_date_format: '{{dayOfMonth}} {{shortMonthName}} {{year}} {{0hours}}:{{0minutes}}', |
|
197 |
statuses: { |
|
198 |
"valide": "Validée", |
|
199 |
"a_valider": "A valider", |
|
200 |
"a_realiser": "A réaliser" |
|
201 |
} |
|
202 |
} |
|
203 |
|
|
204 |
for (var _i = 0; _i < Tlns.Defaults.Timeline.timescales.length; _i++) { |
|
205 |
Tlns.Defaults.Timeline.timescales[_i].level = _i; |
|
206 |
} |
|
207 |
|
|
208 |
/* Templates */ |
|
209 |
|
|
210 |
Tlns.Templates.Timeline = '<ul class="Onglets"><li class="Onglet-Tl active">Frise chronologique</li><li class="Onglet-Ls">Liste des occurrences</li></ul><div class="Tl-Main"><div class="Tl-TopBar"><div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-AddButton"></div></div><div class="Tl-TopBar-Spacer Tl-Border-Right"></div>' |
|
211 |
+ '<div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-PreviousButton"></div></div><div class="Tl-TopBar-TimeSpan Tl-TopBar-TextBtn Tl-Border-Right">--/--</div>' |
|
212 |
+ '<div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-SyncButton"></div></div><div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-NextButton"></div></div><div class="Tl-TopBar-Spacer Tl-Border-Right"></div>' |
|
213 |
+ '<div class="Tl-TopBar-Timescales">{{#timescales}}<div class="Tl-TopBar-Button Tl-TopBar-TextBtn Tl-Border-Right" data-level="{{level}}">{{label}}</div>{{/timescales}}</div></div>' |
|
214 |
+ '<div class="Tl-BottomPart"><ul class="Tl-UniversLabels"></ul>' |
|
215 |
+ '<div class="Tl-MainPart"><div class="Tl-Layer Tl-Grid"></div><canvas class="Tl-Layer Tl-Canvas"></canvas><canvas class="Tl-Layer Tl-Linking-Canvas"></canvas><div class="Tl-Layer Tl-Occurrences"></div>' |
|
216 |
+ '<ul class="Tl-Adding"><li class="Tl-AddingTitle">Ajout d\'une occurrence</li><li><span>Narrative</span><div class="Tl-AddOccurrence Tl-Occnarrative" occurrence-type="narrative" title="Glisser sur la frise chronologique pour ajouter"></div></li>' |
|
217 |
+ '<li><span>De Publication</span><div class="Tl-AddOccurrence Tl-Occpublication" occurrence-type="publication" title="Glisser sur la frise chronologique pour ajouter"></div></li></ul></div>' |
|
218 |
+ '<div class="Tl-Overlay-Container"><div class="Tl-Overlay-Box"><div class="Tl-Overlay"><div class="Tl-Overlay-Tip-Top"></div><div class="Tl-Overlay-Main"></div><div class="Tl-Overlay-Tip-Bottom"></div></div></div></div></div></div>' |
|
219 |
|
|
220 |
+'<div class="Ls-Main"><div class="Ls-Filtres"><h2>Filtres :</h2>' |
|
221 |
+ '<div class="Ls-Column"><h3>Univers :</h3><ul class="Ls-Univers"></ul></div>' |
|
222 |
+ '<div class="Ls-Column"><h3>Type d\'occurrence :</h3><ul class="Ls-Occtypes"><li data="narrative" class="Ls-Critere Ls-Active Ls-CrWithIcon"><div class="Ls-OccIcon Tl-Occnarrative"></div>Narratives</li><li data="publication" class="Ls-Critere Ls-Active Ls-CrWithIcon"><div class="Ls-OccIcon Tl-Occpublication"></div>de Publication</li></ul>' |
|
223 |
+ '<h3>Statut :</h3><ul class="Ls-Occstatuses"><li data="a_realiser" class="Ls-Critere Ls-Active Ls-CrWithIcon"><div class="Ls-OccIcon Tl-Occpublication Tl-Occa_realiser"></div>À réaliser</li><li data="a_valider" class="Ls-Critere Ls-Active Ls-CrWithIcon"><div class="Ls-OccIcon Tl-Occpublication Tl-Occa_valider"></div>À valider</li><li data="valide" class="Ls-Critere Ls-Active Ls-CrWithIcon"><div class="Ls-OccIcon Tl-Occpublication Tl-Occvalide"></div>Validé</li></ul>' |
|
224 |
+ '<h3>Est au JT :</h3><ul class="Ls-IsJt"><li class="Ls-Critere Ls-Active" data="1">Oui</li><li class="Ls-Critere Ls-Active" data="0">Non</li></ul></div>' |
|
225 |
+ '<div class="Ls-Column"><h3>Recherche par titre :</h3><p><input class="Ls-Search" type="search" placeholder="Rechercher" /></p><h3>Date :</h3><p><label class="Ls-Label">Du </label><input class="Ls-From-Date Ls-Input" /></p><p><label class="Ls-Label">à </label><input class="Ls-From-Time Ls-Input" /></p><p><label class="Ls-Label">Au </label><input class="Ls-To-Date Ls-Input" /></p><p><label class="Ls-Label">à </label><input class="Ls-To-Time Ls-Input" /></p></div>' |
|
226 |
+ '</div><div class="Ls-Resultats"><h2>Occurrences :</h2><ul class="Ls-Occurrences"></ul></div></div>'; |
|
227 |
|
|
228 |
Tlns.Templates.Univers = '<span class="Tl-UniversText">{{title}}</span>'; |
|
229 |
|
|
230 |
Tlns.Templates.Univers_List = '{{#univers}}<li data="{{id}}" class="Ls-Critere Ls-Active">{{title}}</li>{{/univers}}'; |
|
231 |
|
|
232 |
Tlns.Templates.Occurrence = '{{#clusters}}<div class="Tl-Cluster" style="left: {{x}}px; top: {{y}}px;" cluster-contents="{{contents}}">' |
|
233 |
+ '<div class="Tl-ClusterCount">{{occurrences.length}}</div></div>{{/clusters}}' |
|
234 |
+ '{{#occurrences}}<div class="Tl-Occurrence Tl-OccOnGrid Tl-Occ{{type}} Tl-Occ{{status}}{{#editing}} Tl-Editing{{/editing}}" occurrence-id="{{id}}" style="left: {{x}}px; top: {{y}}px;">' |
|
235 |
// + '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}' |
|
236 |
+ '<div class="Tl-Link"{{#editing}} style="display: block"{{/editing}}></div></div>{{/occurrences}}{{#open_cluster}}<div class="Tl-ClusterOverlay" style="left: {{x}}px; top: {{y}}px;">' |
|
237 |
+ '{{#occurrences}}<div class="Tl-Occurrence Tl-OccInCluster Tl-Occ{{type}} Tl-Occ{{status}}{{#editing}} Tl-Editing{{/editing}}" occurrence-id="{{id}}">' |
|
238 |
+ '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}<div class="Tl-Link"{{#editing}} style="display: block"{{/editing}}></div></div>{{/occurrences}}</div>{{/open_cluster}}'; |
|
239 |
|
|
240 |
Tlns.Templates.Occurrence_List = '{{#occurrences}}<li class="Ls-Occurrence"><div class="Ls-OccIcon Tl-Occ{{type}} Tl-Occ{{status}}"></div><h4 class="Ls-Occurrence-Title">{{title}}</h4>' |
|
241 |
+ '<p class="Ls-Occ-More">{{formatted_date}} — {{univers.title}} — {{translated_status}} — {{#jt}}Au JT{{/jt}}{{^jt}}Hors JT{{/jt}}</p><div style="clear:both;"></div></li>{{/occurrences}}'; |
|
242 |
|
|
243 |
Tlns.Templates.OccurrenceTooltip = '<h3 class="Tl-Tooltip-Title">{{title}}</h3><p class="Tl-Tooltip-Date">{{formatted_date}} — {{translated_status}}</p>' |
|
244 |
+ '<p class="Tl-Tooltip-Description">{{description}}</p>' |
|
245 |
// + '<p class="Tl-Tooltip-Characters">{{univers.mainCharacter}}{{#characters}}, {{.}}{{/characters}}</p>' |
|
246 |
|
|
247 |
/* Classes */ |
|
248 |
|
|
249 |
Tlns.Classes.Timeline = function(_options) { |
|
250 |
|
|
251 |
/* Setting Defaults */ |
|
252 |
Tlns.Utils.SetDefaults(this, Tlns.Defaults.Timeline, _options); |
|
253 |
|
|
254 |
/* Setting container CSS */ |
|
255 |
this.$ = $('#' + this.container).html(Mustache.to_html(Tlns.Templates.Timeline, this)); |
|
256 |
|
|
257 |
this.$.find('.Tl-Main').css({ |
|
258 |
width : this.width + "px", |
|
259 |
height : this.height + "px" |
|
260 |
}); |
|
261 |
this.main_height = this.height - this.$.find('.Tl-TopBar').outerHeight(); |
|
262 |
this.$.find('.Tl-BottomPart').css("height", this.main_height + "px"); |
|
263 |
this.$.find('.Tl-MainPart').css("width", this.main_width + "px"); |
|
264 |
this.$.find('.Tl-Overlay-Container').css("left", (this.$.find('.Tl-BottomPart').outerWidth() - this.main_width) + "px"); |
|
265 |
this.$.find('canvas.Tl-Layer').attr({ |
|
266 |
width: this.main_width, |
|
267 |
height: this.main_height |
|
268 |
}); |
|
269 |
var _o = this.$.find('.Tl-MainPart').offset(); |
|
270 |
this.dragging_bounds = { |
|
271 |
left: _o.left, |
|
272 |
top: _o.top, |
|
273 |
right: _o.left + this.$.find('.Tl-MainPart').outerWidth(), |
|
274 |
bottom: _o.top + this.$.find('.Tl-MainPart').outerHeight(), |
|
275 |
}; |
|
276 |
|
|
277 |
var _this = this; |
|
278 |
|
|
279 |
this.throttledDrawGrid = _.throttle(function() { |
|
280 |
_this.drawGrid(); |
|
281 |
}, 150); |
|
282 |
|
|
283 |
this.throttledDrawList = _.throttle(function() { |
|
284 |
_this.drawList(); |
|
285 |
}, 150); |
|
286 |
|
|
287 |
this.setLevel(this.level); |
|
288 |
|
|
289 |
this.$.find('.Tl-TopBar-Timescales>div').click(function() { |
|
290 |
_this.setLevel($(this).attr("data-level")); |
|
291 |
}); |
|
292 |
|
|
293 |
this.$.find('.Tl-TopBar-SyncButton').click(function() { |
|
294 |
_this.sync_now = !_this.sync_now; |
|
295 |
_this.changeSpan(); |
|
296 |
}) |
|
297 |
|
|
298 |
this.$.find('.Tl-TopBar-PreviousButton').click(function() { |
|
299 |
_this.offsetTime(-_this.timescales[_this.level].span / 4); |
|
300 |
}); |
|
301 |
|
|
302 |
this.$.find('.Tl-TopBar-NextButton').click(function() { |
|
303 |
_this.offsetTime(_this.timescales[_this.level].span / 4); |
|
304 |
}); |
|
305 |
|
|
306 |
this.$.find('.Tl-MainPart').mousedown(function(_event) { |
|
307 |
_this.onMouseDown(_event); |
|
308 |
return false; |
|
309 |
}); |
|
310 |
|
|
311 |
this.$.find('.Tl-MainPart').mousemove(function(_event) { |
|
312 |
_this.onMouseMove(_event); |
|
313 |
return false; |
|
314 |
}); |
|
315 |
|
|
316 |
this.$.find('.Tl-MainPart').mouseup(function(_event) { |
|
317 |
_this.onMouseUp(_event); |
|
318 |
return false; |
|
319 |
}); |
|
320 |
|
|
321 |
this.$.find('.Tl-MainPart').mousewheel(function(_event, _delta) { |
|
322 |
var _newLevel = Math.max(0,Math.min(_this.timescales.length-1, (_delta < 0 ? -1 : 1) + parseInt(_this.level))); |
|
323 |
if (_newLevel != _this.level) { |
|
324 |
_this.hideTooltip(); |
|
325 |
var _deltaX = _event.pageX - _this.dragging_bounds.left, |
|
326 |
_tAtMouse = _this.timeFromMouse(_event.pageX), |
|
327 |
_newScale = _this.main_width / (_this.timescales[_newLevel].span), |
|
328 |
_newStart = _tAtMouse - _deltaX / _newScale; |
|
329 |
_this.central_time = _newStart + _this.timescales[_newLevel].span / 2; |
|
330 |
_this.setLevel(_newLevel); |
|
331 |
} |
|
332 |
return false; |
|
333 |
}); |
|
334 |
|
|
335 |
this.$.find('.Tl-Overlay-Box').mouseover(function(_event) { |
|
336 |
$(this).show(); |
|
337 |
}).mouseout(function(_event) { |
|
338 |
$(this).hide(); |
|
339 |
}); |
|
340 |
|
|
341 |
this.$.find('.Tl-TopBar-AddButton').click(function() { |
|
342 |
$(this).toggleClass('active'); |
|
343 |
_this.$.find('.Tl-Adding').toggle(); |
|
344 |
}); |
|
345 |
|
|
346 |
this.$.find('.Tl-AddOccurrence').mousedown(function(_event) { |
|
347 |
var _el = $(this), |
|
348 |
_type = _el.attr("occurrence-type"), |
|
349 |
_d = _this.timeFromMouse(_event.pageX), |
|
350 |
_u = _this.universFromMouse(_event.pageY), |
|
351 |
_occ = _this.createOrUpdateOccurrence( |
|
352 |
_type, |
|
353 |
{ |
|
354 |
datePublication: Math.floor(_d / 1000), |
|
355 |
titre: '<Nouvelle occurrence>', |
|
356 |
idUnivers: _this.univers[_u].id, |
|
357 |
statut: 'a_realiser', |
|
358 |
jt: false |
|
359 |
} |
|
360 |
); |
|
361 |
_occ.just_created = true; |
|
362 |
_occ.editing = true; |
|
363 |
_this.editing_occurrence = _occ; |
|
364 |
_this.dragging_type = "occurrence"; |
|
365 |
window.setTimeout(function () { |
|
366 |
_this.$.find('.Tl-TopBar-AddButton').removeClass('active'); |
|
367 |
_this.$.find('.Tl-Adding').hide(); |
|
368 |
}, 200); |
|
369 |
_this.throttledDrawGrid(); |
|
370 |
}).mouseup(function(_event) { |
|
371 |
_this.onMouseUp(_event); |
|
372 |
return false; |
|
373 |
}); |
|
374 |
|
|
375 |
/* Loading Univers */ |
|
376 |
$.getJSON(this.url_univers, function(_data) { |
|
377 |
_this.onUniversLoaded(_data); |
|
378 |
}); |
|
379 |
|
|
380 |
/* LIST */ |
|
381 |
|
|
382 |
this.$.find("li.Ls-Critere").click(function() { |
|
383 |
$(this).toggleClass("Ls-Active"); |
|
384 |
_this.throttledDrawList(); |
|
385 |
}); |
|
386 |
this.$.find(".Ls-Search").bind("keyup change click", function() { |
|
387 |
_this.throttledDrawList(); |
|
388 |
}); |
|
389 |
this.$.find(".Ls-From-Date, .Ls-To-Date").datepicker( |
|
390 |
{ |
|
391 |
dateFormat: "dd/mm/yy", |
|
392 |
dayNames: [ "Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi" ], |
|
393 |
dayNamesShort: [ "Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam" ], |
|
394 |
dayNamesMin: [ "D", "L", "Ma", "Me", "J", "V", "S" ], |
|
395 |
monthNames: [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" ], |
|
396 |
monthNamesShort: [ "Jan", "Fév", "Mar", "Avr", "Mai", "Jun", "Jul", "Aoû", "Sep", "Oct", "Nov", "Déc" ], |
|
397 |
showOtherMonths: true, |
|
398 |
selectOtherMonths: true |
|
399 |
} |
|
400 |
).change(function() { |
|
401 |
var _val = $(this).val(); |
|
402 |
if (_val) { |
|
403 |
$(this).val(Tlns.Utils.dateFieldProcess( _val ).text); |
|
404 |
} |
|
405 |
_this.drawList(); |
|
406 |
}).bind("keyup", function() { |
|
407 |
_this.throttledDrawList(); |
|
408 |
}); |
|
409 |
this.$.find(".Ls-From-Time, .Ls-To-Time").change(function() { |
|
410 |
var _val = $(this).val(); |
|
411 |
if (_val) { |
|
412 |
$(this).val(Tlns.Utils.timeFieldProcess( _val ).text); |
|
413 |
} |
|
414 |
_this.throttledDrawList(); |
|
415 |
}).bind("keyup", function() { |
|
416 |
_this.throttledDrawList(); |
|
417 |
}); |
|
418 |
|
|
419 |
this.$.find(".Onglet-Tl").click(function() { |
|
420 |
_this.$.find(".Tl-Main").show(); |
|
421 |
_this.$.find(".Ls-Main").hide(); |
|
422 |
_this.$.find(".Onglet-Ls").removeClass("active"); |
|
423 |
_this.$.find(".Onglet-Tl").addClass("active"); |
|
424 |
_this.throttledDrawGrid(); |
|
425 |
}); |
|
426 |
|
|
427 |
this.$.find(".Onglet-Ls").click(function() { |
|
428 |
_this.$.find(".Ls-Main").show(); |
|
429 |
_this.$.find(".Tl-Main").hide(); |
|
430 |
_this.$.find(".Onglet-Tl").removeClass("active"); |
|
431 |
_this.$.find(".Onglet-Ls").addClass("active"); |
|
432 |
_this.throttledDrawList(); |
|
433 |
}); |
|
434 |
|
|
435 |
|
|
436 |
/* BINDING MEDIADATA EVENTS */ |
|
437 |
|
|
438 |
$("body").bind("AjoutOccurrenceEditeur MiseAJourOccurrenceEditeur", function(_event, _data) { |
|
439 |
var _type = _data.typeOccurrence.replace(/^occurrence/i,'').toLowerCase(); |
|
440 |
_this.createOrUpdateOccurrence(_type, _data); |
|
441 |
_this.throttledDrawGrid(); |
|
442 |
}); |
|
443 |
|
|
444 |
$("body").bind("SuppressionOccurrenceEditeur", function(_event, _data) { |
|
445 |
var _id = _data.typeOccurrence.replace(/^occurrence/i,'').toLowerCase() + '_' + _data.id; |
|
446 |
_this.deleteOccurrence(_id); |
|
447 |
_this.throttledDrawGrid(); |
|
448 |
}); |
|
449 |
|
|
450 |
$("body").bind("AjoutDependanceEditeur", function(_event, _data) { |
|
451 |
var _sourceId = _data.typeOccurrence.replace(/^occurrence/i,'').toLowerCase() + '_' + _data.id, |
|
452 |
_targetId = _data.typeOccurrenceCible.replace(/^occurrence/i,'').toLowerCase() + '_' + _data.idCible; |
|
453 |
_this.getOccurrence(_sourceId).addDependency(_targetId); |
|
454 |
_this.throttledDrawGrid(); |
|
455 |
}); |
|
456 |
|
|
457 |
$("body").bind("SuppressionDependanceEditeur", function(_event, _data) { |
|
458 |
var _sourceId = _data.typeOccurrence.replace(/^occurrence/i,'').toLowerCase() + '_' + _data.id, |
|
459 |
_targetId = _data.typeOccurrenceCible.replace(/^occurrence/i,'').toLowerCase() + '_' + _data.idCible; |
|
460 |
_this.getOccurrence(_sourceId).addDependency(_targetId); |
|
461 |
_this.throttledDrawGrid(); |
|
462 |
}); |
|
463 |
|
|
464 |
|
|
465 |
} |
|
466 |
|
|
467 |
Tlns.Classes.Timeline.prototype.onMouseDown = function(_event) { |
|
468 |
this.mouse_down = true; |
|
469 |
this.is_dragging = false; |
|
470 |
this.start_pos = { |
|
471 |
x: _event.pageX, |
|
472 |
y: _event.pageY |
|
473 |
}; |
|
474 |
if (typeof this.dragging_type === "undefined") { |
|
475 |
this.time_at_start = this.central_time; |
|
476 |
this.dragging_type = "timeline"; |
|
477 |
} |
|
478 |
} |
|
479 |
|
|
480 |
Tlns.Classes.Timeline.prototype.onMouseUp = function(_event) { |
|
481 |
if (this.is_dragging) { |
|
482 |
switch (this.dragging_type) { |
|
483 |
case "occurrence": |
|
484 |
var _event = ( this.editing_occurrence.just_created ? "Ajout" : "MiseAJour" ) + "OccurrenceTimeline", |
|
485 |
_data = { |
|
486 |
id: this.editing_occurrence.original_id, |
|
487 |
typeOccurrence: "occurrence" + this.editing_occurrence.type.replace(/^./,function(_l) { return _l.toUpperCase()}), |
|
488 |
datePublication : Math.floor(this.editing_occurrence.date / 1000), |
|
489 |
titre : this.editing_occurrence.title, |
|
490 |
idUnivers: this.editing_occurrence.univers_id, |
|
491 |
statut: this.statuses[this.editing_occurrence.status], |
|
492 |
JT: +!!this.editing_occurrence.jt |
|
493 |
} |
|
494 |
$("body").trigger(_event, _data); |
|
495 |
this.editing_occurrence.editing = false; |
|
496 |
this.editing_occurrence.just_created = false; |
|
497 |
this.throttledDrawGrid(); |
|
498 |
break; |
|
499 |
case "link": |
|
500 |
this.editing_occurrence.editing = false; |
|
501 |
this.throttledDrawGrid(); |
|
502 |
var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
503 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
504 |
break; |
|
505 |
} |
|
506 |
} else { |
|
507 |
if (this.dragging_type == "occurrence" || this.dragging_type == "link") { |
|
508 |
if (this.editing_occurrence.just_created) { |
|
509 |
this.deleteOccurrence(this.editing_occurrence.id); |
|
510 |
this.throttledDrawGrid(); |
|
511 |
} else { |
|
512 |
var _data = { |
|
513 |
id: this.editing_occurrence.original_id, |
|
514 |
typeOccurrence: "occurrence" + this.editing_occurrence.type.replace(/^./,function(_l) { return _l.toUpperCase()}) |
|
515 |
} |
|
516 |
$("body").trigger("SelectionOccurrenceTimeline", _data); |
|
517 |
} |
|
518 |
} |
|
519 |
} |
|
520 |
this.mouse_down = false; |
|
521 |
this.is_dragging = false; |
|
522 |
this.dragging_type = undefined; |
|
523 |
} |
|
524 |
|
|
525 |
Tlns.Classes.Timeline.prototype.timeFromX = function(_x) { |
|
526 |
return Math.max(this.start_time,Math.min(this.end_time, this.start_time + _x / this.current_scale)); |
|
527 |
} |
|
528 |
|
|
529 |
Tlns.Classes.Timeline.prototype.timeFromMouse = function(_pageX) { |
|
530 |
return this.timeFromX(_pageX - this.dragging_bounds.left); |
|
531 |
} |
|
532 |
|
|
533 |
Tlns.Classes.Timeline.prototype.universFromY = function(_y) { |
|
534 |
return Math.max(0,Math.min(this.univers.length, Math.floor(_y / this.univers_height))) |
|
535 |
} |
|
536 |
|
|
537 |
Tlns.Classes.Timeline.prototype.universFromMouse = function(_pageY) { |
|
538 |
return this.universFromY(_pageY - this.dragging_bounds.top); |
|
539 |
} |
|
540 |
|
|
541 |
Tlns.Classes.Timeline.prototype.onMouseMove = function(_event) { |
|
542 |
if (this.mouse_down) { |
|
543 |
this.is_dragging = true; |
|
544 |
this.hideTooltip(); |
|
545 |
switch (this.dragging_type) { |
|
546 |
case "occurrence": |
|
547 |
var _d = this.timeFromMouse(_event.pageX); |
|
548 |
this.editing_occurrence.date = _d; |
|
549 |
this.editing_occurrence.formatted_date = Tlns.Utils.dateFormat(this.editing_occurrence.date,this.tooltip_date_format); |
|
550 |
var _u = this.universFromMouse(_event.pageY); |
|
551 |
this.editing_occurrence.univers = this.univers[_u]; |
|
552 |
this.editing_occurrence.univers_id = this.univers[_u].id; |
|
553 |
this.throttledDrawGrid(); |
|
554 |
break; |
|
555 |
case "timeline": |
|
556 |
this.setTime(this.time_at_start + Math.floor(( this.start_pos.x - _event.pageX ) / this.current_scale)); |
|
557 |
break; |
|
558 |
case "link": |
|
559 |
var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
560 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
561 |
Tlns.Utils.drawArrow( |
|
562 |
_ctx, |
|
563 |
'#800080', |
|
564 |
this.editing_occurrence.x, |
|
565 |
this.editing_occurrence.y + Math.floor(this.univers_height / 2), |
|
566 |
_event.pageX - this.dragging_bounds.left, |
|
567 |
_event.pageY - this.dragging_bounds.top |
|
568 |
); |
|
569 |
break; |
|
570 |
} |
|
571 |
} |
|
572 |
} |
|
573 |
|
|
574 |
Tlns.Classes.Timeline.prototype.onUniversLoaded = function(_data) { |
|
575 |
this.univers = []; |
|
576 |
if(_data.length) { |
|
577 |
this.univers_height = Math.floor(this.main_height / _data.length); |
|
578 |
} |
|
579 |
for(var _i = 0; _i < _data.length; _i++) { |
|
580 |
this.univers.push(new Tlns.Classes.Univers(_data[_i], this, _i)); |
|
581 |
} |
|
582 |
|
|
583 |
this.$.find(".Ls-Univers").html(Mustache.to_html(Tlns.Templates.Univers_List, this)); |
|
584 |
var _this = this; |
|
585 |
this.$.find(".Ls-Univers li.Ls-Critere").click( function() { |
|
586 |
$(this).toggleClass("Ls-Active"); |
|
587 |
_this.throttledDrawList(); |
|
588 |
}); |
|
589 |
this.loadOccurrences(); |
|
590 |
} |
|
591 |
|
|
592 |
Tlns.Classes.Timeline.prototype.offsetTime = function(_timeOffset) { |
|
593 |
this.setTime(this.central_time + _timeOffset); |
|
594 |
} |
|
595 |
|
|
596 |
Tlns.Classes.Timeline.prototype.setTime = function(_centralTime) { |
|
597 |
this.sync_now = false; |
|
598 |
this.central_time = _centralTime; |
|
599 |
this.changeSpan(); |
|
600 |
} |
|
601 |
|
|
602 |
Tlns.Classes.Timeline.prototype.setLevel = function(_level) { |
|
603 |
if (_level >= 0 && _level < this.timescales.length) { |
|
604 |
this.$.find('.Tl-TopBar-Timescales>div').each(function() { |
|
605 |
var _el = $(this); |
|
606 |
if (_el.attr("data-level") == _level) { |
|
607 |
_el.addClass("active"); |
|
608 |
} else { |
|
609 |
_el.removeClass("active"); |
|
610 |
} |
|
611 |
}); |
|
612 |
this.level = _level; |
|
613 |
this.changeSpan(); |
|
614 |
} |
|
615 |
} |
|
616 |
|
|
617 |
Tlns.Classes.Timeline.prototype.changeSpan = function() { |
|
618 |
var _now = new Date().valueOf(); |
|
619 |
if (this.sync_now) { |
|
620 |
this.central_time = _now; |
|
621 |
} |
|
622 |
var _timescale = this.timescales[this.level]; |
|
623 |
this.current_scale = this.main_width / (_timescale.span); |
|
624 |
this.start_time = this.central_time - (_timescale.span / 2); |
|
625 |
this.end_time = this.central_time + (_timescale.span / 2); |
|
626 |
this.$.find(".Ls-From-Time").val(Tlns.Utils.dateFormat(this.start_time, '{{0hours}}:{{0minutes}}')); |
|
627 |
this.$.find(".Ls-From-Date").val(Tlns.Utils.dateFormat(this.start_time, '{{0dayOfMonth}}/{{0monthNumber}}/{{year}}')); |
|
628 |
this.$.find(".Ls-To-Time").val(Tlns.Utils.dateFormat(this.end_time, '{{0hours}}:{{0minutes}}')); |
|
629 |
this.$.find(".Ls-To-Date").val(Tlns.Utils.dateFormat(this.end_time, '{{0dayOfMonth}}/{{0monthNumber}}/{{year}}')); |
|
630 |
this.throttledDrawGrid(); |
|
631 |
this.throttledDrawList(); |
|
632 |
} |
|
633 |
|
|
634 |
Tlns.Classes.Timeline.prototype.drawGrid = function() { |
|
635 |
if (this.sync_now) { |
|
636 |
this.$.find('.Tl-TopBar-SyncButton').addClass("active"); |
|
637 |
} else { |
|
638 |
this.$.find('.Tl-TopBar-SyncButton').removeClass("active"); |
|
639 |
} |
|
640 |
var _now = new Date().valueOf(), |
|
641 |
_timescale = this.timescales[this.level], |
|
642 |
_offset = new Date().getTimezoneOffset() * 60000, |
|
643 |
_grid_width = Math.floor(_timescale.grid_interval * this.current_scale), |
|
644 |
_roundstart = Math.floor((this.start_time - _offset) / _timescale.grid_interval) * _timescale.grid_interval + _offset, |
|
645 |
_html = ''; |
|
646 |
this.$.find('.Tl-TopBar-TimeSpan').html(Tlns.Utils.dateFormat(this.start_time, _timescale.start_date_format) + ' - ' + Tlns.Utils.dateFormat(this.end_time, _timescale.end_date_format)); |
|
647 |
for (var _t = _roundstart; _t < this.end_time; _t += _timescale.grid_interval) { |
|
648 |
var _x = this.current_scale * (_t - this.start_time); |
|
649 |
if (_x > 0) { |
|
650 |
_html += '<div class="Tl-Grid-Column" style="width:' + _grid_width + 'px; left: ' + _x + 'px">' |
|
651 |
+ '<div class="Tl-Grid-Label">' + Tlns.Utils.dateFormat(_t, _timescale.grid_date_format) + '</div></div>'; |
|
652 |
} |
|
653 |
} |
|
654 |
if (this.start_time <= _now && this.end_time >= _now) { |
|
655 |
_html += '<div class="Tl-Grid-Now" style="left: ' + this.current_scale * (_now - this.start_time) + 'px"></div>' |
|
656 |
} |
|
657 |
this.$.find('.Tl-Grid').html(_html); |
|
658 |
this.drawOccurrences(); |
|
659 |
} |
|
660 |
|
|
661 |
Tlns.Classes.Timeline.prototype.loadOccurrences = function() { |
|
662 |
var _this = this; |
|
663 |
_(this.urls_occurrences).each(function(_url_occ) { |
|
664 |
$.getJSON(_url_occ.url, function(_data) { |
|
665 |
_this.onOccurrencesLoaded(_data, _url_occ.type); |
|
666 |
}); |
|
667 |
}); |
|
668 |
|
|
669 |
} |
|
670 |
|
|
671 |
Tlns.Classes.Timeline.prototype.onOccurrencesLoaded = function(_data, _type) { |
|
672 |
for (var _i = 0; _i < _data.length; _i++) { |
|
673 |
this.createOrUpdateOccurrence(_type, _data[_i]); |
|
674 |
} |
|
675 |
if (!this.mouse_down) { |
|
676 |
this.drawOccurrences(); |
|
677 |
} |
|
678 |
this.throttledDrawList(); |
|
679 |
} |
|
680 |
|
|
681 |
Tlns.Classes.Timeline.prototype.deleteOccurrence = function(_id) { |
|
682 |
this.occurrences = _(this.occurrences).reject(function(_occ) { |
|
683 |
return _occ.id == _id; |
|
684 |
}); |
|
685 |
} |
|
686 |
|
|
687 |
Tlns.Classes.Timeline.prototype.getOccurrence = function(_id) { |
|
688 |
return _(this.occurrences).find(function(_occ) { |
|
689 |
return _occ.id == _id; |
|
690 |
}); |
|
691 |
} |
|
692 |
|
|
693 |
Tlns.Classes.Timeline.prototype.createOrUpdateOccurrence = function(_type, _data) { |
|
694 |
var _id = _type + "_" + _data.id, |
|
695 |
_occurrence = this.getOccurrence(_id); |
|
696 |
if (typeof _occurrence === "undefined") { |
|
697 |
_occurrence = new Tlns.Classes.Occurrence(this); |
|
698 |
this.occurrences.push(_occurrence); |
|
699 |
} |
|
700 |
_occurrence.update(_type, _data); |
|
701 |
return _occurrence; |
|
702 |
} |
|
703 |
|
|
704 |
Tlns.Classes.Timeline.prototype.showTooltip = function(_x, _y, _html, _isUp) { |
|
705 |
this.$.find('.Tl-Overlay-Box') |
|
706 |
.removeClass(_isUp ? 'Tl-Overlay-Down' : 'Tl-Overlay-Up') |
|
707 |
.addClass(_isUp ? 'Tl-Overlay-Up' : 'Tl-Overlay-Down') |
|
708 |
.show() |
|
709 |
.css({ |
|
710 |
left: _x + "px", |
|
711 |
top: _y + "px" |
|
712 |
}); |
|
713 |
this.$.find('.Tl-Overlay-Main').html(_html); |
|
714 |
} |
|
715 |
|
|
716 |
Tlns.Classes.Timeline.prototype.hideTooltip = function() { |
|
717 |
this.$.find('.Tl-Overlay-Box').hide(); |
|
718 |
} |
|
719 |
|
|
720 |
Tlns.Classes.Timeline.prototype.drawOccurrences = function() { |
|
721 |
var _this = this, |
|
722 |
_visible = _(this.occurrences).filter(function(_occ) { |
|
723 |
return (_occ.date >= _this.start_time && _occ.date <= _this.end_time && _occ.status); |
|
724 |
}); |
|
725 |
_(_visible).each(function(_occ) { |
|
726 |
_occ.x = _this.current_scale * (_occ.date - _this.start_time); |
|
727 |
_occ.y = _occ.univers.y; |
|
728 |
_occ.in_cluster = false; |
|
729 |
}); |
|
730 |
|
|
731 |
var _moved = true; |
|
732 |
while (_moved) { |
|
733 |
_moved = false; |
|
734 |
for (var _i = 0; _i < _visible.length; _i++) { |
|
735 |
for (var _j = 0; _j < _i; _j++) { |
|
736 |
if (_visible[_j].univers_id == _visible[_i].univers_id |
|
737 |
&& _visible[_j].x != _visible[_i].x |
|
738 |
&& Math.abs(_visible[_j].x-_visible[_i].x) < this.cluster_spacing |
|
739 |
) { |
|
740 |
_moved = true; |
|
741 |
_visible[_i].x = this.cluster_spacing * Math.round(_visible[_i].x / this.cluster_spacing); |
|
742 |
_visible[_j].x = this.cluster_spacing * Math.round(_visible[_j].x / this.cluster_spacing); |
|
743 |
} |
|
744 |
} |
|
745 |
} |
|
746 |
} |
|
747 |
var _clusters = [], |
|
748 |
_openCluster = false; |
|
749 |
for (var _i = 0; _i < _visible.length; _i++) { |
|
750 |
for (var _j = 0; _j < _i; _j++) { |
|
751 |
if (_visible[_j].univers_id == _visible[_i].univers_id && _visible[_j].x == _visible[_i].x) { |
|
752 |
_visible[_j].in_cluster = true; |
|
753 |
_visible[_i].in_cluster = true; |
|
754 |
var _x = _visible[_j].x, |
|
755 |
_y = _visible[_j].y; |
|
756 |
_cluster = _(_clusters).find(function(_c) { return _c.x == _x && _c.y == _y }); |
|
757 |
if (typeof _cluster === "undefined") { |
|
758 |
_cluster = { x: _x, y: _y, occurrences: [] }; |
|
759 |
_clusters.push(_cluster); |
|
760 |
} |
|
761 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
762 |
return _o.type == _visible[_j].type && _o.id == _visible[_j].id; |
|
763 |
})) { |
|
764 |
_cluster.occurrences.push(_visible[_j]); |
|
765 |
} |
|
766 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
767 |
return _o.type == _visible[_i].type && _o.id == _visible[_i].id; |
|
768 |
})) { |
|
769 |
_cluster.occurrences.push(_visible[_i]); |
|
770 |
} |
|
771 |
} |
|
772 |
} |
|
773 |
} |
|
774 |
_(_clusters).each(function(_cluster) { |
|
775 |
_cluster.occurrences = _(_cluster.occurrences).sortBy(function(_o) { |
|
776 |
return _o.date; |
|
777 |
}); |
|
778 |
_cluster.contents = _cluster.occurrences.map(function(_o) { |
|
779 |
return _o.type + ":" + _o.id; |
|
780 |
}).join("|"); |
|
781 |
if (_cluster.contents == _this.open_cluster) { |
|
782 |
_openCluster = _cluster; |
|
783 |
} |
|
784 |
}); |
|
785 |
|
|
786 |
|
|
787 |
var _links = []; |
|
788 |
|
|
789 |
_(_visible).each(function(_occurrence) { |
|
790 |
_(_occurrence.dependsOn).each(function(_dependance) { |
|
791 |
var _parent = _(_visible).find(function(_o) { |
|
792 |
return _o.id == _dependance; |
|
793 |
}); |
|
794 |
if (typeof _parent !== "undefined") { |
|
795 |
_links.push({ |
|
796 |
from_x: _occurrence.x, |
|
797 |
from_y: _occurrence.y + Math.floor(_this.univers_height / 2), |
|
798 |
to_x: _parent.x, |
|
799 |
to_y: _parent.y + Math.floor(_this.univers_height / 2) |
|
800 |
}); |
|
801 |
} |
|
802 |
}); |
|
803 |
}); |
|
804 |
|
|
805 |
var _ctx = this.$.find('.Tl-Canvas')[0].getContext('2d'); |
|
806 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
807 |
_(_links).each(function(_link) { |
|
808 |
Tlns.Utils.drawArrow(_ctx, "#505050", _link.from_x,_link.from_y, _link.to_x,_link.to_y); |
|
809 |
}); |
|
810 |
|
|
811 |
var _html = Mustache.to_html(Tlns.Templates.Occurrence, { |
|
812 |
occurrences:_(_visible).reject(function(_o) {return _o.in_cluster}), |
|
813 |
clusters: _clusters, |
|
814 |
open_cluster: _openCluster |
|
815 |
}); |
|
816 |
this.$.find('.Tl-Occurrences').html(_html); |
|
817 |
|
|
818 |
|
|
819 |
if (_openCluster) { |
|
820 |
var _w = this.$.find('.Tl-Occurrence').width(), |
|
821 |
_ww = _w * _openCluster.occurrences.length; |
|
822 |
this.$.find('.Tl-ClusterOverlay').css({ |
|
823 |
"margin-left": - Math.floor(_ww/2) + "px", |
|
824 |
width: _ww |
|
825 |
}); |
|
826 |
_(_openCluster.occurrences).each(function(_o, _i) { |
|
827 |
_o.y = _o.y - 20; |
|
828 |
_o.x = _o.x - (_ww / 2) + ((_i + .5) * _w); |
|
829 |
}); |
|
830 |
} |
|
831 |
|
|
832 |
this.$.find('.Tl-Occurrence').mousedown(function() { |
|
833 |
var _el = $(this), |
|
834 |
_id = _el.attr("occurrence-id"); |
|
835 |
if (typeof _id !== "undefined") { |
|
836 |
_this.editing_occurrence = _this.getOccurrence(_id); |
|
837 |
if (typeof _this.dragging_type === "undefined" && typeof _this.editing_occurrence !== "undefined" /* && !_this.editing_occurrence.locked */ ) { |
|
838 |
_this.dragging_type = "occurrence"; |
|
839 |
_this.editing_occurrence.editing = true; |
|
840 |
} |
|
841 |
} |
|
842 |
}).mouseover(function(_event) { |
|
843 |
var _el = $(this), |
|
844 |
_id = _el.attr("occurrence-id"); |
|
845 |
if (typeof _id !== "undefined") { |
|
846 |
var _occurrence = _this.getOccurrence(_id); |
|
847 |
// if (!_occurrence.locked) { |
|
848 |
_el.find('.Tl-Link').show(); |
|
849 |
// } |
|
850 |
if (!_this.is_dragging) { |
|
851 |
var _html = Mustache.to_html(Tlns.Templates.OccurrenceTooltip, _occurrence); |
|
852 |
_this.showTooltip(_occurrence.x, _occurrence.y, _html, (_event.pageY - _this.dragging_bounds.top) >= (.4 * _this.main_height) ); |
|
853 |
} |
|
854 |
} |
|
855 |
}).mouseout(function() { |
|
856 |
var _el = $(this), |
|
857 |
_id = _el.attr("occurrence-id"); |
|
858 |
if (typeof _id !== "undefined") { |
|
859 |
var _occurrence = _this.getOccurrence(_id); |
|
860 |
_this.hideTooltip(); |
|
861 |
if (!_occurrence.editing) { |
|
862 |
$(this).find('.Tl-Link').hide(); |
|
863 |
} |
|
864 |
} |
|
865 |
}).mouseup(function() { |
|
866 |
var _el = $(this); |
|
867 |
if (_this.dragging_type == "link") { |
|
868 |
var _target = _el.attr("occurrence-id"); |
|
869 |
if (_target != _this.editing_occurrence.id) { |
|
870 |
_this.editing_occurrence.addDependency(_target); |
|
871 |
$("body").trigger("AjoutDependanceTimeline", |
|
872 |
{ |
|
873 |
id: _this.editing_occurrence.original_id, |
|
874 |
typeOccurrence: "occurrence" + _this.editing_occurrence.type.replace(/^./,function(_l) { return _l.toUpperCase()}), |
|
875 |
idCible: _target.replace(/^.*_/,''), |
|
876 |
typeOccurrenceCible: "occurrence" + _target.replace(/_.*$/,'').replace(/^./,function(_l) { return _l.toUpperCase()}) |
|
877 |
} |
|
878 |
); |
|
879 |
} |
|
880 |
} |
|
881 |
}); |
|
882 |
|
|
883 |
this.$.find('.Tl-Link').mousedown(function() { |
|
884 |
var _el = $(this).parent(), |
|
885 |
_id = _el.attr("occurrence-id"); |
|
886 |
_this.editing_occurrence = _this.getOccurrence(_id); |
|
887 |
if (typeof _this.editing_occurrence !== "undefined" /* && !_this.editing_occurrence.locked */ ) { |
|
888 |
_this.dragging_type = "link"; |
|
889 |
_this.editing_occurrence.editing = true; |
|
890 |
} |
|
891 |
}) |
|
892 |
|
|
893 |
this.$.find('.Tl-Cluster').click(function() { |
|
894 |
var _el = $(this), |
|
895 |
_contents = _el.attr("cluster-contents"); |
|
896 |
if (_this.open_cluster == _contents) { |
|
897 |
_this.open_cluster = false; |
|
898 |
} else { |
|
899 |
_this.open_cluster = _contents; |
|
900 |
} |
|
901 |
_this.throttledDrawGrid(); |
|
902 |
}) |
|
903 |
} |
|
904 |
|
|
905 |
Tlns.Classes.Timeline.prototype.drawList = function() { |
|
906 |
var _universfilter = this.$.find(".Ls-Univers li.Ls-Active").map(function(){return $(this).attr("data")}), |
|
907 |
_occtypefilter = this.$.find(".Ls-Occtypes li.Ls-Active").map(function(){return $(this).attr("data")}), |
|
908 |
_statusfilter = this.$.find(".Ls-Occstatuses li.Ls-Active").map(function(){return $(this).attr("data")}), |
|
909 |
_jtfilter = this.$.find(".Ls-IsJt li.Ls-Active").map(function(){return !!+$(this).attr("data")}), |
|
910 |
_title = this.$.find(".Ls-Search").val() || "", |
|
911 |
_titleregexp = new RegExp( "(" + _title.replace(/(\W)/gm, "\\$1") + ")", "gim" ), |
|
912 |
_startdate = false, |
|
913 |
_enddate = false, |
|
914 |
_fromDate = this.$.find(".Ls-From-Date").val(), |
|
915 |
_toDate = this.$.find(".Ls-To-Date").val(); |
|
916 |
if (_fromDate) { |
|
917 |
var _date = Tlns.Utils.dateFieldProcess(_fromDate), |
|
918 |
_time = Tlns.Utils.timeFieldProcess(this.$.find(".Ls-From-Time").val()); |
|
919 |
_startdate = new Date(_date.year, _date.month - 1, _date.date, _time.hours, _time.minutes); |
|
920 |
} |
|
921 |
if (_toDate) { |
|
922 |
var _date = Tlns.Utils.dateFieldProcess(_toDate), |
|
923 |
_time = Tlns.Utils.timeFieldProcess(this.$.find(".Ls-To-Time").val()); |
|
924 |
_enddate = new Date(_date.year, _date.month - 1, _date.date, _time.hours, _time.minutes); |
|
925 |
} |
|
926 |
this.$.find(".Ls-Occurrences").html( |
|
927 |
Mustache.to_html( |
|
928 |
Tlns.Templates.Occurrence_List, |
|
929 |
{ |
|
930 |
occurrences: this.occurrences.filter(function(_occ) { |
|
931 |
var _titletest = (!!_occ.title.match(_titleregexp)), |
|
932 |
_keep = ( |
|
933 |
( !_title || _titletest ) |
|
934 |
&& (_(_occtypefilter).indexOf(_occ.type) !== -1) |
|
935 |
&& (_(_universfilter).indexOf(_occ.univers_id) !== -1) |
|
936 |
&& (_(_statusfilter).indexOf(_occ.status) !== -1) |
|
937 |
&& (_(_jtfilter).indexOf(_occ.jt) !== -1) |
|
938 |
&& ( !_fromDate || _occ.date >= _startdate ) |
|
939 |
&& ( !_toDate || _occ.date <= _enddate ) |
|
940 |
); |
|
941 |
return _keep; |
|
942 |
}) |
|
943 |
} |
|
944 |
) |
|
945 |
); |
|
946 |
if (_title) { |
|
947 |
this.$.find(".Ls-Occurrence-Title").each(function() { |
|
948 |
$(this).html($(this).text().replace(_titleregexp, "<span style='background:yellow'>$1</span>")); |
|
949 |
}); |
|
950 |
} |
|
951 |
} |
|
952 |
|
|
953 |
Tlns.Classes.Timeline.prototype.getUnivers = function(_id) { |
|
954 |
return _(this.univers).find(function(_univ) { |
|
955 |
return (_univ.id == _id); |
|
956 |
}); |
|
957 |
} |
|
958 |
|
|
959 |
/* |
|
960 |
* Univers |
|
961 |
*/ |
|
962 |
|
|
963 |
Tlns.Classes.Univers = function(_data, _timeline, _index) { |
|
964 |
this.id = _data.idUnivers; |
|
965 |
this.index = _index; |
|
966 |
this.title = _data.nomUnivers; |
|
967 |
// this.mainCharacter = _data.personnage; |
|
968 |
this.y = (_timeline.univers_height * _index); |
|
969 |
|
|
970 |
this.$label = $('<li>').css({ |
|
971 |
height : _timeline.univers_height + "px" |
|
972 |
}).html(Mustache.to_html(Tlns.Templates.Univers, this)) |
|
973 |
.addClass((_index % 2) ? 'Tl-Line-Odd' : 'Tl-Line-Even'); |
|
974 |
|
|
975 |
_timeline.$.find('.Tl-UniversLabels').append(this.$label); |
|
976 |
var _txt = this.title, |
|
977 |
_span = this.$label.find('span'); |
|
978 |
while (_span.outerWidth() > (_timeline.width - _timeline.main_width) && _txt) { |
|
979 |
_txt = _txt.substr(0, _txt.length - 1); |
|
980 |
_span.html(_txt + '…'); |
|
981 |
} |
|
982 |
} |
|
983 |
|
|
984 |
/* |
|
985 |
* Occurrence |
|
986 |
*/ |
|
987 |
|
|
988 |
Tlns.Classes.Occurrence = function(_timeline) { |
|
989 |
this.timeline = _timeline; |
|
990 |
} |
|
991 |
|
|
992 |
Tlns.Classes.Occurrence.prototype.update = function(_type, _data) { |
|
993 |
this.type = _type; |
|
994 |
if (typeof _data.idOccurrencePublication !== "undefined" || typeof _data.id !== "undefined" || typeof this.original_id === "undefined") { |
|
995 |
this.original_id = _data.idOccurrencePublication || _data.id || Tlns.Utils.guid(); |
|
996 |
} |
|
997 |
this.id = _type + "_" + this.original_id; |
|
998 |
if (typeof _data.date !== "undefined" || typeof _data.datePublication !== "undefined") { |
|
999 |
this.date = 1000 * (_data.datePublication || _data.date); |
|
1000 |
} else { |
|
1001 |
if (typeof this.date === "undefined") { |
|
1002 |
this.date = new Date().valueOf(); |
|
1003 |
} |
|
1004 |
} |
|
1005 |
this.formatted_date = Tlns.Utils.dateFormat(this.date,Tlns.Defaults.Timeline.tooltip_date_format); |
|
1006 |
if (typeof _data.titre !== "undefined" || typeof this.title === "undefined") { |
|
1007 |
this.title = _data.titre || "<untitled>"; |
|
1008 |
} |
|
1009 |
if (typeof _data.idUnivers !== "undefined") { |
|
1010 |
this.univers_id = _data.idUnivers; |
|
1011 |
} |
|
1012 |
this.univers = this.timeline.getUnivers(this.univers_id); |
|
1013 |
if (typeof _data.statut !== "undefined" || typeof this.status === "undefined") { |
|
1014 |
switch(_data.statut) { |
|
1015 |
case "Validée": |
|
1016 |
case "valide": |
|
1017 |
this.status = "valide" |
|
1018 |
break; |
|
1019 |
case "A valider": |
|
1020 |
case "a_valider": |
|
1021 |
this.status = "a_valider"; |
|
1022 |
break; |
|
1023 |
case "A réaliser": |
|
1024 |
case "a_realiser": |
|
1025 |
this.status = "a_realiser"; |
|
1026 |
break; |
|
1027 |
default: |
|
1028 |
this.status = false; |
|
1029 |
} |
|
1030 |
} |
|
1031 |
if (typeof _data.JT !== "undefined") { |
|
1032 |
this.jt = !!+_data.JT; |
|
1033 |
} |
|
1034 |
this.translated_status = Tlns.Defaults.Timeline.statuses[this.status]; |
|
1035 |
// this.published = (_data.publication && _data.publication == "En ligne"); |
|
1036 |
// this.locked = _data.verrouille || false; |
|
1037 |
// this.characters = _data.personnagesSecondaires || []; |
|
1038 |
this.dependsOn = []; |
|
1039 |
if (_data.dependanceNarrative) { |
|
1040 |
for (var _i = 0; _i < _data.dependanceNarrative.length; _i++) { |
|
1041 |
this.dependsOn.push("narrative_" + _data.dependanceNarrative[_i]) |
|
1042 |
} |
|
1043 |
} |
|
1044 |
if (_data.dependancePublication) { |
|
1045 |
for (var _i = 0; _i < _data.dependancePublication.length; _i++) { |
|
1046 |
this.dependsOn.push("publication_" + _data.dependancePublication[_i]) |
|
1047 |
} |
|
1048 |
} |
|
1049 |
var _tmp = $('<p>').html(_data.accroche || ""); |
|
1050 |
this.description = _tmp.text().trim().replace(/(^.{60,80})[\s].+$/m,'$1…'); |
|
1051 |
} |
|
1052 |
|
|
1053 |
Tlns.Classes.Occurrence.prototype.addDependency = function(_id) { |
|
1054 |
if (_(this.dependsOn).indexOf(_id) == -1) { |
|
1055 |
this.dependsOn.push(_id); |
|
1056 |
} |
|
1057 |
} |
|
1058 |
|
|
1059 |
Tlns.Classes.Occurrence.prototype.removeDependency = function(_id) { |
|
1060 |
this.dependsOn = _(this.dependsOn).reject(function(_n) { |
|
1061 |
return _n == _id; |
|
1062 |
}); |
|
1063 |
} |
|
1064 |
|
|
1065 |
Tlns.Classes.Occurrence.prototype.toString = function() { |
|
1066 |
return "Occurrence " + this.type + ': "' + this.title + '"'; |
|
1067 |
} |