author | veltr |
Mon, 09 Jul 2012 19:44:02 +0200 | |
changeset 75 | ef3377d7a4f7 |
parent 74 | e107c77600e8 |
child 77 | 04b8157f077b |
permissions | -rw-r--r-- |
65 | 1 |
/* |
2 |
* Main Timeline code |
|
3 |
*/ |
|
4 |
||
5 |
window.Tlns = { |
|
6 |
Utils : {}, |
|
7 |
Defaults : {}, |
|
8 |
Templates : {}, |
|
9 |
Classes : {} |
|
10 |
}; |
|
11 |
||
12 |
/* Utility Functions */ |
|
13 |
||
75 | 14 |
Tlns.Utils.zeroPad = function(_n) { |
15 |
return (_n < 10 ? "0" : "") + _n; |
|
16 |
} |
|
17 |
||
65 | 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 _data !== "object") { |
|
39 |
_date = new Date(_date); |
|
40 |
} |
|
41 |
var _params = { |
|
42 |
hours: _date.getHours(), |
|
75 | 43 |
"0hours": Tlns.Utils.zeroPad(_date.getHours()), |
65 | 44 |
minutes: _date.getMinutes(), |
75 | 45 |
"0minutes": Tlns.Utils.zeroPad(_date.getMinutes()), |
65 | 46 |
seconds: _date.getSeconds(), |
75 | 47 |
"0seconds": Tlns.Utils.zeroPad(_date.getSeconds()), |
65 | 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(), |
|
75 | 51 |
"0dayOfMonth": Tlns.Utils.zeroPad(_date.getDate()), |
65 | 52 |
monthNumber: 1+_date.getMonth(), |
75 | 53 |
"0monthNumber": Tlns.Utils.zeroPad(1+_date.getMonth()), |
65 | 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 |
||
71 | 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 |
||
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
67 |
Tlns.Utils.drawArrow = function(_ctx, _color, _x1, _y1, _x2, _y2) { |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
68 |
_ctx.strokeStyle = _color; |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
69 |
_ctx.fillStyle = _color; |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
70 |
_ctx.beginPath(); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
71 |
_ctx.moveTo(_x1,_y1); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
72 |
_ctx.lineTo(_x2,_y2); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
73 |
_ctx.stroke(); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
74 |
var _mod = Math.sqrt(Math.pow(_x2 - _x1, 2) + Math.pow(_y2 - _y1, 2)), |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
75 |
_xu = (_x2 - _x1) / _mod, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
76 |
_yu = (_y2 - _y1) / _mod, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
77 |
_xm = (_x1 + _x2) / 2, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
78 |
_ym = (_y1 + _y2) / 2, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
79 |
_arrowWidth = 4, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
80 |
_arrowLength = 8, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
81 |
_x3 = _xm - _arrowLength * _xu + _arrowWidth * _yu, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
82 |
_y3 = _ym - _arrowLength * _yu - _arrowWidth * _xu, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
83 |
_x4 = _xm - _arrowLength * _xu - _arrowWidth * _yu, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
84 |
_y4 = _ym - _arrowLength * _yu + _arrowWidth * _xu; |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
85 |
_ctx.beginPath(); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
86 |
_ctx.moveTo(_x3, _y3); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
87 |
_ctx.lineTo(_xm, _ym); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
88 |
_ctx.lineTo(_x4, _y4); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
89 |
_ctx.fill(); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
90 |
_ctx.stroke(); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
91 |
} |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
92 |
|
75 | 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 |
||
65 | 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", |
|
66 | 184 |
span : 60 * 60 * 1000, |
65 | 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 |
url_occurrences: '', |
|
66 | 194 |
occurrences: [], |
75 | 195 |
cluster_spacing: 12, |
196 |
tooltip_date_format: '{{dayOfMonth}} {{shortMonthName}} {{year}} {{0hours}}:{{0minutes}}', |
|
197 |
statuses: { |
|
198 |
"valide": "Validée", |
|
199 |
"a_valider": "À valider", |
|
200 |
"a_realiser": "À réaliser" |
|
201 |
} |
|
65 | 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 |
||
75 | 210 |
Tlns.Templates.Timeline = '<ul class="Onglets"><li>Frise chronologique</li><li>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>' |
65 | 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>' |
|
71 | 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>' |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
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>' |
75 | 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>' |
74 | 219 |
|
75 | 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></div>' |
|
224 |
+ '<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>' |
|
225 |
+ '</div><div class="Ls-Resultats"><h2>Occurrences :</h2><ul class="Ls-Occurrences"></ul></div></div>'; |
|
65 | 226 |
|
66 | 227 |
Tlns.Templates.Univers = '<span class="Tl-UniversText">{{title}}</span>'; |
228 |
||
75 | 229 |
Tlns.Templates.Univers_List = '{{#univers}}<li data="{{id}}" class="Ls-Critere Ls-Active">{{title}}</li>{{/univers}}'; |
74 | 230 |
|
75 | 231 |
Tlns.Templates.Occurrence = '{{#clusters}}<div class="Tl-Cluster" style="left: {{x}}px; top: {{y}}px;" cluster-contents="{{contents}}">' |
70 | 232 |
+ '<div class="Tl-ClusterCount">{{occurrences.length}}</div></div>{{/clusters}}' |
75 | 233 |
+ '{{#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;">' |
234 |
// + '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}' |
|
235 |
+ '<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;">' |
|
236 |
+ '{{#occurrences}}<div class="Tl-Occurrence Tl-OccInCluster Tl-Occ{{type}} Tl-Occ{{status}}{{#editing}} Tl-Editing{{/editing}}" occurrence-id="{{id}}">' |
|
70 | 237 |
+ '{{#locked}}<div class="Tl-Locked"></div>{{/locked}}<div class="Tl-Link"{{#editing}} style="display: block"{{/editing}}></div></div>{{/occurrences}}</div>{{/open_cluster}}'; |
74 | 238 |
|
75 | 239 |
Tlns.Templates.Occurrence_List = '{{#occurrences}}<li class="Ls-Occurrence"><div class="Ls-OccIcon Tl-Occ{{type}} Tl-Occ{{status}}"></div><div class="Ls-Occurrence-Title">{{title}}</div><div class="Tl-Tooltip-Date">{{formatted_date}}</div><div style="clear:both;"></div></li>{{/occurrences}}'; |
74 | 240 |
|
75 | 241 |
Tlns.Templates.OccurrenceTooltip = '<h3 class="Tl-Tooltip-Title">{{title}}</h3><p class="Tl-Tooltip-Date">{{formatted_date}} - {{translated_status}}</p>' |
70 | 242 |
+ '<p class="Tl-Tooltip-Description">{{description}}</p><p class="Tl-Tooltip-Characters">{{univers.mainCharacter}}{{#characters}}, {{.}}{{/characters}}</p>' |
65 | 243 |
|
244 |
/* Classes */ |
|
245 |
||
246 |
Tlns.Classes.Timeline = function(_options) { |
|
247 |
||
248 |
/* Setting Defaults */ |
|
249 |
Tlns.Utils.SetDefaults(this, Tlns.Defaults.Timeline, _options); |
|
250 |
||
251 |
/* Setting container CSS */ |
|
75 | 252 |
this.$ = $('#' + this.container).html(Mustache.to_html(Tlns.Templates.Timeline, this)); |
253 |
|
|
254 |
this.$.find('.Tl-Main').css({ |
|
65 | 255 |
width : this.width + "px", |
256 |
height : this.height + "px" |
|
257 |
}); |
|
258 |
this.main_height = this.height - this.$.find('.Tl-TopBar').outerHeight(); |
|
259 |
this.$.find('.Tl-BottomPart').css("height", this.main_height + "px"); |
|
260 |
this.$.find('.Tl-MainPart').css("width", this.main_width + "px"); |
|
67 | 261 |
this.$.find('.Tl-Overlay-Container').css("left", (this.$.find('.Tl-BottomPart').outerWidth() - this.main_width) + "px"); |
70 | 262 |
this.$.find('canvas.Tl-Layer').attr({ |
67 | 263 |
width: this.main_width, |
264 |
height: this.main_height |
|
265 |
}); |
|
65 | 266 |
var _o = this.$.find('.Tl-MainPart').offset(); |
267 |
this.dragging_bounds = { |
|
268 |
left: _o.left, |
|
269 |
top: _o.top, |
|
270 |
right: _o.left + this.$.find('.Tl-MainPart').outerWidth(), |
|
271 |
bottom: _o.top + this.$.find('.Tl-MainPart').outerHeight(), |
|
272 |
}; |
|
273 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
274 |
var _this = this; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
275 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
276 |
this.throttledDrawGrid = _.throttle(function() { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
277 |
_this.drawGrid(); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
278 |
}, 150); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
279 |
|
75 | 280 |
this.throttledDrawList = _.throttle(function() { |
281 |
_this.drawList(); |
|
282 |
}, 150); |
|
283 |
|
|
65 | 284 |
this.setLevel(this.level); |
285 |
|
|
286 |
this.$.find('.Tl-TopBar-Timescales>div').click(function() { |
|
287 |
_this.setLevel($(this).attr("data-level")); |
|
288 |
}); |
|
289 |
|
|
290 |
this.$.find('.Tl-TopBar-SyncButton').click(function() { |
|
291 |
_this.sync_now = !_this.sync_now; |
|
292 |
_this.drawGrid(); |
|
293 |
}) |
|
294 |
|
|
295 |
this.$.find('.Tl-TopBar-PreviousButton').click(function() { |
|
296 |
_this.offsetTime(-_this.timescales[_this.level].span / 4); |
|
297 |
}); |
|
298 |
|
|
299 |
this.$.find('.Tl-TopBar-NextButton').click(function() { |
|
300 |
_this.offsetTime(_this.timescales[_this.level].span / 4); |
|
301 |
}); |
|
302 |
|
|
303 |
this.$.find('.Tl-MainPart').mousedown(function(_event) { |
|
304 |
_this.onMouseDown(_event); |
|
305 |
return false; |
|
306 |
}); |
|
307 |
|
|
308 |
this.$.find('.Tl-MainPart').mousemove(function(_event) { |
|
309 |
_this.onMouseMove(_event); |
|
310 |
return false; |
|
311 |
}); |
|
312 |
|
|
313 |
this.$.find('.Tl-MainPart').mouseup(function(_event) { |
|
314 |
_this.onMouseUp(_event); |
|
315 |
return false; |
|
316 |
}); |
|
317 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
318 |
this.$.find('.Tl-MainPart').mousewheel(function(_event, _delta) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
319 |
var _newLevel = Math.max(0,Math.min(_this.timescales.length-1, (_delta < 0 ? -1 : 1) + parseInt(_this.level))); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
320 |
if (_newLevel != _this.level) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
321 |
_this.hideTooltip(); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
322 |
var _deltaX = _event.pageX - _this.dragging_bounds.left, |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
323 |
_tAtMouse = _this.timeFromMouse(_event.pageX), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
324 |
_newScale = _this.main_width / (_this.timescales[_newLevel].span), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
325 |
_newStart = _tAtMouse - _deltaX / _newScale; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
326 |
_this.central_time = _newStart + _this.timescales[_newLevel].span / 2; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
327 |
_this.setLevel(_newLevel); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
328 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
329 |
return false; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
330 |
}); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
331 |
|
66 | 332 |
this.$.find('.Tl-Overlay-Box').mouseover(function(_event) { |
333 |
$(this).show(); |
|
334 |
}).mouseout(function(_event) { |
|
335 |
$(this).hide(); |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
336 |
}); |
65 | 337 |
|
71 | 338 |
this.$.find('.Tl-TopBar-AddButton').click(function() { |
339 |
$(this).toggleClass('active'); |
|
340 |
_this.$.find('.Tl-Adding').toggle(); |
|
341 |
}); |
|
342 |
|
|
343 |
this.$.find('.Tl-AddOccurrence').mousedown(function(_event) { |
|
344 |
var _el = $(this), |
|
345 |
_type = _el.attr("occurrence-type"), |
|
346 |
_d = _this.timeFromMouse(_event.pageX), |
|
347 |
_u = _this.universFromMouse(_event.pageY), |
|
348 |
_occ = _this.createOrUpdateOccurrence( |
|
349 |
_type, |
|
350 |
{ |
|
351 |
date: _d, |
|
352 |
titre: '<Nouvelle occurrence>', |
|
353 |
univers: _this.univers[_u].id, |
|
75 | 354 |
publie: true, |
355 |
statut: 'a_realiser' |
|
71 | 356 |
} |
357 |
); |
|
358 |
_occ.just_created = true; |
|
359 |
_occ.editing = true; |
|
360 |
_this.editing_occurrence = _occ; |
|
361 |
_this.dragging_type = "occurrence"; |
|
362 |
window.setTimeout(function () { |
|
363 |
_this.$.find('.Tl-TopBar-AddButton').removeClass('active'); |
|
364 |
_this.$.find('.Tl-Adding').hide(); |
|
365 |
}, 200); |
|
366 |
_this.throttledDrawGrid(); |
|
367 |
}).mouseup(function(_event) { |
|
368 |
_this.onMouseUp(_event); |
|
369 |
return false; |
|
370 |
}); |
|
371 |
|
|
65 | 372 |
/* Loading Univers */ |
373 |
$.getJSON(this.url_univers, function(_data) { |
|
374 |
_this.onUniversLoaded(_data); |
|
375 |
}); |
|
74 | 376 |
|
75 | 377 |
/* LIST */ |
74 | 378 |
|
75 | 379 |
$("li.Ls-Critere").click(function() { |
380 |
$(this).toggleClass("Ls-Active"); |
|
381 |
_this.throttledDrawList(); |
|
382 |
}); |
|
383 |
$(".Ls-Search").bind("keyup change click", function() { |
|
384 |
_this.throttledDrawList(); |
|
385 |
}); |
|
386 |
$(".Ls-From-Date, .Ls-To-Date").datepicker( |
|
387 |
{ |
|
388 |
dateFormat: "dd/mm/yy", |
|
389 |
dayNames: [ "Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi" ], |
|
390 |
dayNamesShort: [ "Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam" ], |
|
391 |
dayNamesMin: [ "D", "L", "Ma", "Me", "J", "V", "S" ], |
|
392 |
monthNames: [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" ], |
|
393 |
monthNamesShort: [ "Jan", "Fév", "Mar", "Avr", "Mai", "Jun", "Jul", "Aoû", "Sep", "Oct", "Nov", "Déc" ], |
|
394 |
showOtherMonths: true, |
|
395 |
selectOtherMonths: true |
|
396 |
} |
|
397 |
).change(function() { |
|
398 |
var _val = $(this).val(); |
|
399 |
if (_val) { |
|
400 |
$(this).val(Tlns.Utils.dateFieldProcess( _val ).text); |
|
401 |
} |
|
74 | 402 |
_this.drawList(); |
75 | 403 |
}).bind("keyup", function() { |
404 |
_this.throttledDrawList(); |
|
405 |
}); |
|
406 |
$(".Ls-From-Time, .Ls-To-Time").change(function() { |
|
407 |
var _val = $(this).val(); |
|
408 |
if (_val) { |
|
409 |
$(this).val(Tlns.Utils.timeFieldProcess( _val ).text); |
|
410 |
} |
|
411 |
_this.throttledDrawList(); |
|
412 |
}).bind("keyup", function() { |
|
413 |
_this.throttledDrawList(); |
|
74 | 414 |
}); |
415 |
|
|
65 | 416 |
} |
417 |
||
418 |
Tlns.Classes.Timeline.prototype.onMouseDown = function(_event) { |
|
419 |
this.mouse_down = true; |
|
420 |
this.is_dragging = false; |
|
421 |
this.start_pos = { |
|
422 |
x: _event.pageX, |
|
423 |
y: _event.pageY |
|
424 |
}; |
|
66 | 425 |
if (typeof this.dragging_type === "undefined") { |
67 | 426 |
this.time_at_start = this.central_time; |
66 | 427 |
this.dragging_type = "timeline"; |
65 | 428 |
} |
429 |
} |
|
430 |
||
431 |
Tlns.Classes.Timeline.prototype.onMouseUp = function(_event) { |
|
67 | 432 |
if (this.is_dragging) { |
433 |
switch (this.dragging_type) { |
|
434 |
case "occurrence": |
|
435 |
this.editing_occurrence.editing = false; |
|
71 | 436 |
this.editing_occurrence.just_created = false; |
67 | 437 |
this.throttledDrawGrid(); |
438 |
break; |
|
70 | 439 |
case "link": |
440 |
this.editing_occurrence.editing = false; |
|
441 |
this.throttledDrawGrid(); |
|
442 |
var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
443 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
444 |
break; |
|
67 | 445 |
} |
71 | 446 |
} else { |
447 |
if (this.dragging_type == "occurrence" && this.editing_occurrence.just_created) { |
|
448 |
this.deleteOccurrence(this.editing_occurrence.type, this.editing_occurrence.id); |
|
449 |
this.throttledDrawGrid(); |
|
450 |
} |
|
67 | 451 |
} |
65 | 452 |
this.mouse_down = false; |
453 |
this.is_dragging = false; |
|
66 | 454 |
this.dragging_type = undefined; |
65 | 455 |
} |
456 |
||
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
457 |
Tlns.Classes.Timeline.prototype.timeFromX = function(_x) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
458 |
return Math.max(this.start_time,Math.min(this.end_time, this.start_time + _x / this.current_scale)); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
459 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
460 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
461 |
Tlns.Classes.Timeline.prototype.timeFromMouse = function(_pageX) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
462 |
return this.timeFromX(_pageX - this.dragging_bounds.left); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
463 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
464 |
|
71 | 465 |
Tlns.Classes.Timeline.prototype.universFromY = function(_y) { |
466 |
return Math.max(0,Math.min(this.univers.length, Math.floor(_y / this.univers_height))) |
|
467 |
} |
|
468 |
||
469 |
Tlns.Classes.Timeline.prototype.universFromMouse = function(_pageY) { |
|
470 |
return this.universFromY(_pageY - this.dragging_bounds.top); |
|
471 |
} |
|
472 |
||
65 | 473 |
Tlns.Classes.Timeline.prototype.onMouseMove = function(_event) { |
474 |
if (this.mouse_down) { |
|
475 |
this.is_dragging = true; |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
476 |
this.hideTooltip(); |
69 | 477 |
switch (this.dragging_type) { |
478 |
case "occurrence": |
|
479 |
var _d = this.timeFromMouse(_event.pageX); |
|
480 |
this.editing_occurrence.date = _d; |
|
74 | 481 |
this.editing_occurrence.formatted_date = Tlns.Utils.dateFormat(this.editing_occurrence.date,this.tooltip_date_format); |
71 | 482 |
var _u = this.universFromMouse(_event.pageY); |
69 | 483 |
this.editing_occurrence.univers = this.univers[_u]; |
484 |
this.editing_occurrence.univers_id = this.univers[_u].id; |
|
485 |
this.throttledDrawGrid(); |
|
486 |
break; |
|
487 |
case "timeline": |
|
488 |
this.setTime(this.time_at_start + Math.floor(( this.start_pos.x - _event.pageX ) / this.current_scale)); |
|
489 |
break; |
|
70 | 490 |
case "link": |
491 |
var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
492 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
493 |
Tlns.Utils.drawArrow( |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
494 |
_ctx, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
495 |
'#800080', |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
496 |
this.editing_occurrence.x, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
497 |
this.editing_occurrence.y + Math.floor(this.univers_height / 2), |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
498 |
_event.pageX - this.dragging_bounds.left, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
499 |
_event.pageY - this.dragging_bounds.top |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
500 |
); |
70 | 501 |
break; |
65 | 502 |
} |
503 |
} |
|
504 |
} |
|
505 |
||
506 |
Tlns.Classes.Timeline.prototype.onUniversLoaded = function(_data) { |
|
507 |
this.univers = []; |
|
508 |
if(_data.length) { |
|
509 |
this.univers_height = Math.floor(this.main_height / _data.length); |
|
510 |
} |
|
511 |
for(var _i = 0; _i < _data.length; _i++) { |
|
512 |
this.univers.push(new Tlns.Classes.Univers(_data[_i], this, _i)); |
|
513 |
} |
|
74 | 514 |
|
515 |
$(".Ls-Univers").html(Mustache.to_html(Tlns.Templates.Univers_List, this)); |
|
516 |
var _this = this; |
|
75 | 517 |
$(".Ls-Univers li.Ls-Critere").click( function() { |
518 |
$(this).toggleClass("Ls-Active"); |
|
519 |
_this.throttledDrawList(); |
|
74 | 520 |
}); |
66 | 521 |
this.loadOccurrences(); |
65 | 522 |
} |
523 |
||
524 |
Tlns.Classes.Timeline.prototype.offsetTime = function(_timeOffset) { |
|
525 |
this.setTime(this.central_time + _timeOffset); |
|
526 |
} |
|
527 |
||
528 |
Tlns.Classes.Timeline.prototype.setTime = function(_centralTime) { |
|
529 |
this.sync_now = false; |
|
530 |
this.central_time = _centralTime; |
|
75 | 531 |
this.changeSpan(); |
65 | 532 |
} |
533 |
||
534 |
Tlns.Classes.Timeline.prototype.setLevel = function(_level) { |
|
535 |
if (_level >= 0 && _level < this.timescales.length) { |
|
536 |
this.$.find('.Tl-TopBar-Timescales>div').each(function() { |
|
537 |
var _el = $(this); |
|
538 |
if (_el.attr("data-level") == _level) { |
|
539 |
_el.addClass("active"); |
|
540 |
} else { |
|
541 |
_el.removeClass("active"); |
|
542 |
} |
|
543 |
}); |
|
544 |
this.level = _level; |
|
75 | 545 |
this.changeSpan(); |
65 | 546 |
} |
547 |
} |
|
548 |
||
75 | 549 |
Tlns.Classes.Timeline.prototype.changeSpan = function() { |
65 | 550 |
var _now = new Date().valueOf(); |
551 |
if (this.sync_now) { |
|
552 |
this.central_time = _now; |
|
553 |
this.$.find('.Tl-TopBar-SyncButton').addClass("active"); |
|
554 |
} else { |
|
555 |
this.$.find('.Tl-TopBar-SyncButton').removeClass("active"); |
|
556 |
} |
|
75 | 557 |
var _timescale = this.timescales[this.level]; |
558 |
this.current_scale = this.main_width / (_timescale.span); |
|
66 | 559 |
this.start_time = this.central_time - (_timescale.span / 2); |
560 |
this.end_time = this.central_time + (_timescale.span / 2); |
|
75 | 561 |
$(".Ls-From-Time").val(Tlns.Utils.dateFormat(this.start_time, '{{0hours}}:{{0minutes}}')); |
562 |
$(".Ls-From-Date").val(Tlns.Utils.dateFormat(this.start_time, '{{0dayOfMonth}}/{{0monthNumber}}/{{year}}')); |
|
563 |
$(".Ls-To-Time").val(Tlns.Utils.dateFormat(this.end_time, '{{0hours}}:{{0minutes}}')); |
|
564 |
$(".Ls-To-Date").val(Tlns.Utils.dateFormat(this.end_time, '{{0dayOfMonth}}/{{0monthNumber}}/{{year}}')); |
|
565 |
this.throttledDrawGrid(); |
|
566 |
this.throttledDrawList(); |
|
567 |
} |
|
568 |
||
569 |
Tlns.Classes.Timeline.prototype.drawGrid = function() { |
|
570 |
var _now = new Date().valueOf(), |
|
571 |
_timescale = this.timescales[this.level], |
|
572 |
_offset = new Date().getTimezoneOffset() * 60000, |
|
573 |
_grid_width = Math.floor(_timescale.grid_interval * this.current_scale), |
|
66 | 574 |
_roundstart = Math.floor((this.start_time - _offset) / _timescale.grid_interval) * _timescale.grid_interval + _offset, |
65 | 575 |
_html = ''; |
66 | 576 |
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)); |
577 |
for (var _t = _roundstart; _t < this.end_time; _t += _timescale.grid_interval) { |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
578 |
var _x = this.current_scale * (_t - this.start_time); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
579 |
if (_x > 0) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
580 |
_html += '<div class="Tl-Grid-Column" style="width:' + _grid_width + 'px; left: ' + _x + 'px">' |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
581 |
+ '<div class="Tl-Grid-Label">' + Tlns.Utils.dateFormat(_t, _timescale.grid_date_format) + '</div></div>'; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
582 |
} |
65 | 583 |
} |
66 | 584 |
if (this.start_time <= _now && this.end_time >= _now) { |
67 | 585 |
_html += '<div class="Tl-Grid-Now" style="left: ' + this.current_scale * (_now - this.start_time) + 'px"></div>' |
65 | 586 |
} |
587 |
this.$.find('.Tl-Grid').html(_html); |
|
66 | 588 |
this.drawOccurrences(); |
589 |
} |
|
590 |
||
591 |
Tlns.Classes.Timeline.prototype.loadOccurrences = function() { |
|
592 |
var _url = Mustache.to_html(this.url_occurrences, { |
|
593 |
from_time: this.start_time, |
|
594 |
to_time: this.end_time |
|
595 |
}), |
|
596 |
_this = this; |
|
597 |
$.getJSON(_url, function(_data) { |
|
598 |
_this.onOccurrencesLoaded(_data); |
|
599 |
}); |
|
600 |
} |
|
601 |
||
602 |
Tlns.Classes.Timeline.prototype.onOccurrencesLoaded = function(_data) { |
|
603 |
if (typeof _data.occurrencesNarratives === "object" && _data.occurrencesNarratives !== null) { |
|
604 |
for (var _i = 0; _i < _data.occurrencesNarratives.length; _i++) { |
|
605 |
this.createOrUpdateOccurrence("narrative", _data.occurrencesNarratives[_i]); |
|
606 |
} |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
607 |
for (var _i = 0; _i < _data.occurrencesPublication.length; _i++) { |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
608 |
this.createOrUpdateOccurrence("publication", _data.occurrencesPublication[_i]); |
66 | 609 |
} |
610 |
} |
|
611 |
if (!this.mouse_down) { |
|
612 |
this.drawOccurrences(); |
|
613 |
} |
|
75 | 614 |
this.throttledDrawList(); |
66 | 615 |
} |
616 |
||
72 | 617 |
Tlns.Classes.Timeline.prototype.deleteOccurrence = function(_id) { |
71 | 618 |
this.occurrences = _(this.occurrences).reject(function(_occ) { |
72 | 619 |
return occ.id == _id; |
71 | 620 |
}); |
621 |
} |
|
622 |
||
72 | 623 |
Tlns.Classes.Timeline.prototype.getOccurrence = function(_id) { |
66 | 624 |
return _(this.occurrences).find(function(_occ) { |
72 | 625 |
return _occ.id == _id; |
66 | 626 |
}); |
627 |
} |
|
628 |
||
629 |
Tlns.Classes.Timeline.prototype.createOrUpdateOccurrence = function(_type, _data) { |
|
72 | 630 |
var _id = _type + "_" + _data.id, |
631 |
_occurrence = this.getOccurrence(_id); |
|
66 | 632 |
if (typeof _occurrence === "undefined") { |
633 |
_occurrence = new Tlns.Classes.Occurrence(this); |
|
634 |
this.occurrences.push(_occurrence); |
|
635 |
} |
|
636 |
_occurrence.update(_type, _data); |
|
71 | 637 |
return _occurrence; |
66 | 638 |
} |
639 |
||
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
640 |
Tlns.Classes.Timeline.prototype.showTooltip = function(_x, _y, _html, _isUp) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
641 |
this.$.find('.Tl-Overlay-Box') |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
642 |
.removeClass(_isUp ? 'Tl-Overlay-Down' : 'Tl-Overlay-Up') |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
643 |
.addClass(_isUp ? 'Tl-Overlay-Up' : 'Tl-Overlay-Down') |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
644 |
.show() |
66 | 645 |
.css({ |
646 |
left: _x + "px", |
|
647 |
top: _y + "px" |
|
648 |
}); |
|
649 |
this.$.find('.Tl-Overlay-Main').html(_html); |
|
650 |
} |
|
651 |
||
652 |
Tlns.Classes.Timeline.prototype.hideTooltip = function() { |
|
653 |
this.$.find('.Tl-Overlay-Box').hide(); |
|
65 | 654 |
} |
655 |
||
656 |
Tlns.Classes.Timeline.prototype.drawOccurrences = function() { |
|
66 | 657 |
var _this = this, |
658 |
_visible = _(this.occurrences).filter(function(_occ) { |
|
659 |
return (_occ.date >= _this.start_time && _occ.date <= _this.end_time && _occ.published); |
|
660 |
}); |
|
661 |
_(_visible).each(function(_occ) { |
|
67 | 662 |
_occ.x = _this.current_scale * (_occ.date - _this.start_time); |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
663 |
_occ.y = _occ.univers.y; |
66 | 664 |
_occ.in_cluster = false; |
665 |
}); |
|
65 | 666 |
|
66 | 667 |
var _moved = true; |
668 |
while (_moved) { |
|
669 |
_moved = false; |
|
670 |
for (var _i = 0; _i < _visible.length; _i++) { |
|
671 |
for (var _j = 0; _j < _i; _j++) { |
|
672 |
if (_visible[_j].univers_id == _visible[_i].univers_id |
|
673 |
&& _visible[_j].x != _visible[_i].x |
|
674 |
&& Math.abs(_visible[_j].x-_visible[_i].x) < this.cluster_spacing |
|
675 |
) { |
|
676 |
_moved = true; |
|
677 |
_visible[_i].x = this.cluster_spacing * Math.round(_visible[_i].x / this.cluster_spacing); |
|
678 |
_visible[_j].x = this.cluster_spacing * Math.round(_visible[_j].x / this.cluster_spacing); |
|
679 |
} |
|
680 |
} |
|
681 |
} |
|
682 |
} |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
683 |
var _clusters = [], |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
684 |
_openCluster = false; |
66 | 685 |
for (var _i = 0; _i < _visible.length; _i++) { |
686 |
for (var _j = 0; _j < _i; _j++) { |
|
687 |
if (_visible[_j].univers_id == _visible[_i].univers_id && _visible[_j].x == _visible[_i].x) { |
|
688 |
_visible[_j].in_cluster = true; |
|
689 |
_visible[_i].in_cluster = true; |
|
690 |
var _x = _visible[_j].x, |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
691 |
_y = _visible[_j].y; |
66 | 692 |
_cluster = _(_clusters).find(function(_c) { return _c.x == _x && _c.y == _y }); |
693 |
if (typeof _cluster === "undefined") { |
|
694 |
_cluster = { x: _x, y: _y, occurrences: [] }; |
|
695 |
_clusters.push(_cluster); |
|
696 |
} |
|
697 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
698 |
return _o.type == _visible[_j].type && _o.id == _visible[_j].id; |
|
699 |
})) { |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
700 |
_cluster.occurrences.push(_visible[_j]); |
66 | 701 |
} |
702 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
703 |
return _o.type == _visible[_i].type && _o.id == _visible[_i].id; |
|
704 |
})) { |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
705 |
_cluster.occurrences.push(_visible[_i]); |
66 | 706 |
} |
707 |
} |
|
708 |
} |
|
709 |
} |
|
710 |
_(_clusters).each(function(_cluster) { |
|
70 | 711 |
_cluster.occurrences = _(_cluster.occurrences).sortBy(function(_o) { |
712 |
return _o.date; |
|
713 |
}); |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
714 |
_cluster.contents = _cluster.occurrences.map(function(_o) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
715 |
return _o.type + ":" + _o.id; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
716 |
}).join("|"); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
717 |
if (_cluster.contents == _this.open_cluster) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
718 |
_openCluster = _cluster; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
719 |
} |
66 | 720 |
}); |
721 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
722 |
|
67 | 723 |
var _links = []; |
724 |
|
|
725 |
_(_visible).each(function(_occurrence) { |
|
726 |
_(_occurrence.dependsOn).each(function(_dependance) { |
|
727 |
var _parent = _(_visible).find(function(_o) { |
|
72 | 728 |
return _o.id == _dependance; |
67 | 729 |
}); |
730 |
if (typeof _parent !== "undefined") { |
|
731 |
_links.push({ |
|
732 |
from_x: _occurrence.x, |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
733 |
from_y: _occurrence.y + Math.floor(_this.univers_height / 2), |
67 | 734 |
to_x: _parent.x, |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
735 |
to_y: _parent.y + Math.floor(_this.univers_height / 2) |
67 | 736 |
}); |
737 |
} |
|
738 |
}); |
|
739 |
}); |
|
740 |
|
|
741 |
var _ctx = this.$.find('.Tl-Canvas')[0].getContext('2d'); |
|
742 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
743 |
_(_links).each(function(_link) { |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
744 |
Tlns.Utils.drawArrow(_ctx, "#505050", _link.from_x,_link.from_y, _link.to_x,_link.to_y); |
70 | 745 |
}); |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
746 |
|
66 | 747 |
var _html = Mustache.to_html(Tlns.Templates.Occurrence, { |
748 |
occurrences:_(_visible).reject(function(_o) {return _o.in_cluster}), |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
749 |
clusters: _clusters, |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
750 |
open_cluster: _openCluster |
66 | 751 |
}); |
752 |
this.$.find('.Tl-Occurrences').html(_html); |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
753 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
754 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
755 |
if (_openCluster) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
756 |
var _w = this.$.find('.Tl-Occurrence').width(), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
757 |
_ww = _w * _openCluster.occurrences.length; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
758 |
this.$.find('.Tl-ClusterOverlay').css({ |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
759 |
"margin-left": - Math.floor(_ww/2) + "px", |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
760 |
width: _ww |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
761 |
}); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
762 |
_(_openCluster.occurrences).each(function(_o, _i) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
763 |
_o.y = _o.y - 20; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
764 |
_o.x = _o.x - (_ww / 2) + ((_i + .5) * _w); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
765 |
}); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
766 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
767 |
|
66 | 768 |
this.$.find('.Tl-Occurrence').mousedown(function() { |
71 | 769 |
var _el = $(this), |
770 |
_id = _el.attr("occurrence-id"); |
|
72 | 771 |
if (typeof _id !== "undefined") { |
772 |
_this.editing_occurrence = _this.getOccurrence(_id); |
|
75 | 773 |
if (typeof _this.dragging_type === "undefined" && typeof _this.editing_occurrence !== "undefined" /* && !_this.editing_occurrence.locked */ ) { |
71 | 774 |
_this.dragging_type = "occurrence"; |
775 |
_this.editing_occurrence.editing = true; |
|
776 |
} |
|
67 | 777 |
} |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
778 |
}).mouseover(function(_event) { |
66 | 779 |
var _el = $(this), |
71 | 780 |
_id = _el.attr("occurrence-id"); |
72 | 781 |
if (typeof _id !== "undefined") { |
782 |
var _occurrence = _this.getOccurrence(_id); |
|
75 | 783 |
// if (!_occurrence.locked) { |
784 |
_el.find('.Tl-Link').show(); |
|
785 |
// } |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
786 |
if (!_this.is_dragging) { |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
787 |
var _html = Mustache.to_html(Tlns.Templates.OccurrenceTooltip, _occurrence); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
788 |
_this.showTooltip(_occurrence.x, _occurrence.y, _html, (_event.pageY - _this.dragging_bounds.top) >= (.4 * _this.main_height) ); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
789 |
} |
70 | 790 |
} |
66 | 791 |
}).mouseout(function() { |
70 | 792 |
var _el = $(this), |
71 | 793 |
_id = _el.attr("occurrence-id"); |
72 | 794 |
if (typeof _id !== "undefined") { |
795 |
var _occurrence = _this.getOccurrence(_id); |
|
71 | 796 |
_this.hideTooltip(); |
797 |
if (!_occurrence.editing) { |
|
798 |
$(this).find('.Tl-Link').hide(); |
|
799 |
} |
|
70 | 800 |
} |
801 |
}).mouseup(function() { |
|
802 |
var _el = $(this); |
|
72 | 803 |
if (_this.dragging_type == "link") { |
70 | 804 |
_this.editing_occurrence.addDependency(_el.attr("occurrence-id")); |
805 |
} |
|
66 | 806 |
}); |
70 | 807 |
|
808 |
this.$.find('.Tl-Link').mousedown(function() { |
|
72 | 809 |
var _el = $(this).parent(), |
810 |
_id = _el.attr("occurrence-id"); |
|
811 |
_this.editing_occurrence = _this.getOccurrence(_id); |
|
75 | 812 |
if (typeof _this.editing_occurrence !== "undefined" /* && !_this.editing_occurrence.locked */ ) { |
70 | 813 |
_this.dragging_type = "link"; |
814 |
_this.editing_occurrence.editing = true; |
|
815 |
} |
|
816 |
}) |
|
817 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
818 |
this.$.find('.Tl-Cluster').click(function() { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
819 |
var _el = $(this), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
820 |
_contents = _el.attr("cluster-contents"); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
821 |
if (_this.open_cluster == _contents) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
822 |
_this.open_cluster = false; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
823 |
} else { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
824 |
_this.open_cluster = _contents; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
825 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
826 |
_this.throttledDrawGrid(); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
827 |
}) |
65 | 828 |
} |
829 |
||
74 | 830 |
Tlns.Classes.Timeline.prototype.drawList = function() { |
75 | 831 |
var _universfilter = $(".Ls-Univers li.Ls-Active").map(function(){return $(this).attr("data")}), |
832 |
_occtypefilter = $(".Ls-Occtypes li.Ls-Active").map(function(){return $(this).attr("data")}), |
|
833 |
_statusfilter = $(".Ls-Occstatuses li.Ls-Active").map(function(){return $(this).attr("data")}), |
|
834 |
_title = $(".Ls-Search").val() || "", |
|
835 |
_titleregexp = new RegExp( "(" + _title.replace(/(\W)/gm, "\\$1") + ")", "gim" ), |
|
836 |
_startdate = false, |
|
837 |
_enddate = false, |
|
838 |
_fromDate = $(".Ls-From-Date").val(), |
|
839 |
_toDate = $(".Ls-To-Date").val(); |
|
840 |
if (_fromDate) { |
|
841 |
var _date = Tlns.Utils.dateFieldProcess(_fromDate), |
|
842 |
_time = Tlns.Utils.timeFieldProcess($(".Ls-From-Time").val()); |
|
843 |
_startdate = new Date(_date.year, _date.month - 1, _date.date, _time.hours, _time.minutes); |
|
844 |
} |
|
845 |
if (_toDate) { |
|
846 |
var _date = Tlns.Utils.dateFieldProcess(_toDate), |
|
847 |
_time = Tlns.Utils.timeFieldProcess($(".Ls-To-Time").val()); |
|
848 |
_enddate = new Date(_date.year, _date.month - 1, _date.date, _time.hours, _time.minutes); |
|
849 |
} |
|
74 | 850 |
$(".Ls-Occurrences").html( |
851 |
Mustache.to_html( |
|
852 |
Tlns.Templates.Occurrence_List, |
|
853 |
{ |
|
854 |
occurrences: this.occurrences.filter(function(_occ) { |
|
855 |
var _titletest = (!!_occ.title.match(_titleregexp)), |
|
856 |
_keep = ( |
|
75 | 857 |
( !_title || _titletest ) |
74 | 858 |
&& (_(_occtypefilter).indexOf(_occ.type) !== -1) |
859 |
&& (_(_universfilter).indexOf(_occ.univers_id) !== -1) |
|
75 | 860 |
&& (_(_statusfilter).indexOf(_occ.status) !== -1) |
861 |
&& ( !_fromDate || _occ.date >= _startdate ) |
|
862 |
&& ( !_toDate || _occ.date <= _enddate ) |
|
74 | 863 |
); |
864 |
return _keep; |
|
865 |
}) |
|
866 |
} |
|
867 |
) |
|
868 |
); |
|
869 |
if (_title) { |
|
75 | 870 |
$(".Ls-Occurrence-Title").each(function() { |
74 | 871 |
$(this).html($(this).text().replace(_titleregexp, "<span style='background:yellow'>$1</span>")); |
872 |
}); |
|
873 |
} |
|
874 |
} |
|
875 |
||
66 | 876 |
Tlns.Classes.Timeline.prototype.getUnivers = function(_id) { |
877 |
return _(this.univers).find(function(_univ) { |
|
878 |
return (_univ.id == _id); |
|
879 |
}); |
|
880 |
} |
|
881 |
||
882 |
/* |
|
883 |
* Univers |
|
884 |
*/ |
|
885 |
||
65 | 886 |
Tlns.Classes.Univers = function(_data, _timeline, _index) { |
887 |
this.id = _data.id; |
|
888 |
this.index = _index; |
|
889 |
this.title = _data.nom; |
|
890 |
this.mainCharacter = _data.personnage; |
|
66 | 891 |
this.y = (_timeline.univers_height * _index); |
65 | 892 |
|
893 |
this.$label = $('<li>').css({ |
|
894 |
height : _timeline.univers_height + "px" |
|
895 |
}).html(Mustache.to_html(Tlns.Templates.Univers, this)) |
|
66 | 896 |
.addClass((_index % 2) ? 'Tl-Line-Odd' : 'Tl-Line-Even'); |
65 | 897 |
|
898 |
_timeline.$.find('.Tl-UniversLabels').append(this.$label); |
|
899 |
var _txt = _data.nom, |
|
900 |
_span = this.$label.find('span'); |
|
901 |
||
902 |
while (_span.outerWidth() > (_timeline.width - _timeline.main_width) && _txt) { |
|
903 |
_txt = _txt.substr(0, _txt.length - 1); |
|
904 |
_span.html(_txt + '…'); |
|
905 |
} |
|
906 |
} |
|
66 | 907 |
|
908 |
/* |
|
909 |
* Occurrence |
|
910 |
*/ |
|
911 |
||
912 |
Tlns.Classes.Occurrence = function(_timeline) { |
|
913 |
this.timeline = _timeline; |
|
914 |
} |
|
915 |
||
916 |
Tlns.Classes.Occurrence.prototype.update = function(_type, _data) { |
|
917 |
this.type = _type; |
|
72 | 918 |
this.original_id = _data.id || Tlns.Utils.guid(); |
919 |
this.id = _type + "_" + this.original_id; |
|
66 | 920 |
this.date = _data.date || _data.datePublication; |
74 | 921 |
this.formatted_date = Tlns.Utils.dateFormat(this.date,Tlns.Defaults.Timeline.tooltip_date_format); |
66 | 922 |
this.title = _data.titre || "<untitled>"; |
923 |
this.univers_id = _data.univers; |
|
924 |
this.univers = this.timeline.getUnivers(this.univers_id); |
|
925 |
this.status = _data.statut; |
|
75 | 926 |
this.translated_status = Tlns.Defaults.Timeline.statuses[this.status]; |
66 | 927 |
this.published = _data.publie || false; |
75 | 928 |
// this.locked = _data.verrouille || false; |
66 | 929 |
this.characters = _data.personnagesSecondaires || []; |
72 | 930 |
this.dependsOn = _(_data.dependDe || []).map(function(_id) { |
931 |
return "narrative_" + _id; |
|
932 |
}); |
|
70 | 933 |
this.description = _data.description || ""; |
934 |
} |
|
935 |
||
936 |
Tlns.Classes.Occurrence.prototype.addDependency = function(_id) { |
|
937 |
if (_(this.dependsOn).indexOf(_id) == -1) { |
|
938 |
this.dependsOn.push(_id); |
|
939 |
} |
|
66 | 940 |
} |
941 |
||
942 |
Tlns.Classes.Occurrence.prototype.toString = function() { |
|
943 |
return "Occurrence " + this.type + ': "' + this.title + '"'; |
|
944 |
} |