hdalab/js/gomina.js
changeset 115 46c0f7a935d1
parent 110 6455b65fa3b7
child 117 dc6c3ac62efa
--- 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 = '<div id="addtofilter"><h3>'
-                + data.content_count
-                + ' contenus pour ce tag</h3><p><a href="#" onclick="filterTag($(\'#tagname\').text()); return false;">Ajouter au filtrage</a></p></div><h2 id="tagname">'
-                + data.requested_label
-                + '</h2></div>';
+            $("#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 += '<h3><a href="'
                     + data.wikipedia_url
@@ -59,88 +59,115 @@
                     }).join('')
                     + '</ul>';
             }
-            $("#taginfo").html(_html);
+            $("#tagdata").html(_html);
         });
-    $.getJSON("filter.php", _urlParam, updateDisplay);
-    if (gomNs.sessiondata.period || gomNs.sessiondata.filters.tag.length != 1 || gomNs.sessiondata.filters.tag[0] != _taglabel) {
-        $("#bandefiltre").addClass("inactif");
-        $("#showsearch").removeClass("actif");
-    } else {
-        $("#bandefiltre").removeClass("inactif");
-        $("#showsearch").addClass("actif");
-    }
+    filterTag(_taglabel);
     $("#showlist").removeClass("actif");
 }
 
 function filterTag(_tagLabel) {
-    gomNs.sessiondata.filters.tag.push(_tagLabel);
-    updateFilters();
-    debouncedSaveChanges();
+    var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view];
+    if (_curView.type == 'filter') {
+        _curView.tag.push(_tagLabel);
+        updateFilters();
+        debouncedSaveChanges();
+    }
 }
 
 function removeFilter(_index) {
-    gomNs.sessiondata.filters.tag.splice(_index,1);
-    updateFilters();
-    debouncedSaveChanges();
-}
-
-function removePeriod() {
-    $("#dateslider").slider("values",0,0).slider("values",1,gomNs.tlPixels).slideUp();
-    gomNs.sessiondata.filters.period = null;
-    updateFilters();
-    debouncedSaveChanges();
+    var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view];
+    if (_curView.type == 'filter') {
+        _curView.tag.splice(_index,1);
+        updateFilters();
+        debouncedSaveChanges();
+    }
 }
 
 function getUpdates() {
-    var _params = {};
-    if (gomNs.sessiondata.filters.period) {
-        _params.period = gomNs.sessiondata.filters.period.join(',');
+    var _params = {},
+        _curView = gomNs.sessiondata.views[gomNs.sessiondata.view];
+    if (_curView.type == 'filter') {
+        if (_curView.period && !(_curView.period[0] == gomNs.minYear && _curView.period[1] == gomNs.maxYear)) {
+            _params.period = _curView.period.join(',');
+        }
+        if (_curView.tag.length) {
+            _params.label = _curView.tag.join(',');
+        }
+        $.getJSON("filter.php", _params, updateDisplay);
     }
-    if (gomNs.sessiondata.filters.tag.length) {
-        _params.label = gomNs.sessiondata.filters.tag.join(',');
-    }
-    $.getJSON("filter.php", _params, updateDisplay);
 }
 
-var debouncedGetUpdates = _.debounce(getUpdates, 200);
+var debouncedGetUpdates = _.debounce(getUpdates, 300);
 
 function updatePeriod(_n, _val) {
-    var _int = parseInt(_val);
-    if (_int != NaN) {
-        gomNs.sessiondata.filters.period[_n] = _int;
-        updateFilters();
-        debouncedSaveChanges();
-        debouncedHideSlider();
+    var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view];
+    if (_curView.type == 'filter') {
+        var _int = parseInt(_val);
+        if (_int != NaN) {
+            if ((_n == 1 && _val >= _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 = '<li class="nofilter">Aucun filtre</li>';
     }
+    if (_curView.period) {
+        _htmFilters += '<li class="filperiod"><span class="spyr" id="sp_0" onclick="changeSpan(this);">'
+            + _curView.period[0]
+            + '</span> à <span class="spyr" id="sp_1" onclick="changeSpan(this);">'
+            + _curView.period[1]
+            + '</span></li>';
+        $("#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 '<li class="filtag">'
                 + _t
                 + '<a href="#" class="remfil" onclick="removeFilter('
@@ -148,19 +175,7 @@
                 + '); return false;">[x]</a></li>'; 
         }).join("");
     }
-    if (gomNs.sessiondata.filters.period) {
-        _htmFilters += '<li class="filperiod" onclick="$(\'#dateslider\').show(); debouncedHideSlider();"><span class="spyr" id="sp_0" onclick="changeSpan(this);">'
-            + gomNs.sessiondata.filters.period[0]
-            + '</span>-<span class="spyr" id="sp_1" onclick="changeSpan(this);">'
-            + gomNs.sessiondata.filters.period[1]
-            + '</span><a href="#" class="remfil" onclick="removePeriod(); return false;">[x]</a></li>';
-        $("#dateslider").slider("values",0,yearToPx(gomNs.sessiondata.filters.period[0]))
-            .slider("values",1,yearToPx(gomNs.sessiondata.filters.period[1]));
-    } else {
-        _htmFilters += '<li><a href="#" onclick="$(\'#dateslider\').show(); debouncedHideSlider(); return false;">Filtrer par période</a></li>';
-    }
     $("#filters").html(_htmFilters);
-    $("#bandefiltre").attr("class","");
     debouncedGetUpdates();
 }
 
@@ -168,7 +183,7 @@
     if (contentdata && contentdata.length) {
         var _htmlCl = '<ul id="contentlist">'
             + contentdata.map(function(_d) {
-                return '<li class="content-item"><h3>'
+                var _html = '<li class="content-item"><h3>'
                     + _d.title
                     + '</h3><h4><a href="'
                     + _d.url
@@ -188,27 +203,38 @@
                     + _d.id
                     + '"><ul><li>'
                     + (gomNs.sessiondata.annotations[_d.id] && gomNs.sessiondata.annotations[_d.id].texte ? gomNs.sessiondata.annotations[_d.id].texte.replace(/\n/gm,"</p><p>") : 'Annoter ce contenu...')
-                    + '</li></ul></div>'
-                    + ( gomNs.write_allowed
-                        ? '<p><a href="#" class="addremlist" contentid="'
-                            + _d.id
-                            + '">'
-                            + ( gomNs.sessiondata.liste.indexOf(_d.id) == -1 ? 'Ajouter à ma liste' : 'Retirer de ma liste' )
-                            + '</a></p>'
-                        : '' )
-                    + '</li>';
+                    + '</li></ul></div>';
+                if (gomNs.write_allowed) {
+                    _(gomNs.sessiondata.views).each(function(_view, _k) {
+                        if (_view.type == 'list') {
+                            _html += '<p><a href="#" class="addremlist" contentid="'
+                                + _d.id
+                                + '" viewid="'
+                                + _k
+                                + '">'
+                                + ( _view.list.indexOf(_d.id) == -1 ? 'Ajouter à' : 'Retirer de' )
+                                + ' "'
+                                + _.escape(_view.name)
+                                + '"</a></p>'
+                        }
+                    });
+                }
+                _html += '</li>';
+                return _html;
             }).join('')
             + '</ul>';
         $("#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 = '<ul><li>' + (this.value.length ? gomNs.sessiondata.annotations[_id].texte.replace(/\n/gm,"</li><li>") : 'Annoter ce contenu...' ) + '</ul>';
+                        debouncedSaveChanges();
+                    });
+                    $(this).html(_el);
+                    _el.focus();
+                    _el.select();
                 }
-                gomNs.sessiondata.annotations[_id].texte = _.escape(this.value);
-                this.parentNode.innerHTML = '<ul><li>' + (this.value.length ? gomNs.sessiondata.annotations[_id].texte.replace(/\n/gm,"</li><li>") : 'Annoter ce contenu...' ) + '</ul>';
-                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 ? '' : '<span class="lectseul"> (lecture seule)</span>' ) );
+        $("#ongletsvues").html(gomNs.sessiondata.views.map(function(_v, _k) {
+            return '<li class="lienvue" id="view_'
+                + _k
+                + '" onclick="changeView('
+                + _k
+                + '); return false;"><a href="#">'
+                + _.escape(_v.name)
+                + '</a></li>';
+        }).join(""))
+        if (data.write_allowed) {
+            $("#bloc_gestvue").show();
+        } else {
+            $("#bloc_gestvue").hide();
+        }
+        $("#sessionname").html(gomNs.sessiondata.title
+            + ( data.write_allowed ? '' : '<span class="lectseul"> (lecture seule)</span>' ) );
         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 '<li style="left: '
+            + parseInt(yearToPx(_v))
+            + 'px"><div class="datelabel">'
+            + _v
+            + '</div></li>'
+    }).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 = '<ul id="widgetlist">';
+    $("div.bloc").each(function() {
+       gomNs.widgetList.push(this.id);
+       _html += '<li><input type="checkbox" id="chbx_'
+        + this.id
+        + '" /><label>' + $(this).find("h2").html() + '</label></li>'
     });
-    getInitialView();
+    _html + '</ul>';
+    $("#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();
+    })
 });