diff -r e7086d345a7c -r 46c0f7a935d1 hdalab/js/gomina.js --- a/hdalab/js/gomina.js Tue Jan 17 00:19:27 2012 +0100 +++ b/hdalab/js/gomina.js Mon Jan 30 18:20:21 2012 +0100 @@ -8,6 +8,7 @@ tlPixels: 960, tlGamma: 6, heatGamma: 4, + displayedDates: [-5000,0,500,1000,1200,1400,1600,1700,1750,1800,1850,1900,1950,2010], } function yearToPx(year) { @@ -24,11 +25,10 @@ $.getJSON("taginfo.php", _urlParam, function(data) { - var _html = '

' - + data.content_count - + ' contenus pour ce tag

Ajouter au filtrage

' - + data.requested_label - + '

'; + $("#tagsearch").val(data.requested_label).removeClass("grise"); + $("#tagcount").html(data.content_count + + ' contenu' + (data.content_count > 1 ? 's' : '') + ' pour ce tag'); + var _html = ''; if (data.wikipedia_url) { _html += '

= _curView.period[0]) || (_n == 0 && _val <= _curView.period[1])) { + _curView.period[_n] = _int; + } + updateFilters(); + debouncedSaveChanges(); + } } } function changeSpan(_this) { - if (!$(_this).children().length) { - var _el = document.createElement('input'), - _n = _this.id.split('_')[1]; - _el.value = gomNs.sessiondata.filters.period[_n]; - _el.style.width = $(_this).width() + 'px'; - $(_el).focusout(function() { - updatePeriod(_n, this.value); - }).keypress(function(e) { - if (e.keyCode == 13) { + var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; + if (_curView.type == 'filter') { + if (!$(_this).children().length) { + var _el = document.createElement('input'), + _n = _this.id.split('_')[1]; + _el.value = _curView.period[_n]; + _el.style.width = $(_this).width() + 'px'; + $(_el).focusout(function() { updatePeriod(_n, this.value); - } - }); - $(_this).html(_el); - _el.focus(); - _el.select(); + }).keypress(function(e) { + if (e.keyCode == 13) { + updatePeriod(_n, this.value); + } + }); + $(_this).html(_el); + _el.focus(); + _el.select(); + } } } function updateFilters() { + var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; + if (_curView.type != 'filter') { + return; + } var _htmFilters = '', - _fl = gomNs.sessiondata.filters.tag.length; - if (!gomNs.sessiondata.filters.period && !_fl) { + _fl = _curView.tag.length; + if (!_curView.period && !_fl) { _htmFilters = '
  • Aucun filtre
  • '; } + if (_curView.period) { + _htmFilters += '
  • ' + + _curView.period[0] + + ' à ' + + _curView.period[1] + + '
  • '; + $("#handle_0").css({ + "left" : yearToPx(_curView.period[0])+"px", + }).attr("year", _curView.period[0]) + .find(".handleinner") + .css({ + "margin-left" : "-20px" + }); + $("#handle_1").css({ + "left" : yearToPx(_curView.period[1])+"px", + }).attr("year", _curView.period[1]) + .find(".handleinner") + .css({ + "margin-left" : "0" + }); + } if (_fl) { - _htmFilters += _(gomNs.sessiondata.filters.tag).map(function(_t, _i) { + _htmFilters += _(_curView.tag).map(function(_t, _i) { return '
  • ' + _t + '[x]
  • '; }).join(""); } - if (gomNs.sessiondata.filters.period) { - _htmFilters += '
  • ' - + gomNs.sessiondata.filters.period[0] - + '-' - + gomNs.sessiondata.filters.period[1] - + '[x]
  • '; - $("#dateslider").slider("values",0,yearToPx(gomNs.sessiondata.filters.period[0])) - .slider("values",1,yearToPx(gomNs.sessiondata.filters.period[1])); - } else { - _htmFilters += '
  • Filtrer par période
  • '; - } $("#filters").html(_htmFilters); - $("#bandefiltre").attr("class",""); debouncedGetUpdates(); } @@ -168,7 +183,7 @@ if (contentdata && contentdata.length) { var _htmlCl = ''; + if (gomNs.write_allowed) { + _(gomNs.sessiondata.views).each(function(_view, _k) { + if (_view.type == 'list') { + _html += '

    ' + + ( _view.list.indexOf(_d.id) == -1 ? 'Ajouter à' : 'Retirer de' ) + + ' "' + + _.escape(_view.name) + + '"

    ' + } + }); + } + _html += ''; + return _html; }).join('') + ''; $("#contents").html(_htmlCl).scrollTop(0); $("a.addremlist").click(function() { var _id = $(this).attr("contentid"), - _io = gomNs.sessiondata.liste.indexOf(_id); + _vid = + _view = gomNs.sessiondata.views[$(this).attr("viewid")], + _io = _view.list.indexOf(_id); if ( _io == -1) { - gomNs.sessiondata.liste.push(_id); - $(this).html('Retirer de ma liste'); + _view.list.push(_id); + $(this).html('Retirer de "' + _.escape(_view.name) + '"' ); } else { - gomNs.sessiondata.liste.splice(_io, 1); - $(this).html('Ajouter à ma liste'); + _view.list.splice(_io, 1); + $(this).html('Ajouter à "' + _.escape(_view.name) + '"'); } if (gomNs.sessiondata.view == 1) { showView(); @@ -216,25 +242,27 @@ debouncedSaveChanges(); return false; }) - $("div.content-annotation").click(function() { - if (gomNs.write_allowed && this.children[0].tagName == 'UL') { - var _el = document.createElement('textarea'), - _id = $(this).attr("contentid"); - _el.innerHTML = (gomNs.sessiondata.annotations[_id] && gomNs.sessiondata.annotations[_id].texte) ? gomNs.sessiondata.annotations[_id].texte : ''; - $(_el).focusout(function() { - var _id = this.parentNode.attributes.contentid.nodeValue; - if (!gomNs.sessiondata.annotations[_id]) { - gomNs.sessiondata.annotations[_id] = {}; + if (gomNs.write_allowed) { + $("div.content-annotation").click(function() { + if (this.children[0].tagName == 'UL') { + var _el = document.createElement('textarea'), + _id = $(this).attr("contentid"); + _el.innerHTML = (gomNs.sessiondata.annotations[_id] && gomNs.sessiondata.annotations[_id].texte) ? gomNs.sessiondata.annotations[_id].texte : ''; + $(_el).focusout(function() { + var _id = this.parentNode.attributes.contentid.nodeValue; + if (!gomNs.sessiondata.annotations[_id]) { + gomNs.sessiondata.annotations[_id] = {}; + } + gomNs.sessiondata.annotations[_id].texte = _.escape(this.value); + this.parentNode.innerHTML = ''; + debouncedSaveChanges(); + }); + $(this).html(_el); + _el.focus(); + _el.select(); } - gomNs.sessiondata.annotations[_id].texte = _.escape(this.value); - this.parentNode.innerHTML = ''; - debouncedSaveChanges(); }); - $(this).html(_el); - _el.focus(); - _el.select(); } - }); } else { $("#contents").html(""); @@ -266,6 +294,14 @@ }) }); } + if (gomNs.sessiondata.view == 0) { + var _h0 = $("#handle_0").position().left, + _h1 = $("#handle_1").position().left; + gomNs.dhmPaper.rect(Math.min(_h0, _h1) - 1, 0, Math.abs(_h0 - _h1) + 2, 20).attr({ + "stroke" : "rgb(128,0,0)", + "stroke-width" : "3" + }); + } if (data.tags.length) { var _scores = _(data.tags).map(function(_d) { return parseInt(_d.score)}), _maxTag = _(_scores).max(), @@ -293,14 +329,56 @@ _(data.countries).each(function(_c) { var _cc = gomNs.countries[_c.isocode]; if (_cc) { - var _r = parseInt(255 * _c.score / _max), - _b = parseInt( (255 - _r)/2) ; + var _gb = parseInt(255 * (1 - _c.score / _max )); _(_cc.gPolygons).each(function(_p) { _p.setOptions({ - "fillColor" : "rgb(" + _r + ",0," + _b + ")", - }) - } ); - } + "fillColor" : ( _c.score ? "rgb(255," + _gb + "," + _gb + ")" : "#7070a0" ), + }); + }); + } + }); + } + if (data.disciplines) { + var _disc = data.disciplines.filter(function(_d) { + return +_d.score > 0; + }), + _echelle = d3.scale + .linear() + .range([0, 120]) + .domain([0, d3.max(_disc, function(_d) { return +_d.score })]), + _barres = gomNs.disChart.selectAll("g.discbarre").data(_disc); + + var _newels = _barres.enter() + .append("svg:g") + .attr("class","discbarre"); + + _newels.append("svg:rect") + .attr("stroke","none") + .attr("fill","rgb(255,128,128)") + .attr("x","0"). + attr("y","0") + .attr("height","25"); + _newels.append("svg:text") + .attr("font-size","12px") + .attr("x","5") + .attr("y","16"); + + _barres.exit().remove(); + + _barres.on("click", function(_d) { + tagInfo(_d.label); + }).on("mouseover", function() { + d3.select(this).select("rect").attr("fill","rgb(128,128,255)"); + }).on("mouseout", function() { + d3.select(this).select("rect").attr("fill","rgb(255,128,128)"); + }).attr("transform",function(_d,_k) { + return "translate(" + ( 30 + 40 * _k ) + ",120) rotate(-90)"; + }); + _barres.select("text").text(function(_d) { + return _d.label; + }); + _barres.select("rect").attr("width", function(_d) { + return _echelle(_d.score); }); } } @@ -315,32 +393,42 @@ } } -var debouncedSaveChanges = _.debounce(saveChanges, 1000); +var debouncedSaveChanges = _.debounce(saveChanges, 3000); function changeView(nview) { - gomNs.sessiondata.view = nview; - debouncedSaveChanges(); - showView(); + var _curView = gomNs.sessiondata.views[nview]; + if (_curView.type == 'list' && (!_curView.list || !_curView.list.length)) { + alert("La liste de contenus est vide ! Ajoutez des contenus pour afficher la liste !"); + } else { + gomNs.sessiondata.view = nview; + debouncedSaveChanges(); + showView(); + } } function showView() { - $("#showsearch, #showlist").removeClass("actif"); - switch(gomNs.sessiondata.view) { - case 1: - if (gomNs.sessiondata.liste && gomNs.sessiondata.liste.length) { - $("#showlist").addClass("actif"); - $("#bandefiltre").hide(); - $.getJSON("filter.php", { - contentlist: gomNs.sessiondata.liste.join(',') - }, updateDisplay); - break; - } else { - alert("La liste de contenus est vide ! Ajoutez des contenus pour afficher la liste !"); - } - default: - $("#showsearch").addClass("actif"); - $("#bandefiltre").show(); + $(".lienvue").removeClass("actif"); + $("#view_" + gomNs.sessiondata.view).addClass("actif"); + var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; + $("#titrevue").val(_curView.name); + $("#bloc_gestvue h2").html('Gérer la vue "' + _.escape(_curView.name) + '"'); + $("div.bloc").show(); + $("#widgetlist input").prop("checked",true); + _(_curView.hiddenWidgets).each(function(_w) { + $("#chbx_" + _w).prop("checked",false); + $("#" + _w).hide(); + }) + switch(_curView.type) { + case 'list': + $("#bandefiltre, .handle").hide(); + $.getJSON("filter.php", { + contentlist: _curView.list.join(',') + }, updateDisplay); + break; + case 'filter': + $("#bandefiltre, .handle").show(); updateFilters(); + break; } } @@ -375,21 +463,44 @@ } if (!gomNs.sessiondata.view) { gomNs.sessiondata.view = 0; - // 0 pour les résultats de recherche, 1 pour la liste + } + if (!gomNs.sessiondata.views) { + gomNs.sessiondata.views = []; } - if (!gomNs.sessiondata.filters) { - gomNs.sessiondata.filters = { - period : null, - tag : [], - } - } - if (!gomNs.sessiondata.liste) { - gomNs.sessiondata.liste = []; + if (!gomNs.sessiondata.views.length) { + gomNs.sessiondata.views[0] = { + type: 'filter', + name: 'Mes résultats de recherche', + period: [ gomNs.minYear, gomNs.maxYear ], + tag: [], + hiddenWidgets: [], + }; + gomNs.sessiondata.views[1] = { + type: 'list', + name: 'Ma liste', + list: [], + hiddenWidgets: [], + }; } if (!gomNs.sessiondata.annotations) { gomNs.sessiondata.annotations = {}; } - $("#sessionname").html(gomNs.sessiondata.title + ( data.write_allowed ? '' : ' (lecture seule)' ) ); + $("#ongletsvues").html(gomNs.sessiondata.views.map(function(_v, _k) { + return '
  • ' + + _.escape(_v.name) + + '
  • '; + }).join("")) + if (data.write_allowed) { + $("#bloc_gestvue").show(); + } else { + $("#bloc_gestvue").hide(); + } + $("#sessionname").html(gomNs.sessiondata.title + + ( data.write_allowed ? '' : ' (lecture seule)' ) ); gomNs.hrefinterval = setInterval(function() { if (document.location.hash != gomNs.hash) { console.log("Changement de hash"); @@ -407,9 +518,6 @@ debouncedSaveChanges(); } -var debouncedHideSlider = _.debounce(function() { - $("#dateslider").slideUp(); -}, 2000); $(document).ready(function() { gomNs.map = new google.maps.Map(document.getElementById("map"), @@ -419,43 +527,55 @@ mapTypeId: google.maps.MapTypeId.SATELLITE }); $.getJSON('lib/countries.geo.json', showCountries); - $("#dates li").each(function() { - $(this).css({ - "left" : parseInt(yearToPx(parseInt($(this).text()))) + "px" - }); - }); + var _html = gomNs.displayedDates.map(function(_v) { + return '
  • ' + + _v + + '
  • ' + }).join(''); + $("#dates").html(_html); $("#apartager").click(function() { var _pu = $("#partageurls"); $(this).attr("class",_pu.is(":visible") ? "" : "actif"); _pu.slideToggle(); return false; }) - $( "#dateslider" ).slider({ - range: true, - min: 0, - max: gomNs.tlPixels, - values: [ 0, gomNs.tlPixels ], - slide: function( event, ui ) { - gomNs.sessiondata.filters.period = ui.values.map(function(_v) { - return parseInt(pxToYear(_v)); - }); - updateFilters(); - debouncedSaveChanges(); - debouncedHideSlider(); + $(".handle").draggable({ + "axis" : "x", + "containment" : "parent", + "drag": function() { + $(this).attr("year",parseInt(pxToYear($(this).position().left))); + var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; + if (_curView.type == 'filter') { + var _h0 = $("#handle_0"), + _h1 = $("#handle_1"), + _h0v = parseInt(_h0.attr("year")), + _h1v = parseInt(_h1.attr("year")); + _curView.period = [ Math.min(_h0v, _h1v), Math.max(_h0v, _h1v)]; + _h0.find(".handleinner").css({ + "margin-left" : (_h0v>_h1v ? "0" : "-20px") + }) + _h1.find(".handleinner").css({ + "margin-left" : (_h1v>_h0v ? "0" : "-20px") + }) + updateFilters(); + debouncedSaveChanges(); + } } - }).hide(); + }) var _defLab = $( "#tagsearch" ).val(); $( "#tagsearch" ).autocomplete({ source: "tagsearch.php", minLength: 2, select: function( event, ui ) { tagInfo(ui.item.label); - $(this).val(_defLab); return false; } - }).focusin(function() { + }).addClass("grise") + .focusin(function() { if ($(this).val() == _defLab) { - $(this).val(""); + $(this).val("").removeClass("grise"); } }); $("#sessionname").click(function() { @@ -474,13 +594,42 @@ _el.select(); } }); - $("#showlist").click(function() { - changeView(1); - return false; + $("#titrevue").change(function() { + var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; + _curView.name = $(this).val(); + $("#view_" + gomNs.sessiondata.view + " a").html(_.escape(_curView.name)) + debouncedSaveChanges(); + }); + gomNs.disChart = d3.select("#disciplines") + .append("svg:svg") + .attr("width", 475) + .attr("height", 120); + getInitialView(); + $(".barrebloc").click(function() { + $(this).next().slideToggle(); }); - $("#affres, #showsearch").click(function() { - changeView(0); - return false; + gomNs.widgetList = []; + var _html = ''; + $("#gestvue").append(_html); + $("#widgetlist input").change(function() { + var _newWL = []; + $("#widgetlist input").each(function(_k, _e) { + var _id = _e.id.substr(5); + if (!$(_e).prop("checked")) { + $("#" + _id).hide(); + _newWL.push(_id); + } else { + $("#" + _id).show(); + } + }); + gomNs.sessiondata.views[gomNs.sessiondata.view].hiddenWidgets = _newWL; + debouncedSaveChanges(); + }) });