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.timeFieldProcess = function(_val) { |
|
68 |
var _h = 0, |
|
69 |
_m = 0, |
|
70 |
_matches = _val.match(/(\d+)/g); |
|
71 |
if (_matches && _matches.length) { |
|
72 |
_h = Math.min(23, +(_matches[0])); |
|
73 |
if (_matches.length > 1) { |
|
74 |
_m = Math.min(59, +(_matches[1])); |
|
75 |
} |
|
76 |
} |
|
77 |
return { |
|
78 |
hours: _h, |
|
79 |
minutes: _m, |
|
80 |
text: Tlns.Utils.zeroPad(_h) + ':' + Tlns.Utils.zeroPad(_m) |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
Tlns.Utils.dateFieldProcess = function(_val) { |
|
85 |
var _now = new Date(), |
|
86 |
_y = _now.getFullYear(), |
|
87 |
_m = 1 + _now.getMonth(), |
|
88 |
_d = _now.getDate(), |
|
89 |
_matches = _val.match(/(\d+)/g); |
|
90 |
if (_matches && _matches.length) { |
|
91 |
_d = Math.min(31, +(_matches[0])); |
|
92 |
if (_matches.length > 1) { |
|
93 |
_m = Math.min(12, +(_matches[1])); |
|
94 |
} |
|
95 |
if (_matches.length > 2) { |
|
96 |
_y = parseInt(_matches[2]); |
|
97 |
if (_y < 2000) { |
|
98 |
_y += 2000; |
|
99 |
} |
|
100 |
_y = Math.min(2020, Math.max(2000, _y)); |
|
101 |
} |
|
102 |
} |
|
103 |
return { |
|
104 |
year: _y, |
|
105 |
month: _m, |
|
106 |
date: _d, |
|
107 |
text: Tlns.Utils.zeroPad(_d) + '/' + Tlns.Utils.zeroPad(_m) + '/' + _y |
|
108 |
} |
|
109 |
} |
|
110 |
|
83
|
111 |
Tlns.Utils.clickActiveProcess = function(_el) { |
|
112 |
if (_el.hasClass("Ls-Active")) { |
|
113 |
if (!_el.siblings(":not(.Ls-Active)").length) { |
|
114 |
_el.siblings().removeClass("Ls-Active"); |
|
115 |
} else { |
|
116 |
if (!_el.siblings(".Ls-Active").length) { |
|
117 |
_el.siblings().addClass("Ls-Active"); |
|
118 |
} |
|
119 |
_el.removeClass("Ls-Active"); |
|
120 |
} |
|
121 |
} else { |
|
122 |
_el.addClass("Ls-Active"); |
|
123 |
} |
|
124 |
} |
|
125 |
|
81
|
126 |
/* Defaults */ |
|
127 |
|
|
128 |
Tlns.Defaults.Timeline = { |
88
|
129 |
email: "", |
|
130 |
token: "", |
81
|
131 |
container : "timeline", |
88
|
132 |
width : 780, |
|
133 |
height : 225, |
81
|
134 |
min_width : 400, |
|
135 |
min_height : 100, |
88
|
136 |
main_width : 700, |
|
137 |
linelabels : [], |
81
|
138 |
timescales : [{ |
|
139 |
label : "Mois", |
|
140 |
span : 32 * 86400 * 1000, |
|
141 |
grid_interval : 5 * 86400 * 1000, |
|
142 |
grid_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
143 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
144 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}} {{year}}' |
|
145 |
}, { |
|
146 |
label : "Semaine", |
|
147 |
span : 8 * 86400 * 1000, |
|
148 |
grid_interval : 86400 * 1000, |
|
149 |
grid_date_format : '{{shortDayOfWeek}} {{0dayOfMonth}}/{{0monthNumber}}', |
|
150 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
151 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}}' |
|
152 |
}, { |
|
153 |
label : "2 jours", |
|
154 |
span : 2 * 86400 * 1000, |
|
155 |
grid_interval : 8 * 3600 * 1000, |
|
156 |
grid_date_format : '{{shortDayOfWeek}} {{0dayOfMonth}}/{{0monthNumber}} {{hours}}h', |
|
157 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}}', |
|
158 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}}' |
|
159 |
}, { |
|
160 |
label : "Demi-Journée", |
|
161 |
span : 12 * 3600 * 1000, |
|
162 |
grid_interval : 2 * 3600 * 1000, |
|
163 |
grid_date_format : '{{hours}}h', |
|
164 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}} {{hours}}h', |
|
165 |
end_date_format : '{{dayOfMonth}} {{shortMonthName}} {{hours}}h' |
|
166 |
}, { |
|
167 |
label : "3 Heures", |
|
168 |
span : 3 * 3600 * 1000, |
|
169 |
grid_interval : 30 * 60 * 1000, |
|
170 |
grid_date_format : '{{0hours}}:{{0minutes}}', |
|
171 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}} {{0hours}}:{{0minutes}}', |
|
172 |
end_date_format : '{{0hours}}:{{0minutes}}' |
|
173 |
}, { |
|
174 |
label : "1 Heure", |
|
175 |
span : 60 * 60 * 1000, |
|
176 |
grid_interval : 15 * 60 * 1000, |
|
177 |
grid_date_format : '{{0hours}}:{{0minutes}}', |
|
178 |
start_date_format : '{{dayOfMonth}} {{shortMonthName}} {{0hours}}:{{0minutes}}', |
|
179 |
end_date_format : '{{0hours}}:{{0minutes}}' |
|
180 |
}], |
|
181 |
level: 0, |
|
182 |
central_time: 0, |
|
183 |
sync_now: true, |
88
|
184 |
api_endpoint: "", |
|
185 |
api_method: "fetchAll", |
81
|
186 |
occurrences: [], |
|
187 |
cluster_spacing: 12, |
|
188 |
tooltip_date_format: '{{dayOfMonth}} {{shortMonthName}} {{year}} {{0hours}}:{{0minutes}}', |
|
189 |
statuses: { |
|
190 |
"valide": "Validée", |
|
191 |
"a_valider": "A valider", |
|
192 |
"a_realiser": "A réaliser" |
|
193 |
} |
|
194 |
} |
|
195 |
|
|
196 |
for (var _i = 0; _i < Tlns.Defaults.Timeline.timescales.length; _i++) { |
|
197 |
Tlns.Defaults.Timeline.timescales[_i].level = _i; |
|
198 |
} |
|
199 |
|
|
200 |
/* Templates */ |
|
201 |
|
87
|
202 |
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">' |
81
|
203 |
+ '<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>' |
|
204 |
+ '<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>' |
|
205 |
+ '<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>' |
|
206 |
+ '<div class="Tl-BottomPart"><ul class="Tl-UniversLabels"></ul>' |
88
|
207 |
+ '<div class="Tl-MainPart"><div class="Tl-Layer Tl-Grid"></div><div class="Tl-Layer Tl-Occurrences"></div>' |
87
|
208 |
+ '</div>' |
81
|
209 |
+ '<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>' |
|
210 |
|
83
|
211 |
+'<div class="Ls-Main"><div class="Ls-Filtres">' |
|
212 |
+ '<div class="Ls-Column"><h2>Filtres :</h2><h3>Univers :</h3><ul class="Ls-Univers"></ul></div>' |
81
|
213 |
+ '<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
|
214 |
+ '<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>' |
|
215 |
+ '<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>' |
|
216 |
+ '<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
|
217 |
+ '</div><div class="Ls-Resultats"><h2>Occurrences :</h2><ul class="Ls-Occurrences"></ul></div></div>'; |
|
218 |
|
|
219 |
Tlns.Templates.Univers = '<span class="Tl-UniversText">{{title}}</span>'; |
|
220 |
|
|
221 |
Tlns.Templates.Univers_List = '{{#univers}}<li data="{{id}}" class="Ls-Critere Ls-Active">{{title}}</li>{{/univers}}'; |
|
222 |
|
83
|
223 |
Tlns.Templates.Formats_List = '{{#formats}}<li class="Ls-Critere Ls-Active">{{.}}</li>{{/formats}}'; |
|
224 |
|
81
|
225 |
Tlns.Templates.Occurrence = '{{#clusters}}<div class="Tl-Cluster" style="left: {{x}}px; top: {{y}}px;" cluster-contents="{{contents}}">' |
|
226 |
+ '<div class="Tl-ClusterCount">{{occurrences.length}}</div></div>{{/clusters}}' |
|
227 |
+ '{{#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;">' |
|
228 |
// + '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}' |
87
|
229 |
+ '</div>{{/occurrences}}{{#open_cluster}}<div class="Tl-ClusterOverlay" style="left: {{x}}px; top: {{y}}px;">' |
81
|
230 |
+ '{{#occurrences}}<div class="Tl-Occurrence Tl-OccInCluster Tl-Occ{{type}} Tl-Occ{{status}}{{#editing}} Tl-Editing{{/editing}}" occurrence-id="{{id}}">' |
87
|
231 |
+ '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}</div>{{/occurrences}}</div>{{/open_cluster}}'; |
81
|
232 |
|
82
|
233 |
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>' |
88
|
234 |
+ '<p class="Ls-Occ-More">{{formatted_date}} — {{univers.title}} — {{translated_status}}{{#format}} — {{format}}{{/format}}</p><div style="clear:both;"></div></li>{{/occurrences}}'; |
81
|
235 |
|
83
|
236 |
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
|
237 |
+ '<p class="Tl-Tooltip-Description">{{description}}</p>' |
|
238 |
// + '<p class="Tl-Tooltip-Characters">{{univers.mainCharacter}}{{#characters}}, {{.}}{{/characters}}</p>' |
|
239 |
|
|
240 |
/* Classes */ |
|
241 |
|
|
242 |
Tlns.Classes.Timeline = function(_options) { |
|
243 |
|
|
244 |
/* Setting Defaults */ |
|
245 |
Tlns.Utils.SetDefaults(this, Tlns.Defaults.Timeline, _options); |
|
246 |
|
|
247 |
/* Setting container CSS */ |
|
248 |
this.$ = $('#' + this.container).html(Mustache.to_html(Tlns.Templates.Timeline, this)); |
|
249 |
|
|
250 |
this.$.find('.Tl-Main').css({ |
|
251 |
width : this.width + "px", |
|
252 |
height : this.height + "px" |
|
253 |
}); |
|
254 |
this.main_height = this.height - this.$.find('.Tl-TopBar').outerHeight(); |
82
|
255 |
//this.main_height = this.height - 27; |
81
|
256 |
this.$.find('.Tl-BottomPart').css("height", this.main_height + "px"); |
|
257 |
this.$.find('.Tl-MainPart').css("width", this.main_width + "px"); |
|
258 |
this.$.find('.Tl-Overlay-Container').css("left", (this.$.find('.Tl-BottomPart').outerWidth() - this.main_width) + "px"); |
88
|
259 |
|
81
|
260 |
var _o = this.$.find('.Tl-MainPart').offset(); |
|
261 |
this.dragging_bounds = { |
|
262 |
left: _o.left, |
|
263 |
top: _o.top, |
|
264 |
right: _o.left + this.$.find('.Tl-MainPart').outerWidth(), |
|
265 |
bottom: _o.top + this.$.find('.Tl-MainPart').outerHeight(), |
|
266 |
}; |
88
|
267 |
this.$.find('.Tl-UniversLabels').css({ |
|
268 |
width: this.width - this.main_width |
|
269 |
}); |
81
|
270 |
|
|
271 |
var _this = this; |
|
272 |
|
|
273 |
this.throttledDrawGrid = _.throttle(function() { |
|
274 |
_this.drawGrid(); |
|
275 |
}, 150); |
|
276 |
|
|
277 |
this.throttledDrawList = _.throttle(function() { |
|
278 |
_this.drawList(); |
|
279 |
}, 150); |
|
280 |
|
|
281 |
this.setLevel(this.level); |
|
282 |
|
|
283 |
this.$.find('.Tl-TopBar-Timescales>div').click(function() { |
|
284 |
_this.setLevel($(this).attr("data-level")); |
|
285 |
}); |
|
286 |
|
|
287 |
this.$.find('.Tl-TopBar-SyncButton').click(function() { |
|
288 |
_this.sync_now = !_this.sync_now; |
|
289 |
_this.changeSpan(); |
|
290 |
}) |
|
291 |
|
|
292 |
this.$.find('.Tl-TopBar-PreviousButton').click(function() { |
|
293 |
_this.offsetTime(-_this.timescales[_this.level].span / 4); |
|
294 |
}); |
|
295 |
|
|
296 |
this.$.find('.Tl-TopBar-NextButton').click(function() { |
|
297 |
_this.offsetTime(_this.timescales[_this.level].span / 4); |
|
298 |
}); |
|
299 |
|
|
300 |
this.$.find('.Tl-MainPart').mousedown(function(_event) { |
|
301 |
_this.onMouseDown(_event); |
|
302 |
return false; |
|
303 |
}); |
|
304 |
|
|
305 |
this.$.find('.Tl-MainPart').mousemove(function(_event) { |
|
306 |
_this.onMouseMove(_event); |
|
307 |
return false; |
|
308 |
}); |
|
309 |
|
|
310 |
this.$.find('.Tl-MainPart').mouseup(function(_event) { |
|
311 |
_this.onMouseUp(_event); |
|
312 |
return false; |
|
313 |
}); |
|
314 |
|
|
315 |
this.$.find('.Tl-MainPart').mousewheel(function(_event, _delta) { |
|
316 |
var _newLevel = Math.max(0,Math.min(_this.timescales.length-1, (_delta < 0 ? -1 : 1) + parseInt(_this.level))); |
|
317 |
if (_newLevel != _this.level) { |
|
318 |
_this.hideTooltip(); |
|
319 |
var _deltaX = _event.pageX - _this.dragging_bounds.left, |
|
320 |
_tAtMouse = _this.timeFromMouse(_event.pageX), |
|
321 |
_newScale = _this.main_width / (_this.timescales[_newLevel].span), |
|
322 |
_newStart = _tAtMouse - _deltaX / _newScale; |
|
323 |
_this.central_time = _newStart + _this.timescales[_newLevel].span / 2; |
|
324 |
_this.setLevel(_newLevel); |
|
325 |
} |
|
326 |
return false; |
|
327 |
}); |
|
328 |
|
|
329 |
this.$.find('.Tl-Overlay-Box').mouseover(function(_event) { |
|
330 |
$(this).show(); |
|
331 |
}).mouseout(function(_event) { |
|
332 |
$(this).hide(); |
|
333 |
}); |
87
|
334 |
|
81
|
335 |
|
|
336 |
/* LIST */ |
|
337 |
|
|
338 |
this.$.find("li.Ls-Critere").click(function() { |
83
|
339 |
Tlns.Utils.clickActiveProcess($(this)); |
81
|
340 |
_this.throttledDrawList(); |
|
341 |
}); |
|
342 |
this.$.find(".Ls-Search").bind("keyup change click", function() { |
|
343 |
_this.throttledDrawList(); |
|
344 |
}); |
|
345 |
this.$.find(".Ls-From-Date, .Ls-To-Date").datepicker( |
|
346 |
{ |
|
347 |
dateFormat: "dd/mm/yy", |
|
348 |
dayNames: [ "Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi" ], |
|
349 |
dayNamesShort: [ "Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam" ], |
|
350 |
dayNamesMin: [ "D", "L", "Ma", "Me", "J", "V", "S" ], |
|
351 |
monthNames: [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" ], |
|
352 |
monthNamesShort: [ "Jan", "Fév", "Mar", "Avr", "Mai", "Jun", "Jul", "Aoû", "Sep", "Oct", "Nov", "Déc" ], |
|
353 |
showOtherMonths: true, |
|
354 |
selectOtherMonths: true |
|
355 |
} |
|
356 |
).change(function() { |
|
357 |
var _val = $(this).val(); |
|
358 |
if (_val) { |
|
359 |
$(this).val(Tlns.Utils.dateFieldProcess( _val ).text); |
|
360 |
} |
|
361 |
_this.drawList(); |
|
362 |
}).bind("keyup", function() { |
|
363 |
_this.throttledDrawList(); |
|
364 |
}); |
|
365 |
this.$.find(".Ls-From-Time, .Ls-To-Time").change(function() { |
|
366 |
var _val = $(this).val(); |
|
367 |
if (_val) { |
|
368 |
$(this).val(Tlns.Utils.timeFieldProcess( _val ).text); |
|
369 |
} |
|
370 |
_this.throttledDrawList(); |
|
371 |
}).bind("keyup", function() { |
|
372 |
_this.throttledDrawList(); |
|
373 |
}); |
83
|
374 |
this.$.find(".Ls-All").click(function() { |
|
375 |
_this.$.find(".Ls-Critere").addClass("Ls-Active"); |
|
376 |
_this.throttledDrawList(); |
|
377 |
}); |
|
378 |
this.$.find(".Ls-None").click(function() { |
|
379 |
_this.$.find(".Ls-Critere").removeClass("Ls-Active"); |
|
380 |
_this.throttledDrawList(); |
|
381 |
}); |
81
|
382 |
|
|
383 |
this.$.find(".Onglet-Tl").click(function() { |
|
384 |
_this.$.find(".Tl-Main").show(); |
|
385 |
_this.$.find(".Ls-Main").hide(); |
|
386 |
_this.$.find(".Onglet-Ls").removeClass("active"); |
|
387 |
_this.$.find(".Onglet-Tl").addClass("active"); |
|
388 |
_this.throttledDrawGrid(); |
|
389 |
}); |
|
390 |
|
|
391 |
this.$.find(".Onglet-Ls").click(function() { |
|
392 |
_this.$.find(".Ls-Main").show(); |
|
393 |
_this.$.find(".Tl-Main").hide(); |
|
394 |
_this.$.find(".Onglet-Tl").removeClass("active"); |
|
395 |
_this.$.find(".Onglet-Ls").addClass("active"); |
|
396 |
_this.throttledDrawList(); |
|
397 |
}); |
87
|
398 |
|
88
|
399 |
this.onUniversLoaded(this.linelabels); |
81
|
400 |
|
|
401 |
} |
|
402 |
|
|
403 |
Tlns.Classes.Timeline.prototype.onMouseDown = function(_event) { |
|
404 |
this.mouse_down = true; |
|
405 |
this.is_dragging = false; |
|
406 |
this.start_pos = { |
|
407 |
x: _event.pageX, |
|
408 |
y: _event.pageY |
|
409 |
}; |
|
410 |
if (typeof this.dragging_type === "undefined") { |
|
411 |
this.time_at_start = this.central_time; |
|
412 |
this.dragging_type = "timeline"; |
|
413 |
} |
|
414 |
} |
|
415 |
|
|
416 |
Tlns.Classes.Timeline.prototype.onMouseUp = function(_event) { |
|
417 |
this.mouse_down = false; |
|
418 |
this.is_dragging = false; |
|
419 |
this.dragging_type = undefined; |
|
420 |
} |
|
421 |
|
|
422 |
Tlns.Classes.Timeline.prototype.timeFromX = function(_x) { |
|
423 |
return Math.max(this.start_time,Math.min(this.end_time, this.start_time + _x / this.current_scale)); |
|
424 |
} |
|
425 |
|
|
426 |
Tlns.Classes.Timeline.prototype.timeFromMouse = function(_pageX) { |
|
427 |
return this.timeFromX(_pageX - this.dragging_bounds.left); |
|
428 |
} |
|
429 |
|
|
430 |
Tlns.Classes.Timeline.prototype.universFromY = function(_y) { |
|
431 |
return Math.max(0,Math.min(this.univers.length, Math.floor(_y / this.univers_height))) |
|
432 |
} |
|
433 |
|
|
434 |
Tlns.Classes.Timeline.prototype.universFromMouse = function(_pageY) { |
|
435 |
return this.universFromY(_pageY - this.dragging_bounds.top); |
|
436 |
} |
|
437 |
|
|
438 |
Tlns.Classes.Timeline.prototype.onMouseMove = function(_event) { |
85
|
439 |
if (this.mouse_down && !this.is_dragging) { |
|
440 |
var _dx = this.start_pos.x - _event.pageX, |
|
441 |
_dy = this.start_pos.y - _event.pageY, |
|
442 |
_sqd = _dx * _dx + _dy * _dy; |
|
443 |
if (_sqd > 16) { |
|
444 |
this.is_dragging = true; |
|
445 |
} |
|
446 |
} |
|
447 |
if (this.is_dragging) { |
81
|
448 |
this.hideTooltip(); |
|
449 |
switch (this.dragging_type) { |
|
450 |
case "timeline": |
|
451 |
this.setTime(this.time_at_start + Math.floor(( this.start_pos.x - _event.pageX ) / this.current_scale)); |
|
452 |
break; |
|
453 |
} |
|
454 |
} |
|
455 |
} |
|
456 |
|
|
457 |
Tlns.Classes.Timeline.prototype.onUniversLoaded = function(_data) { |
|
458 |
this.univers = []; |
|
459 |
if(_data.length) { |
|
460 |
this.univers_height = Math.floor(this.main_height / _data.length); |
|
461 |
} |
|
462 |
for(var _i = 0; _i < _data.length; _i++) { |
|
463 |
this.univers.push(new Tlns.Classes.Univers(_data[_i], this, _i)); |
|
464 |
} |
|
465 |
|
83
|
466 |
this.$.find(".Ls-Univers").html( |
|
467 |
Mustache.to_html( |
|
468 |
Tlns.Templates.Univers_List, |
|
469 |
{ |
|
470 |
univers: _(this.univers).map(function(_u) { |
|
471 |
return { |
|
472 |
id: _u.id, |
|
473 |
title: _u.title.replace(/(^.{10,20})[\s].+$/m,'$1…') |
|
474 |
} |
|
475 |
}) |
|
476 |
} |
|
477 |
) |
|
478 |
); |
81
|
479 |
var _this = this; |
|
480 |
this.$.find(".Ls-Univers li.Ls-Critere").click( function() { |
83
|
481 |
Tlns.Utils.clickActiveProcess($(this)); |
81
|
482 |
_this.throttledDrawList(); |
|
483 |
}); |
|
484 |
this.loadOccurrences(); |
|
485 |
} |
|
486 |
|
|
487 |
Tlns.Classes.Timeline.prototype.offsetTime = function(_timeOffset) { |
|
488 |
this.setTime(this.central_time + _timeOffset); |
|
489 |
} |
|
490 |
|
|
491 |
Tlns.Classes.Timeline.prototype.setTime = function(_centralTime) { |
|
492 |
this.sync_now = false; |
|
493 |
this.central_time = _centralTime; |
|
494 |
this.changeSpan(); |
|
495 |
} |
|
496 |
|
|
497 |
Tlns.Classes.Timeline.prototype.setLevel = function(_level) { |
|
498 |
if (_level >= 0 && _level < this.timescales.length) { |
|
499 |
this.$.find('.Tl-TopBar-Timescales>div').each(function() { |
|
500 |
var _el = $(this); |
|
501 |
if (_el.attr("data-level") == _level) { |
|
502 |
_el.addClass("active"); |
|
503 |
} else { |
|
504 |
_el.removeClass("active"); |
|
505 |
} |
|
506 |
}); |
|
507 |
this.level = _level; |
|
508 |
this.changeSpan(); |
|
509 |
} |
|
510 |
} |
|
511 |
|
|
512 |
Tlns.Classes.Timeline.prototype.changeSpan = function() { |
|
513 |
var _now = new Date().valueOf(); |
|
514 |
if (this.sync_now) { |
|
515 |
this.central_time = _now; |
|
516 |
} |
|
517 |
var _timescale = this.timescales[this.level]; |
|
518 |
this.current_scale = this.main_width / (_timescale.span); |
|
519 |
this.start_time = this.central_time - (_timescale.span / 2); |
|
520 |
this.end_time = this.central_time + (_timescale.span / 2); |
|
521 |
this.$.find(".Ls-From-Time").val(Tlns.Utils.dateFormat(this.start_time, '{{0hours}}:{{0minutes}}')); |
|
522 |
this.$.find(".Ls-From-Date").val(Tlns.Utils.dateFormat(this.start_time, '{{0dayOfMonth}}/{{0monthNumber}}/{{year}}')); |
|
523 |
this.$.find(".Ls-To-Time").val(Tlns.Utils.dateFormat(this.end_time, '{{0hours}}:{{0minutes}}')); |
|
524 |
this.$.find(".Ls-To-Date").val(Tlns.Utils.dateFormat(this.end_time, '{{0dayOfMonth}}/{{0monthNumber}}/{{year}}')); |
|
525 |
this.throttledDrawGrid(); |
|
526 |
this.throttledDrawList(); |
|
527 |
} |
|
528 |
|
|
529 |
Tlns.Classes.Timeline.prototype.drawGrid = function() { |
|
530 |
if (this.sync_now) { |
|
531 |
this.$.find('.Tl-TopBar-SyncButton').addClass("active"); |
|
532 |
} else { |
|
533 |
this.$.find('.Tl-TopBar-SyncButton').removeClass("active"); |
|
534 |
} |
|
535 |
var _now = new Date().valueOf(), |
|
536 |
_timescale = this.timescales[this.level], |
|
537 |
_offset = new Date().getTimezoneOffset() * 60000, |
|
538 |
_grid_width = Math.floor(_timescale.grid_interval * this.current_scale), |
|
539 |
_roundstart = Math.floor((this.start_time - _offset) / _timescale.grid_interval) * _timescale.grid_interval + _offset, |
|
540 |
_html = ''; |
|
541 |
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)); |
|
542 |
for (var _t = _roundstart; _t < this.end_time; _t += _timescale.grid_interval) { |
|
543 |
var _x = this.current_scale * (_t - this.start_time); |
|
544 |
if (_x > 0) { |
|
545 |
_html += '<div class="Tl-Grid-Column" style="width:' + _grid_width + 'px; left: ' + _x + 'px">' |
|
546 |
+ '<div class="Tl-Grid-Label">' + Tlns.Utils.dateFormat(_t, _timescale.grid_date_format) + '</div></div>'; |
|
547 |
} |
|
548 |
} |
|
549 |
if (this.start_time <= _now && this.end_time >= _now) { |
|
550 |
_html += '<div class="Tl-Grid-Now" style="left: ' + this.current_scale * (_now - this.start_time) + 'px"></div>' |
|
551 |
} |
|
552 |
this.$.find('.Tl-Grid').html(_html); |
|
553 |
this.drawOccurrences(); |
|
554 |
} |
|
555 |
|
|
556 |
Tlns.Classes.Timeline.prototype.loadOccurrences = function() { |
|
557 |
var _this = this; |
88
|
558 |
$.getJSON(this.api_endpoint, { |
|
559 |
method: this.api_method, |
|
560 |
api_key: this.token, |
|
561 |
mail: this.email |
|
562 |
}, function(_data) { |
|
563 |
console.log(_data); |
|
564 |
_this.onOccurrencesLoaded(_data); |
81
|
565 |
}); |
|
566 |
|
|
567 |
} |
|
568 |
|
88
|
569 |
Tlns.Classes.Timeline.prototype.onOccurrencesLoaded = function(_data) { |
|
570 |
for (var _i = 0; _i < _data.data.length; _i++) { |
|
571 |
this.createOrUpdateOccurrence(_data.data[_i]); |
81
|
572 |
} |
|
573 |
if (!this.mouse_down) { |
|
574 |
this.drawOccurrences(); |
|
575 |
} |
83
|
576 |
this.$.find(".Ls-Formats").html( |
|
577 |
Mustache.to_html( |
|
578 |
Tlns.Templates.Formats_List, |
|
579 |
{ |
|
580 |
formats: _(this.occurrences).chain().pluck('format').unique().value() |
|
581 |
} |
|
582 |
) |
|
583 |
); |
|
584 |
var _this = this; |
|
585 |
this.$.find(".Ls-Formats li.Ls-Critere").click( function() { |
|
586 |
Tlns.Utils.clickActiveProcess($(this)); |
|
587 |
_this.throttledDrawList(); |
|
588 |
}); |
81
|
589 |
this.throttledDrawList(); |
|
590 |
} |
|
591 |
|
|
592 |
Tlns.Classes.Timeline.prototype.deleteOccurrence = function(_id) { |
|
593 |
this.occurrences = _(this.occurrences).reject(function(_occ) { |
|
594 |
return _occ.id == _id; |
|
595 |
}); |
|
596 |
} |
|
597 |
|
|
598 |
Tlns.Classes.Timeline.prototype.getOccurrence = function(_id) { |
|
599 |
return _(this.occurrences).find(function(_occ) { |
|
600 |
return _occ.id == _id; |
|
601 |
}); |
|
602 |
} |
|
603 |
|
88
|
604 |
Tlns.Classes.Timeline.prototype.createOrUpdateOccurrence = function(_data) { |
|
605 |
var _id = _data.id, |
81
|
606 |
_occurrence = this.getOccurrence(_id); |
|
607 |
if (typeof _occurrence === "undefined") { |
|
608 |
_occurrence = new Tlns.Classes.Occurrence(this); |
|
609 |
this.occurrences.push(_occurrence); |
|
610 |
} |
88
|
611 |
_occurrence.update(_data); |
81
|
612 |
return _occurrence; |
|
613 |
} |
|
614 |
|
|
615 |
Tlns.Classes.Timeline.prototype.showTooltip = function(_x, _y, _html, _isUp) { |
|
616 |
this.$.find('.Tl-Overlay-Box') |
|
617 |
.removeClass(_isUp ? 'Tl-Overlay-Down' : 'Tl-Overlay-Up') |
|
618 |
.addClass(_isUp ? 'Tl-Overlay-Up' : 'Tl-Overlay-Down') |
|
619 |
.show() |
|
620 |
.css({ |
|
621 |
left: _x + "px", |
|
622 |
top: _y + "px" |
|
623 |
}); |
|
624 |
this.$.find('.Tl-Overlay-Main').html(_html); |
85
|
625 |
|
81
|
626 |
} |
|
627 |
|
|
628 |
Tlns.Classes.Timeline.prototype.hideTooltip = function() { |
|
629 |
this.$.find('.Tl-Overlay-Box').hide(); |
|
630 |
} |
|
631 |
|
|
632 |
Tlns.Classes.Timeline.prototype.drawOccurrences = function() { |
85
|
633 |
var _this = this; |
|
634 |
_(this.occurrences).each(function(_occ) { |
81
|
635 |
_occ.x = _this.current_scale * (_occ.date - _this.start_time); |
|
636 |
_occ.y = _occ.univers.y; |
|
637 |
_occ.in_cluster = false; |
|
638 |
}); |
85
|
639 |
var _visible = _(this.occurrences).filter(function(_occ) { |
|
640 |
return (_occ.date >= _this.start_time && _occ.date <= _this.end_time && _occ.status); |
|
641 |
}); |
81
|
642 |
|
|
643 |
var _moved = true; |
|
644 |
while (_moved) { |
|
645 |
_moved = false; |
|
646 |
for (var _i = 0; _i < _visible.length; _i++) { |
|
647 |
for (var _j = 0; _j < _i; _j++) { |
|
648 |
if (_visible[_j].univers_id == _visible[_i].univers_id |
|
649 |
&& _visible[_j].x != _visible[_i].x |
|
650 |
&& Math.abs(_visible[_j].x-_visible[_i].x) < this.cluster_spacing |
|
651 |
) { |
|
652 |
_moved = true; |
|
653 |
_visible[_i].x = this.cluster_spacing * Math.round(_visible[_i].x / this.cluster_spacing); |
|
654 |
_visible[_j].x = this.cluster_spacing * Math.round(_visible[_j].x / this.cluster_spacing); |
|
655 |
} |
|
656 |
} |
|
657 |
} |
|
658 |
} |
|
659 |
var _clusters = [], |
|
660 |
_openCluster = false; |
|
661 |
for (var _i = 0; _i < _visible.length; _i++) { |
|
662 |
for (var _j = 0; _j < _i; _j++) { |
|
663 |
if (_visible[_j].univers_id == _visible[_i].univers_id && _visible[_j].x == _visible[_i].x) { |
|
664 |
_visible[_j].in_cluster = true; |
|
665 |
_visible[_i].in_cluster = true; |
|
666 |
var _x = _visible[_j].x, |
|
667 |
_y = _visible[_j].y; |
|
668 |
_cluster = _(_clusters).find(function(_c) { return _c.x == _x && _c.y == _y }); |
|
669 |
if (typeof _cluster === "undefined") { |
|
670 |
_cluster = { x: _x, y: _y, occurrences: [] }; |
|
671 |
_clusters.push(_cluster); |
|
672 |
} |
|
673 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
674 |
return _o.type == _visible[_j].type && _o.id == _visible[_j].id; |
|
675 |
})) { |
|
676 |
_cluster.occurrences.push(_visible[_j]); |
|
677 |
} |
|
678 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
679 |
return _o.type == _visible[_i].type && _o.id == _visible[_i].id; |
|
680 |
})) { |
|
681 |
_cluster.occurrences.push(_visible[_i]); |
|
682 |
} |
|
683 |
} |
|
684 |
} |
|
685 |
} |
|
686 |
_(_clusters).each(function(_cluster) { |
|
687 |
_cluster.occurrences = _(_cluster.occurrences).sortBy(function(_o) { |
|
688 |
return _o.date; |
|
689 |
}); |
|
690 |
_cluster.contents = _cluster.occurrences.map(function(_o) { |
84
|
691 |
return _o.id; |
81
|
692 |
}).join("|"); |
|
693 |
if (_cluster.contents == _this.open_cluster) { |
|
694 |
_openCluster = _cluster; |
|
695 |
} |
|
696 |
}); |
|
697 |
|
|
698 |
var _html = Mustache.to_html(Tlns.Templates.Occurrence, { |
|
699 |
occurrences:_(_visible).reject(function(_o) {return _o.in_cluster}), |
|
700 |
clusters: _clusters, |
|
701 |
open_cluster: _openCluster |
|
702 |
}); |
|
703 |
this.$.find('.Tl-Occurrences').html(_html); |
|
704 |
|
|
705 |
|
|
706 |
if (_openCluster) { |
|
707 |
var _w = this.$.find('.Tl-Occurrence').width(), |
|
708 |
_ww = _w * _openCluster.occurrences.length; |
|
709 |
this.$.find('.Tl-ClusterOverlay').css({ |
|
710 |
"margin-left": - Math.floor(_ww/2) + "px", |
|
711 |
width: _ww |
|
712 |
}); |
|
713 |
_(_openCluster.occurrences).each(function(_o, _i) { |
|
714 |
_o.y = _o.y - 20; |
|
715 |
_o.x = _o.x - (_ww / 2) + ((_i + .5) * _w); |
|
716 |
}); |
|
717 |
} |
|
718 |
|
|
719 |
this.$.find('.Tl-Occurrence').mousedown(function() { |
|
720 |
var _el = $(this), |
|
721 |
_id = _el.attr("occurrence-id"); |
|
722 |
if (typeof _id !== "undefined") { |
|
723 |
_this.editing_occurrence = _this.getOccurrence(_id); |
|
724 |
if (typeof _this.dragging_type === "undefined" && typeof _this.editing_occurrence !== "undefined" /* && !_this.editing_occurrence.locked */ ) { |
|
725 |
_this.dragging_type = "occurrence"; |
83
|
726 |
} |
|
727 |
if (!_this.editing_occurrence.editing) { |
|
728 |
_(_this.occurrences).each(function(_occ) { |
|
729 |
_occ.editing = false; |
|
730 |
}); |
81
|
731 |
_this.editing_occurrence.editing = true; |
|
732 |
} |
83
|
733 |
_this.throttledDrawGrid(); |
81
|
734 |
} |
|
735 |
}).mouseover(function(_event) { |
|
736 |
var _el = $(this), |
|
737 |
_id = _el.attr("occurrence-id"); |
|
738 |
if (typeof _id !== "undefined") { |
|
739 |
var _occurrence = _this.getOccurrence(_id); |
|
740 |
if (!_this.is_dragging) { |
|
741 |
var _html = Mustache.to_html(Tlns.Templates.OccurrenceTooltip, _occurrence); |
|
742 |
_this.showTooltip(_occurrence.x, _occurrence.y, _html, (_event.pageY - _this.dragging_bounds.top) >= (.4 * _this.main_height) ); |
|
743 |
} |
|
744 |
} |
|
745 |
}).mouseout(function() { |
|
746 |
var _el = $(this), |
|
747 |
_id = _el.attr("occurrence-id"); |
|
748 |
if (typeof _id !== "undefined") { |
|
749 |
var _occurrence = _this.getOccurrence(_id); |
|
750 |
_this.hideTooltip(); |
|
751 |
} |
|
752 |
}); |
87
|
753 |
|
81
|
754 |
this.$.find('.Tl-Cluster').click(function() { |
|
755 |
var _el = $(this), |
|
756 |
_contents = _el.attr("cluster-contents"); |
|
757 |
if (_this.open_cluster == _contents) { |
|
758 |
_this.open_cluster = false; |
|
759 |
} else { |
|
760 |
_this.open_cluster = _contents; |
|
761 |
} |
|
762 |
_this.throttledDrawGrid(); |
|
763 |
}) |
|
764 |
} |
|
765 |
|
|
766 |
Tlns.Classes.Timeline.prototype.drawList = function() { |
|
767 |
var _universfilter = this.$.find(".Ls-Univers li.Ls-Active").map(function(){return $(this).attr("data")}), |
|
768 |
_occtypefilter = this.$.find(".Ls-Occtypes li.Ls-Active").map(function(){return $(this).attr("data")}), |
83
|
769 |
_formatsfilter = this.$.find(".Ls-Formats li.Ls-Active").map(function(){return $(this).text()}), |
81
|
770 |
_statusfilter = this.$.find(".Ls-Occstatuses li.Ls-Active").map(function(){return $(this).attr("data")}), |
|
771 |
_jtfilter = this.$.find(".Ls-IsJt li.Ls-Active").map(function(){return !!+$(this).attr("data")}), |
|
772 |
_title = this.$.find(".Ls-Search").val() || "", |
|
773 |
_titleregexp = new RegExp( "(" + _title.replace(/(\W)/gm, "\\$1") + ")", "gim" ), |
|
774 |
_startdate = false, |
|
775 |
_enddate = false, |
|
776 |
_fromDate = this.$.find(".Ls-From-Date").val(), |
|
777 |
_toDate = this.$.find(".Ls-To-Date").val(); |
|
778 |
if (_fromDate) { |
|
779 |
var _date = Tlns.Utils.dateFieldProcess(_fromDate), |
|
780 |
_time = Tlns.Utils.timeFieldProcess(this.$.find(".Ls-From-Time").val()); |
|
781 |
_startdate = new Date(_date.year, _date.month - 1, _date.date, _time.hours, _time.minutes); |
|
782 |
} |
|
783 |
if (_toDate) { |
|
784 |
var _date = Tlns.Utils.dateFieldProcess(_toDate), |
|
785 |
_time = Tlns.Utils.timeFieldProcess(this.$.find(".Ls-To-Time").val()); |
|
786 |
_enddate = new Date(_date.year, _date.month - 1, _date.date, _time.hours, _time.minutes); |
|
787 |
} |
|
788 |
this.$.find(".Ls-Occurrences").html( |
|
789 |
Mustache.to_html( |
|
790 |
Tlns.Templates.Occurrence_List, |
|
791 |
{ |
85
|
792 |
occurrences: _(this.occurrences).chain().filter(function(_occ) { |
81
|
793 |
var _titletest = (!!_occ.title.match(_titleregexp)), |
|
794 |
_keep = ( |
|
795 |
( !_title || _titletest ) |
83
|
796 |
&& _(_occtypefilter).include(_occ.type) |
|
797 |
&& _(_universfilter).include(_occ.univers_id) |
|
798 |
&& _(_statusfilter).include(_occ.status) |
|
799 |
&& _(_formatsfilter).include(_occ.format) |
|
800 |
&& _(_jtfilter).include(_occ.jt) |
81
|
801 |
&& ( !_fromDate || _occ.date >= _startdate ) |
|
802 |
&& ( !_toDate || _occ.date <= _enddate ) |
|
803 |
); |
|
804 |
return _keep; |
85
|
805 |
}).sortBy(function(_occ) { |
|
806 |
return _occ.date; |
|
807 |
}).value() |
81
|
808 |
} |
|
809 |
) |
|
810 |
); |
|
811 |
if (_title) { |
|
812 |
this.$.find(".Ls-Occurrence-Title").each(function() { |
|
813 |
$(this).html($(this).text().replace(_titleregexp, "<span style='background:yellow'>$1</span>")); |
|
814 |
}); |
|
815 |
} |
82
|
816 |
this.$.find(".Ls-Occurrence").click(function() { |
|
817 |
var _id = $(this).attr("data-id"), |
|
818 |
_data = { |
|
819 |
id: _id.replace(/^.*_/,''), |
|
820 |
typeOccurrence: "Occurrence" + _id.replace(/_.*$/,'').replace(/^./,function(_l) { return _l.toUpperCase()}) |
|
821 |
} |
|
822 |
return false; |
|
823 |
}); |
81
|
824 |
} |
|
825 |
|
|
826 |
Tlns.Classes.Timeline.prototype.getUnivers = function(_id) { |
|
827 |
return _(this.univers).find(function(_univ) { |
|
828 |
return (_univ.id == _id); |
|
829 |
}); |
|
830 |
} |
|
831 |
|
|
832 |
/* |
|
833 |
* Univers |
|
834 |
*/ |
|
835 |
|
|
836 |
Tlns.Classes.Univers = function(_data, _timeline, _index) { |
88
|
837 |
this.id = "u_" + _index; |
81
|
838 |
this.index = _index; |
88
|
839 |
this.title = _data; |
81
|
840 |
// this.mainCharacter = _data.personnage; |
|
841 |
this.y = (_timeline.univers_height * _index); |
|
842 |
|
|
843 |
this.$label = $('<li>').css({ |
|
844 |
height : _timeline.univers_height + "px" |
88
|
845 |
}).html(Mustache.to_html(Tlns.Templates.Univers, this)); |
81
|
846 |
|
|
847 |
_timeline.$.find('.Tl-UniversLabels').append(this.$label); |
|
848 |
} |
|
849 |
|
|
850 |
/* |
|
851 |
* Occurrence |
|
852 |
*/ |
|
853 |
|
|
854 |
Tlns.Classes.Occurrence = function(_timeline) { |
|
855 |
this.timeline = _timeline; |
|
856 |
} |
|
857 |
|
88
|
858 |
Tlns.Classes.Occurrence.prototype.update = function(_data) { |
|
859 |
this.original_data = _data; |
|
860 |
this.id = _data.id; |
|
861 |
this.date = new Date(1000 * (_data.dateFirstPublication || _data.dateCreate) || Date.now); |
81
|
862 |
this.formatted_date = Tlns.Utils.dateFormat(this.date,Tlns.Defaults.Timeline.tooltip_date_format); |
88
|
863 |
this.title = _data.title; |
|
864 |
this.univers_id = this.timeline.univers[Math.floor(this.timeline.univers.length * Math.random())].id; |
81
|
865 |
this.univers = this.timeline.getUnivers(this.univers_id); |
88
|
866 |
this.type = "publication"; |
81
|
867 |
if (typeof _data.statut !== "undefined" || typeof this.status === "undefined") { |
|
868 |
switch(_data.statut) { |
|
869 |
case "Validée": |
|
870 |
case "valide": |
|
871 |
this.status = "valide" |
|
872 |
break; |
|
873 |
case "A réaliser": |
|
874 |
case "a_realiser": |
|
875 |
this.status = "a_realiser"; |
|
876 |
break; |
84
|
877 |
case "A valider": |
|
878 |
case "a_valider": |
81
|
879 |
default: |
84
|
880 |
this.status = "a_valider"; |
81
|
881 |
} |
|
882 |
} |
83
|
883 |
if (typeof _data.typeOccurrencePublication !== "undefined" || typeof this.format === "undefined") { |
|
884 |
this.format = _data.typeOccurrencePublication || 'Format non défini'; |
|
885 |
} |
81
|
886 |
this.translated_status = Tlns.Defaults.Timeline.statuses[this.status]; |
|
887 |
// this.published = (_data.publication && _data.publication == "En ligne"); |
|
888 |
// this.locked = _data.verrouille || false; |
|
889 |
// this.characters = _data.personnagesSecondaires || []; |
88
|
890 |
var _tmp = $('<p>').html(_data.resume || ""); |
83
|
891 |
this.description = _tmp.text().trim().replace(/(\n|\r|\r\n)/mg,' ').replace(/(^.{60,80})[\s].+$/m,'$1…'); |
81
|
892 |
} |
|
893 |
|
|
894 |
Tlns.Classes.Occurrence.prototype.addDependency = function(_id) { |
|
895 |
if (_(this.dependsOn).indexOf(_id) == -1) { |
|
896 |
this.dependsOn.push(_id); |
|
897 |
} |
|
898 |
} |
|
899 |
|
|
900 |
Tlns.Classes.Occurrence.prototype.removeDependency = function(_id) { |
|
901 |
this.dependsOn = _(this.dependsOn).reject(function(_n) { |
|
902 |
return _n == _id; |
|
903 |
}); |
|
904 |
} |
|
905 |
|
|
906 |
Tlns.Classes.Occurrence.prototype.toString = function() { |
|
907 |
return "Occurrence " + this.type + ': "' + this.title + '"'; |
|
908 |
} |