author | veltr |
Wed, 11 Jul 2012 18:02:57 +0200 | |
changeset 77 | 04b8157f077b |
parent 75 | ef3377d7a4f7 |
child 78 | 3fe54fb581f5 |
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, |
|
77 | 193 |
urls_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 |
||
77 | 210 |
Tlns.Templates.Timeline = '<ul class="Onglets"><li class="Onglet-Tl active">Frise chronologique</li><li class="Onglet-Ls">Liste des occurrences</li></ul><div class="Tl-Main"><div class="Tl-TopBar"><div class="Tl-TopBar-Button Tl-Border-Right"><div class="Tl-TopBar-AddButton"></div></div><div class="Tl-TopBar-Spacer Tl-Border-Right"></div>' |
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>' |
77 | 242 |
+ '<p class="Tl-Tooltip-Description">{{description}}</p>' |
243 |
// + '<p class="Tl-Tooltip-Characters">{{univers.mainCharacter}}{{#characters}}, {{.}}{{/characters}}</p>' |
|
65 | 244 |
|
245 |
/* Classes */ |
|
246 |
||
247 |
Tlns.Classes.Timeline = function(_options) { |
|
248 |
||
249 |
/* Setting Defaults */ |
|
250 |
Tlns.Utils.SetDefaults(this, Tlns.Defaults.Timeline, _options); |
|
251 |
||
252 |
/* Setting container CSS */ |
|
75 | 253 |
this.$ = $('#' + this.container).html(Mustache.to_html(Tlns.Templates.Timeline, this)); |
254 |
|
|
255 |
this.$.find('.Tl-Main').css({ |
|
65 | 256 |
width : this.width + "px", |
257 |
height : this.height + "px" |
|
258 |
}); |
|
259 |
this.main_height = this.height - this.$.find('.Tl-TopBar').outerHeight(); |
|
260 |
this.$.find('.Tl-BottomPart').css("height", this.main_height + "px"); |
|
261 |
this.$.find('.Tl-MainPart').css("width", this.main_width + "px"); |
|
67 | 262 |
this.$.find('.Tl-Overlay-Container').css("left", (this.$.find('.Tl-BottomPart').outerWidth() - this.main_width) + "px"); |
70 | 263 |
this.$.find('canvas.Tl-Layer').attr({ |
67 | 264 |
width: this.main_width, |
265 |
height: this.main_height |
|
266 |
}); |
|
65 | 267 |
var _o = this.$.find('.Tl-MainPart').offset(); |
268 |
this.dragging_bounds = { |
|
269 |
left: _o.left, |
|
270 |
top: _o.top, |
|
271 |
right: _o.left + this.$.find('.Tl-MainPart').outerWidth(), |
|
272 |
bottom: _o.top + this.$.find('.Tl-MainPart').outerHeight(), |
|
273 |
}; |
|
274 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
275 |
var _this = this; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
276 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
277 |
this.throttledDrawGrid = _.throttle(function() { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
278 |
_this.drawGrid(); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
279 |
}, 150); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
280 |
|
75 | 281 |
this.throttledDrawList = _.throttle(function() { |
282 |
_this.drawList(); |
|
283 |
}, 150); |
|
284 |
|
|
65 | 285 |
this.setLevel(this.level); |
286 |
|
|
287 |
this.$.find('.Tl-TopBar-Timescales>div').click(function() { |
|
288 |
_this.setLevel($(this).attr("data-level")); |
|
289 |
}); |
|
290 |
|
|
291 |
this.$.find('.Tl-TopBar-SyncButton').click(function() { |
|
292 |
_this.sync_now = !_this.sync_now; |
|
77 | 293 |
_this.changeSpan(); |
65 | 294 |
}) |
295 |
|
|
296 |
this.$.find('.Tl-TopBar-PreviousButton').click(function() { |
|
297 |
_this.offsetTime(-_this.timescales[_this.level].span / 4); |
|
298 |
}); |
|
299 |
|
|
300 |
this.$.find('.Tl-TopBar-NextButton').click(function() { |
|
301 |
_this.offsetTime(_this.timescales[_this.level].span / 4); |
|
302 |
}); |
|
303 |
|
|
304 |
this.$.find('.Tl-MainPart').mousedown(function(_event) { |
|
305 |
_this.onMouseDown(_event); |
|
306 |
return false; |
|
307 |
}); |
|
308 |
|
|
309 |
this.$.find('.Tl-MainPart').mousemove(function(_event) { |
|
310 |
_this.onMouseMove(_event); |
|
311 |
return false; |
|
312 |
}); |
|
313 |
|
|
314 |
this.$.find('.Tl-MainPart').mouseup(function(_event) { |
|
315 |
_this.onMouseUp(_event); |
|
316 |
return false; |
|
317 |
}); |
|
318 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
319 |
this.$.find('.Tl-MainPart').mousewheel(function(_event, _delta) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
320 |
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
|
321 |
if (_newLevel != _this.level) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
322 |
_this.hideTooltip(); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
323 |
var _deltaX = _event.pageX - _this.dragging_bounds.left, |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
324 |
_tAtMouse = _this.timeFromMouse(_event.pageX), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
325 |
_newScale = _this.main_width / (_this.timescales[_newLevel].span), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
326 |
_newStart = _tAtMouse - _deltaX / _newScale; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
327 |
_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
|
328 |
_this.setLevel(_newLevel); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
329 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
330 |
return false; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
331 |
}); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
332 |
|
66 | 333 |
this.$.find('.Tl-Overlay-Box').mouseover(function(_event) { |
334 |
$(this).show(); |
|
335 |
}).mouseout(function(_event) { |
|
336 |
$(this).hide(); |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
337 |
}); |
65 | 338 |
|
71 | 339 |
this.$.find('.Tl-TopBar-AddButton').click(function() { |
340 |
$(this).toggleClass('active'); |
|
341 |
_this.$.find('.Tl-Adding').toggle(); |
|
342 |
}); |
|
343 |
|
|
344 |
this.$.find('.Tl-AddOccurrence').mousedown(function(_event) { |
|
345 |
var _el = $(this), |
|
346 |
_type = _el.attr("occurrence-type"), |
|
347 |
_d = _this.timeFromMouse(_event.pageX), |
|
348 |
_u = _this.universFromMouse(_event.pageY), |
|
349 |
_occ = _this.createOrUpdateOccurrence( |
|
350 |
_type, |
|
351 |
{ |
|
77 | 352 |
datePublication: Math.floor(_d / 1000), |
71 | 353 |
titre: '<Nouvelle occurrence>', |
77 | 354 |
idUnivers: _this.univers[_u].id, |
75 | 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 |
|
77 | 379 |
this.$.find("li.Ls-Critere").click(function() { |
75 | 380 |
$(this).toggleClass("Ls-Active"); |
381 |
_this.throttledDrawList(); |
|
382 |
}); |
|
77 | 383 |
this.$.find(".Ls-Search").bind("keyup change click", function() { |
75 | 384 |
_this.throttledDrawList(); |
385 |
}); |
|
77 | 386 |
this.$.find(".Ls-From-Date, .Ls-To-Date").datepicker( |
75 | 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 |
}); |
|
77 | 406 |
this.$.find(".Ls-From-Time, .Ls-To-Time").change(function() { |
75 | 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 |
|
|
77 | 416 |
this.$.find(".Onglet-Tl").click(function() { |
417 |
_this.$.find(".Tl-Main").show(); |
|
418 |
_this.$.find(".Ls-Main").hide(); |
|
419 |
_this.$.find(".Onglet-Ls").removeClass("active"); |
|
420 |
_this.$.find(".Onglet-Tl").addClass("active"); |
|
421 |
}); |
|
422 |
|
|
423 |
this.$.find(".Onglet-Ls").click(function() { |
|
424 |
_this.$.find(".Ls-Main").show(); |
|
425 |
_this.$.find(".Tl-Main").hide(); |
|
426 |
_this.$.find(".Onglet-Tl").removeClass("active"); |
|
427 |
_this.$.find(".Onglet-Ls").addClass("active"); |
|
428 |
}); |
|
65 | 429 |
} |
430 |
||
431 |
Tlns.Classes.Timeline.prototype.onMouseDown = function(_event) { |
|
432 |
this.mouse_down = true; |
|
433 |
this.is_dragging = false; |
|
434 |
this.start_pos = { |
|
435 |
x: _event.pageX, |
|
436 |
y: _event.pageY |
|
437 |
}; |
|
66 | 438 |
if (typeof this.dragging_type === "undefined") { |
67 | 439 |
this.time_at_start = this.central_time; |
66 | 440 |
this.dragging_type = "timeline"; |
65 | 441 |
} |
442 |
} |
|
443 |
||
444 |
Tlns.Classes.Timeline.prototype.onMouseUp = function(_event) { |
|
67 | 445 |
if (this.is_dragging) { |
446 |
switch (this.dragging_type) { |
|
447 |
case "occurrence": |
|
448 |
this.editing_occurrence.editing = false; |
|
71 | 449 |
this.editing_occurrence.just_created = false; |
67 | 450 |
this.throttledDrawGrid(); |
451 |
break; |
|
70 | 452 |
case "link": |
453 |
this.editing_occurrence.editing = false; |
|
454 |
this.throttledDrawGrid(); |
|
455 |
var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
456 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
457 |
break; |
|
67 | 458 |
} |
71 | 459 |
} else { |
460 |
if (this.dragging_type == "occurrence" && this.editing_occurrence.just_created) { |
|
461 |
this.deleteOccurrence(this.editing_occurrence.type, this.editing_occurrence.id); |
|
462 |
this.throttledDrawGrid(); |
|
463 |
} |
|
67 | 464 |
} |
65 | 465 |
this.mouse_down = false; |
466 |
this.is_dragging = false; |
|
66 | 467 |
this.dragging_type = undefined; |
65 | 468 |
} |
469 |
||
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
470 |
Tlns.Classes.Timeline.prototype.timeFromX = function(_x) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
471 |
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
|
472 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
473 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
474 |
Tlns.Classes.Timeline.prototype.timeFromMouse = function(_pageX) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
475 |
return this.timeFromX(_pageX - this.dragging_bounds.left); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
476 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
477 |
|
71 | 478 |
Tlns.Classes.Timeline.prototype.universFromY = function(_y) { |
479 |
return Math.max(0,Math.min(this.univers.length, Math.floor(_y / this.univers_height))) |
|
480 |
} |
|
481 |
||
482 |
Tlns.Classes.Timeline.prototype.universFromMouse = function(_pageY) { |
|
483 |
return this.universFromY(_pageY - this.dragging_bounds.top); |
|
484 |
} |
|
485 |
||
65 | 486 |
Tlns.Classes.Timeline.prototype.onMouseMove = function(_event) { |
487 |
if (this.mouse_down) { |
|
488 |
this.is_dragging = true; |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
489 |
this.hideTooltip(); |
69 | 490 |
switch (this.dragging_type) { |
491 |
case "occurrence": |
|
492 |
var _d = this.timeFromMouse(_event.pageX); |
|
493 |
this.editing_occurrence.date = _d; |
|
74 | 494 |
this.editing_occurrence.formatted_date = Tlns.Utils.dateFormat(this.editing_occurrence.date,this.tooltip_date_format); |
71 | 495 |
var _u = this.universFromMouse(_event.pageY); |
69 | 496 |
this.editing_occurrence.univers = this.univers[_u]; |
497 |
this.editing_occurrence.univers_id = this.univers[_u].id; |
|
498 |
this.throttledDrawGrid(); |
|
499 |
break; |
|
500 |
case "timeline": |
|
501 |
this.setTime(this.time_at_start + Math.floor(( this.start_pos.x - _event.pageX ) / this.current_scale)); |
|
502 |
break; |
|
70 | 503 |
case "link": |
504 |
var _ctx = this.$.find('.Tl-Linking-Canvas')[0].getContext('2d'); |
|
505 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
506 |
Tlns.Utils.drawArrow( |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
507 |
_ctx, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
508 |
'#800080', |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
509 |
this.editing_occurrence.x, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
510 |
this.editing_occurrence.y + Math.floor(this.univers_height / 2), |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
511 |
_event.pageX - this.dragging_bounds.left, |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
512 |
_event.pageY - this.dragging_bounds.top |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
513 |
); |
70 | 514 |
break; |
65 | 515 |
} |
516 |
} |
|
517 |
} |
|
518 |
||
519 |
Tlns.Classes.Timeline.prototype.onUniversLoaded = function(_data) { |
|
520 |
this.univers = []; |
|
521 |
if(_data.length) { |
|
522 |
this.univers_height = Math.floor(this.main_height / _data.length); |
|
523 |
} |
|
524 |
for(var _i = 0; _i < _data.length; _i++) { |
|
525 |
this.univers.push(new Tlns.Classes.Univers(_data[_i], this, _i)); |
|
526 |
} |
|
74 | 527 |
|
77 | 528 |
this.$.find(".Ls-Univers").html(Mustache.to_html(Tlns.Templates.Univers_List, this)); |
74 | 529 |
var _this = this; |
77 | 530 |
this.$.find(".Ls-Univers li.Ls-Critere").click( function() { |
75 | 531 |
$(this).toggleClass("Ls-Active"); |
532 |
_this.throttledDrawList(); |
|
74 | 533 |
}); |
66 | 534 |
this.loadOccurrences(); |
65 | 535 |
} |
536 |
||
537 |
Tlns.Classes.Timeline.prototype.offsetTime = function(_timeOffset) { |
|
538 |
this.setTime(this.central_time + _timeOffset); |
|
539 |
} |
|
540 |
||
541 |
Tlns.Classes.Timeline.prototype.setTime = function(_centralTime) { |
|
542 |
this.sync_now = false; |
|
543 |
this.central_time = _centralTime; |
|
75 | 544 |
this.changeSpan(); |
65 | 545 |
} |
546 |
||
547 |
Tlns.Classes.Timeline.prototype.setLevel = function(_level) { |
|
548 |
if (_level >= 0 && _level < this.timescales.length) { |
|
549 |
this.$.find('.Tl-TopBar-Timescales>div').each(function() { |
|
550 |
var _el = $(this); |
|
551 |
if (_el.attr("data-level") == _level) { |
|
552 |
_el.addClass("active"); |
|
553 |
} else { |
|
554 |
_el.removeClass("active"); |
|
555 |
} |
|
556 |
}); |
|
557 |
this.level = _level; |
|
75 | 558 |
this.changeSpan(); |
65 | 559 |
} |
560 |
} |
|
561 |
||
75 | 562 |
Tlns.Classes.Timeline.prototype.changeSpan = function() { |
65 | 563 |
var _now = new Date().valueOf(); |
564 |
if (this.sync_now) { |
|
565 |
this.central_time = _now; |
|
566 |
} |
|
75 | 567 |
var _timescale = this.timescales[this.level]; |
568 |
this.current_scale = this.main_width / (_timescale.span); |
|
66 | 569 |
this.start_time = this.central_time - (_timescale.span / 2); |
570 |
this.end_time = this.central_time + (_timescale.span / 2); |
|
77 | 571 |
this.$.find(".Ls-From-Time").val(Tlns.Utils.dateFormat(this.start_time, '{{0hours}}:{{0minutes}}')); |
572 |
this.$.find(".Ls-From-Date").val(Tlns.Utils.dateFormat(this.start_time, '{{0dayOfMonth}}/{{0monthNumber}}/{{year}}')); |
|
573 |
this.$.find(".Ls-To-Time").val(Tlns.Utils.dateFormat(this.end_time, '{{0hours}}:{{0minutes}}')); |
|
574 |
this.$.find(".Ls-To-Date").val(Tlns.Utils.dateFormat(this.end_time, '{{0dayOfMonth}}/{{0monthNumber}}/{{year}}')); |
|
75 | 575 |
this.throttledDrawGrid(); |
576 |
this.throttledDrawList(); |
|
577 |
} |
|
578 |
||
579 |
Tlns.Classes.Timeline.prototype.drawGrid = function() { |
|
77 | 580 |
if (this.sync_now) { |
581 |
this.$.find('.Tl-TopBar-SyncButton').addClass("active"); |
|
582 |
} else { |
|
583 |
this.$.find('.Tl-TopBar-SyncButton').removeClass("active"); |
|
584 |
} |
|
75 | 585 |
var _now = new Date().valueOf(), |
586 |
_timescale = this.timescales[this.level], |
|
587 |
_offset = new Date().getTimezoneOffset() * 60000, |
|
588 |
_grid_width = Math.floor(_timescale.grid_interval * this.current_scale), |
|
66 | 589 |
_roundstart = Math.floor((this.start_time - _offset) / _timescale.grid_interval) * _timescale.grid_interval + _offset, |
65 | 590 |
_html = ''; |
66 | 591 |
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)); |
592 |
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
|
593 |
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
|
594 |
if (_x > 0) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
595 |
_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
|
596 |
+ '<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
|
597 |
} |
65 | 598 |
} |
66 | 599 |
if (this.start_time <= _now && this.end_time >= _now) { |
67 | 600 |
_html += '<div class="Tl-Grid-Now" style="left: ' + this.current_scale * (_now - this.start_time) + 'px"></div>' |
65 | 601 |
} |
602 |
this.$.find('.Tl-Grid').html(_html); |
|
66 | 603 |
this.drawOccurrences(); |
604 |
} |
|
605 |
||
606 |
Tlns.Classes.Timeline.prototype.loadOccurrences = function() { |
|
77 | 607 |
var _this = this; |
608 |
_(this.urls_occurrences).each(function(_url_occ) { |
|
609 |
$.getJSON(_url_occ.url, function(_data) { |
|
610 |
_this.onOccurrencesLoaded(_data, _url_occ.type); |
|
611 |
}); |
|
66 | 612 |
}); |
77 | 613 |
|
66 | 614 |
} |
615 |
||
77 | 616 |
Tlns.Classes.Timeline.prototype.onOccurrencesLoaded = function(_data, _type) { |
617 |
for (var _i = 0; _i < _data.length; _i++) { |
|
618 |
this.createOrUpdateOccurrence(_type, _data[_i]); |
|
66 | 619 |
} |
620 |
if (!this.mouse_down) { |
|
621 |
this.drawOccurrences(); |
|
622 |
} |
|
75 | 623 |
this.throttledDrawList(); |
66 | 624 |
} |
625 |
||
72 | 626 |
Tlns.Classes.Timeline.prototype.deleteOccurrence = function(_id) { |
71 | 627 |
this.occurrences = _(this.occurrences).reject(function(_occ) { |
72 | 628 |
return occ.id == _id; |
71 | 629 |
}); |
630 |
} |
|
631 |
||
72 | 632 |
Tlns.Classes.Timeline.prototype.getOccurrence = function(_id) { |
66 | 633 |
return _(this.occurrences).find(function(_occ) { |
72 | 634 |
return _occ.id == _id; |
66 | 635 |
}); |
636 |
} |
|
637 |
||
638 |
Tlns.Classes.Timeline.prototype.createOrUpdateOccurrence = function(_type, _data) { |
|
72 | 639 |
var _id = _type + "_" + _data.id, |
640 |
_occurrence = this.getOccurrence(_id); |
|
66 | 641 |
if (typeof _occurrence === "undefined") { |
642 |
_occurrence = new Tlns.Classes.Occurrence(this); |
|
643 |
this.occurrences.push(_occurrence); |
|
644 |
} |
|
645 |
_occurrence.update(_type, _data); |
|
71 | 646 |
return _occurrence; |
66 | 647 |
} |
648 |
||
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
649 |
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
|
650 |
this.$.find('.Tl-Overlay-Box') |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
651 |
.removeClass(_isUp ? 'Tl-Overlay-Down' : 'Tl-Overlay-Up') |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
652 |
.addClass(_isUp ? 'Tl-Overlay-Up' : 'Tl-Overlay-Down') |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
653 |
.show() |
66 | 654 |
.css({ |
655 |
left: _x + "px", |
|
656 |
top: _y + "px" |
|
657 |
}); |
|
658 |
this.$.find('.Tl-Overlay-Main').html(_html); |
|
659 |
} |
|
660 |
||
661 |
Tlns.Classes.Timeline.prototype.hideTooltip = function() { |
|
662 |
this.$.find('.Tl-Overlay-Box').hide(); |
|
65 | 663 |
} |
664 |
||
665 |
Tlns.Classes.Timeline.prototype.drawOccurrences = function() { |
|
66 | 666 |
var _this = this, |
667 |
_visible = _(this.occurrences).filter(function(_occ) { |
|
77 | 668 |
return (_occ.date >= _this.start_time && _occ.date <= _this.end_time && _occ.status); |
66 | 669 |
}); |
670 |
_(_visible).each(function(_occ) { |
|
67 | 671 |
_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
|
672 |
_occ.y = _occ.univers.y; |
66 | 673 |
_occ.in_cluster = false; |
674 |
}); |
|
65 | 675 |
|
66 | 676 |
var _moved = true; |
677 |
while (_moved) { |
|
678 |
_moved = false; |
|
679 |
for (var _i = 0; _i < _visible.length; _i++) { |
|
680 |
for (var _j = 0; _j < _i; _j++) { |
|
681 |
if (_visible[_j].univers_id == _visible[_i].univers_id |
|
682 |
&& _visible[_j].x != _visible[_i].x |
|
683 |
&& Math.abs(_visible[_j].x-_visible[_i].x) < this.cluster_spacing |
|
684 |
) { |
|
685 |
_moved = true; |
|
686 |
_visible[_i].x = this.cluster_spacing * Math.round(_visible[_i].x / this.cluster_spacing); |
|
687 |
_visible[_j].x = this.cluster_spacing * Math.round(_visible[_j].x / this.cluster_spacing); |
|
688 |
} |
|
689 |
} |
|
690 |
} |
|
691 |
} |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
692 |
var _clusters = [], |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
693 |
_openCluster = false; |
66 | 694 |
for (var _i = 0; _i < _visible.length; _i++) { |
695 |
for (var _j = 0; _j < _i; _j++) { |
|
696 |
if (_visible[_j].univers_id == _visible[_i].univers_id && _visible[_j].x == _visible[_i].x) { |
|
697 |
_visible[_j].in_cluster = true; |
|
698 |
_visible[_i].in_cluster = true; |
|
699 |
var _x = _visible[_j].x, |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
700 |
_y = _visible[_j].y; |
66 | 701 |
_cluster = _(_clusters).find(function(_c) { return _c.x == _x && _c.y == _y }); |
702 |
if (typeof _cluster === "undefined") { |
|
703 |
_cluster = { x: _x, y: _y, occurrences: [] }; |
|
704 |
_clusters.push(_cluster); |
|
705 |
} |
|
706 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
707 |
return _o.type == _visible[_j].type && _o.id == _visible[_j].id; |
|
708 |
})) { |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
709 |
_cluster.occurrences.push(_visible[_j]); |
66 | 710 |
} |
711 |
if ("undefined" === typeof _(_cluster.occurrences).find(function(_o) { |
|
712 |
return _o.type == _visible[_i].type && _o.id == _visible[_i].id; |
|
713 |
})) { |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
714 |
_cluster.occurrences.push(_visible[_i]); |
66 | 715 |
} |
716 |
} |
|
717 |
} |
|
718 |
} |
|
719 |
_(_clusters).each(function(_cluster) { |
|
70 | 720 |
_cluster.occurrences = _(_cluster.occurrences).sortBy(function(_o) { |
721 |
return _o.date; |
|
722 |
}); |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
723 |
_cluster.contents = _cluster.occurrences.map(function(_o) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
724 |
return _o.type + ":" + _o.id; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
725 |
}).join("|"); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
726 |
if (_cluster.contents == _this.open_cluster) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
727 |
_openCluster = _cluster; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
728 |
} |
66 | 729 |
}); |
730 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
731 |
|
67 | 732 |
var _links = []; |
733 |
|
|
734 |
_(_visible).each(function(_occurrence) { |
|
735 |
_(_occurrence.dependsOn).each(function(_dependance) { |
|
736 |
var _parent = _(_visible).find(function(_o) { |
|
72 | 737 |
return _o.id == _dependance; |
67 | 738 |
}); |
739 |
if (typeof _parent !== "undefined") { |
|
740 |
_links.push({ |
|
741 |
from_x: _occurrence.x, |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
742 |
from_y: _occurrence.y + Math.floor(_this.univers_height / 2), |
67 | 743 |
to_x: _parent.x, |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
744 |
to_y: _parent.y + Math.floor(_this.univers_height / 2) |
67 | 745 |
}); |
746 |
} |
|
747 |
}); |
|
748 |
}); |
|
749 |
|
|
750 |
var _ctx = this.$.find('.Tl-Canvas')[0].getContext('2d'); |
|
751 |
_ctx.clearRect(0,0,this.main_width, this.main_height); |
|
752 |
_(_links).each(function(_link) { |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
753 |
Tlns.Utils.drawArrow(_ctx, "#505050", _link.from_x,_link.from_y, _link.to_x,_link.to_y); |
70 | 754 |
}); |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
755 |
|
66 | 756 |
var _html = Mustache.to_html(Tlns.Templates.Occurrence, { |
757 |
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
|
758 |
clusters: _clusters, |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
759 |
open_cluster: _openCluster |
66 | 760 |
}); |
761 |
this.$.find('.Tl-Occurrences').html(_html); |
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
762 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
763 |
|
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
764 |
if (_openCluster) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
765 |
var _w = this.$.find('.Tl-Occurrence').width(), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
766 |
_ww = _w * _openCluster.occurrences.length; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
767 |
this.$.find('.Tl-ClusterOverlay').css({ |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
768 |
"margin-left": - Math.floor(_ww/2) + "px", |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
769 |
width: _ww |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
770 |
}); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
771 |
_(_openCluster.occurrences).each(function(_o, _i) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
772 |
_o.y = _o.y - 20; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
773 |
_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
|
774 |
}); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
775 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
776 |
|
66 | 777 |
this.$.find('.Tl-Occurrence').mousedown(function() { |
71 | 778 |
var _el = $(this), |
779 |
_id = _el.attr("occurrence-id"); |
|
72 | 780 |
if (typeof _id !== "undefined") { |
781 |
_this.editing_occurrence = _this.getOccurrence(_id); |
|
75 | 782 |
if (typeof _this.dragging_type === "undefined" && typeof _this.editing_occurrence !== "undefined" /* && !_this.editing_occurrence.locked */ ) { |
71 | 783 |
_this.dragging_type = "occurrence"; |
784 |
_this.editing_occurrence.editing = true; |
|
785 |
} |
|
67 | 786 |
} |
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
787 |
}).mouseover(function(_event) { |
66 | 788 |
var _el = $(this), |
71 | 789 |
_id = _el.attr("occurrence-id"); |
72 | 790 |
if (typeof _id !== "undefined") { |
791 |
var _occurrence = _this.getOccurrence(_id); |
|
75 | 792 |
// if (!_occurrence.locked) { |
793 |
_el.find('.Tl-Link').show(); |
|
794 |
// } |
|
73
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
795 |
if (!_this.is_dragging) { |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
796 |
var _html = Mustache.to_html(Tlns.Templates.OccurrenceTooltip, _occurrence); |
642ef9139fad
Replaced "Production" by "Publication". Added beautiful arrows
veltr
parents:
72
diff
changeset
|
797 |
_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
|
798 |
} |
70 | 799 |
} |
66 | 800 |
}).mouseout(function() { |
70 | 801 |
var _el = $(this), |
71 | 802 |
_id = _el.attr("occurrence-id"); |
72 | 803 |
if (typeof _id !== "undefined") { |
804 |
var _occurrence = _this.getOccurrence(_id); |
|
71 | 805 |
_this.hideTooltip(); |
806 |
if (!_occurrence.editing) { |
|
807 |
$(this).find('.Tl-Link').hide(); |
|
808 |
} |
|
70 | 809 |
} |
810 |
}).mouseup(function() { |
|
811 |
var _el = $(this); |
|
72 | 812 |
if (_this.dragging_type == "link") { |
70 | 813 |
_this.editing_occurrence.addDependency(_el.attr("occurrence-id")); |
814 |
} |
|
66 | 815 |
}); |
70 | 816 |
|
817 |
this.$.find('.Tl-Link').mousedown(function() { |
|
72 | 818 |
var _el = $(this).parent(), |
819 |
_id = _el.attr("occurrence-id"); |
|
820 |
_this.editing_occurrence = _this.getOccurrence(_id); |
|
75 | 821 |
if (typeof _this.editing_occurrence !== "undefined" /* && !_this.editing_occurrence.locked */ ) { |
70 | 822 |
_this.dragging_type = "link"; |
823 |
_this.editing_occurrence.editing = true; |
|
824 |
} |
|
825 |
}) |
|
826 |
|
|
68
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
827 |
this.$.find('.Tl-Cluster').click(function() { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
828 |
var _el = $(this), |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
829 |
_contents = _el.attr("cluster-contents"); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
830 |
if (_this.open_cluster == _contents) { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
831 |
_this.open_cluster = false; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
832 |
} else { |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
833 |
_this.open_cluster = _contents; |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
834 |
} |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
835 |
_this.throttledDrawGrid(); |
4def147b1604
Added a visualization of the contents of clusters + mousewheel support
veltr
parents:
67
diff
changeset
|
836 |
}) |
65 | 837 |
} |
838 |
||
74 | 839 |
Tlns.Classes.Timeline.prototype.drawList = function() { |
77 | 840 |
var _universfilter = this.$.find(".Ls-Univers li.Ls-Active").map(function(){return $(this).attr("data")}), |
841 |
_occtypefilter = this.$.find(".Ls-Occtypes li.Ls-Active").map(function(){return $(this).attr("data")}), |
|
842 |
_statusfilter = this.$.find(".Ls-Occstatuses li.Ls-Active").map(function(){return $(this).attr("data")}), |
|
843 |
_title = this.$.find(".Ls-Search").val() || "", |
|
75 | 844 |
_titleregexp = new RegExp( "(" + _title.replace(/(\W)/gm, "\\$1") + ")", "gim" ), |
845 |
_startdate = false, |
|
846 |
_enddate = false, |
|
77 | 847 |
_fromDate = this.$.find(".Ls-From-Date").val(), |
848 |
_toDate = this.$.find(".Ls-To-Date").val(); |
|
75 | 849 |
if (_fromDate) { |
850 |
var _date = Tlns.Utils.dateFieldProcess(_fromDate), |
|
77 | 851 |
_time = Tlns.Utils.timeFieldProcess(this.$.find(".Ls-From-Time").val()); |
75 | 852 |
_startdate = new Date(_date.year, _date.month - 1, _date.date, _time.hours, _time.minutes); |
853 |
} |
|
854 |
if (_toDate) { |
|
855 |
var _date = Tlns.Utils.dateFieldProcess(_toDate), |
|
77 | 856 |
_time = Tlns.Utils.timeFieldProcess(this.$.find(".Ls-To-Time").val()); |
75 | 857 |
_enddate = new Date(_date.year, _date.month - 1, _date.date, _time.hours, _time.minutes); |
858 |
} |
|
77 | 859 |
this.$.find(".Ls-Occurrences").html( |
74 | 860 |
Mustache.to_html( |
861 |
Tlns.Templates.Occurrence_List, |
|
862 |
{ |
|
863 |
occurrences: this.occurrences.filter(function(_occ) { |
|
864 |
var _titletest = (!!_occ.title.match(_titleregexp)), |
|
865 |
_keep = ( |
|
75 | 866 |
( !_title || _titletest ) |
74 | 867 |
&& (_(_occtypefilter).indexOf(_occ.type) !== -1) |
868 |
&& (_(_universfilter).indexOf(_occ.univers_id) !== -1) |
|
75 | 869 |
&& (_(_statusfilter).indexOf(_occ.status) !== -1) |
870 |
&& ( !_fromDate || _occ.date >= _startdate ) |
|
871 |
&& ( !_toDate || _occ.date <= _enddate ) |
|
74 | 872 |
); |
873 |
return _keep; |
|
874 |
}) |
|
875 |
} |
|
876 |
) |
|
877 |
); |
|
878 |
if (_title) { |
|
77 | 879 |
this.$.find(".Ls-Occurrence-Title").each(function() { |
74 | 880 |
$(this).html($(this).text().replace(_titleregexp, "<span style='background:yellow'>$1</span>")); |
881 |
}); |
|
882 |
} |
|
883 |
} |
|
884 |
||
66 | 885 |
Tlns.Classes.Timeline.prototype.getUnivers = function(_id) { |
886 |
return _(this.univers).find(function(_univ) { |
|
887 |
return (_univ.id == _id); |
|
888 |
}); |
|
889 |
} |
|
890 |
||
891 |
/* |
|
892 |
* Univers |
|
893 |
*/ |
|
894 |
||
65 | 895 |
Tlns.Classes.Univers = function(_data, _timeline, _index) { |
77 | 896 |
this.id = _data.idUnivers; |
65 | 897 |
this.index = _index; |
77 | 898 |
this.title = _data.nomUnivers; |
899 |
// this.mainCharacter = _data.personnage; |
|
66 | 900 |
this.y = (_timeline.univers_height * _index); |
65 | 901 |
|
902 |
this.$label = $('<li>').css({ |
|
903 |
height : _timeline.univers_height + "px" |
|
904 |
}).html(Mustache.to_html(Tlns.Templates.Univers, this)) |
|
66 | 905 |
.addClass((_index % 2) ? 'Tl-Line-Odd' : 'Tl-Line-Even'); |
65 | 906 |
|
907 |
_timeline.$.find('.Tl-UniversLabels').append(this.$label); |
|
77 | 908 |
var _txt = this.title, |
65 | 909 |
_span = this.$label.find('span'); |
910 |
while (_span.outerWidth() > (_timeline.width - _timeline.main_width) && _txt) { |
|
911 |
_txt = _txt.substr(0, _txt.length - 1); |
|
912 |
_span.html(_txt + '…'); |
|
913 |
} |
|
914 |
} |
|
66 | 915 |
|
916 |
/* |
|
917 |
* Occurrence |
|
918 |
*/ |
|
919 |
||
920 |
Tlns.Classes.Occurrence = function(_timeline) { |
|
921 |
this.timeline = _timeline; |
|
922 |
} |
|
923 |
||
924 |
Tlns.Classes.Occurrence.prototype.update = function(_type, _data) { |
|
925 |
this.type = _type; |
|
77 | 926 |
this.original_id = _data.idOccurrencePublication || _data.id || Tlns.Utils.guid(); |
72 | 927 |
this.id = _type + "_" + this.original_id; |
77 | 928 |
this.date = 1000 * (_data.datePublication || _data.date); |
74 | 929 |
this.formatted_date = Tlns.Utils.dateFormat(this.date,Tlns.Defaults.Timeline.tooltip_date_format); |
66 | 930 |
this.title = _data.titre || "<untitled>"; |
77 | 931 |
this.univers_id = _data.idUnivers; |
66 | 932 |
this.univers = this.timeline.getUnivers(this.univers_id); |
77 | 933 |
switch(_data.statut) { |
934 |
case "Validée": |
|
935 |
case "valide": |
|
936 |
this.status = "valide" |
|
937 |
break; |
|
938 |
case "A valider": |
|
939 |
case "a_valider": |
|
940 |
this.status = "a_valider"; |
|
941 |
break; |
|
942 |
case "A réaliser": |
|
943 |
case "a_realiser": |
|
944 |
this.status = "a_realiser"; |
|
945 |
break; |
|
946 |
default: |
|
947 |
this.status = false; |
|
948 |
} |
|
75 | 949 |
this.translated_status = Tlns.Defaults.Timeline.statuses[this.status]; |
77 | 950 |
// this.published = (_data.publication && _data.publication == "En ligne"); |
75 | 951 |
// this.locked = _data.verrouille || false; |
77 | 952 |
// this.characters = _data.personnagesSecondaires || []; |
953 |
this.dependsOn = []; |
|
954 |
if (_data.dependanceNarrative) { |
|
955 |
for (var _i = 0; _i < _data.dependanceNarrative.length; _i++) { |
|
956 |
this.dependsOn.push("narrative_" + _data.dependanceNarrative[_i]) |
|
957 |
} |
|
958 |
} |
|
959 |
if (_data.dependancePublication) { |
|
960 |
for (var _i = 0; _i < _data.dependancePublication.length; _i++) { |
|
961 |
this.dependsOn.push("publication_" + _data.dependancePublication[_i]) |
|
962 |
} |
|
963 |
} |
|
964 |
var _tmp = $('<p>').html(_data.accroche || ""); |
|
965 |
this.description = _tmp.text().trim().replace(/(^.{60,80})[\s].+$/m,'$1…'); |
|
70 | 966 |
} |
967 |
||
968 |
Tlns.Classes.Occurrence.prototype.addDependency = function(_id) { |
|
969 |
if (_(this.dependsOn).indexOf(_id) == -1) { |
|
970 |
this.dependsOn.push(_id); |
|
971 |
} |
|
66 | 972 |
} |
973 |
||
974 |
Tlns.Classes.Occurrence.prototype.toString = function() { |
|
975 |
return "Occurrence " + this.type + ': "' + this.title + '"'; |
|
976 |
} |