client/js/renderer/viewrepr.js
author rougeronj
Thu, 18 Jun 2015 17:18:00 +0200
changeset 506 460de050f800
child 508 dd526b1b283a
permissions -rw-r--r--
Create Viewrepr which handle the representation of the View. - Put in all the function about Hidden Nodes - In scene, initializes this.view with the first view of the project (later it will be handled by a view manager)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
506
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
     1
define(['jquery', 'underscore', 'requtils', 'renderer/baserepresentation'], function ($, _, requtils, BaseRepresentation) {
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
     2
    'use strict';
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
     3
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
     4
    var Utils = requtils.getUtils();
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
     5
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
     6
    /* Rkns.Renderer.View Class */
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
     7
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
     8
    /* The representation for the view. */
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
     9
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    10
    var ViewRepr = Utils.inherit(BaseRepresentation);
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    11
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    12
    _(ViewRepr.prototype).extend({
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    13
        _init: function() {
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    14
            var _this = this;
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    15
            this.$ = $(".Rk-Render");
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    16
            this.type = "View";
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    17
            this.hiddenNodes = [];
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    18
            
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    19
//            this.$.find(".Rk-ZoomSetSaved").click( function() {
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    20
//                var view = _this.renkan.project.get("views").last();
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    21
//                if(view){
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    22
//                    //_this.setScale(view.get("zoom_level"), new paper.Point(view.get("offset")));
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    23
                _this.showNodes(false);
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    24
                if (this.options.hide_nodes){
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    25
                    this.hiddenNodes = (this.model.get("hidden_nodes") || []).concat();
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    26
                    this.hideNodes();                    
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    27
                }
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    28
//                }
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    29
//            });
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    30
            
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    31
            this.$.find(".Rk-ShowHiddenNodes").mouseenter( function() {
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    32
                _this.showNodes(true);
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    33
                _this.$.find(".Rk-ShowHiddenNodes").mouseleave( function() {
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    34
                    _this.hideNodes();
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    35
                });
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    36
            });
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    37
            this.$.find(".Rk-ShowHiddenNodes").click( function() {
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    38
                _this.showNodes(false);
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    39
                _this.$.find(".Rk-ShowHiddenNodes").off( "mouseleave" ); 
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    40
            });
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    41
            if(this.renkan.project.get("views").length > 0 && this.renkan.options.save_view){
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    42
                this.$.find(".Rk-ZoomSetSaved").show();
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    43
            }
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    44
        },
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    45
        redraw: function(options) {
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    46
        },
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    47
        addHiddenNode: function(_model){
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    48
            this.hideNode(_model);
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    49
            this.hiddenNodes.push(_model.id);
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    50
        },
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    51
        hideNode: function(_model){
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    52
            if (typeof this.renderer.getRepresentationByModel(_model) !== 'undefined'){
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    53
                this.renderer.getRepresentationByModel(_model).hide();
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    54
            }
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    55
        },
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    56
        hideNodes: function(){
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    57
            var _this = this;
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    58
            this.hiddenNodes.forEach(function(_id, index){
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    59
                var node = _this.renkan.project.get("nodes").get(_id);
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    60
                if (typeof node !== 'undefined'){
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    61
                    return _this.hideNode(_this.renkan.project.get("nodes").get(_id));
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    62
                }else{
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    63
                    _this.hiddenNodes.splice(index, 1);
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    64
                }
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    65
            });
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    66
            paper.view.draw();
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    67
        },
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    68
        showNodes: function(ghost){
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    69
            var _this = this;
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    70
            this.hiddenNodes.forEach(function(_id){
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    71
                _this.renderer.getRepresentationByModel(_this.renkan.project.get("nodes").get(_id)).show(ghost);
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    72
            });
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    73
            if (!ghost){
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    74
                this.hiddenNodes = [];
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    75
            }
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    76
            paper.view.draw();
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    77
        },
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    78
    }).value();
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    79
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    80
    return ViewRepr;
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    81
460de050f800 Create Viewrepr which handle the representation of the View.
rougeronj
parents:
diff changeset
    82
});