# HG changeset patch # User rougeronj # Date 1435248589 -7200 # Node ID a8f02d66bf022980f614b4edb27f846e1b232e9d # Parent 53260578072da548885b36314fe4d285e59424d6 adapt the viewRepr to support a temp View (a representation without a model) update the router to send a event also if the parameters are null diff -r 53260578072d -r a8f02d66bf02 client/js/renderer/scene.js --- a/client/js/renderer/scene.js Wed Jun 24 17:15:51 2015 +0200 +++ b/client/js/renderer/scene.js Thu Jun 25 18:09:49 2015 +0200 @@ -337,7 +337,6 @@ }, 3000); } else{ - _this.view = _this.addRepresentation("View", _this.renkan.project.get("views").last()); Backbone.history.start(); _thRedraw(); } @@ -366,14 +365,6 @@ _thRedraw(); } }); -// this.renkan.project.on("add:views", function(_view) { -// if (!_this.view){ -// _this.view = _this.addRepresentation("View", _view); -// } -// if (!_this.renkan.project.get("loadingStatus")){ -// _thRedraw(); -// } -// }); this.renkan.project.on("change:title", function(_model, _title) { var el = _this.$.find(".Rk-PadTitle"); if (el.is("input")) { @@ -496,12 +487,12 @@ _(Scene.prototype).extend({ fixSize: function() { - if( this.renkan.options.default_view && this.view) { - this.view.setScale(view.get("zoom_level"), new paper.Point(view.get("offset"))); - } - else{ - this.view.autoScale(); - } +// if(typeothis.view) { +// this.view.setScale(view.get("zoom_level"), new paper.Point(view.get("offset"))); +// } +// else{ +// this.view.autoScale(); +// } }, drawSector: function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) { var _options = this.renkan.options, @@ -693,7 +684,7 @@ var RendererType = requtils.getRenderer()[_type]; var _repr = new RendererType(this, _model); this.representations.push(_repr); - return _repr; + return _repr; }, addRepresentations: function(_type, _collection) { var _this = this; @@ -1212,10 +1203,44 @@ }, parameters: function(_params){ + if ($.isEmptyObject(_params)){ + this.view = this.addRepresentation("View", this.renkan.project.get("views").last()); + return; + } if (typeof _params.idnode !== 'undefined'){ + console.log('params idnode'); this.unhighlightAll(); this.highlightModel(this.renkan.project.get("nodes").get(_params.idnode)); } + if (typeof _params.view !== 'undefined'){ + var viewParams = _params.view.split(","); + if (viewParams.length >= 3){ + var params = { + "project": this.renkan.project, + "zoom_level": parseFloat(viewParams[0]), + "offset": { + "x": parseFloat(viewParams[1]), + "y": parseFloat(viewParams[2]) + }, + "hidden_nodes": [] + }; + for (var i = 3; i < viewParams.length; i++){ + params.hidden_nodes.push(viewParams[i]); + } + //var view = new Rkns.Models.View(params); + + if (this.view){ + this.view.showNodes(false); + this.removeRepresentation(this.view); + } + + this.view = this.addRepresentation("View", null); + this.view.params = params; + this.view.init(); + } else { + this.view = this.addRepresentation("View", this.renkan.project.get("views").last()); + } + } }, foldBins: function() { var foldBinsButton = this.$.find(".Rk-Fold-Bins"), diff -r 53260578072d -r a8f02d66bf02 client/js/renderer/viewrepr.js --- a/client/js/renderer/viewrepr.js Wed Jun 24 17:15:51 2015 +0200 +++ b/client/js/renderer/viewrepr.js Thu Jun 25 18:09:49 2015 +0200 @@ -18,6 +18,17 @@ this.scale = 1; this.initialScale = 1; this.offset = paper.view.center; + this.params = {}; + + if (this.model){ + this.params = { + "zoom_level": _this.model.get("zoom_level"), + "offset": _this.model.get("offset"), + "hidden_nodes": _this.model.get("hidden_nodes") + }; + } + + this.init(); var bindClick = function(selector, fname) { _this.$.find(selector).click(function(evt) { @@ -31,20 +42,29 @@ bindClick(".Rk-ZoomFit", "autoScale"); this.$.find(".Rk-ZoomSave").click( function() { - var offset = {}; - offset.x = _this.offset.x; - offset.y = _this.offset.y; - _this.model.set( { zoom_level:_this.scale, offset:offset, hidden_nodes: _this.hiddenNodes.concat() } ); + var offset = { + "x": _this.offset.x, + "y": _this.offset.y + }; + //TODO: make the if else the same function + if (_this.model){ + _this.model.set( { zoom_level:_this.scale, offset:offset, hidden_nodes: _this.hiddenNodes.concat() } ); + }else{ + _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.$.find(".Rk-ZoomSetSaved").click( function() { - if(_this.model){ - _this.setScale(_this.model.get("zoom_level"), new paper.Point(_this.model.get("offset"))); - _this.showNodes(false); - if (_this.options.hide_nodes){ - _this.hiddenNodes = (_this.model.get("hidden_nodes") || []).concat(); - _this.hideNodes(); - } + _this.setScale(_this.params.zoom_level, new paper.Point(_this.params.offset)); + _this.showNodes(false); + if (_this.options.hide_nodes){ + _this.hiddenNodes = (_this.params.hidden_nodes || []).concat(); + _this.hideNodes(); } }); @@ -63,7 +83,16 @@ } }, redraw: function(options) { - //console.log("redraw view repr"); + //console.log("view : ", this.model.toJSON()); + }, + init: function(){ + var _this = this; + _this.setScale(_this.params.zoom_level, new paper.Point(_this.params.offset)); + _this.showNodes(false); + if (_this.options.hide_nodes){ + _this.hiddenNodes = (_this.params.hidden_nodes || []).concat(); + _this.hideNodes(); + } }, addHiddenNode: function(_model){ this.hideNode(_model); @@ -99,10 +128,8 @@ setScale: function(_newScale, _offset) { if ((_newScale/this.initialScale) > Utils._MIN_SCALE && (_newScale/this.initialScale) < Utils._MAX_SCALE) { this.scale = _newScale; - this.renderer.scale = _newScale; if (_offset) { this.offset = _offset; - this.renderer.offset = _offset; } this.renderer.redraw(); } diff -r 53260578072d -r a8f02d66bf02 client/js/router.js --- a/client/js/router.js Wed Jun 24 17:15:51 2015 +0200 +++ b/client/js/router.js Thu Jun 25 18:09:49 2015 +0200 @@ -11,14 +11,13 @@ index: function (parameters) { var result = {}; - if (parameters === null){ - return; + if (parameters !== null){ + parameters.split("&").forEach(function(part) { + var item = part.split("="); + result[item[0]] = decodeURIComponent(item[1]); + }); } - parameters.split("&").forEach(function(part) { - var item = part.split("="); - result[item[0]] = decodeURIComponent(item[1]); - }); - this.trigger('router', result); + this.trigger('router', result); } });