client/js/renderer/viewrepr.js
changeset 524 904effa4b6d7
parent 521 0d9b3f1b97e7
child 525 03aa989092bb
equal deleted inserted replaced
523:dc04aa440c11 524:904effa4b6d7
    44             this.$.find(".Rk-ZoomSave").click( function() {
    44             this.$.find(".Rk-ZoomSave").click( function() {
    45                 var offset = {
    45                 var offset = {
    46                     "x": _this.offset.x,
    46                     "x": _this.offset.x,
    47                     "y": _this.offset.y
    47                     "y": _this.offset.y
    48                 };
    48                 };
    49                 //TODO: make the if else the same function
    49                 _this.model = _this.renkan.project.addView( { zoom_level:_this.scale, offset:offset, hidden_nodes: _this.hiddenNodes.concat() } );
    50                 if (_this.model && _this.renkan.project.get("views").indexOf(_this.model) > 0){
       
    51                     _this.model.set( { zoom_level:_this.scale, offset:offset, hidden_nodes: _this.hiddenNodes.concat() } );
       
    52                 }else{
       
    53                     _this.model = _this.renkan.project.addView( { zoom_level:_this.scale, offset:offset, hidden_nodes: _this.hiddenNodes.concat() } );
       
    54                 }
       
    55                 _this.params = {
    50                 _this.params = {
    56                         "zoom_level": _this.model.get("zoom_level"),
    51                         "zoom_level": _this.model.get("zoom_level"),
    57                         "offset": _this.model.get("offset"),
    52                         "offset": _this.model.get("offset"),
    58                         "hidden_nodes": _this.model.get("hidden_nodes")
    53                         "hidden_nodes": _this.model.get("hidden_nodes")
    59                 };
    54                 };
    60                 _this.updateUrl();
    55                 _this.updateUrl();
    61             });
    56             });
    62             
    57             
    63             this.$.find(".Rk-ZoomSetSaved").click( function() {
    58             this.$.find(".Rk-ZoomSetSaved").click( function() {
       
    59                 _this.model = _this.renkan.project.get("views").at(_this.renkan.project.get("views").length -1);
       
    60                 _this.params = {
       
    61                         "zoom_level": _this.model.get("zoom_level"),
       
    62                         "offset": _this.model.get("offset"),
       
    63                         "hidden_nodes": _this.model.get("hidden_nodes")
       
    64                 };
    64                 _this.setScale(_this.params.zoom_level, new paper.Point(_this.params.offset));
    65                 _this.setScale(_this.params.zoom_level, new paper.Point(_this.params.offset));
    65                 _this.showNodes(false);
    66                 _this.showNodes(false);
    66                 if (_this.options.hide_nodes){
    67                 if (_this.options.hide_nodes){
    67                     _this.hiddenNodes = (_this.params.hidden_nodes || []).concat();
    68                     _this.hiddenNodes = (_this.params.hidden_nodes || []).concat();
    68                     _this.hideNodes();
    69                     _this.hideNodes();
    69                 }
    70                 }
       
    71                 _this.updateUrl();
    70             });
    72             });
    71             
    73             
    72             this.$.find(".Rk-ShowHiddenNodes").mouseenter( function() {
    74             this.$.find(".Rk-ShowHiddenNodes").mouseenter( function() {
    73                 _this.showNodes(true);
    75                 _this.showNodes(true);
    74                 _this.$.find(".Rk-ShowHiddenNodes").mouseleave( function() {
    76                 _this.$.find(".Rk-ShowHiddenNodes").mouseleave( function() {
    87             //console.log("view : ", this.model.toJSON());
    89             //console.log("view : ", this.model.toJSON());
    88         },
    90         },
    89         init: function(){
    91         init: function(){
    90             var _this = this;
    92             var _this = this;
    91             _this.setScale(_this.params.zoom_level, new paper.Point(_this.params.offset));
    93             _this.setScale(_this.params.zoom_level, new paper.Point(_this.params.offset));
    92             _this.showNodes(false);
    94             
    93             if (_this.options.hide_nodes){
    95             if (_this.options.hide_nodes){
    94                 _this.hiddenNodes = (_this.params.hidden_nodes || []).concat();
    96                 _this.hiddenNodes = (_this.params.hidden_nodes || []).concat();
    95                 _this.hideNodes();
    97                 _this.hideNodes();
    96             }
    98             }
    97         },
    99         },
   200                 }
   202                 }
   201                 result.view = Math.round(this.offset.x*1000)/1000 + ',' + Math.round(this.offset.y*1000)/1000 + ',' + Math.round(this.scale*1000)/1000;
   203                 result.view = Math.round(this.offset.x*1000)/1000 + ',' + Math.round(this.offset.y*1000)/1000 + ',' + Math.round(this.scale*1000)/1000;
   202 
   204 
   203                 if (this.renkan.project.get("views").indexOf(this.model) > -1){
   205                 if (this.renkan.project.get("views").indexOf(this.model) > -1){
   204                     result.idView = this.renkan.project.get("views").indexOf(this.model);
   206                     result.idView = this.renkan.project.get("views").indexOf(this.model);
       
   207                     if (result.idView === this.renkan.project.get("views").length - 1){
       
   208                         result.idView = -1;
       
   209                     }
   205                 } else {
   210                 } else {
   206                     if (result.idView){
   211                     if (result.idView){
   207                         delete result.idView;
   212                         delete result.idView;
   208                     }
   213                     }
   209                 }
   214                 }
   210                 this.renkan.router.navigate("?" + decodeURIComponent($.param(result)), {trigger: false, replace: true});
   215                 this.renkan.router.navigate("?" + decodeURIComponent($.param(result)), {trigger: false, replace: true});
   211             }
   216             }
   212         },
   217         },
       
   218         destroy: function(_event) {
       
   219             this._super("destroy");
       
   220             this.showNodes(false);
       
   221         }
   213     }).value();
   222     }).value();
   214 
   223 
   215     return ViewRepr;
   224     return ViewRepr;
   216 
   225 
   217 });
   226 });