big change : facette urls manages with location search parameters, and not anymore with session info.
authorcavaliet
Thu, 25 Sep 2014 17:14:29 +0200
changeset 341 9a854bb09f34
parent 340 6a7bc9190de5
child 342 a0fa17c48236
big change : facette urls manages with location search parameters, and not anymore with session info.
src/hdalab/static/hdalab/js/gomina.js
src/hdalab/templates/facettes.html
src/hdalab/urls.py
--- a/src/hdalab/static/hdalab/js/gomina.js	Thu Sep 25 12:16:51 2014 +0200
+++ b/src/hdalab/static/hdalab/js/gomina.js	Thu Sep 25 17:14:29 2014 +0200
@@ -44,7 +44,7 @@
             _rgb.push(Math.floor(_exp*gomNs.gradientEnd[i] + (1-_exp)*gomNs.gradientStart[i]));
         }
     }
-    return "rgb(" + _rgb.join(",") + ")"
+    return "rgb(" + _rgb.join(",") + ")";
 }
 
 function polygon_to_gmap(polycoords, dbpedia_uri) {
@@ -119,7 +119,7 @@
         	_curView[_type].push(_label);
     	}
         updateFilters();
-        debouncedSaveChanges();
+        //debouncedSaveChanges();
     }
 }
 
@@ -128,7 +128,7 @@
     if (_curView.type == 'filter') {
         _curView[_type].splice(_index,1);
         updateFilters();
-        debouncedSaveChanges();
+        //debouncedSaveChanges();
     }
 }
 
@@ -161,7 +161,7 @@
                 _curView.period[_n] = _int;
             }
             updateFilters();
-            debouncedSaveChanges();
+            //debouncedSaveChanges();
         }
     }
 }
@@ -172,7 +172,7 @@
         _curView.period[0] = gomNs.minYear;
         _curView.period[1] = gomNs.maxYear;
         updateFilters();
-        debouncedSaveChanges();
+        //debouncedSaveChanges();
     }
 }
 
@@ -198,7 +198,10 @@
     }
 }
 
-function updateFilters() {
+function updateFilters(initial) {
+    if(typeof initial==="undefined"){
+        initial = false;
+    }
     var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view];
     if (_curView.type != 'filter') {
         return;
@@ -261,8 +264,12 @@
         }).join("");
     }
     $("#renkan-link").attr("href",url_renkan);
+    if(!initial){
+        history.replaceState(null, null, url_renkan.substr(url_renkan.lastIndexOf("?")));
+    }
     $("#filters").html(_htmFilters).hide();
     debouncedGetUpdates();
+    
 }
 
 function displayContents(contentdata) {
@@ -306,16 +313,16 @@
                             + '&nbsp;<a class="mind-map-icon" href="' + gomNs.urls.renkan + '?label=' + _t.label + '" target="_blank">placeholder</a></h3>'
                             + '</li>';
                     }).join('')
-                    + '</ul><h4>'+gettext("Annotations")+'</h4><div class="content-annotation" contentid="'
+                    /*+ '</ul><h4>'+gettext("Annotations")+'</h4><div class="content-annotation" contentid="'
                     + _d.id
                     + '">'
                     + ( gomNs.sessiondata.annotations[_d.id] && gomNs.sessiondata.annotations[_d.id].texte
                         ? '<ul><li>'
                             + _.escape(gomNs.sessiondata.annotations[_d.id].texte).replace(/\n/gm,"</li><li>")
                             + '</li>'
-                        : ( gomNs.write_allowed ? '<ul><li>'+gettext("Annoter ce contenu")+'...</li></ul>' : '' ) )
+                        : ( gomNs.write_allowed ? '<ul><li>'+gettext("Annoter ce contenu")+'...</li></ul>' : '' ) )*/
                     + '</div>';
-                if (gomNs.write_allowed) {
+                /*if (gomNs.write_allowed) {
                     _(gomNs.sessiondata.views).each(function(_view, _k) {
                         if (_view.type == 'list') {
                             _html += '<p><a href="#" class="addremlist" contentid="'
@@ -327,13 +334,13 @@
                                 + '</a></p>'
                         }
                     });
-                }
+                }*/
                 _html += '</li>';
                 return _html;
             }).join('')
             + '</ul>';
         $("#contents").html(_htmlCl).scrollTop(0);
