cms/app-client/app/components/discourses-component.js
changeset 184 558a3522343c
parent 183 cc8b022088c8
child 185 191883bd16a6
equal deleted inserted replaced
183:cc8b022088c8 184:558a3522343c
    46                 .style("width", function(d) { return Math.max(10 + d.r, d.r) * 2 + 'px'; })
    46                 .style("width", function(d) { return Math.max(10 + d.r, d.r) * 2 + 'px'; })
    47                 .style("height", function(d) { return Math.max(10 + d.r, d.r) * 2 + 'px'; })
    47                 .style("height", function(d) { return Math.max(10 + d.r, d.r) * 2 + 'px'; })
    48                 .style("position", "absolute")
    48                 .style("position", "absolute")
    49                 .style("left", function(d) { return d.x - Math.max(10 + d.r, d.r) + 'px'; })
    49                 .style("left", function(d) { return d.x - Math.max(10 + d.r, d.r) + 'px'; })
    50                 .style("top", function(d) { return d.y - Math.max(10 + d.r, d.r) + 'px'; })
    50                 .style("top", function(d) { return d.y - Math.max(10 + d.r, d.r) + 'px'; })
    51                 .on('click', function(d) { document.location = self.setQueryString('discours', d.name); });
    51                 .on('click', function(d) { self.get('setQueryParameters')(d.name); });
    52             
    52             
    53             item.append("span")
    53             item.append("span")
    54                 .text(function(d) { return d.name; })
    54                 .text(function(d) { return d.name; })
    55                 .style("text-align", "center")
    55                 .style("text-align", "center")
    56                 .style("display", function(d) { return d.children ? 'none' : 'inline-block'; })
    56                 .style("display", function(d) { return d.children ? 'none' : 'inline-block'; })
    71             svg_nodes.enter().append("g")
    71             svg_nodes.enter().append("g")
    72                 .attr("class", function(d) { return "node" + (!d.children ? " leaf" : ""); })
    72                 .attr("class", function(d) { return "node" + (!d.children ? " leaf" : ""); })
    73                 .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
    73                 .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
    74 
    74 
    75             var leaf = svg.selectAll(".leaf")
    75             var leaf = svg.selectAll(".leaf")
    76                 .on('click', function(d) { document.location = self.setQueryString('discours', d.name); });
    76                 .on('click', function(d) { self.get('setQueryParameters')(d.name); });
    77             
    77             
    78             leaf.append("circle")
    78             leaf.append("circle")
    79                 .attr("r", function(d) { return Math.max(7.5 + d.r * 2, d.r * 2); })
    79                 .attr("r", function(d) { return Math.max(7.5 + d.r * 2, d.r * 2); })
    80                 .attr("fill", function(d) { return d.fill; })
    80                 .attr("fill", function(d) { return d.fill; })
    81                 .attr("stroke", function() { return "#000"; });
    81                 .attr("stroke", function() { return "#000"; });
   106         Object.keys(children).forEach(function(key) {
   106         Object.keys(children).forEach(function(key) {
   107             nodes.children.push(children[key]);
   107             nodes.children.push(children[key]);
   108         });
   108         });
   109 
   109 
   110         return nodes;
   110         return nodes;
   111     },
       
   112 
       
   113     setQueryString: function(field, value) {
       
   114         var hash = document.location.href.split('?');
       
   115         var query_parameters = hash.length > 1 ? hash.pop() : '';
       
   116 
       
   117         // Unserialize
       
   118         var parameters = [];
       
   119         query_parameters.split('&').forEach(function(parameter){
       
   120             var object = parameter.split('=');
       
   121             if(object[1]) {
       
   122                 parameters[object[0]] = object[1];
       
   123             }
       
   124         });
       
   125 
       
   126         // Serialize
       
   127         var string = [];
       
   128         parameters[field] = encodeURI(value);
       
   129         Object.keys(parameters).forEach(function(key) {
       
   130             string.push(key + '=' + parameters[key]);
       
   131         });
       
   132 
       
   133         return hash + '?' + string.join('&');
       
   134     }
   111     }
   135     
   112     
   136 });
   113 });