- add option to prevent url parameters behavior
authorrougeronj
Thu, 24 Sep 2015 13:31:13 +0200
changeset 547 0ce3dcdf24f7
parent 546 6fd067e988d7
child 548 f5cd65589fa7
- add option to prevent url parameters behavior - on load, in case there is no view in the project, create and save one autoscaled
client/js/defaults.js
client/js/renderer/scene.js
client/js/renderer/viewrepr.js
--- a/client/js/defaults.js	Tue Sep 22 15:35:43 2015 +0200
+++ b/client/js/defaults.js	Thu Sep 24 13:31:13 2015 +0200
@@ -52,7 +52,9 @@
     default_index_view: -1,
     
     /* URL parsing */
-    update_url:true,
+    url_parameters: true,
+        /* accept or not hash parameters in the url */
+    update_url: true,
         /* update the url each time the paper shift or on zoom in/out, with the serialized view (offset and scale) */
     
 
--- a/client/js/renderer/scene.js	Tue Sep 22 15:35:43 2015 +0200
+++ b/client/js/renderer/scene.js	Thu Sep 24 13:31:13 2015 +0200
@@ -330,7 +330,11 @@
         });
         
         this.renkan.project.on("loaded", function(){
-            Backbone.history.start();
+            if (_this.renkan.options.url_parameters){
+                Backbone.history.start();                
+            } else {
+                _this.fixSize();
+            }
             _this.redrawActive = true;
             _thRedraw();
         });
@@ -490,12 +494,9 @@
     _(Scene.prototype).extend({
         fixSize: function() {
             if(typeof this.view === 'undefined') {
-                this.view = this.addRepresentation("View", this.renkan.project.get("views").last());
-                this.view.setScale(view.get("zoom_level"), new paper.Point(view.get("offset")));
+                this.view = this.addRepresentation("View", this.renkan.project.get("views").first());
             }
-            else{
-                this.view.autoScale();
-            }
+            this.view.autoScale();
         },
         drawSector: function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) {
             var _options = this.renkan.options,
@@ -1232,7 +1233,7 @@
                 } else{
                     this.view = this.addRepresentation("View", null);
                     this.view.params = params;
-                    this.view.init();
+                    this.view.initWithParams();
                 }
             }
             if (!this.view){
--- a/client/js/renderer/viewrepr.js	Tue Sep 22 15:35:43 2015 +0200
+++ b/client/js/renderer/viewrepr.js	Thu Sep 24 13:31:13 2015 +0200
@@ -28,7 +28,7 @@
                 };
             }
                 
-            this.init();
+            this.initWithParams();
             
             var bindClick = function(selector, fname) {
                 _this.$.find(selector).click(function(evt) {
@@ -40,20 +40,7 @@
             bindClick(".Rk-ZoomOut", "zoomOut");
             bindClick(".Rk-ZoomIn", "zoomIn");
             bindClick(".Rk-ZoomFit", "autoScale");
-            
-            this.$.find(".Rk-ZoomSave").click( function() {
-                var offset = {
-                    "x": _this.offset.x,
-                    "y": _this.offset.y
-                };
-                _this.model = _this.renkan.project.addView( { zoom_level:_this.scale, offset:offset, hidden_nodes: _this.hiddenNodes.concat() } );
-                _this.params = {
-                        "zoom_level": _this.model.get("zoom_level"),
-                        "offset": _this.model.get("offset"),
-                        "hidden_nodes": _this.model.get("hidden_nodes")
-                };
-                _this.updateUrl();
-            });
+            bindClick(".Rk-ZoomSave", "saveView");
             
             this.$.find(".Rk-ZoomSetSaved").click( function() {
                 _this.model = _this.renkan.project.get("views").at(_this.renkan.project.get("views").length -1);
@@ -88,14 +75,36 @@
         redraw: function(options) {
             //console.log("view : ", this.model.toJSON());
         },
-        init: function(){
+        initWithParams: function(){
             var _this = this;
+
             _this.setScale(_this.params.zoom_level, new paper.Point(_this.params.offset));
             
             if (_this.options.hide_nodes){
                 _this.hiddenNodes = (_this.params.hidden_nodes || []).concat();
                 _this.hideNodes();
             }
+
+            if (_this.renkan.project.get("views").length === 0){
+                _this.saveView();
+            }
+        },
+        saveView: function(){
+            var _this = this;
+            
+            var offset = {
+                "x": _this.offset.x,
+                "y": _this.offset.y
+            };
+            
+            _this.model = _this.renkan.project.addView( { zoom_level:_this.scale, offset:offset, hidden_nodes: _this.hiddenNodes.concat() } );
+            _this.params = {
+                    "zoom_level": _this.model.get("zoom_level"),
+                    "offset": _this.model.get("offset"),
+                    "hidden_nodes": _this.model.get("hidden_nodes")
+            };
+            
+            _this.updateUrl();
         },
         addHiddenNode: function(_model){
             this.hideNode(_model);