|
109
|
1 |
/** |
|
|
2 |
* @author raph |
|
|
3 |
*/ |
|
|
4 |
|
|
|
5 |
var gomNs = { |
|
|
6 |
minYear: -5000, |
|
|
7 |
maxYear: 2010, |
|
|
8 |
tlPixels: 960, |
|
|
9 |
tlGamma: 6, |
|
|
10 |
heatGamma: 4, |
|
115
|
11 |
displayedDates: [-5000,0,500,1000,1200,1400,1600,1700,1750,1800,1850,1900,1950,2010], |
|
109
|
12 |
} |
|
|
13 |
|
|
|
14 |
function yearToPx(year) { |
|
|
15 |
return gomNs.tlPixels * Math.pow( ( year - gomNs.minYear ) / ( gomNs.maxYear - gomNs.minYear ), gomNs.tlGamma ); |
|
|
16 |
} |
|
|
17 |
|
|
|
18 |
function pxToYear(px) { |
|
|
19 |
return gomNs.minYear + ( gomNs.maxYear - gomNs.minYear ) * Math.pow( px / gomNs.tlPixels, 1 / gomNs.tlGamma ); |
|
|
20 |
} |
|
|
21 |
|
|
|
22 |
|
|
|
23 |
function tagInfo(_taglabel) { |
|
|
24 |
var _urlParam = { "label": _taglabel }; |
|
|
25 |
$.getJSON("taginfo.php", |
|
|
26 |
_urlParam, |
|
|
27 |
function(data) { |
|
115
|
28 |
$("#tagsearch").val(data.requested_label).removeClass("grise"); |
|
|
29 |
$("#tagcount").html(data.content_count |
|
|
30 |
+ ' contenu' + (data.content_count > 1 ? 's' : '') + ' pour ce tag'); |
|
|
31 |
var _html = ''; |
|
109
|
32 |
if (data.wikipedia_url) { |
|
|
33 |
_html += '<h3><a href="' |
|
|
34 |
+ data.wikipedia_url |
|
|
35 |
+ '" target="_blank">Wikipédia: ' |
|
|
36 |
+ decodeURI(data.wikipedia_url.match(/[^\/]+$/)[0]).replace("_"," ") |
|
|
37 |
+ '</a></h3>' |
|
|
38 |
} |
|
|
39 |
if (data.thumbnail) { |
|
|
40 |
_html += '<img id="img_wikipedia" src="' |
|
|
41 |
+ data.thumbnail |
|
|
42 |
+ '" />'; |
|
|
43 |
} |
|
|
44 |
if (data.abstract) { |
|
|
45 |
_html += '<p>' + _(data.abstract).escape() + '</p>'; |
|
|
46 |
} |
|
|
47 |
if (data.links) { |
|
|
48 |
var _lC = data.requested_label.toLowerCase(); |
|
|
49 |
var _t = data.links.map(function(d) { |
|
|
50 |
return (d.subject.toLowerCase() == _lC) ? d.object : d.subject; |
|
|
51 |
}); |
|
|
52 |
_t.sort(); |
|
|
53 |
_t = _(_t).uniq(true); |
|
|
54 |
_html += '<h3>Tags liés (dbpedia)</h3><ul class="content-tags">' |
|
|
55 |
+ _t.map(function(d) { |
|
|
56 |
return '<li class="content-tag-item"><a href="#" onclick="tagInfo($(this).text()); return false;">' |
|
|
57 |
+ d |
|
|
58 |
+ '</a></li>'; |
|
|
59 |
}).join('') |
|
|
60 |
+ '</ul>'; |
|
|
61 |
} |
|
115
|
62 |
$("#tagdata").html(_html); |
|
109
|
63 |
}); |
|
115
|
64 |
filterTag(_taglabel); |
|
110
|
65 |
$("#showlist").removeClass("actif"); |
|
109
|
66 |
} |
|
|
67 |
|
|
|
68 |
function filterTag(_tagLabel) { |
|
115
|
69 |
var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
|
|
70 |
if (_curView.type == 'filter') { |
|
|
71 |
_curView.tag.push(_tagLabel); |
|
|
72 |
updateFilters(); |
|
|
73 |
debouncedSaveChanges(); |
|
|
74 |
} |
|
109
|
75 |
} |
|
|
76 |
|
|
|
77 |
function removeFilter(_index) { |
|
115
|
78 |
var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
|
|
79 |
if (_curView.type == 'filter') { |
|
|
80 |
_curView.tag.splice(_index,1); |
|
|
81 |
updateFilters(); |
|
|
82 |
debouncedSaveChanges(); |
|
|
83 |
} |
|
109
|
84 |
} |
|
|
85 |
|
|
|
86 |
function getUpdates() { |
|
115
|
87 |
var _params = {}, |
|
|
88 |
_curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
|
|
89 |
if (_curView.type == 'filter') { |
|
|
90 |
if (_curView.period && !(_curView.period[0] == gomNs.minYear && _curView.period[1] == gomNs.maxYear)) { |
|
|
91 |
_params.period = _curView.period.join(','); |
|
|
92 |
} |
|
|
93 |
if (_curView.tag.length) { |
|
|
94 |
_params.label = _curView.tag.join(','); |
|
|
95 |
} |
|
|
96 |
$.getJSON("filter.php", _params, updateDisplay); |
|
109
|
97 |
} |
|
|
98 |
} |
|
|
99 |
|
|
115
|
100 |
var debouncedGetUpdates = _.debounce(getUpdates, 300); |
|
109
|
101 |
|
|
110
|
102 |
function updatePeriod(_n, _val) { |
|
115
|
103 |
var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
|
|
104 |
if (_curView.type == 'filter') { |
|
|
105 |
var _int = parseInt(_val); |
|
|
106 |
if (_int != NaN) { |
|
|
107 |
if ((_n == 1 && _val >= _curView.period[0]) || (_n == 0 && _val <= _curView.period[1])) { |
|
|
108 |
_curView.period[_n] = _int; |
|
|
109 |
} |
|
|
110 |
updateFilters(); |
|
|
111 |
debouncedSaveChanges(); |
|
|
112 |
} |
|
110
|
113 |
} |
|
|
114 |
} |
|
|
115 |
|
|
|
116 |
function changeSpan(_this) { |
|
115
|
117 |
var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
|
|
118 |
if (_curView.type == 'filter') { |
|
|
119 |
if (!$(_this).children().length) { |
|
|
120 |
var _el = document.createElement('input'), |
|
|
121 |
_n = _this.id.split('_')[1]; |
|
|
122 |
_el.value = _curView.period[_n]; |
|
|
123 |
_el.style.width = $(_this).width() + 'px'; |
|
|
124 |
$(_el).focusout(function() { |
|
110
|
125 |
updatePeriod(_n, this.value); |
|
115
|
126 |
}).keypress(function(e) { |
|
|
127 |
if (e.keyCode == 13) { |
|
|
128 |
updatePeriod(_n, this.value); |
|
|
129 |
} |
|
|
130 |
}); |
|
|
131 |
$(_this).html(_el); |
|
|
132 |
_el.focus(); |
|
|
133 |
_el.select(); |
|
|
134 |
} |
|
110
|
135 |
} |
|
|
136 |
} |
|
|
137 |
|
|
109
|
138 |
function updateFilters() { |
|
115
|
139 |
var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
|
|
140 |
if (_curView.type != 'filter') { |
|
|
141 |
return; |
|
|
142 |
} |
|
109
|
143 |
var _htmFilters = '', |
|
115
|
144 |
_fl = _curView.tag.length; |
|
|
145 |
if (!_curView.period && !_fl) { |
|
109
|
146 |
_htmFilters = '<li class="nofilter">Aucun filtre</li>'; |
|
|
147 |
} |
|
115
|
148 |
if (_curView.period) { |
|
|
149 |
_htmFilters += '<li class="filperiod"><span class="spyr" id="sp_0" onclick="changeSpan(this);">' |
|
|
150 |
+ _curView.period[0] |
|
|
151 |
+ '</span> à <span class="spyr" id="sp_1" onclick="changeSpan(this);">' |
|
|
152 |
+ _curView.period[1] |
|
|
153 |
+ '</span></li>'; |
|
|
154 |
$("#handle_0").css({ |
|
|
155 |
"left" : yearToPx(_curView.period[0])+"px", |
|
|
156 |
}).attr("year", _curView.period[0]) |
|
|
157 |
.find(".handleinner") |
|
|
158 |
.css({ |
|
|
159 |
"margin-left" : "-20px" |
|
|
160 |
}); |
|
|
161 |
$("#handle_1").css({ |
|
|
162 |
"left" : yearToPx(_curView.period[1])+"px", |
|
|
163 |
}).attr("year", _curView.period[1]) |
|
|
164 |
.find(".handleinner") |
|
|
165 |
.css({ |
|
|
166 |
"margin-left" : "0" |
|
|
167 |
}); |
|
|
168 |
} |
|
109
|
169 |
if (_fl) { |
|
115
|
170 |
_htmFilters += _(_curView.tag).map(function(_t, _i) { |
|
109
|
171 |
return '<li class="filtag">' |
|
|
172 |
+ _t |
|
|
173 |
+ '<a href="#" class="remfil" onclick="removeFilter(' |
|
|
174 |
+ _i |
|
|
175 |
+ '); return false;">[x]</a></li>'; |
|
|
176 |
}).join(""); |
|
|
177 |
} |
|
|
178 |
$("#filters").html(_htmFilters); |
|
|
179 |
debouncedGetUpdates(); |
|
|
180 |
} |
|
|
181 |
|
|
|
182 |
function displayContents(contentdata) { |
|
|
183 |
if (contentdata && contentdata.length) { |
|
|
184 |
var _htmlCl = '<ul id="contentlist">' |
|
|
185 |
+ contentdata.map(function(_d) { |
|
115
|
186 |
var _html = '<li class="content-item"><h3>' |
|
109
|
187 |
+ _d.title |
|
|
188 |
+ '</h3><h4><a href="' |
|
|
189 |
+ _d.url |
|
|
190 |
+ '" target="_blank">' |
|
|
191 |
+ _d.url |
|
|
192 |
+ '</a></h4><p>' |
|
|
193 |
+ _d.description |
|
|
194 |
+ '</p><ul class="content-tags">' |
|
|
195 |
+ _d.tags.map(function(_t) { |
|
|
196 |
return '<li class="content-tag-item"><a href="#" onclick="tagInfo($(this).text()); return false;"' |
|
|
197 |
+ (_t.match ? ' class="tagmatch"' : '') |
|
|
198 |
+ '>' |
|
|
199 |
+ _t.label |
|
|
200 |
+ '</a></li>'; |
|
|
201 |
}).join('') |
|
|
202 |
+ '</ul><h4>Annotations</h4><div class="content-annotation" contentid="' |
|
|
203 |
+ _d.id |
|
117
|
204 |
+ '">' |
|
|
205 |
+ ( gomNs.sessiondata.annotations[_d.id] && gomNs.sessiondata.annotations[_d.id].texte |
|
|
206 |
? '<ul><li>' |
|
|
207 |
+ _.escape(gomNs.sessiondata.annotations[_d.id].texte).replace(/\n/gm,"</li><li>") |
|
|
208 |
+ '</li>' |
|
|
209 |
: ( gomNs.write_allowed ? '<ul><li>Annoter ce contenu...</li></ul>' : '' ) ) |
|
|
210 |
+ '</div>'; |
|
115
|
211 |
if (gomNs.write_allowed) { |
|
|
212 |
_(gomNs.sessiondata.views).each(function(_view, _k) { |
|
|
213 |
if (_view.type == 'list') { |
|
|
214 |
_html += '<p><a href="#" class="addremlist" contentid="' |
|
|
215 |
+ _d.id |
|
|
216 |
+ '" viewid="' |
|
|
217 |
+ _k |
|
|
218 |
+ '">' |
|
|
219 |
+ ( _view.list.indexOf(_d.id) == -1 ? 'Ajouter à' : 'Retirer de' ) |
|
|
220 |
+ ' "' |
|
|
221 |
+ _.escape(_view.name) |
|
|
222 |
+ '"</a></p>' |
|
|
223 |
} |
|
|
224 |
}); |
|
|
225 |
} |
|
|
226 |
_html += '</li>'; |
|
|
227 |
return _html; |
|
109
|
228 |
}).join('') |
|
|
229 |
+ '</ul>'; |
|
|
230 |
$("#contents").html(_htmlCl).scrollTop(0); |
|
110
|
231 |
$("a.addremlist").click(function() { |
|
|
232 |
var _id = $(this).attr("contentid"), |
|
115
|
233 |
_vid = |
|
|
234 |
_view = gomNs.sessiondata.views[$(this).attr("viewid")], |
|
|
235 |
_io = _view.list.indexOf(_id); |
|
110
|
236 |
if ( _io == -1) { |
|
115
|
237 |
_view.list.push(_id); |
|
|
238 |
$(this).html('Retirer de "' + _.escape(_view.name) + '"' ); |
|
110
|
239 |
} else { |
|
115
|
240 |
_view.list.splice(_io, 1); |
|
|
241 |
$(this).html('Ajouter à "' + _.escape(_view.name) + '"'); |
|
110
|
242 |
} |
|
|
243 |
if (gomNs.sessiondata.view == 1) { |
|
|
244 |
showView(); |
|
|
245 |
} |
|
|
246 |
debouncedSaveChanges(); |
|
|
247 |
return false; |
|
|
248 |
}) |
|
115
|
249 |
if (gomNs.write_allowed) { |
|
|
250 |
$("div.content-annotation").click(function() { |
|
|
251 |
if (this.children[0].tagName == 'UL') { |
|
|
252 |
var _el = document.createElement('textarea'), |
|
|
253 |
_id = $(this).attr("contentid"); |
|
|
254 |
_el.innerHTML = (gomNs.sessiondata.annotations[_id] && gomNs.sessiondata.annotations[_id].texte) ? gomNs.sessiondata.annotations[_id].texte : ''; |
|
|
255 |
$(_el).focusout(function() { |
|
|
256 |
var _id = this.parentNode.attributes.contentid.nodeValue; |
|
|
257 |
if (!gomNs.sessiondata.annotations[_id]) { |
|
|
258 |
gomNs.sessiondata.annotations[_id] = {}; |
|
|
259 |
} |
|
117
|
260 |
gomNs.sessiondata.annotations[_id].texte = this.value; |
|
|
261 |
this.parentNode.innerHTML = '<ul><li>' + (this.value.length ? _.escape(gomNs.sessiondata.annotations[_id].texte).replace(/\n/gm,"</li><li>") : 'Annoter ce contenu...' ) + '</ul>'; |
|
115
|
262 |
debouncedSaveChanges(); |
|
|
263 |
}); |
|
|
264 |
$(this).html(_el); |
|
|
265 |
_el.focus(); |
|
|
266 |
_el.select(); |
|
109
|
267 |
} |
|
|
268 |
}); |
|
|
269 |
} |
|
|
270 |
} |
|
|
271 |
else { |
|
|
272 |
$("#contents").html(""); |
|
|
273 |
} |
|
|
274 |
} |
|
|
275 |
|
|
|
276 |
function updateDisplay(data) { |
|
|
277 |
if (gomNs.dhmPaper) { |
|
|
278 |
gomNs.dhmPaper.clear(); |
|
|
279 |
} else { |
|
|
280 |
gomNs.dhmPaper = new Raphael("dateheat"); |
|
|
281 |
} |
|
|
282 |
var _s = (data.count>1?'s':''); |
|
|
283 |
$("#contentcount").html('<b>'+data.count+'</b> notice'+_s); |
|
|
284 |
var _sl = data.sparkline.length; |
|
|
285 |
if (_sl) { |
|
|
286 |
var _maxheat = _(data.sparkline).max(function(_d) { return parseInt(_d.score); }).score, |
|
|
287 |
_exp = 1 / gomNs.heatGamma, |
|
|
288 |
_scale = Math.pow(_maxheat, - _exp); |
|
|
289 |
_(data.sparkline).each(function(_d, _i) { |
|
|
290 |
var _nxt = (_i == _sl - 1) ? gomNs.maxYear + 1 : data.sparkline[_i + 1].year, |
|
|
291 |
_x1 = yearToPx(_d.year), |
|
|
292 |
_x2 = yearToPx(_nxt), |
|
|
293 |
_heat = _scale * Math.pow(_d.score, _exp); |
|
|
294 |
gomNs.dhmPaper.rect(_x1, 0, _x2 - _x1, 20).attr({ |
|
|
295 |
"fill" : "rgb(255, 128, 128)", |
|
|
296 |
"opacity" : _heat, |
|
|
297 |
"stroke" : "none" |
|
|
298 |
}) |
|
|
299 |
}); |
|
|
300 |
} |
|
115
|
301 |
if (gomNs.sessiondata.view == 0) { |
|
|
302 |
var _h0 = $("#handle_0").position().left, |
|
|
303 |
_h1 = $("#handle_1").position().left; |
|
|
304 |
gomNs.dhmPaper.rect(Math.min(_h0, _h1) - 1, 0, Math.abs(_h0 - _h1) + 2, 20).attr({ |
|
|
305 |
"stroke" : "rgb(128,0,0)", |
|
|
306 |
"stroke-width" : "3" |
|
|
307 |
}); |
|
|
308 |
} |
|
109
|
309 |
if (data.tags.length) { |
|
|
310 |
var _scores = _(data.tags).map(function(_d) { return parseInt(_d.score)}), |
|
|
311 |
_maxTag = _(_scores).max(), |
|
|
312 |
_minTag = Math.min(_(_scores).min(), _maxTag - 1), |
|
|
313 |
_scale = 20 / Math.sqrt(_maxTag - _minTag), |
|
|
314 |
_htmlTc = '<ul id="tclist">' |
|
|
315 |
+ _(data.tags).map(function(_d) { |
|
|
316 |
return '<li style="font-size:' |
|
|
317 |
+ parseInt(10 + _scale * Math.sqrt(_d.score - _minTag)) |
|
|
318 |
+ 'px;"><a href="#" onclick="tagInfo($(this).text()); return false;"' |
|
|
319 |
+ (_d.match ? ' class="tagmatch"' : '') |
|
|
320 |
+ '>' |
|
|
321 |
+ _d.label |
|
|
322 |
+ '</a></li>'; |
|
|
323 |
}).join('') |
|
|
324 |
+ '</ul>'; |
|
|
325 |
$("#tagcloud").html(_htmlTc); |
|
|
326 |
} |
|
|
327 |
else { |
|
|
328 |
$("#tagcloud").html("<h4>Pas de mots-clés trouvés</h4>"); |
|
|
329 |
} |
|
|
330 |
displayContents(data.contents); |
|
110
|
331 |
if (gomNs.countries && data.countries) { |
|
|
332 |
var _max = Math.max(1, _(data.countries).max(function(_c) { return _c.score}).score); |
|
|
333 |
_(data.countries).each(function(_c) { |
|
|
334 |
var _cc = gomNs.countries[_c.isocode]; |
|
|
335 |
if (_cc) { |
|
115
|
336 |
var _gb = parseInt(255 * (1 - _c.score / _max )); |
|
110
|
337 |
_(_cc.gPolygons).each(function(_p) { |
|
|
338 |
_p.setOptions({ |
|
115
|
339 |
"fillColor" : ( _c.score ? "rgb(255," + _gb + "," + _gb + ")" : "#7070a0" ), |
|
|
340 |
}); |
|
|
341 |
}); |
|
|
342 |
} |
|
|
343 |
}); |
|
|
344 |
} |
|
|
345 |
if (data.disciplines) { |
|
|
346 |
var _disc = data.disciplines.filter(function(_d) { |
|
|
347 |
return +_d.score > 0; |
|
|
348 |
}), |
|
|
349 |
_echelle = d3.scale |
|
|
350 |
.linear() |
|
|
351 |
.range([0, 120]) |
|
|
352 |
.domain([0, d3.max(_disc, function(_d) { return +_d.score })]), |
|
|
353 |
_barres = gomNs.disChart.selectAll("g.discbarre").data(_disc); |
|
|
354 |
|
|
|
355 |
var _newels = _barres.enter() |
|
|
356 |
.append("svg:g") |
|
|
357 |
.attr("class","discbarre"); |
|
|
358 |
|
|
|
359 |
_newels.append("svg:rect") |
|
|
360 |
.attr("stroke","none") |
|
|
361 |
.attr("fill","rgb(255,128,128)") |
|
|
362 |
.attr("x","0"). |
|
|
363 |
attr("y","0") |
|
|
364 |
.attr("height","25"); |
|
|
365 |
_newels.append("svg:text") |
|
|
366 |
.attr("font-size","12px") |
|
|
367 |
.attr("x","5") |
|
|
368 |
.attr("y","16"); |
|
|
369 |
|
|
|
370 |
_barres.exit().remove(); |
|
|
371 |
|
|
|
372 |
_barres.on("click", function(_d) { |
|
|
373 |
tagInfo(_d.label); |
|
|
374 |
}).on("mouseover", function() { |
|
|
375 |
d3.select(this).select("rect").attr("fill","rgb(128,128,255)"); |
|
|
376 |
}).on("mouseout", function() { |
|
|
377 |
d3.select(this).select("rect").attr("fill","rgb(255,128,128)"); |
|
|
378 |
}).attr("transform",function(_d,_k) { |
|
|
379 |
return "translate(" + ( 30 + 40 * _k ) + ",120) rotate(-90)"; |
|
|
380 |
}); |
|
|
381 |
_barres.select("text").text(function(_d) { |
|
|
382 |
return _d.label; |
|
|
383 |
}); |
|
|
384 |
_barres.select("rect").attr("width", function(_d) { |
|
|
385 |
return _echelle(_d.score); |
|
110
|
386 |
}); |
|
|
387 |
} |
|
109
|
388 |
} |
|
|
389 |
|
|
|
390 |
function saveChanges() { |
|
|
391 |
if (gomNs.sessionid && gomNs.sessionkey) { |
|
|
392 |
$.getJSON("sessioninfo.php", { |
|
|
393 |
"sessionid" : gomNs.sessionid, |
|
|
394 |
"sessionkey" : gomNs.sessionkey, |
|
|
395 |
"data" : JSON.stringify(gomNs.sessiondata), |
|
|
396 |
}); |
|
|
397 |
} |
|
|
398 |
} |
|
|
399 |
|
|
115
|
400 |
var debouncedSaveChanges = _.debounce(saveChanges, 3000); |
|
109
|
401 |
|
|
110
|
402 |
function changeView(nview) { |
|
115
|
403 |
var _curView = gomNs.sessiondata.views[nview]; |
|
|
404 |
if (_curView.type == 'list' && (!_curView.list || !_curView.list.length)) { |
|
|
405 |
alert("La liste de contenus est vide ! Ajoutez des contenus pour afficher la liste !"); |
|
|
406 |
} else { |
|
|
407 |
gomNs.sessiondata.view = nview; |
|
|
408 |
debouncedSaveChanges(); |
|
|
409 |
showView(); |
|
|
410 |
} |
|
110
|
411 |
} |
|
|
412 |
|
|
|
413 |
function showView() { |
|
115
|
414 |
$(".lienvue").removeClass("actif"); |
|
|
415 |
$("#view_" + gomNs.sessiondata.view).addClass("actif"); |
|
|
416 |
var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
|
|
417 |
$("#titrevue").val(_curView.name); |
|
|
418 |
$("#bloc_gestvue h2").html('Gérer la vue "' + _.escape(_curView.name) + '"'); |
|
|
419 |
$("div.bloc").show(); |
|
|
420 |
$("#widgetlist input").prop("checked",true); |
|
|
421 |
_(_curView.hiddenWidgets).each(function(_w) { |
|
|
422 |
$("#chbx_" + _w).prop("checked",false); |
|
|
423 |
$("#" + _w).hide(); |
|
117
|
424 |
}); |
|
|
425 |
$("#notes").html( _curView.notes |
|
|
426 |
? '<ul><li>' + _.escape(_curView.notes).replace(/\n/gm,"</li><li>") + '</li></ul>' |
|
|
427 |
: ( gomNs.write_allowed ? '<ul><li>Annoter cette vue...</li></ul>' : '' ) ); |
|
115
|
428 |
switch(_curView.type) { |
|
|
429 |
case 'list': |
|
|
430 |
$("#bandefiltre, .handle").hide(); |
|
|
431 |
$.getJSON("filter.php", { |
|
|
432 |
contentlist: _curView.list.join(',') |
|
|
433 |
}, updateDisplay); |
|
|
434 |
break; |
|
|
435 |
case 'filter': |
|
|
436 |
$("#bandefiltre, .handle").show(); |
|
110
|
437 |
updateFilters(); |
|
115
|
438 |
break; |
|
110
|
439 |
} |
|
|
440 |
} |
|
|
441 |
|
|
117
|
442 |
function displayViewList() { |
|
|
443 |
$("#ongletsvues").html(gomNs.sessiondata.views.map(function(_v, _k) { |
|
|
444 |
return '<li class="lienvue" id="view_' |
|
|
445 |
+ _k |
|
|
446 |
+ '" onclick="changeView(' |
|
|
447 |
+ _k |
|
|
448 |
+ '); return false;"><a href="#">' |
|
|
449 |
+ _.escape(_v.name) |
|
|
450 |
+ '</a></li>'; |
|
|
451 |
}).join("")) |
|
|
452 |
} |
|
|
453 |
|
|
109
|
454 |
function getInitialView() { |
|
|
455 |
var _urlParam = {}; |
|
|
456 |
if (document.location.hash) { |
|
|
457 |
var _tab = document.location.hash.replace("#","").split("-"); |
|
|
458 |
_urlParam.sessionid = _tab[0]; |
|
|
459 |
if (_tab.length > 1) { |
|
|
460 |
_urlParam.sessionkey = _tab[1]; |
|
|
461 |
} |
|
|
462 |
} |
|
|
463 |
$.getJSON("sessioninfo.php", _urlParam, function(data) { |
|
|
464 |
gomNs.sessionid = data.sessionid; |
|
|
465 |
if (data.sessionkey) { |
|
|
466 |
gomNs.sessionkey = data.sessionkey; |
|
|
467 |
} |
|
|
468 |
gomNs.write_allowed = data.write_allowed; |
|
|
469 |
if (data.write_allowed) { |
|
|
470 |
$("#partagerw").show(); |
|
|
471 |
} else { |
|
|
472 |
$("#partagerw").hide(); |
|
|
473 |
} |
|
|
474 |
var _baseUrl = document.location.href.split("#")[0]; |
|
|
475 |
$("#rourl").html(_baseUrl + "#" + data.sessionid ); |
|
|
476 |
gomNs.hash = "#" + data.sessionid + (data.sessionkey ? '-' + data.sessionkey : ''); |
|
|
477 |
document.location.hash = gomNs.hash; |
|
|
478 |
$("#rwurl").html(_baseUrl + gomNs.hash); |
|
|
479 |
gomNs.sessiondata = JSON.parse(data.data); |
|
|
480 |
if (!gomNs.sessiondata.title) { |
|
|
481 |
gomNs.sessiondata.title = 'Nouvelle session'; |
|
|
482 |
} |
|
115
|
483 |
if (!gomNs.sessiondata.views) { |
|
|
484 |
gomNs.sessiondata.views = []; |
|
110
|
485 |
} |
|
115
|
486 |
if (!gomNs.sessiondata.views.length) { |
|
117
|
487 |
addView( 'filter', 'Mes résultats de recherche' ); |
|
|
488 |
addView( 'list', 'Ma liste' ); |
|
109
|
489 |
} |
|
|
490 |
if (!gomNs.sessiondata.annotations) { |
|
|
491 |
gomNs.sessiondata.annotations = {}; |
|
|
492 |
} |
|
115
|
493 |
if (data.write_allowed) { |
|
|
494 |
$("#bloc_gestvue").show(); |
|
|
495 |
} else { |
|
|
496 |
$("#bloc_gestvue").hide(); |
|
|
497 |
} |
|
|
498 |
$("#sessionname").html(gomNs.sessiondata.title |
|
|
499 |
+ ( data.write_allowed ? '' : '<span class="lectseul"> (lecture seule)</span>' ) ); |
|
109
|
500 |
gomNs.hrefinterval = setInterval(function() { |
|
|
501 |
if (document.location.hash != gomNs.hash) { |
|
|
502 |
clearInterval(gomNs.hrefinterval); |
|
|
503 |
getInitialView(); |
|
|
504 |
} |
|
|
505 |
}, 500); |
|
117
|
506 |
displayViewList(); |
|
110
|
507 |
showView(); |
|
109
|
508 |
}); |
|
|
509 |
} |
|
|
510 |
|
|
|
511 |
function changeSessionTitle(title) { |
|
|
512 |
gomNs.sessiondata.title = _.escape(title); |
|
|
513 |
$("#sessionname").html(gomNs.sessiondata.title); |
|
|
514 |
debouncedSaveChanges(); |
|
|
515 |
} |
|
|
516 |
|
|
117
|
517 |
function addView(viewtype, viewname) { |
|
|
518 |
var _content = { |
|
|
519 |
type: viewtype, |
|
|
520 |
name: viewname, |
|
|
521 |
hiddenWidgets: [], |
|
|
522 |
}; |
|
|
523 |
switch(viewtype) { |
|
|
524 |
case 'filter': |
|
|
525 |
_content.period = [ gomNs.minYear, gomNs.maxYear ]; |
|
|
526 |
_content.tag = []; |
|
|
527 |
gomNs.sessiondata.view = gomNs.sessiondata.views.length; |
|
|
528 |
break; |
|
|
529 |
case 'list': |
|
|
530 |
_content.list = []; |
|
|
531 |
break; |
|
|
532 |
} |
|
|
533 |
gomNs.sessiondata.views.push(_content); |
|
|
534 |
debouncedSaveChanges(); |
|
|
535 |
} |
|
109
|
536 |
|
|
|
537 |
$(document).ready(function() { |
|
110
|
538 |
gomNs.map = new google.maps.Map(document.getElementById("map"), |
|
|
539 |
{ |
|
|
540 |
center: new google.maps.LatLng(30, 0), |
|
|
541 |
zoom: 1, |
|
|
542 |
mapTypeId: google.maps.MapTypeId.SATELLITE |
|
|
543 |
}); |
|
|
544 |
$.getJSON('lib/countries.geo.json', showCountries); |
|
115
|
545 |
var _html = gomNs.displayedDates.map(function(_v) { |
|
|
546 |
return '<li style="left: ' |
|
|
547 |
+ parseInt(yearToPx(_v)) |
|
|
548 |
+ 'px"><div class="datelabel">' |
|
|
549 |
+ _v |
|
|
550 |
+ '</div></li>' |
|
|
551 |
}).join(''); |
|
|
552 |
$("#dates").html(_html); |
|
109
|
553 |
$("#apartager").click(function() { |
|
110
|
554 |
var _pu = $("#partageurls"); |
|
|
555 |
$(this).attr("class",_pu.is(":visible") ? "" : "actif"); |
|
|
556 |
_pu.slideToggle(); |
|
109
|
557 |
return false; |
|
|
558 |
}) |
|
115
|
559 |
$(".handle").draggable({ |
|
|
560 |
"axis" : "x", |
|
|
561 |
"containment" : "parent", |
|
|
562 |
"drag": function() { |
|
|
563 |
$(this).attr("year",parseInt(pxToYear($(this).position().left))); |
|
|
564 |
var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
|
|
565 |
if (_curView.type == 'filter') { |
|
|
566 |
var _h0 = $("#handle_0"), |
|
|
567 |
_h1 = $("#handle_1"), |
|
|
568 |
_h0v = parseInt(_h0.attr("year")), |
|
|
569 |
_h1v = parseInt(_h1.attr("year")); |
|
|
570 |
_curView.period = [ Math.min(_h0v, _h1v), Math.max(_h0v, _h1v)]; |
|
|
571 |
_h0.find(".handleinner").css({ |
|
|
572 |
"margin-left" : (_h0v>_h1v ? "0" : "-20px") |
|
|
573 |
}) |
|
|
574 |
_h1.find(".handleinner").css({ |
|
|
575 |
"margin-left" : (_h1v>_h0v ? "0" : "-20px") |
|
|
576 |
}) |
|
|
577 |
updateFilters(); |
|
|
578 |
debouncedSaveChanges(); |
|
|
579 |
} |
|
109
|
580 |
} |
|
115
|
581 |
}) |
|
109
|
582 |
var _defLab = $( "#tagsearch" ).val(); |
|
|
583 |
$( "#tagsearch" ).autocomplete({ |
|
|
584 |
source: "tagsearch.php", |
|
|
585 |
minLength: 2, |
|
|
586 |
select: function( event, ui ) { |
|
|
587 |
tagInfo(ui.item.label); |
|
|
588 |
return false; |
|
|
589 |
} |
|
115
|
590 |
}).addClass("grise") |
|
|
591 |
.focusin(function() { |
|
109
|
592 |
if ($(this).val() == _defLab) { |
|
115
|
593 |
$(this).val("").removeClass("grise"); |
|
109
|
594 |
} |
|
|
595 |
}); |
|
|
596 |
$("#sessionname").click(function() { |
|
|
597 |
if (gomNs.write_allowed && !$(this).children().length) { |
|
|
598 |
var _el = document.createElement('input'); |
|
|
599 |
_el.value = gomNs.sessiondata.title; |
|
|
600 |
$(_el).focusout(function() { |
|
|
601 |
changeSessionTitle(this.value); |
|
|
602 |
}).keypress(function(e) { |
|
|
603 |
if (e.keyCode == 13) { |
|
|
604 |
changeSessionTitle(this.value); |
|
|
605 |
} |
|
|
606 |
}); |
|
|
607 |
$(this).html(_el); |
|
|
608 |
_el.focus(); |
|
|
609 |
_el.select(); |
|
|
610 |
} |
|
|
611 |
}); |
|
115
|
612 |
$("#titrevue").change(function() { |
|
|
613 |
var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
|
|
614 |
_curView.name = $(this).val(); |
|
|
615 |
$("#view_" + gomNs.sessiondata.view + " a").html(_.escape(_curView.name)) |
|
|
616 |
debouncedSaveChanges(); |
|
|
617 |
}); |
|
117
|
618 |
$("#notes").click(function() { |
|
|
619 |
if (gomNs.write_allowed) { |
|
|
620 |
if (this.children[0].tagName == 'UL') { |
|
|
621 |
var _el = document.createElement('textarea'), |
|
|
622 |
_curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
|
|
623 |
_el.innerHTML = _curView.notes ? _curView.notes : ''; |
|
|
624 |
$(_el).focusout(function() { |
|
|
625 |
_curView.notes = this.value; |
|
|
626 |
this.parentNode.innerHTML = '<ul><li>' + (this.value.length ? _.escape(_curView.notes).replace(/\n/gm,"</li><li>") : 'Annoter cette vue...' ) + '</ul>'; |
|
|
627 |
debouncedSaveChanges(); |
|
|
628 |
}); |
|
|
629 |
$(this).html(_el); |
|
|
630 |
_el.focus(); |
|
|
631 |
_el.select(); |
|
|
632 |
} |
|
|
633 |
} |
|
|
634 |
}); |
|
115
|
635 |
gomNs.disChart = d3.select("#disciplines") |
|
|
636 |
.append("svg:svg") |
|
|
637 |
.attr("width", 475) |
|
|
638 |
.attr("height", 120); |
|
|
639 |
getInitialView(); |
|
|
640 |
$(".barrebloc").click(function() { |
|
|
641 |
$(this).next().slideToggle(); |
|
110
|
642 |
}); |
|
115
|
643 |
gomNs.widgetList = []; |
|
|
644 |
var _html = '<ul id="widgetlist">'; |
|
|
645 |
$("div.bloc").each(function() { |
|
|
646 |
gomNs.widgetList.push(this.id); |
|
|
647 |
_html += '<li><input type="checkbox" id="chbx_' |
|
|
648 |
+ this.id |
|
|
649 |
+ '" /><label>' + $(this).find("h2").html() + '</label></li>' |
|
110
|
650 |
}); |
|
115
|
651 |
_html + '</ul>'; |
|
|
652 |
$("#gestvue").append(_html); |
|
117
|
653 |
$("#nouvellevue").click(function() { |
|
|
654 |
$("#plusdevues").slideToggle(); |
|
|
655 |
return false; |
|
|
656 |
}) |
|
115
|
657 |
$("#widgetlist input").change(function() { |
|
|
658 |
var _newWL = []; |
|
|
659 |
$("#widgetlist input").each(function(_k, _e) { |
|
|
660 |
var _id = _e.id.substr(5); |
|
|
661 |
if (!$(_e).prop("checked")) { |
|
|
662 |
$("#" + _id).hide(); |
|
|
663 |
_newWL.push(_id); |
|
|
664 |
} else { |
|
|
665 |
$("#" + _id).show(); |
|
|
666 |
} |
|
|
667 |
}); |
|
|
668 |
gomNs.sessiondata.views[gomNs.sessiondata.view].hiddenWidgets = _newWL; |
|
|
669 |
debouncedSaveChanges(); |
|
117
|
670 |
}); |
|
|
671 |
$("#nouv_resrech").click(function() { |
|
|
672 |
var _txt = prompt("Comment souhaitez-vous nommer votre nouvelle vue ?","Nouveaux résultats de recherche"); |
|
|
673 |
if (_txt !== null) { |
|
|
674 |
addView('filter', _txt); |
|
|
675 |
displayViewList(); |
|
|
676 |
} |
|
|
677 |
return false; |
|
|
678 |
}); |
|
|
679 |
$("#nouv_liste").click(function() { |
|
|
680 |
var _txt = prompt("Comment souhaitez-vous nommer votre nouvelle vue ?","Nouvelle liste"); |
|
|
681 |
if (_txt !== null) { |
|
|
682 |
addView('list', _txt); |
|
|
683 |
displayViewList(); |
|
|
684 |
} |
|
|
685 |
return false; |
|
|
686 |
}); |
|
109
|
687 |
}); |