Set discours querystring from controller
authorChloe Laisne <chloe.laisne@gmail.com>
Fri, 10 Jun 2016 16:46:41 +0200
changeset 184 558a3522343c
parent 183 cc8b022088c8
child 185 191883bd16a6
Set discours querystring from controller
cms/app-client/app/components/discourses-component.js
cms/app-client/app/controllers/tabs/discours.js
cms/app-client/app/templates/tabs/discours.hbs
--- a/cms/app-client/app/components/discourses-component.js	Fri Jun 10 16:19:25 2016 +0200
+++ b/cms/app-client/app/components/discourses-component.js	Fri Jun 10 16:46:41 2016 +0200
@@ -48,7 +48,7 @@
                 .style("position", "absolute")
                 .style("left", function(d) { return d.x - Math.max(10 + d.r, d.r) + 'px'; })
                 .style("top", function(d) { return d.y - Math.max(10 + d.r, d.r) + 'px'; })
-                .on('click', function(d) { document.location = self.setQueryString('discours', d.name); });
+                .on('click', function(d) { self.get('setQueryParameters')(d.name); });
             
             item.append("span")
                 .text(function(d) { return d.name; })
@@ -73,7 +73,7 @@
                 .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
 
             var leaf = svg.selectAll(".leaf")
-                .on('click', function(d) { document.location = self.setQueryString('discours', d.name); });
+                .on('click', function(d) { self.get('setQueryParameters')(d.name); });
             
             leaf.append("circle")
                 .attr("r", function(d) { return Math.max(7.5 + d.r * 2, d.r * 2); })
@@ -108,29 +108,6 @@
         });
 
         return nodes;
-    },
-
-    setQueryString: function(field, value) {
-        var hash = document.location.href.split('?');
-        var query_parameters = hash.length > 1 ? hash.pop() : '';
-
-        // Unserialize
-        var parameters = [];
-        query_parameters.split('&').forEach(function(parameter){
-            var object = parameter.split('=');
-            if(object[1]) {
-                parameters[object[0]] = object[1];
-            }
-        });
-
-        // Serialize
-        var string = [];
-        parameters[field] = encodeURI(value);
-        Object.keys(parameters).forEach(function(key) {
-            string.push(key + '=' + parameters[key]);
-        });
-
-        return hash + '?' + string.join('&');
     }
     
 });
--- a/cms/app-client/app/controllers/tabs/discours.js	Fri Jun 10 16:19:25 2016 +0200
+++ b/cms/app-client/app/controllers/tabs/discours.js	Fri Jun 10 16:46:41 2016 +0200
@@ -1,5 +1,11 @@
 import Ember from 'ember';
 
 export default Ember.Controller.extend({
-	
+
+    actions: {
+        transitionTo: function(id) {
+            this.transitionToRoute({ queryParams: { 'discours': id } });
+        }   
+    }
+    
 });
--- a/cms/app-client/app/templates/tabs/discours.hbs	Fri Jun 10 16:19:25 2016 +0200
+++ b/cms/app-client/app/templates/tabs/discours.hbs	Fri Jun 10 16:46:41 2016 +0200
@@ -1,1 +1,1 @@
-{{discourses-component}}
\ No newline at end of file
+{{discourses-component setQueryParameters=( action 'transitionTo' ) }}
\ No newline at end of file