client/js/renderer/viewrepr.js
changeset 510 a8f02d66bf02
parent 508 dd526b1b283a
child 511 4a48a1a9fd1e
equal deleted inserted replaced
509:53260578072d 510:a8f02d66bf02
    16             this.type = "View";
    16             this.type = "View";
    17             this.hiddenNodes = [];
    17             this.hiddenNodes = [];
    18             this.scale = 1;
    18             this.scale = 1;
    19             this.initialScale = 1;
    19             this.initialScale = 1;
    20             this.offset = paper.view.center;
    20             this.offset = paper.view.center;
       
    21             this.params = {};
       
    22             
       
    23             if (this.model){
       
    24                 this.params = {
       
    25                     "zoom_level": _this.model.get("zoom_level"),
       
    26                     "offset": _this.model.get("offset"),
       
    27                     "hidden_nodes": _this.model.get("hidden_nodes")
       
    28                 };
       
    29             }
       
    30                 
       
    31             this.init();
    21             
    32             
    22             var bindClick = function(selector, fname) {
    33             var bindClick = function(selector, fname) {
    23                 _this.$.find(selector).click(function(evt) {
    34                 _this.$.find(selector).click(function(evt) {
    24                     _this[fname](evt);
    35                     _this[fname](evt);
    25                     return false;
    36                     return false;
    29             bindClick(".Rk-ZoomOut", "zoomOut");
    40             bindClick(".Rk-ZoomOut", "zoomOut");
    30             bindClick(".Rk-ZoomIn", "zoomIn");
    41             bindClick(".Rk-ZoomIn", "zoomIn");
    31             bindClick(".Rk-ZoomFit", "autoScale");
    42             bindClick(".Rk-ZoomFit", "autoScale");
    32             
    43             
    33             this.$.find(".Rk-ZoomSave").click( function() {
    44             this.$.find(".Rk-ZoomSave").click( function() {
    34                 var offset = {};
    45                 var offset = {
    35                 offset.x = _this.offset.x;
    46                     "x": _this.offset.x,
    36                 offset.y = _this.offset.y;
    47                     "y": _this.offset.y
    37                 _this.model.set( { zoom_level:_this.scale, offset:offset, hidden_nodes: _this.hiddenNodes.concat() } );
    48                 };
       
    49                 //TODO: make the if else the same function
       
    50                 if (_this.model){
       
    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 = {
       
    56                         "zoom_level": _this.model.get("zoom_level"),
       
    57                         "offset": _this.model.get("offset"),
       
    58                         "hidden_nodes": _this.model.get("hidden_nodes")
       
    59                 };
    38             });
    60             });
    39             
    61             
    40             this.$.find(".Rk-ZoomSetSaved").click( function() {
    62             this.$.find(".Rk-ZoomSetSaved").click( function() {
    41                 if(_this.model){
    63                 _this.setScale(_this.params.zoom_level, new paper.Point(_this.params.offset));
    42                     _this.setScale(_this.model.get("zoom_level"), new paper.Point(_this.model.get("offset")));
    64                 _this.showNodes(false);
    43                     _this.showNodes(false);
    65                 if (_this.options.hide_nodes){
    44                     if (_this.options.hide_nodes){
    66                     _this.hiddenNodes = (_this.params.hidden_nodes || []).concat();
    45                         _this.hiddenNodes = (_this.model.get("hidden_nodes") || []).concat();
    67                     _this.hideNodes();
    46                         _this.hideNodes();
       
    47                     }
       
    48                 }
    68                 }
    49             });
    69             });
    50             
    70             
    51             this.$.find(".Rk-ShowHiddenNodes").mouseenter( function() {
    71             this.$.find(".Rk-ShowHiddenNodes").mouseenter( function() {
    52                 _this.showNodes(true);
    72                 _this.showNodes(true);
    61             if(this.renkan.project.get("views").length > 0 && this.renkan.options.save_view){
    81             if(this.renkan.project.get("views").length > 0 && this.renkan.options.save_view){
    62                 this.$.find(".Rk-ZoomSetSaved").show();
    82                 this.$.find(".Rk-ZoomSetSaved").show();
    63             }
    83             }
    64         },
    84         },
    65         redraw: function(options) {
    85         redraw: function(options) {
    66             //console.log("redraw view repr");
    86             //console.log("view : ", this.model.toJSON());
       
    87         },
       
    88         init: function(){
       
    89             var _this = this;
       
    90             _this.setScale(_this.params.zoom_level, new paper.Point(_this.params.offset));
       
    91             _this.showNodes(false);
       
    92             if (_this.options.hide_nodes){
       
    93                 _this.hiddenNodes = (_this.params.hidden_nodes || []).concat();
       
    94                 _this.hideNodes();
       
    95             }
    67         },
    96         },
    68         addHiddenNode: function(_model){
    97         addHiddenNode: function(_model){
    69             this.hideNode(_model);
    98             this.hideNode(_model);
    70             this.hiddenNodes.push(_model.id);
    99             this.hiddenNodes.push(_model.id);
    71         },
   100         },
    97             paper.view.draw();
   126             paper.view.draw();
    98         },
   127         },
    99         setScale: function(_newScale, _offset) {
   128         setScale: function(_newScale, _offset) {
   100             if ((_newScale/this.initialScale) > Utils._MIN_SCALE && (_newScale/this.initialScale) < Utils._MAX_SCALE) {
   129             if ((_newScale/this.initialScale) > Utils._MIN_SCALE && (_newScale/this.initialScale) < Utils._MAX_SCALE) {
   101                 this.scale = _newScale;
   130                 this.scale = _newScale;
   102                 this.renderer.scale = _newScale;
       
   103                 if (_offset) {
   131                 if (_offset) {
   104                     this.offset = _offset;
   132                     this.offset = _offset;
   105                     this.renderer.offset = _offset;
       
   106                 }
   133                 }
   107                 this.renderer.redraw();
   134                 this.renderer.redraw();
   108             }
   135             }
   109         },
   136         },
   110         zoomOut: function() {
   137         zoomOut: function() {