-        $("a.addremlist").click(function() {
+        /*$("a.addremlist").click(function() {
             var _id = $(this).attr("contentid"),
                 _vid = 
                 _view = gomNs.sessiondata.views[$(this).attr("viewid")],
@@ -350,8 +357,8 @@
             }
             debouncedSaveChanges();
             return false;
-        })
-        if (gomNs.write_allowed) {
+        });*/
+        /*if (gomNs.write_allowed) {
             $("div.content-annotation").click(function() {
                 if (this.children[0].tagName == 'UL') {
                     var _el = document.createElement('textarea'),
@@ -371,7 +378,7 @@
                     _el.select();
                 }
             });
-        }
+        }*/
     }
     else {
         $("#contents").html("");
@@ -494,7 +501,7 @@
     }
 }
 
-function saveChanges() {
+/*function saveChanges() {
     if (gomNs.sessionid && gomNs.sessionkey) {
         $.getJSON(gomNs.urls['session_info'], {
             "sessionid" : gomNs.sessionid,
@@ -502,11 +509,11 @@
             "data" : JSON.stringify(gomNs.sessiondata),
         });
     }
-}
+}*/
 
-var debouncedSaveChanges = _.debounce(saveChanges, 3000);
+//var debouncedSaveChanges = _.debounce(saveChanges, 3000);
 
-function changeView(nview) {
+/*function changeView(nview) {
     var _curView = gomNs.sessiondata.views[nview];
     if (_curView.type == 'list' && (!_curView.list || !_curView.list.length)) {
         alert(gettext("La liste de contenus est vide ! Ajoutez des contenus pour afficher la liste !"));
@@ -515,9 +522,12 @@
         debouncedSaveChanges();
         showView();
     }
-}
+}*/
 
-function showView() {
+function showView(initial) {
+    if(typeof initial==="undefined"){
+        initial = false;
+    }
     $(".lienvue").removeClass("actif");
     $("#view_" + gomNs.sessiondata.view).addClass("actif");
     var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view];
@@ -542,12 +552,12 @@
             break;
         case 'filter':
             $("#bandefiltre, .handle").show();
-            updateFilters();
+            updateFilters(initial);
             break;
     }
 }
 
-function displayViewList() {
+/*function displayViewList() {
     $("#ongletsvues").html(gomNs.sessiondata.views.map(function(_v, _k) {
             return '<li class="lienvue" id="view_'
                 + _k
@@ -557,70 +567,115 @@
                 + _.escape(_v.name)
                 + '</a></li>';
         }).join(""))
+}*/
+
+
+function getURLParameter(name) {
+    return decodeURI(
+        (RegExp(name + '=' + '(.+?)(&|$)').exec(document.location.search)||[,null])[1]
+    );
 }
 
 function getInitialView() {
-    var _urlParam = {};
-    if (document.location.hash) {
-        var _tab = document.location.hash.replace("#","").split(":");
-        _urlParam.sessionid = _tab[0];
-        if (_tab.length > 1) {
-            _urlParam.sessionkey = _tab[1];
+    var _urlParam = {
+        period: [ gomNs.minYear, gomNs.maxYear ],
+        country: [],
+        tag: []
+    };
+    if (document.location.search) {
+        var p = decodeURIComponent(getURLParameter("period"));
+        if(p!="null"){
+            p = p.split(",");
         }
-    }
-    $.getJSON(gomNs.urls['session_info'], _urlParam, function(data) {
-        gomNs.sessionid = data.sessionid;
-        if (data.sessionkey) {
-            gomNs.sessionkey = data.sessionkey;
+        else{
+            p = [ gomNs.minYear, gomNs.maxYear ];
         }
-        gomNs.write_allowed = data.write_allowed;
-        if (data.write_allowed) {
-            $("#partagerw").show();
-        } else {
-            $("#partagerw").hide();
+        var c = decodeURIComponent(getURLParameter("country"));
+        if(c!="null"){
+            c = c.split(",");
+            c = c.filter(function(n){ return n!="" });
+        }
+        else{
+            c = [];
         }
-        var _baseUrl = document.location.href.split("#")[0];
-        gomNs.hash = "#" + data.sessionid + (data.sessionkey ? (':' + data.sessionkey) : '');
-        document.location.hash = gomNs.hash;
-        gomNs.sessiondata = typeof data.data == "string" ? JSON.parse(data.data) : (typeof data.data == "object" ? data.data : {});
-        if (!gomNs.sessiondata.title) {
-            gomNs.sessiondata.title = gettext('Nouvelle session');
+        var t = decodeURIComponent(getURLParameter("label"));
+        if(t!="null"){
+            t = t.split(",");
+            t = t.filter(function(n){ return n!="" });
+        }
+        else{
+            t = [];
         }
-        if (!gomNs.sessiondata.views) {
-            gomNs.sessiondata.views = [];
-        }
-        if (!gomNs.sessiondata.views.length) {
-            addView( 'filter', gettext('Mes resultats de recherche') );
-            addView( 'list', gettext('Ma liste') );
-        }
-        if (!gomNs.sessiondata.annotations) {
-            gomNs.sessiondata.annotations = {};
+        _urlParam.period = p;
+        _urlParam.country = c;
+        _urlParam.tag = t;
+    }
+    // Not getting session info anymore, build data object
+    var data = {
+        data: {
+            view: 0,
+            views: [
+                {
+                    type: "filter",
+                    period: _urlParam.period,
+                    country: _urlParam.country,
+                    tag: _urlParam.tag
+                }
+            ]
         }
-        if (data.write_allowed) {
-            $("#bloc_gestvue").show();
-        } else {
-            $("#bloc_gestvue").hide();
+    };
+    
+    /*gomNs.sessionid = data.sessionid;
+    if (data.sessionkey) {
+        gomNs.sessionkey = data.sessionkey;
+    }
+    gomNs.write_allowed = data.write_allowed;
+    if (data.write_allowed) {
+        $("#partagerw").show();
+    } else {
+        $("#partagerw").hide();
+    }*/
+    //var _baseUrl = document.location.href.split("#")[0];
+    //gomNs.hash = "#" + data.sessionid + (data.sessionkey ? (':' + data.sessionkey) : '');
+    //document.location.hash = gomNs.hash;
+    gomNs.sessiondata = typeof data.data == "string" ? JSON.parse(data.data) : (typeof data.data == "object" ? data.data : {});
+    /*if (!gomNs.sessiondata.title) {
+        gomNs.sessiondata.title = gettext('Nouvelle session');
+    }*/
+    if (!gomNs.sessiondata.views) {
+        gomNs.sessiondata.views = [];
+    }
+    /*if (!gomNs.sessiondata.views.length) {
+        addView( 'filter', gettext('Mes resultats de recherche') );
+        addView( 'list', gettext('Ma liste') );
+    }
+    if (!gomNs.sessiondata.annotations) {
+        gomNs.sessiondata.annotations = {};
+    }
+    if (data.write_allowed) {
+        $("#bloc_gestvue").show();
+    } else {
+        $("#bloc_gestvue").hide();
+    }
+    $("#sessionname").html(_.escape(gomNs.sessiondata.title)
+        + ( data.write_allowed ? '' : '<span class="lectseul"> ('+gettext("lecture seule")+')</span>' ) );
+    gomNs.hrefinterval = setInterval(function() {
+        if (document.location.hash != gomNs.hash) {
+            clearInterval(gomNs.hrefinterval);
+            getInitialView();
         }
-        $("#sessionname").html(_.escape(gomNs.sessiondata.title)
-            + ( data.write_allowed ? '' : '<span class="lectseul"> ('+gettext("lecture seule")+')</span>' ) );
-        gomNs.hrefinterval = setInterval(function() {
-            if (document.location.hash != gomNs.hash) {
-                clearInterval(gomNs.hrefinterval);
-                getInitialView();
-            }
-        }, 500);
-        displayViewList();
-        showView();
-    });
+    }, 500);*/
+    //displayViewList();
+    showView(true);
 }
 
-function changeSessionTitle(title) {
+/*function changeSessionTitle(title) {
     gomNs.sessiondata.title = title;
     $("#sessionname").html(_.escape(gomNs.sessiondata.title));
     debouncedSaveChanges();
-}
+}*/
 
-function addView(viewtype, viewname) {
+/*function addView(viewtype, viewname) {
     var _content = {
         type: viewtype,
         name: viewname,
@@ -639,10 +694,9 @@
     }
     gomNs.sessiondata.views.push(_content);
     debouncedSaveChanges();
-}
+}*/
 
 function animLoad() {
-    //console.log("animLoad");
     var _d = $("#waiting"),
         _w = _d.width(),
         _h = _d.height(),
@@ -718,7 +772,7 @@
             + '</div></li>'
     }).join('');
     $("#dates").html(_html);
-    $("#apartager").click(function() {
+    /*$("#apartager").click(function() {
         var _pu = $("#partageurls");
         if (_pu.is(":visible")) {
             $(this).removeClass("actif");
@@ -744,8 +798,8 @@
             }
         });
         return false;
-    })
-    $("#partagero").click(function() {
+    });*/
+    /*$("#partagero").click(function() {
         $("#partagero").addClass("actif");
         $("#partagerw").removeClass("actif");
         var _url = document.location.href.split("#")[0] + "#" + gomNs.sessionid;
@@ -760,7 +814,7 @@
         $("#zc-partageinput").val( _url.replace(/^(.{30}).{3,1000}(.{20})$/,'$1 … $2') );
         gomNs.clip.setText( _url );
         return false;
-    });
+    });*/
     $(".handle").draggable({
         "axis" : "x",
         "containment" : "parent",
@@ -780,11 +834,11 @@
                     "margin-left" : (_h1v>_h0v ? "0" : "-20px")
                 })
                 updateFilters();
-                debouncedSaveChanges();
+                //debouncedSaveChanges();
             }
         }
     });
-    $("#sessionname").click(function() {
+    /*$("#sessionname").click(function() {
         if (gomNs.write_allowed && !$(this).children().length) {
             var _el = document.createElement('input');
             _el.value = gomNs.sessiondata.title;
@@ -799,15 +853,15 @@
             _el.focus();
             _el.select();
         }
-    });
-    $("#titrevue").keyup(function() {
+    });*/
+    /*$("#titrevue").keyup(function() {
         var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view];
         _curView.name = $(this).val();
         $("#view_" + gomNs.sessiondata.view + " a").html(_.escape(_curView.name))
         $("#bloc_gestvue h2").html(gettext('Gerer la vue')+' "' + _.escape(_curView.name) + '"');
         debouncedSaveChanges();
-    });
-    $("#notes").click(function() {
+    });*/
+    /*$("#notes").click(function() {
         if (gomNs.write_allowed) {
             if (this.children[0].tagName == 'UL') {
                 var _el = document.createElement('textarea'),
@@ -823,11 +877,7 @@
                 _el.select();
             }
         }
-    });
-/*    gomNs.disChart = d3.select("#disciplines")
-        .append("svg:svg")
-        .attr("width", 475)
-        .attr("height", 120); */
+    });*/
     getInitialView();
     $(".barrebloc").click(function() {
         $(this).next().slideToggle(); 
@@ -841,7 +891,7 @@
         + '" /><label>' + $(this).find("h2").html() + '</label></li>'
     });
     _html + '</ul>';
-    $("#gestvue").append(_html);
+    /*$("#gestvue").append(_html);
     $("#nouvellevue").click(function() {
         $("#plusdevues").slideToggle();
         return false;
@@ -875,7 +925,7 @@
            displayViewList();
        }
        return false;
-    });
+    });*/
         $(" #tagform ").submit(function() {
         return false;
     });
--- a/src/hdalab/templates/facettes.html	Thu Sep 25 12:16:51 2014 +0200
+++ b/src/hdalab/templates/facettes.html	Thu Sep 25 17:14:29 2014 +0200
@@ -27,7 +27,7 @@
         gomNs.languageCode = '{{LANGUAGE_CODE}}';
         gomNs.urls = {
             'filter': "{% url 'filter' %}",
-            'session_info': "{% url 'session_info' %}",
+            {% comment %}'session_info': "{% url 'session_info' %}",{% endcomment %}
             'countries': "{% static 'hdalab/lib/countries.geo.json' %}",
             'tag_search': "{% url 'tag_search' %}",
             'datasheet': "{% url 'notice' 'ID' %}",
@@ -41,7 +41,7 @@
 
 {% block main_content %}
         <div id="titleleft">
-            <h2 id="hdatitle">{% trans "Recherche par facettes" %}&nbsp;: <span id="sessionname"></span></h2>
+            <h2 id="hdatitle">{% trans "Recherche par facettes" %}</h2>
         </div>
         <div id="titleright">
             <div id='langselect'>
@@ -54,27 +54,6 @@
                     {% endfor %}
                 </form>
             </div>
-            <div id="apartager"><a href="#">{% trans "Partager la session" %}</a></div>
-            <div id="partageurls">
-                <ul>
-                    <li class="actif" id="partagero"><a href="#">{% trans "En lecture seule" %}</a></li>
-                    <li id="partagerw"><a href="#">{% trans "En lecture-ecriture" %}</a></li>
-                </ul>
-                <div id="zc-partageligne">
-                    <label id="zc-partagelabel">{% trans "Copier le lien" %}&nbsp;: </label>
-                    <input id="zc-partageinput" onfocus="select();" />
-                </div>
-            </div>
-            <div id="vues">
-                <h4 id="vuestitre">{% trans "Mes vues :"%}</h4>
-                <ul id="ongletsvues">
-                </ul>
-                <span id="nouvellevue"><a href="#">+</a></span>
-            </div>
-            <ul id="plusdevues">
-                <li id="nouv_resrech"><a href="#">{% trans "Creer une vue sur des resultats de recherche" %}</a></li>
-                <li id="nouv_liste"><a href="#">{% trans "Creer une liste de notices" %}</a></li>
-            </ul>
         </div>
         <div id="waitcontainer">
             <div id="waiting"></div>
@@ -98,7 +77,7 @@
             </div>
         </div>
         <div id="leftcol">
-            <div id="bloc_gestvue">
+            <!--div id="bloc_gestvue">
                 <div class="barrebloc">
                     <h2>{% trans "Gerer la vue" %}</h2>
                 </div>
@@ -109,7 +88,7 @@
                     </div>
                     <h4>{% trans "Blocs visibles :" %}</h4>
                 </div>
-            </div>
+            </div-->
             <div class="bloc" id="bloc_map">
                 <div class="barrebloc">
                     <h2>{% trans "Pays" %}</h2>
@@ -141,12 +120,12 @@
             </div>
         </div>
         <div id="rightcol">
-            <div class="bloc" id="bloc_notes">
+            <!--div class="bloc" id="bloc_notes">
                 <div class="barrebloc">
                     <h2>{% trans "Notes" %}</h2>
                 </div>
                 <div id="notes" class="corpsbloc"></div>
-            </div>
+            </div-->
             <div class="bloc" id="bloc_disciplines">
                 <div class="barrebloc">
                     <h2>{% trans "Disciplines artistiques" %}</h2>
--- a/src/hdalab/urls.py	Thu Sep 25 12:16:51 2014 +0200
+++ b/src/hdalab/urls.py	Thu Sep 25 17:14:29 2014 +0200
@@ -58,7 +58,7 @@
 
 urlpatterns += patterns('hdalab.views.ajax',
     (r'^a/filter$', 'filter', {}, 'filter'),
-    (r'^a/sessioninfo$', 'sessioninfo', {}, 'session_info'),
+    #(r'^a/sessioninfo$', 'sessioninfo', {}, 'session_info'),
     (r'^a/tagsearch$', 'tagsearch', {}, 'tag_search'),
     (r'^a/catsearch$', 'catsearch', {}, 'cat_search'),
     (r'^a/cattree$', 'cattree', {}, 'cat_tree'),