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 |
|
83
|
137 |
Tlns.Utils.clickActiveProcess = function(_el) { |
|
138 |
if (_el.hasClass("Ls-Active")) { |
|
139 |
if (!_el.siblings(":not(.Ls-Active)").length) { |
|
140 |
_el.siblings().removeClass("Ls-Active"); |
|
141 |
} else { |
|
142 |
if (!_el.siblings(".Ls-Active").length) { |
|
143 |
_el.siblings().addClass("Ls-Active"); |
|
144 |
} |
|
145 |
_el.removeClass("Ls-Active"); |
|
146 |
} |
|
147 |
} else { |
|
148 |
_el.addClass("Ls-Active"); |
|
149 |
} |
|
150 |
} |
|
151 |
|
81
|
152 |
/* Defaults */ |
|
153 |
|
|
154 |
Tlns.Defaults.Timeline = { |
|
155 |
container : "timeline", |
|
156 |
width : 950, |
|
157 |
height : 200, |
|
158 |
url_univers : '', |
|
159 |
min_width : 400, |
|
160 |
min_height : 100, |
|
161 |
main_width : 800, |
|
162 |
timescales : [{ |
|
163 |
label : "Mois", |
|
164 |
span : 32 * 86400 * 1000, |
|
165 |
grid_interval : 5 * 86400 * 1000, |
|
166 |
grid_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
167 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
168 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}} {{year}}' |
|
169 |
}, { |
|
170 |
label : "Semaine", |
|
171 |
span : 8 * 86400 * 1000, |
|
172 |
grid_interval : 86400 * 1000, |
|
173 |
grid_date_format : '{{shortDayOfWeek}} {{0dayOfMonth}}/{{0monthNumber}}', |
|
174 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
175 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}}' |
|
176 |
}, { |
|
177 |
label : "2 jours", |
|
178 |
span : 2 * 86400 * 1000, |
|
179 |
grid_interval : 8 * 3600 * 1000, |
|
180 |
grid_date_format : '{{shortDayOfWeek}} {{0dayOfMonth}}/{{0monthNumber}} {{hours}}h', |
|
181 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
182 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}}' |
|
183 |
}, { |
|
184 |
label : "Demi-Journée", |
|
185 |
span : 12 * 3600 * 1000, |
|
186 |
grid_interval : 2 * 3600 * 1000, |
|
187 |
grid_date_format : '{{hours}}h', |
|
188 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}} {{hours}}h', |
|
189 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}} {{hours}}h' |
|
190 |
}, { |
|
191 |
label : "3 Heures", |
|
192 |
span : 3 * 3600 * 1000, |
|
193 |
grid_interval : 30 * 60 * 1000, |
|
194 |
grid_date_format : '{{0hours}}:{{0minutes}}', |
|
195 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}} {{0hours}}:{{0minutes}}', |
|
196 |
end_date_format : '{{0hours}}:{{0minutes}}' |
|
197 |
}, { |
|
198 |
label : "1 Heure", |
|
199 |
span : 60 * 60 * 1000, |
|
200 |
grid_interval : 15 * 60 * 1000, |
|
201 |
grid_date_format : '{{0hours}}:{{0minutes}}', |
|
202 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}} {{0hours}}:{{0minutes}}', |
|
203 |
end_date_format : '{{0hours}}:{{0minutes}}' |
|
204 |
}], |
|
205 |
level: 0, |
|
206 |
central_time: 0, |
|
207 |
sync_now: true, |
|
208 |
urls_occurrences: [], |
|
209 |
occurrences: [], |
|
210 |
cluster_spacing: 12, |
|
211 |
tooltip_date_format: '{{dayOfMonth}} {{shortMonthName}} {{year}} {{0hours}}:{{0minutes}}', |
|
212 |
statuses: { |
|
213 |
"valide": "Validée", |
|
214 |
"a_valider": "A valider", |
|
215 |
"a_realiser": "A réaliser" |
|
216 |
} |
|
217 |
} |
|
218 |
|
|
219 |
for (var _i = 0; _i < Tlns.Defaults.Timeline.timescales.length; _i++) { |
|
220 |
Tlns.Defaults.Timeline.timescales[_i].level = _i; |
|
221 |
} |
|
222 |
|
|
223 |
/* Templates */ |
|
224 |
|
|
225 |
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>' |
|
226 |
+ '<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>' |
|
227 |
+ '<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>' |
|
228 |
+ '<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>' |
|
229 |
+ '<div class="Tl-BottomPart"><ul class="Tl-UniversLabels"></ul>' |
|
230 |
+ '<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>' |
|
231 |
+ '<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>' |
|
232 |
+ '<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>' |
|
233 |
+ '<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>' |
|
234 |
|
83
|
235 |
+'<div class="Ls-Main"><div class="Ls-Filtres">' |
|
236 |
+ '<div class="Ls-Column"><h2>Filtres :</h2><h3>Univers :</h3><ul class="Ls-Univers"></ul></div>' |
81
|
237 |
+ '<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>' |
83
|
238 |
+ '<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></div>' |
|
239 |
+ '<div class="Ls-Column"><h3>Format :</h3><ul class="Ls-Formats"></ul><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>' |
|
240 |
+ '<div class="Ls-Column"><h3>Réinitialiser filtres :</h3><ul><li class="Ls-Critere Ls-Active Ls-All">Tous les contenus</li></ul><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>' |
81
|
241 |
+ '</div><div class="Ls-Resultats"><h2>Occurrences :</h2><ul class="Ls-Occurrences"></ul></div></div>'; |
|
242 |
|
|
243 |
Tlns.Templates.Univers = '<span class="Tl-UniversText">{{title}}</span>'; |
|
244 |
|
|
245 |
Tlns.Templates.Univers_List = '{{#univers}}<li data="{{id}}" class="Ls-Critere Ls-Active">{{title}}</li>{{/univers}}'; |
|
246 |
|
83
|
247 |
Tlns.Templates.Formats_List = '{{#formats}}<li class="Ls-Critere Ls-Active">{{.}}</li>{{/formats}}'; |
|
248 |
|
81
|
249 |
Tlns.Templates.Occurrence = '{{#clusters}}<div class="Tl-Cluster" style="left: {{x}}px; top: {{y}}px;" cluster-contents="{{contents}}">' |
|
250 |
+ '<div class="Tl-ClusterCount">{{occurrences.length}}</div></div>{{/clusters}}' |
|
251 |
+ '{{#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;">' |
|
252 |
// + '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}' |
83
|
253 |
+ '<div class="Tl-Link"></div></div>{{/occurrences}}{{#open_cluster}}<div class="Tl-ClusterOverlay" style="left: {{x}}px; top: {{y}}px;">' |
81
|
254 |
+ '{{#occurrences}}<div class="Tl-Occurrence Tl-OccInCluster Tl-Occ{{type}} Tl-Occ{{status}}{{#editing}} Tl-Editing{{/editing}}" occurrence-id="{{id}}">' |
|
255 |
+ '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}<div class="Tl-Link"{{#editing}} style="display: block"{{/editing}}></div></div>{{/occurrences}}</div>{{/open_cluster}}'; |
|
256 |
|
82
|
257 |
Tlns.Templates.Occurrence_List = '{{#occurrences}}<li class="Ls-Occurrence" data-id="{{id}}"><div class="Ls-OccIcon Tl-Occ{{type}} Tl-Occ{{status}}"></div><h4 class="Ls-Occurrence-Title"><a href="#">{{title}}</a></h4>' |
83
|
258 |
+ '<p class="Ls-Occ-More">{{formatted_date}} — {{univers.title}} — {{translated_status}} — {{#jt}}Au JT{{/jt}}{{^jt}}Hors JT{{/jt}}{{#format}} — {{format}}{{/format}}</p><div style="clear:both;"></div></li>{{/occurrences}}'; |
81
|
259 |
|
83
|
260 |
Tlns.Templates.OccurrenceTooltip = '<h3 class="Tl-Tooltip-Title">{{title}}</h3><p class="Tl-Tooltip-Date">{{formatted_date}} — {{translated_status}} — {{#jt}}Au JT{{/jt}}{{^jt}}Hors JT{{/jt}}{{#format}} — {{format}}{{/format}}</p>' |
81
|
261 |
+ '<p class="Tl-Tooltip-Description">{{description}}</p>' |
|
262 |
// + '<p class="Tl-Tooltip-Characters">{{univers.mainCharacter}}{{#characters}}, {{.}}{{/characters}}</p>' |
|
263 |
|
|
264 |
/* Classes */ |
|
265 |
|
|
266 |
Tlns.Classes.Timeline = function(_options) { |
|
267 |
|
|
268 |
/* Setting Defaults */ |
|
269 |
Tlns.Utils.SetDefaults(this, Tlns.Defaults.Timeline, _options); |
|
270 |
|
|
271 |
/* Setting container CSS */ |
|
272 |
this.$ = $('#' + this.container).html(Mustache.to_html(Tlns.Templates.Timeline, this)); |
|
273 |
|
|
274 |
this.$.find('.Tl-Main').css({ |
|
275 |
width : this.width + "px", |
|
276 |
height : this.height + "px" |
|
277 |
}); |
|
278 |
this.main_height = this.height - this.$.find('.Tl-TopBar').outerHeight(); |
82
|
279 |
//this.main_height = this.height - 27; |
81
|
280 |
this.$.find('.Tl-BottomPart').css("height", this.main_height + "px"); |
|
281 |
this.$.find('.Tl-MainPart').css("width", this.main_width + "px"); |
|
282 |
this.$.find('.Tl-Overlay-Container').css("left", (this.$.find('.Tl-BottomPart').outerWidth() - this.main_width) + "px"); |
|
283 |
this.$.find('canvas.Tl-Layer').attr({ |
|
284 |
width: this.main_width, |
|
285 |
height: this.main_height |
|
286 |
}); |
|
287 |
var _o = this.$.find('.Tl-MainPart').offset(); |
|
288 |
this.dragging_bounds = { |
|
289 |
left: _o.left, |
|
290 |
top: _o.top, |
|
291 |
right: _o.left + this.$.find('.Tl-MainPart').outerWidth(), |
|
292 |
bottom: _o.top + this.$.find('.Tl-MainPart').outerHeight(), |
|
293 |
}; |
|
294 |
|
|
295 |
var _this = this; |
|
296 |
|
|
297 |
this.throttledDrawGrid = _.throttle(function() { |
|
298 |
_this.drawGrid(); |
|
299 |
}, 150); |
|
300 |
|
|
301 |
this.throttledDrawList = _.throttle(function() { |
|
302 |
_this.drawList(); |
|
303 |
}, 150); |
|
304 |
|
|
305 |
this.setLevel(this.level); |
|
306 |
|
|
307 |
this.$.find('.Tl-TopBar-Timescales>div').click(function() { |
|
308 |
_this.setLevel($(this).attr("data-level")); |
|
309 |
}); |
|
310 |
|
|
311 |
this.$.find('.Tl-TopBar-SyncButton').click(function() { |
|
312 |
_this.sync_now = !_this.sync_now; |
|
313 |
_this.changeSpan(); |
|
314 |
}) |
|
315 |
|
|
316 |
this.$.find('.Tl-TopBar-PreviousButton').click(function() { |
|
317 |
_this.offsetTime(-_this.timescales[_this.level].span / 4); |
|
318 |
}); |
|
319 |
|
|
320 |
this.$.find('.Tl-TopBar-NextButton').click(function() { |
|
321 |
_this.offsetTime(_this.timescales[_this.level].span / 4); |
|
322 |
}); |
|
323 |
|
|
324 |
this.$.find('.Tl-MainPart').mousedown(function(_event) { |
|
325 |
_this.onMouseDown(_event); |
|
326 |
return false; |
|
327 |
}); |
|
328 |
|
|
329 |
this.$.find('.Tl-MainPart').mousemove(function(_event) { |
|
330 |
_this.onMouseMove(_event); |
|
331 |
return false; |
|
332 |
}); |
|
333 |
|
|
334 |
this.$.find('.Tl-MainPart').mouseup(function(_event) { |
|
335 |
_this.onMouseUp(_event); |
|
336 |
return false; |
|
337 |
}); |
|
338 |
|
|
339 |
this.$.find('.Tl-MainPart').mousewheel(function(_event, _delta) { |
|
340 |
var _newLevel = Math.max(0,Math.min(_this.timescales.length-1, (_delta < 0 ? -1 : 1) + parseInt(_this.level))); |
|
341 |
if (_newLevel != _this.level) { |
|
342 |
_this.hideTooltip(); |
|
343 |
var _deltaX = _event.pageX - _this.dragging_bounds.left, |
|
344 |
_tAtMouse = _this.timeFromMouse(_event.pageX), |
|
345 |
_newScale = _this.main_width / (_this.timescales[_newLevel].span), |
|
346 |
_newStart = _tAtMouse - _deltaX / _newScale; |
|
347 |
_this.central_time = _newStart + _this.timescales[_newLevel].span / 2; |
|
348 |
_this.setLevel(_newLevel); |
|
349 |
} |
|
350 |
return false; |
|
351 |
}); |
|
352 |
|
|
353 |
this.$.find('.Tl-Overlay-Box').mouseover(function(_event) { |
|
354 |
$(this).show(); |
|
355 |
}).mouseout(function(_event) { |
|
356 |
$(this).hide(); |
|
357 |
}); |
|
358 |
|
|
359 |
this.$.find('.Tl-TopBar-AddButton').click(function() { |
|
360 |
$(this).toggleClass('active'); |
|
361 |
_this.$.find('.Tl-Adding').toggle(); |
|
362 |
}); |
|
363 |
|
|
364 |
this.$.find('.Tl-AddOccurrence').mousedown(function(_event) { |
|
365 |
var _el = $(this), |
|
366 |
_type = _el.attr("occurrence-type"), |
|
367 |
_d = _this.timeFromMouse(_event.pageX), |
|
368 |
_u = _this.universFromMouse(_event.pageY), |
|
369 |
_occ = _this.createOrUpdateOccurrence( |
|
370 |
_type, |
|
371 |
{ |
|
372 |
datePublication: Math.floor(_d / 1000), |
|
373 |
titre: '<Nouvelle occurrence>', |
|
374 |
idUnivers: _this.univers[_u].id, |
|
375 |
statut: 'a_realiser', |
|
376 |
jt: false |
|
377 |
} |
|
378 |
); |
|
379 |
_occ.just_created = true; |
83
|
380 |
_(_this.occurrences).each(function(_occ) { |
|
381 |
_occ.editing = false; |
|
382 |
}); |
81
|
383 |
_occ.editing = true; |
|
384 |
_this.editing_occurrence = _occ; |
|
385 |
_this.dragging_type = "occurrence"; |
|
386 |
window.setTimeout(function () { |
|
387 |
_this.$.find('.Tl-TopBar-AddButton').removeClass('active'); |
|
388 |
_this.$.find('.Tl-Adding').hide(); |
|
389 |
}, 200); |
|
390 |
_this.throttledDrawGrid(); |
|
391 |
}).mouseup(function(_event) { |
|
392 |
_this.onMouseUp(_event); |
|
393 |
return false; |
|
394 |
}); |
|
395 |
|
|
396 |
/* Loading Univers */ |
|
397 |
$.getJSON(this.url_univers, function(_data) { |
|
398 |
_this.onUniversLoaded(_data); |
|
399 |
}); |
|
400 |
|
|
401 |
/* LIST */ |
|
402 |
|
|
403 |
this.$.find("li.Ls-Critere").click(function() { |
83
|
404 |
Tlns.Utils.clickActiveProcess($(this)); |
81
|
405 |
_this.throttledDrawList(); |
|
406 |
}); |
|
407 |
this.$.find(".Ls-Search").bind("keyup change click", function() { |
|
408 |
_this.throttledDrawList(); |
|
409 |
}); |
|
410 |
this.$.find(".Ls-From-Date, .Ls-To-Date").datepicker( |
|
411 |
{ |
|
412 |
dateFormat: "dd/mm/yy", |
|
413 |
dayNames: [ "Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi" ], |
|
414 |
dayNamesShort: [ "Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam" ], |
|
415 |
dayNamesMin: [ "D", "L", "Ma", "Me", "J", "V", "S" ], |
|
416 |
monthNames: [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" ], |
|
417 |
monthNamesShort: [ "Jan", "Fév", "Mar", "Avr", "Mai", "Jun", "Jul", "Aoû", "Sep", "Oct", "Nov", "Déc" ], |
|
418 |
showOtherMonths: true, |
|
419 |
selectOtherMonths: true |
|
420 |
} |
|
421 |
).change(function() { |
|
422 |
var _val = $(this).val(); |
|
423 |
if (_val) { |
|
424 |
$(this).val(Tlns.Utils.dateFieldProcess( _val ).text); |
|
425 |
} |
|
426 |
_this.drawList(); |
|
427 |
}).bind("keyup", function() { |
|
428 |
_this.throttledDrawList(); |
|
429 |
}); |
|
430 |
this.$.find(".Ls-From-Time, .Ls-To-Time").change(function() { |
|
431 |
var _val = $(this).val(); |
|
432 |
if (_val) { |
|
433 |
$(this).val(Tlns.Utils.timeFieldProcess( _val ).text); |
|
434 |
} |
|
435 |
_this.throttledDrawList(); |
|
436 |
}).bind("keyup", function() { |
|
437 |
_this.throttledDrawList(); |
|
438 |
}); |
83
|
439 |
this.$.find(".Ls-All").click(function() { |
|
440 |
_this.$.find(".Ls-Critere").addClass("Ls-Active"); |
|
441 |
_this.throttledDrawList(); |
|
442 |
}); |
|
443 |
this.$.find(".Ls-None").click(function() { |
|
444 |
_this.$.find(".Ls-Critere").removeClass("Ls-Active"); |
|
445 |
_this.throttledDrawList(); |
|
446 |
}); |
81
|
447 |
|
|
448 |
this.$.find(".Onglet-Tl").click(function() { |
|
449 |
_this.$.find(".Tl-Main").show(); |
|
450 |
_this.$.find(".Ls-Main").hide(); |
|
451 |
_this.$.find(".Onglet-Ls").removeClass("active"); |
|
452 |
_this.$.find(".Onglet-Tl").addClass("active"); |
|
453 |
_this.throttledDrawGrid(); |
|
454 |
}); |
|
455 |
|
|
456 |
this.$.find(".Onglet-Ls").click(function() { |
|
457 |
_this.$.find(".Ls-Main").show(); |
|
458 |
_this.$.find(".Tl-Main").hide(); |
|
459 |
_this.$.find(".Onglet-Tl").removeClass("active"); |
|
460 |
_this.$.find(".Onglet-Ls").addClass("active"); |
|
461 |
_this.throttledDrawList(); |
|
462 |
}); |
|
463 |
|
|
464 |
|
|
465 |
/* BINDING MEDIADATA EVENTS */ |
|
466 |
|
|
467 |
$("body").bind("AjoutOccurrenceEditeur MiseAJourOccurrenceEditeur", function(_event, _data) { |
82
|
468 |
var _type = _data.typeOccurrence.replace(/^Occurrence/i,'').toLowerCase(); |
81
|
469 |
_this.createOrUpdateOccurrence(_type, _data); |
|
470 |
_this.throttledDrawGrid(); |
82
|
471 |
_this.throttledDrawList(); |
81
|
472 |
}); |
|
473 |
|
|
474 |
$("body").bind("SuppressionOccurrenceEditeur", function(_event, _data) { |
82
|
475 |
var _id = _data.typeOccurrence.replace(/^Occurrence/i,'').toLowerCase() + '_' + _data.id; |
81
|
476 |
_this.deleteOccurrence(_id); |
|
477 |
_this.throttledDrawGrid(); |
82
|
478 |
_this.throttledDrawList(); |
81
|
479 |
}); |
|
480 |
|
|
481 |
$("body").bind("AjoutDependanceEditeur", function(_event, _data) { |
82
|
482 |
var _sourceId = _data.typeOccurrence.replace(/^Occurrence/i,'').toLowerCase() + '_' + _data.id, |
|
483 |
_targetId = _data.typeOccurrenceCible.replace(/^Occurrence/i,'').toLowerCase() + '_' + _data.idCible; |
81
|
484 |
_this.getOccurrence(_sourceId).addDependency(_targetId); |
|
485 |
_this.throttledDrawGrid(); |
|
486 |
}); |
|
487 |
|
|
488 |
$("body").bind("SuppressionDependanceEditeur", function(_event, _data) { |
82
|
489 |
var _sourceId = _data.typeOccurrence.replace(/^Occurrence/i,'').toLowerCase() + '_' + _data.id, |
|
490 |
_targetId = _data.typeOccurrenceCible.replace(/^Occurrence/i,'').toLowerCase() + '_' + _data.idCible; |
|
491 |
_this.getOccurrence(_sourceId).removeDependency(_targetId); |
81
|
492 |
_this.throttledDrawGrid(); |
|
493 |
}); |
|
494 |
|
83
|
495 |
$("body").bind("SelectionOccurrenceEditeur", function(_event, _data) { |
|
496 |
var _id = _data.typeOccurrence.replace(/^Occurrence/i,'').toLowerCase() + '_' + _data.id; |
|
497 |
_(_this.occurrences).each(function(_occ) { |
|
498 |
_occ.editing = (_occ.id == _id); |
|
499 |
}); |
|
500 |
_this.throttledDrawGrid(); |
|
501 |
}) |
|
502 |
|
81
|
503 |
|
|
504 |
} |
|
505 |
|
|
506 |
Tlns.Classes.Timeline.prototype.onMouseDown = function(_event) { |
|
507 |
this.mouse_down = true; |
|
508 |
this.is_dragging = false; |
|
509 |
this.start_pos = { |
|
510 |
x: _event.pageX, |
|
511 |
y: _event.pageY |
|
512 |
}; |
|
513 |
if (typeof this.dragging_type === "undefined") { |
|
514 |
this.time_at_start = this.central_time; |
|
515 |
this.dragging_type = "timeline"; |
|
516 |
} |
|
517 |
} |
|
518 |
|
|
519 |
Tlns.Classes.Timeline.prototype.onMouseUp = function(_event) { |
|
520 |
if (this.is_dragging) { |
|
521 |
switch (this.dragging_type) { |
|
522 |
case "occurrence": |
|
523 |
var _event = ( this.editing_occurrence.just_created ? "Ajout" : "MiseAJour" ) + "OccurrenceTimeline", |
|
524 |
_data = { |
|
525 |
id: this.editing_occurrence.original_id, |
82
|
526 |
typeOccurrence: "Occurrence" + this.editing_occurrence.type.replace(/^./,function(_l) { return _l.toUpperCase()}), |
81
|
527 |
datePublication : Math.floor(this.editing_occurrence.date / 1000), |
|
528 |
titre : this.editing_occurrence.title, |
|
529 |
idUnivers: this.editing_occurrence.univers_id, |
|
530 |
statut: this.statuses[this.editing_occurrence.status], |
|
531 |
JT: +!!this.editing_occurrence.jt |
|
532 |
} |
|
533 |
$("body").trigger(_event, _data); |
|
534 |
this.editing_occurrence.just_created = false; |
|
535 |
this.throttledDrawGrid(); |
|
536 |
break; |
|
537 |
case "link": |
|
538 |
this.throttledDrawGrid(); |
|
539 |
var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
540 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
541 |
break; |
|
542 |
} |
|
543 |
} else { |
|
544 |
if (this.dragging_type == "occurrence" || this.dragging_type == "link") { |
|
545 |
if (this.editing_occurrence.just_created) { |
|
546 |
this.deleteOccurrence(this.editing_occurrence.id); |
|
547 |
this.throttledDrawGrid(); |
|
548 |
} else { |
|
549 |
var _data = { |
83
|
550 |
id: this.editing_occurrence.original_id, |
|
551 |
typeOccurrence: "Occurrence" + this.editing_occurrence.type.replace(/^./,function(_l) { return _l.toUpperCase()}) |
|
552 |
} |
81
|
553 |
$("body").trigger("SelectionOccurrenceTimeline", _data); |
|
554 |
} |
83
|
555 |
} |
81
|
556 |
} |
83
|
557 |
this.$.find('.Tl-Link').hide(); |
81
|
558 |
this.mouse_down = false; |
|
559 |
this.is_dragging = false; |
|
560 |
this.dragging_type = undefined; |
|
561 |
} |
|
562 |
|
|
563 |
Tlns.Classes.Timeline.prototype.timeFromX = function(_x) { |
|
564 |
return Math.max(this.start_time,Math.min(this.end_time, this.start_time + _x / this.current_scale)); |
|
565 |
} |
|
566 |
|
|
567 |
Tlns.Classes.Timeline.prototype.timeFromMouse = function(_pageX) { |
|
568 |
return this.timeFromX(_pageX - this.dragging_bounds.left); |
|
569 |
} |
|
570 |
|
|
571 |
Tlns.Classes.Timeline.prototype.universFromY = function(_y) { |
|
572 |
return Math.max(0,Math.min(this.univers.length, Math.floor(_y / this.univers_height))) |
|
573 |
} |
|
574 |
|
|
575 |
Tlns.Classes.Timeline.prototype.universFromMouse = function(_pageY) { |
|
576 |
return this.universFromY(_pageY - this.dragging_bounds.top); |
|
577 |
} |
|
578 |
|
|
579 |
Tlns.Classes.Timeline.prototype.onMouseMove = function(_event) { |
|
580 |
if (this.mouse_down) { |
|
581 |
this.is_dragging = true; |
|
582 |
this.hideTooltip(); |
|
583 |
switch (this.dragging_type) { |
|
584 |
case "occurrence": |
|
585 |
var _d = this.timeFromMouse(_event.pageX); |
|
586 |
this.editing_occurrence.date = _d; |
|
587 |
this.editing_occurrence.formatted_date = Tlns.Utils.dateFormat(this.editing_occurrence.date,this.tooltip_date_format); |
|
588 |
var _u = this.universFromMouse(_event.pageY); |
|
589 |
this.editing_occurrence.univers = this.univers[_u]; |
|
590 |
this.editing_occurrence.univers_id = this.univers[_u].id; |
|
591 |
this.throttledDrawGrid(); |
|
592 |
break; |
|
593 |
case "timeline": |
|
594 |
this.setTime(this.time_at_start + Math.floor(( this.start_pos.x - _event.pageX ) / this.current_scale)); |
|
595 |
break; |
|
596 |
case "link": |
|
597 |
var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
598 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
599 |
Tlns.Utils.drawArrow( |
|
600 |
_ctx, |
|
601 |
'#800080', |
|
602 |
this.editing_occurrence.x, |
|
603 |
this.editing_occurrence.y + Math.floor(this.univers_height / 2), |
|
604 |
_event.pageX - this.dragging_bounds.left, |
|
605 |
_event.pageY - this.dragging_bounds.top |
|
606 |
); |
|
607 |
break; |
|
608 |
} |
|
609 |
} |
|
610 |
} |
|
611 |
|
|
612 |
Tlns.Classes.Timeline.prototype.onUniversLoaded = function(_data) { |
|
613 |
this.univers = []; |
|
614 |
if(_data.length) { |
|
615 |
this.univers_height = Math.floor(this.main_height / _data.length); |
|
616 |
} |
|
617 |
for(var _i = 0; _i < _data.length; _i++) { |
|
618 |
this.univers.push(new Tlns.Classes.Univers(_data[_i], this, _i)); |
|
619 |
} |
|
620 |
|
83
|
621 |
this.$.find(".Ls-Univers").html( |
|
622 |
Mustache.to_html( |
|
623 |
Tlns.Templates.Univers_List, |
|
624 |
{ |
|
625 |
univers: _(this.univers).map(function(_u) { |
|
626 |
return { |
|
627 |
id: _u.id, |
|
628 |
title: _u.title.replace(/(^.{10,20})[\s].+$/m,'$1…') |
|
629 |
} |
|
630 |
}) |
|
631 |
} |
|
632 |
) |
|
633 |
); |
81
|
634 |
var _this = this; |
|
635 |
this.$.find(".Ls-Univers li.Ls-Critere").click( function() { |
83
|
636 |
Tlns.Utils.clickActiveProcess($(this)); |
81
|
637 |
_this.throttledDrawList(); |
|
638 |
}); |
|
639 |
this.loadOccurrences(); |
|
640 |
} |
|
641 |
|
|
642 |
Tlns.Classes.Timeline.prototype.offsetTime = function(_timeOffset) { |
|
643 |
this.setTime(this.central_time + _timeOffset); |
|
644 |
} |
|
645 |
|
|
646 |
Tlns.Classes.Timeline.prototype.setTime = function(_centralTime) { |
|
647 |
this.sync_now = false; |
|
648 |
this.central_time = _centralTime; |
|
649 |
this.changeSpan(); |
|
650 |
} |
|
651 |
|
|
652 |
Tlns.Classes.Timeline.prototype.setLevel = function(_level) { |
|
653 |
if (_level >= 0 && _level < this.timescales.length) { |
|
654 |
this.$.find('.Tl-TopBar-Timescales>div').each(function() { |
|
655 |
var _el = $(this); |
|
656 |
if (_el.attr("data-level") == _level) { |
|
657 |
_el.addClass("active"); |
|
658 |
} else { |
|
659 |
_el.removeClass("active"); |
|
660 |
} |
|
661 |
}); |
|
662 |
this.level = _level; |
|
663 |
this.changeSpan(); |
|
664 |
} |
|
665 |
} |
|
666 |
|
|
667 |
Tlns.Classes.Timeline.prototype.changeSpan = function() { |
|
668 |
var _now = new Date().valueOf(); |
|
669 |
if (this.sync_now) { |
|
670 |
this.central_time = _now; |
|
671 |
} |
|
672 |
var _timescale = this.timescales[this.level]; |
|
673 |
this.current_scale = this.main_width / (_timescale.span); |
|
674 |
this.start_time = this.central_time - (_timescale.span / 2); |
|
675 |
this.end_time = this.central_time + (_timescale.span / 2); |
|
676 |
this.$.find(".Ls-From-Time").val(Tlns.Utils.dateFormat(this.start_time, '{{0hours}}:{{0minutes}}')); |
|
677 |
this.$.find(".Ls-From-Date").val(Tlns.Utils.dateFormat(this.start_time, '{{0dayOfMonth}}/{{0monthNumber}}/{{year}}')); |
|
678 |
this.$.find(".Ls-To-Time").val(Tlns.Utils.dateFormat(this.end_time, '{{0hours}}:{{0minutes}}')); |
|
679 |
this.$.find(".Ls-To-Date").val(Tlns.Utils.dateFormat(this.end_time, '{{0dayOfMonth}}/{{0monthNumber}}/{{year}}')); |
|
680 |
this.throttledDrawGrid(); |
|
681 |
this.throttledDrawList(); |
|
682 |
} |
|
683 |
|
|
684 |
Tlns.Classes.Timeline.prototype.drawGrid = function() { |
|
685 |
if (this.sync_now) { |
|
686 |
this.$.find('.Tl-TopBar-SyncButton').addClass("active"); |
|
687 |
} else { |
|
688 |
this.$.find('.Tl-TopBar-SyncButton').removeClass("active"); |
|
689 |
} |
|
690 |
var _now = new Date().valueOf(), |
|
691 |
_timescale = this.timescales[this.level], |
|
692 |
_offset = new Date().getTimezoneOffset() * 60000, |
|
693 |
_grid_width = Math.floor(_timescale.grid_interval * this.current_scale), |
|
694 |
_roundstart = Math.floor((this.start_time - _offset) / _timescale.grid_interval) * _timescale.grid_interval + _offset, |
|
695 |
_html = ''; |
|
696 |
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)); |
|
697 |
for (var _t = _roundstart; _t < this.end_time; _t += _timescale.grid_interval) { |
|
698 |
var _x = this.current_scale * (_t - this.start_time); |
|
699 |
if (_x > 0) { |
|
700 |
_html += '<div class="Tl-Grid-Column" style="width:' + _grid_width + 'px; left: ' + _x + 'px">' |
|
701 |
+ '<div class="Tl-Grid-Label">' + Tlns.Utils.dateFormat(_t, _timescale.grid_date_format) + '</div></div>'; |
|
702 |
} |
|
703 |
} |
|
704 |
if (this.start_time <= _now && this.end_time >= _now) { |
|
705 |
_html += '<div class="Tl-Grid-Now" style="left: ' + this.current_scale * (_now - this.start_time) + 'px"></div>' |
|
706 |
} |
|
707 |
this.$.find('.Tl-Grid').html(_html); |
|
708 |
this.drawOccurrences(); |
|
709 |
} |
|
710 |
|
|
711 |
Tlns.Classes.Timeline.prototype.loadOccurrences = function() { |
|
712 |
var _this = this; |
|
713 |
_(this.urls_occurrences).each(function(_url_occ) { |
|
714 |
$.getJSON(_url_occ.url, function(_data) { |
|
715 |
_this.onOccurrencesLoaded(_data, _url_occ.type); |
|
716 |
}); |
|
717 |
}); |
|
718 |
|
|
719 |
} |
|
720 |
|
|
721 |
Tlns.Classes.Timeline.prototype.onOccurrencesLoaded = function(_data, _type) { |
|
722 |
for (var _i = 0; _i < _data.length; _i++) { |
|
723 |
this.createOrUpdateOccurrence(_type, _data[_i]); |
|
724 |
} |
|
725 |
if (!this.mouse_down) { |
|
726 |
this.drawOccurrences(); |
|
727 |
} |
83
|
728 |
this.$.find(".Ls-Formats").html( |
|
729 |
Mustache.to_html( |
|
730 |
Tlns.Templates.Formats_List, |
|
731 |
{ |
|
732 |
formats: _(this.occurrences).chain().pluck('format').unique().value() |
|
733 |
} |
|
734 |
) |
|
735 |
); |
|
736 |
var _this = this; |
|
737 |
this.$.find(".Ls-Formats li.Ls-Critere").click( function() { |
|
738 |
Tlns.Utils.clickActiveProcess($(this)); |
|
739 |
_this.throttledDrawList(); |
|
740 |
}); |
81
|
741 |
this.throttledDrawList(); |
|
742 |
} |
|
743 |
|
|
744 |
Tlns.Classes.Timeline.prototype.deleteOccurrence = function(_id) { |
|
745 |
this.occurrences = _(this.occurrences).reject(function(_occ) { |
|
746 |
return _occ.id == _id; |
|
747 |
}); |
|
748 |
} |
|
749 |
|
|
750 |
Tlns.Classes.Timeline.prototype.getOccurrence = function(_id) { |
|
751 |
return _(this.occurrences).find(function(_occ) { |
|
752 |
return _occ.id == _id; |
|
753 |
}); |
|
754 |
} |
|
755 |
|
|
756 |
Tlns.Classes.Timeline.prototype.createOrUpdateOccurrence = function(_type, _data) { |
|
757 |
var _id = _type + "_" + _data.id, |
|
758 |
_occurrence = this.getOccurrence(_id); |
|
759 |
if (typeof _occurrence === "undefined") { |
|
760 |
_occurrence = new Tlns.Classes.Occurrence(this); |
|
761 |
this.occurrences.push(_occurrence); |
|
762 |
} |
|
763 |
_occurrence.update(_type, _data); |
|
764 |
return _occurrence; |
|
765 |
} |
|
766 |
|
|
767 |
Tlns.Classes.Timeline.prototype.showTooltip = function(_x, _y, _html, _isUp) { |
|
768 |
this.$.find('.Tl-Overlay-Box') |
|
769 |
.removeClass(_isUp ? 'Tl-Overlay-Down' : 'Tl-Overlay-Up') |
|
770 |
.addClass(_isUp ? 'Tl-Overlay-Up' : 'Tl-Overlay-Down') |
|
771 |
.show() |
|
772 |
.css({ |
|
773 |
left: _x + "px", |
|
774 |
top: _y + "px" |
|
775 |
}); |
|
776 |
this.$.find('.Tl-Overlay-Main').html(_html); |
|
777 |
} |
|
778 |
|
|
779 |
Tlns.Classes.Timeline.prototype.hideTooltip = function() { |
|
780 |
this.$.find('.Tl-Overlay-Box').hide(); |
|
781 |
} |
|
782 |
|
|
783 |
Tlns.Classes.Timeline.prototype.drawOccurrences = function() { |
|
784 |
var _this = this, |
|
785 |
_visible = _(this.occurrences).filter(function(_occ) { |
|
786 |
return (_occ.date >= _this.start_time && _occ.date <= _this.end_time && _occ.status); |
|
787 |
}); |
|
788 |
_(_visible).each(function(_occ) { |
|
789 |
_occ.x = _this.current_scale * (_occ.date - _this.start_time); |
|
790 |
_occ.y = _occ.univers.y; |
|
791 |
_occ.in_cluster = false; |
|
792 |
}); |
|
793 |
|
|
794 |
var _moved = true; |
|
795 |
while (_moved) { |
|
796 |
_moved = false; |
|
797 |
for (var _i = 0; _i < _visible.length; _i++) { |
|
798 |
for (var _j = 0; _j < _i; _j++) { |
|
799 |
if (_visible[_j].univers_id == _visible[_i].univers_id |
|
800 |
&& _visible[_j].x != _visible[_i].x |
|
801 |
&& Math.abs(_visible[_j].x-_visible[_i].x) < this.cluster_spacing |
|
802 |
) { |
|
803 |
_moved = true; |
|
804 |
_visible[_i].x = this.cluster_spacing * Math.round(_visible[_i].x / this.cluster_spacing); |
|
805 |
_visible[_j].x = this.cluster_spacing * Math.round(_visible[_j].x / this.cluster_spacing); |
|
806 |
} |
|
807 |
} |
|
808 |
} |
|
809 |
} |
|
810 |
var _clusters = [], |
|
811 |
_openCluster = false; |
|
812 |
for (var _i = 0; _i < _visible.length; _i++) { |
|
813 |
for (var _j = 0; _j < _i; _j++) { |
|
814 |
if (_visible[_j].univers_id == _visible[_i].univers_id && _visible[_j].x == _visible[_i].x) { |
|
815 |
_visible[_j].in_cluster = true; |
|
816 |
_visible[_i].in_cluster = true; |
|
817 |
var _x = _visible[_j].x, |
|
818 |
_y = _visible[_j].y; |
|
819 |
_cluster = _(_clusters).find(function(_c) { return _c.x == _x && _c.y == _y }); |
|
820 |
if (typeof _cluster === "undefined") { |
|
821 |
_cluster = { x: _x, y: _y, occurrences: [] }; |
|
822 |
_clusters.push(_cluster); |
|
823 |
} |
|
824 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
825 |
return _o.type == _visible[_j].type && _o.id == _visible[_j].id; |
|
826 |
})) { |
|
827 |
_cluster.occurrences.push(_visible[_j]); |
|
828 |
} |
|
829 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
830 |
return _o.type == _visible[_i].type && _o.id == _visible[_i].id; |
|
831 |
})) { |
|
832 |
_cluster.occurrences.push(_visible[_i]); |
|
833 |
} |
|
834 |
} |
|
835 |
} |
|
836 |
} |
|
837 |
_(_clusters).each(function(_cluster) { |
|
838 |
_cluster.occurrences = _(_cluster.occurrences).sortBy(function(_o) { |
|
839 |
return _o.date; |
|
840 |
}); |
|
841 |
_cluster.contents = _cluster.occurrences.map(function(_o) { |
|
842 |
return _o.type + ":" + _o.id; |
|
843 |
}).join("|"); |
|
844 |
if (_cluster.contents == _this.open_cluster) { |
|
845 |
_openCluster = _cluster; |
|
846 |
} |
|
847 |
}); |
|
848 |
|
|
849 |
|
|
850 |
var _links = []; |
|
851 |
|
|
852 |
_(_visible).each(function(_occurrence) { |
|
853 |
_(_occurrence.dependsOn).each(function(_dependance) { |
|
854 |
var _parent = _(_visible).find(function(_o) { |
|
855 |
return _o.id == _dependance; |
|
856 |
}); |
|
857 |
if (typeof _parent !== "undefined") { |
|
858 |
_links.push({ |
|
859 |
from_x: _occurrence.x, |
|
860 |
from_y: _occurrence.y + Math.floor(_this.univers_height / 2), |
|
861 |
to_x: _parent.x, |
|
862 |
to_y: _parent.y + Math.floor(_this.univers_height / 2) |
|
863 |
}); |
|
864 |
} |
|
865 |
}); |
|
866 |
}); |
|
867 |
|
|
868 |
var _ctx = this.$.find('.Tl-Canvas')[0].getContext('2d'); |
|
869 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
870 |
_(_links).each(function(_link) { |
|
871 |
Tlns.Utils.drawArrow(_ctx, "#505050", _link.from_x,_link.from_y, _link.to_x,_link.to_y); |
|
872 |
}); |
|
873 |
|
|
874 |
var _html = Mustache.to_html(Tlns.Templates.Occurrence, { |
|
875 |
occurrences:_(_visible).reject(function(_o) {return _o.in_cluster}), |
|
876 |
clusters: _clusters, |
|
877 |
open_cluster: _openCluster |
|
878 |
}); |
|
879 |
this.$.find('.Tl-Occurrences').html(_html); |
|
880 |
|
|
881 |
|
|
882 |
if (_openCluster) { |
|
883 |
var _w = this.$.find('.Tl-Occurrence').width(), |
|
884 |
_ww = _w * _openCluster.occurrences.length; |
|
885 |
this.$.find('.Tl-ClusterOverlay').css({ |
|
886 |
"margin-left": - Math.floor(_ww/2) + "px", |
|
887 |
width: _ww |
|
888 |
}); |
|
889 |
_(_openCluster.occurrences).each(function(_o, _i) { |
|
890 |
_o.y = _o.y - 20; |
|
891 |
_o.x = _o.x - (_ww / 2) + ((_i + .5) * _w); |
|
892 |
}); |
|
893 |
} |
|
894 |
|
|
895 |
this.$.find('.Tl-Occurrence').mousedown(function() { |
|
896 |
var _el = $(this), |
|
897 |
_id = _el.attr("occurrence-id"); |
|
898 |
if (typeof _id !== "undefined") { |
|
899 |
_this.editing_occurrence = _this.getOccurrence(_id); |
|
900 |
if (typeof _this.dragging_type === "undefined" && typeof _this.editing_occurrence !== "undefined" /* && !_this.editing_occurrence.locked */ ) { |
|
901 |
_this.dragging_type = "occurrence"; |
83
|
902 |
} |
|
903 |
if (!_this.editing_occurrence.editing) { |
|
904 |
_(_this.occurrences).each(function(_occ) { |
|
905 |
_occ.editing = false; |
|
906 |
}); |
81
|
907 |
_this.editing_occurrence.editing = true; |
|
908 |
} |
83
|
909 |
_this.throttledDrawGrid(); |
81
|
910 |
} |
|
911 |
}).mouseover(function(_event) { |
|
912 |
var _el = $(this), |
|
913 |
_id = _el.attr("occurrence-id"); |
|
914 |
if (typeof _id !== "undefined") { |
|
915 |
var _occurrence = _this.getOccurrence(_id); |
|
916 |
// if (!_occurrence.locked) { |
|
917 |
_el.find('.Tl-Link').show(); |
|
918 |
// } |
|
919 |
if (!_this.is_dragging) { |
|
920 |
var _html = Mustache.to_html(Tlns.Templates.OccurrenceTooltip, _occurrence); |
|
921 |
_this.showTooltip(_occurrence.x, _occurrence.y, _html, (_event.pageY - _this.dragging_bounds.top) >= (.4 * _this.main_height) ); |
|
922 |
} |
|
923 |
} |
|
924 |
}).mouseout(function() { |
|
925 |
var _el = $(this), |
|
926 |
_id = _el.attr("occurrence-id"); |
|
927 |
if (typeof _id !== "undefined") { |
|
928 |
var _occurrence = _this.getOccurrence(_id); |
|
929 |
_this.hideTooltip(); |
83
|
930 |
_this.$.find('.Tl-Link').hide(); |
81
|
931 |
} |
|
932 |
}).mouseup(function() { |
|
933 |
var _el = $(this); |
|
934 |
if (_this.dragging_type == "link") { |
|
935 |
var _target = _el.attr("occurrence-id"); |
|
936 |
if (_target != _this.editing_occurrence.id) { |
|
937 |
_this.editing_occurrence.addDependency(_target); |
|
938 |
$("body").trigger("AjoutDependanceTimeline", |
|
939 |
{ |
|
940 |
id: _this.editing_occurrence.original_id, |
82
|
941 |
typeOccurrence: "Occurrence" + _this.editing_occurrence.type.replace(/^./,function(_l) { return _l.toUpperCase()}), |
81
|
942 |
idCible: _target.replace(/^.*_/,''), |
82
|
943 |
typeOccurrenceCible: "Occurrence" + _target.replace(/_.*$/,'').replace(/^./,function(_l) { return _l.toUpperCase()}) |
81
|
944 |
} |
|
945 |
); |
|
946 |
} |
|
947 |
} |
|
948 |
}); |
|
949 |
|
|
950 |
this.$.find('.Tl-Link').mousedown(function() { |
|
951 |
var _el = $(this).parent(), |
|
952 |
_id = _el.attr("occurrence-id"); |
|
953 |
_this.editing_occurrence = _this.getOccurrence(_id); |
|
954 |
if (typeof _this.editing_occurrence !== "undefined" /* && !_this.editing_occurrence.locked */ ) { |
|
955 |
_this.dragging_type = "link"; |
|
956 |
} |
|
957 |
}) |
|
958 |
|
|
959 |
this.$.find('.Tl-Cluster').click(function() { |
|
960 |
var _el = $(this), |
|
961 |
_contents = _el.attr("cluster-contents"); |
|
962 |
if (_this.open_cluster == _contents) { |
|
963 |
_this.open_cluster = false; |
|
964 |
} else { |
|
965 |
_this.open_cluster = _contents; |
|
966 |
} |
|
967 |
_this.throttledDrawGrid(); |
|
968 |
}) |
|
969 |
} |
|
970 |
|
|
971 |
Tlns.Classes.Timeline.prototype.drawList = function() { |
|
972 |
var _universfilter = this.$.find(".Ls-Univers li.Ls-Active").map(function(){return $(this).attr("data")}), |
|
973 |
_occtypefilter = this.$.find(".Ls-Occtypes li.Ls-Active").map(function(){return $(this).attr("data")}), |
83
|
974 |
_formatsfilter = this.$.find(".Ls-Formats li.Ls-Active").map(function(){return $(this).text()}), |
81
|
975 |
_statusfilter = this.$.find(".Ls-Occstatuses li.Ls-Active").map(function(){return $(this).attr("data")}), |
|
976 |
_jtfilter = this.$.find(".Ls-IsJt li.Ls-Active").map(function(){return !!+$(this).attr("data")}), |
|
977 |
_title = this.$.find(".Ls-Search").val() || "", |
|
978 |
_titleregexp = new RegExp( "(" + _title.replace(/(\W)/gm, "\\$1") + ")", "gim" ), |
|
979 |
_startdate = false, |
|
980 |
_enddate = false, |
|
981 |
_fromDate = this.$.find(".Ls-From-Date").val(), |
|
982 |
_toDate = this.$.find(".Ls-To-Date").val(); |
|
983 |
if (_fromDate) { |
|
984 |
var _date = Tlns.Utils.dateFieldProcess(_fromDate), |
|
985 |
_time = Tlns.Utils.timeFieldProcess(this.$.find(".Ls-From-Time").val()); |
|
986 |
_startdate = new Date(_date.year, _date.month - 1, _date.date, _time.hours, _time.minutes); |
|
987 |
} |
|
988 |
if (_toDate) { |
|
989 |
var _date = Tlns.Utils.dateFieldProcess(_toDate), |
|
990 |
_time = Tlns.Utils.timeFieldProcess(this.$.find(".Ls-To-Time").val()); |
|
991 |
_enddate = new Date(_date.year, _date.month - 1, _date.date, _time.hours, _time.minutes); |
|
992 |
} |
|
993 |
this.$.find(".Ls-Occurrences").html( |
|
994 |
Mustache.to_html( |
|
995 |
Tlns.Templates.Occurrence_List, |
|
996 |
{ |
|
997 |
occurrences: this.occurrences.filter(function(_occ) { |
|
998 |
var _titletest = (!!_occ.title.match(_titleregexp)), |
|
999 |
_keep = ( |
|
1000 |
( !_title || _titletest ) |
83
|
1001 |
&& _(_occtypefilter).include(_occ.type) |
|
1002 |
&& _(_universfilter).include(_occ.univers_id) |
|
1003 |
&& _(_statusfilter).include(_occ.status) |
|
1004 |
&& _(_formatsfilter).include(_occ.format) |
|
1005 |
&& _(_jtfilter).include(_occ.jt) |
81
|
1006 |
&& ( !_fromDate || _occ.date >= _startdate ) |
|
1007 |
&& ( !_toDate || _occ.date <= _enddate ) |
|
1008 |
); |
|
1009 |
return _keep; |
|
1010 |
}) |
|
1011 |
} |
|
1012 |
) |
|
1013 |
); |
|
1014 |
if (_title) { |
|
1015 |
this.$.find(".Ls-Occurrence-Title").each(function() { |
|
1016 |
$(this).html($(this).text().replace(_titleregexp, "<span style='background:yellow'>$1</span>")); |
|
1017 |
}); |
|
1018 |
} |
82
|
1019 |
this.$.find(".Ls-Occurrence").click(function() { |
|
1020 |
var _id = $(this).attr("data-id"), |
|
1021 |
_data = { |
|
1022 |
id: _id.replace(/^.*_/,''), |
|
1023 |
typeOccurrence: "Occurrence" + _id.replace(/_.*$/,'').replace(/^./,function(_l) { return _l.toUpperCase()}) |
|
1024 |
} |
|
1025 |
$("body").trigger("SelectionOccurrenceTimeline", _data); |
|
1026 |
return false; |
|
1027 |
}); |
81
|
1028 |
} |
|
1029 |
|
|
1030 |
Tlns.Classes.Timeline.prototype.getUnivers = function(_id) { |
|
1031 |
return _(this.univers).find(function(_univ) { |
|
1032 |
return (_univ.id == _id); |
|
1033 |
}); |
|
1034 |
} |
|
1035 |
|
|
1036 |
/* |
|
1037 |
* Univers |
|
1038 |
*/ |
|
1039 |
|
|
1040 |
Tlns.Classes.Univers = function(_data, _timeline, _index) { |
|
1041 |
this.id = _data.idUnivers; |
|
1042 |
this.index = _index; |
|
1043 |
this.title = _data.nomUnivers; |
|
1044 |
// this.mainCharacter = _data.personnage; |
|
1045 |
this.y = (_timeline.univers_height * _index); |
|
1046 |
|
|
1047 |
this.$label = $('<li>').css({ |
|
1048 |
height : _timeline.univers_height + "px" |
|
1049 |
}).html(Mustache.to_html(Tlns.Templates.Univers, this)) |
|
1050 |
.addClass((_index % 2) ? 'Tl-Line-Odd' : 'Tl-Line-Even'); |
|
1051 |
|
|
1052 |
_timeline.$.find('.Tl-UniversLabels').append(this.$label); |
|
1053 |
var _txt = this.title, |
|
1054 |
_span = this.$label.find('span'); |
|
1055 |
while (_span.outerWidth() > (_timeline.width - _timeline.main_width) && _txt) { |
|
1056 |
_txt = _txt.substr(0, _txt.length - 1); |
|
1057 |
_span.html(_txt + '…'); |
|
1058 |
} |
|
1059 |
} |
|
1060 |
|
|
1061 |
/* |
|
1062 |
* Occurrence |
|
1063 |
*/ |
|
1064 |
|
|
1065 |
Tlns.Classes.Occurrence = function(_timeline) { |
|
1066 |
this.timeline = _timeline; |
|
1067 |
} |
|
1068 |
|
|
1069 |
Tlns.Classes.Occurrence.prototype.update = function(_type, _data) { |
|
1070 |
this.type = _type; |
|
1071 |
if (typeof _data.idOccurrencePublication !== "undefined" || typeof _data.id !== "undefined" || typeof this.original_id === "undefined") { |
|
1072 |
this.original_id = _data.idOccurrencePublication || _data.id || Tlns.Utils.guid(); |
|
1073 |
} |
|
1074 |
this.id = _type + "_" + this.original_id; |
|
1075 |
if (typeof _data.date !== "undefined" || typeof _data.datePublication !== "undefined") { |
|
1076 |
this.date = 1000 * (_data.datePublication || _data.date); |
|
1077 |
} else { |
|
1078 |
if (typeof this.date === "undefined") { |
|
1079 |
this.date = new Date().valueOf(); |
|
1080 |
} |
|
1081 |
} |
|
1082 |
this.formatted_date = Tlns.Utils.dateFormat(this.date,Tlns.Defaults.Timeline.tooltip_date_format); |
|
1083 |
if (typeof _data.titre !== "undefined" || typeof this.title === "undefined") { |
|
1084 |
this.title = _data.titre || "<untitled>"; |
|
1085 |
} |
|
1086 |
if (typeof _data.idUnivers !== "undefined") { |
|
1087 |
this.univers_id = _data.idUnivers; |
|
1088 |
} |
|
1089 |
this.univers = this.timeline.getUnivers(this.univers_id); |
|
1090 |
if (typeof _data.statut !== "undefined" || typeof this.status === "undefined") { |
|
1091 |
switch(_data.statut) { |
|
1092 |
case "Validée": |
|
1093 |
case "valide": |
|
1094 |
this.status = "valide" |
|
1095 |
break; |
|
1096 |
case "A valider": |
|
1097 |
case "a_valider": |
|
1098 |
this.status = "a_valider"; |
|
1099 |
break; |
|
1100 |
case "A réaliser": |
|
1101 |
case "a_realiser": |
|
1102 |
this.status = "a_realiser"; |
|
1103 |
break; |
|
1104 |
default: |
|
1105 |
this.status = false; |
|
1106 |
} |
|
1107 |
} |
83
|
1108 |
if (typeof _data.typeOccurrencePublication !== "undefined" || typeof this.format === "undefined") { |
|
1109 |
this.format = _data.typeOccurrencePublication || 'Format non défini'; |
|
1110 |
} |
81
|
1111 |
if (typeof _data.JT !== "undefined") { |
|
1112 |
this.jt = !!+_data.JT; |
|
1113 |
} |
|
1114 |
this.translated_status = Tlns.Defaults.Timeline.statuses[this.status]; |
|
1115 |
// this.published = (_data.publication && _data.publication == "En ligne"); |
|
1116 |
// this.locked = _data.verrouille || false; |
|
1117 |
// this.characters = _data.personnagesSecondaires || []; |
|
1118 |
this.dependsOn = []; |
|
1119 |
if (_data.dependanceNarrative) { |
|
1120 |
for (var _i = 0; _i < _data.dependanceNarrative.length; _i++) { |
|
1121 |
this.dependsOn.push("narrative_" + _data.dependanceNarrative[_i]) |
|
1122 |
} |
|
1123 |
} |
|
1124 |
if (_data.dependancePublication) { |
|
1125 |
for (var _i = 0; _i < _data.dependancePublication.length; _i++) { |
|
1126 |
this.dependsOn.push("publication_" + _data.dependancePublication[_i]) |
|
1127 |
} |
|
1128 |
} |
|
1129 |
var _tmp = $('<p>').html(_data.accroche || ""); |
83
|
1130 |
this.description = _tmp.text().trim().replace(/(\n|\r|\r\n)/mg,' ').replace(/(^.{60,80})[\s].+$/m,'$1…'); |
81
|
1131 |
} |
|
1132 |
|
|
1133 |
Tlns.Classes.Occurrence.prototype.addDependency = function(_id) { |
|
1134 |
if (_(this.dependsOn).indexOf(_id) == -1) { |
|
1135 |
this.dependsOn.push(_id); |
|
1136 |
} |
|
1137 |
} |
|
1138 |
|
|
1139 |
Tlns.Classes.Occurrence.prototype.removeDependency = function(_id) { |
|
1140 |
this.dependsOn = _(this.dependsOn).reject(function(_n) { |
|
1141 |
return _n == _id; |
|
1142 |
}); |
|
1143 |
} |
|
1144 |
|
|
1145 |
Tlns.Classes.Occurrence.prototype.toString = function() { |
|
1146 |
return "Occurrence " + this.type + ': "' + this.title + '"'; |
|
1147 |
} |