client/js/paper-renderer.js
author cavaliet
Mon, 05 May 2014 17:43:37 +0200
changeset 284 fa8035885814
parent 283 67f3a24a7c01
permissions -rw-r--r--
build renderer with require js
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
     1
/* paper-renderer.js */
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
     2
"use strict";
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
     3
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
     4
(function(root) {
283
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
     5
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
     6
    var Rkns = root.Rkns,
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
     7
    _ = Rkns._,
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
     8
    $ = Rkns.$;
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
     9
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    10
    /* Rkns.Renderer Object */
199
aff7eb118f7d Added Standalone Renkan
veltr
parents: 198
diff changeset
    11
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    12
    /* This object contains constants, utility functions and classes for Renkan's Graph Manipulation GUI */
199
aff7eb118f7d Added Standalone Renkan
veltr
parents: 198
diff changeset
    13
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
    14
    var Renderer = Rkns.Renderer = {};
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
    15
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    16
    /* Rkns.Renderer._BaseRepresentation Class */
199
aff7eb118f7d Added Standalone Renkan
veltr
parents: 198
diff changeset
    17
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    18
    /* In Renkan, a "Representation" is a sort of ViewModel (in the MVVM paradigm) and bridges the gap between
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    19
     * models (written with Backbone.js) and the view (written with Paper.js)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    20
     * Renkan's representations all inherit from Rkns.Renderer._BaseRepresentation '*/
199
aff7eb118f7d Added Standalone Renkan
veltr
parents: 198
diff changeset
    21
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    22
    var _BaseRepresentation = Renderer._BaseRepresentation = function(_renderer, _model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    23
        if (typeof _renderer !== "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    24
            this.renderer = _renderer;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    25
            this.renkan = _renderer.renkan;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    26
            this.project = _renderer.renkan.project;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    27
            this.options = _renderer.renkan.options;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    28
            this.model = _model;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    29
            if (this.model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    30
                var _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    31
                this._changeBinding = function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    32
                    _this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    33
                };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    34
                this._removeBinding = function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    35
                    _renderer.removeRepresentation(_this);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    36
                    _(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    37
                        _renderer.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    38
                    }).defer();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    39
                };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    40
                this._selectBinding = function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    41
                    _this.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    42
                };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    43
                this._unselectBinding = function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    44
                    _this.unselect();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    45
                };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    46
                this.model.on("change", this._changeBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    47
                this.model.on("remove", this._removeBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    48
                this.model.on("select", this._selectBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    49
                this.model.on("unselect", this._unselectBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    50
            }
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
    51
        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    52
    };
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
    53
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    54
    /* Rkns.Renderer._BaseRepresentation Methods */
132
860340d4c645 Improvements for CineCard
veltr
parents: 122
diff changeset
    55
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    56
    _(_BaseRepresentation.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    57
        _super: function(_func) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    58
            return _BaseRepresentation.prototype[_func].apply(this, Array.prototype.slice.call(arguments, 1));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    59
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    60
        redraw: function() {},
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    61
        moveTo: function() {},
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    62
        show: function() {},
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    63
        hide: function() {},
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    64
        select: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    65
            if (this.model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    66
                this.model.trigger("selected");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    67
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    68
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    69
        unselect: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    70
            if (this.model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    71
                this.model.trigger("unselected");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    72
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    73
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    74
        highlight: function() {},
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    75
        unhighlight: function() {},
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    76
        mousedown: function() {},
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    77
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    78
            if (this.model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    79
                this.model.trigger("clicked");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    80
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    81
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    82
        destroy: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    83
            if (this.model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    84
                this.model.off("change", this._changeBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    85
                this.model.off("remove", this._removeBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    86
                this.model.off("select", this._selectBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    87
                this.model.off("unselect", this._unselectBinding );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    88
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    89
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    90
    });
132
860340d4c645 Improvements for CineCard
veltr
parents: 122
diff changeset
    91
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    92
    /* End of Rkns.Renderer._BaseRepresentation Class */
199
aff7eb118f7d Added Standalone Renkan
veltr
parents: 198
diff changeset
    93
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    94
    /* Rkns.Renderer._BaseButton Class */
199
aff7eb118f7d Added Standalone Renkan
veltr
parents: 198
diff changeset
    95
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    96
    /* BaseButton is extended by contextual buttons that appear when hovering on nodes and edges */
132
860340d4c645 Improvements for CineCard
veltr
parents: 122
diff changeset
    97
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
    98
    var _BaseButton = Renderer._BaseButton = Rkns.Utils.inherit(_BaseRepresentation);
1
45cca39b00ac First rendering tests
veltr
parents:
diff changeset
    99
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   100
    _(_BaseButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   101
        moveTo: function(_pos) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   102
            this.sector.moveTo(_pos);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   103
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   104
        show: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   105
            this.sector.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   106
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   107
        hide: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   108
            this.sector.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   109
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   110
        select: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   111
            this.sector.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   112
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   113
        unselect: function(_newTarget) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   114
            this.sector.unselect();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   115
            if (!_newTarget || (_newTarget !== this.source_representation && _newTarget.source_representation !== this.source_representation)) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   116
                this.source_representation.unselect();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   117
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   118
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   119
        destroy: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   120
            this.sector.destroy();
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
   121
        }
170
603ffa4c6fa5 correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents: 169
diff changeset
   122
    });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   123
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   124
    /* End of Rkns.Renderer._BaseButton Class */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   125
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   126
    /* Rkns.Renderer.Node Class */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   127
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   128
    /* The representation for the node : A circle, with an image inside and a text label underneath.
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   129
     * The circle and the image are drawn on canvas and managed by Paper.js.
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   130
     * The text label is an HTML node, managed by jQuery. */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   131
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   132
    var NodeRepr = Renderer.Node = Rkns.Utils.inherit(_BaseRepresentation);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   133
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   134
    _(NodeRepr.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   135
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   136
            this.renderer.node_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   137
            this.type = "Node";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   138
            this.circle = new paper.Path.Circle([0, 0], 1);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   139
            this.circle.__representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   140
            if (this.options.show_node_circles) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   141
                this.circle.strokeWidth = this.options.node_stroke_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   142
                this.h_ratio = 1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   143
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   144
                this.h_ratio = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   145
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   146
            this.title = $('<div class="Rk-Label">').appendTo(this.renderer.labels_$);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   147
            if (this.options.editor_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   148
                this.normal_buttons = [
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   149
                                       new NodeEditButton(this.renderer, null),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   150
                                       new NodeRemoveButton(this.renderer, null),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   151
                                       new NodeLinkButton(this.renderer, null),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   152
                                       new NodeEnlargeButton(this.renderer, null),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   153
                                       new NodeShrinkButton(this.renderer, null)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   154
                                       ];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   155
                this.pending_delete_buttons = [
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   156
                                               new NodeRevertButton(this.renderer, null)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   157
                                               ];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   158
                this.all_buttons = this.normal_buttons.concat(this.pending_delete_buttons);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   159
                for (var i = 0; i < this.all_buttons.length; i++) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   160
                    this.all_buttons[i].source_representation = this;
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
   161
                }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   162
                this.active_buttons = [];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   163
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   164
                this.active_buttons = this.all_buttons = [];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   165
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   166
            this.last_circle_radius = 1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   167
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   168
            if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   169
                this.renderer.minimap.node_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   170
                this.minimap_circle = new paper.Path.Circle([0, 0], 1);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   171
                this.minimap_circle.__representation = this.renderer.minimap.miniframe.__representation;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   172
                this.renderer.minimap.node_group.addChild(this.minimap_circle);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   173
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   174
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   175
        redraw: function(_dontRedrawEdges) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   176
            var _model_coords = new paper.Point(this.model.get("position")),
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
   177
            _baseRadius = this.options.node_size_base * Math.exp((this.model.get("size") || 0) * Rkns.Utils._NODE_SIZE_STEP);
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   178
            if (!this.is_dragging || !this.paper_coords) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   179
                this.paper_coords = this.renderer.toPaperCoords(_model_coords);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   180
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   181
            this.circle_radius = _baseRadius * this.renderer.scale;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   182
            if (this.last_circle_radius !== this.circle_radius) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   183
                this.all_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   184
                    b.setSectorSize();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   185
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   186
                this.circle.scale(this.circle_radius / this.last_circle_radius);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   187
                if (this.node_image) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   188
                    this.node_image.scale(this.circle_radius / this.last_circle_radius);
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
   189
                }
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
   190
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   191
            this.circle.position = this.paper_coords;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   192
            if (this.node_image) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   193
                this.node_image.position = this.paper_coords.subtract(this.image_delta.multiply(this.circle_radius));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   194
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   195
            this.last_circle_radius = this.circle_radius;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   196
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   197
            var old_act_btn = this.active_buttons;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   198
278
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
   199
            var opacity = 1;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   200
            if (this.model.get("delete_scheduled")) {
278
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
   201
                opacity = .5;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   202
                this.active_buttons = this.pending_delete_buttons;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   203
                this.circle.dashArray = [2,2];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   204
            } else {
278
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
   205
                opacity = 1;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   206
                this.active_buttons = this.normal_buttons;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   207
                this.circle.dashArray = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   208
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   209
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   210
            if (this.selected && this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   211
                if (old_act_btn !== this.active_buttons) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   212
                    old_act_btn.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   213
                        b.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   214
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   215
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   216
                this.active_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   217
                    b.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   218
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   219
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   220
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   221
            if (this.node_image) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   222
                this.node_image.opacity = this.highlighted ? opacity * .5 : (opacity - .01);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   223
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   224
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   225
            this.circle.fillColor = this.highlighted ? this.options.highlighted_node_fill_color : this.options.node_fill_color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   226
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   227
            this.circle.opacity = this.options.show_node_circles ? opacity : .01;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   228
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   229
            var _text = this.model.get("title") || this.renkan.translate(this.options.label_untitled_nodes) || "";
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
   230
            _text = Rkns.Utils.shortenText(_text, this.options.node_label_max_length);
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   231
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   232
            if (typeof this.highlighted === "object") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   233
                this.title.html(this.highlighted.replace(_(_text).escape(),'<span class="Rk-Highlighted">$1</span>'));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   234
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   235
                this.title.text(_text);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   236
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   237
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   238
            this.title.css({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   239
                left: this.paper_coords.x,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   240
                top: this.paper_coords.y + this.circle_radius * this.h_ratio + this.options.node_label_distance,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   241
                opacity: opacity
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   242
            });
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
   243
            var _color = this.model.get("color") || (this.model.get("created_by") || Rkns.Utils._USER_PLACEHOLDER(this.renkan)).get("color");
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   244
            this.circle.strokeColor = _color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   245
            var _pc = this.paper_coords;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   246
            this.all_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   247
                b.moveTo(_pc);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   248
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   249
            var lastImage = this.img;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   250
            this.img = this.model.get("image");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   251
            if (this.img && this.img !== lastImage) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   252
                this.showImage();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   253
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   254
            if (this.node_image && !this.img) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   255
                this.node_image.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   256
                delete this.node_image;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   257
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   258
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   259
            if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   260
                this.minimap_circle.fillColor = _color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   261
                var minipos = this.renderer.toMinimapCoords(_model_coords),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   262
                miniradius = this.renderer.minimap.scale * _baseRadius,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   263
                minisize = new paper.Size([miniradius, miniradius]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   264
                this.minimap_circle.fitBounds(minipos.subtract(minisize), minisize.multiply(2));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   265
            }
118
c0e03c7137e3 Fix for edges with missing nodes
veltr
parents: 117
diff changeset
   266
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   267
            if (!_dontRedrawEdges) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   268
                var _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   269
                _.each(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   270
                        this.project.get("edges").filter(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   271
                                function (ed) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   272
                                    return ((ed.get("to") === _this.model) || (ed.get("from") === _this.model));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   273
                                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   274
                        ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   275
                        function(edge, index, list) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   276
                            var repr = _this.renderer.getRepresentationByModel(edge);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   277
                            if (repr && typeof repr.from_representation !== "undefined" && typeof repr.from_representation.paper_coords !== "undefined" && typeof repr.to_representation !== "undefined" && typeof repr.to_representation.paper_coords !== "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   278
                                repr.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   279
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   280
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   281
                );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   282
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   283
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   284
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   285
        showImage: function() {
278
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
   286
            var _image = null;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   287
            if (typeof this.renderer.image_cache[this.img] === "undefined") {
278
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
   288
                _image = new Image();
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   289
                this.renderer.image_cache[this.img] = _image;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   290
                _image.src = this.img;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   291
            } else {
278
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
   292
                _image = this.renderer.image_cache[this.img];
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   293
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   294
            if (_image.width) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   295
                if (this.node_image) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   296
                    this.node_image.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   297
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   298
                this.renderer.node_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   299
                var width = _image.width,
283
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   300
                height = _image.height,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   301
                clipPath = this.model.get("clip_path"),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   302
                hasClipPath = (typeof clipPath !== "undefined" && clipPath),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   303
                _clip = null,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   304
                baseRadius = null,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   305
                centerPoint = null;
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   306
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   307
                if (hasClipPath) {
278
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
   308
                    _clip = new paper.Path();
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
   309
                    var instructions = clipPath.match(/[a-z][^a-z]+/gi) || [],
283
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   310
                    lastCoords = [0,0],
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   311
                    minX = Infinity,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   312
                    minY = Infinity,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   313
                    maxX = -Infinity,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   314
                    maxY = -Infinity;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   315
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   316
                    var transformCoords = function(tabc, relative) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   317
                        var newCoords = tabc.slice(1).map(function(v, k) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   318
                            var res = parseFloat(v),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   319
                            isY = k % 2;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   320
                            if (isY) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   321
                                res = ( res - .5 ) * height;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   322
                            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   323
                                res = ( res - .5 ) * width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   324
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   325
                            if (relative) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   326
                                res += lastCoords[isY];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   327
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   328
                            if (isY) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   329
                                minY = Math.min(minY, res);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   330
                                maxY = Math.max(maxY, res);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   331
                            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   332
                                minX = Math.min(minX, res);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   333
                                maxX = Math.max(maxX, res);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   334
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   335
                            return res;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   336
                        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   337
                        lastCoords = newCoords.slice(-2);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   338
                        return newCoords;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   339
                    };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   340
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   341
                    instructions.forEach(function(instr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   342
                        var coords = instr.match(/([a-z]|[0-9.-]+)/ig) || [""];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   343
                        switch(coords[0]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   344
                        case "M":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   345
                            _clip.moveTo(transformCoords(coords));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   346
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   347
                        case "m":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   348
                            _clip.moveTo(transformCoords(coords, true));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   349
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   350
                        case "L":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   351
                            _clip.lineTo(transformCoords(coords));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   352
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   353
                        case "l":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   354
                            _clip.lineTo(transformCoords(coords, true));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   355
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   356
                        case "C":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   357
                            _clip.cubicCurveTo(transformCoords(coords));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   358
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   359
                        case "c":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   360
                            _clip.cubicCurveTo(transformCoords(coords, true));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   361
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   362
                        case "Q":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   363
                            _clip.quadraticCurveTo(transformCoords(coords));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   364
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   365
                        case "q":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   366
                            _clip.quadraticCurveTo(transformCoords(coords, true));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   367
                            break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   368
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   369
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   370
278
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
   371
                    baseRadius = Math[this.options.node_images_fill_mode ? "min" : "max"](maxX - minX, maxY - minY) / 2;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   372
                    centerPoint = new paper.Point((maxX + minX) / 2, (maxY + minY) / 2);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   373
                    if (!this.options.show_node_circles) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   374
                        this.h_ratio = (maxY - minY) / (2 * baseRadius);
175
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   375
                    }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   376
                } else {
278
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
   377
                    baseRadius = Math[this.options.node_images_fill_mode ? "min" : "max"](width, height) / 2;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   378
                    centerPoint = new paper.Point(0,0);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   379
                    if (!this.options.show_node_circles) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   380
                        this.h_ratio = height / (2 * baseRadius);
175
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   381
                    }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   382
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   383
                var _raster = new paper.Raster(_image);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   384
                _raster.locked = true; // Disable mouse events on icon
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   385
                if (hasClipPath) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   386
                    _raster = new paper.Group(_clip, _raster);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   387
                    _raster.opacity = .99;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   388
                    /* This is a workaround to allow clipping at group level
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   389
                     * If opacity was set to 1, paper.js would merge all clipping groups in one (known bug).
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   390
                     */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   391
                    _raster.clipped = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   392
                    _clip.__representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   393
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   394
                if (this.options.clip_node_images) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   395
                    var _circleClip = new paper.Path.Circle(centerPoint, baseRadius);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   396
                    _raster = new paper.Group(_circleClip, _raster);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   397
                    _raster.opacity = .99;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   398
                    _raster.clipped = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   399
                    _circleClip.__representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   400
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   401
                this.image_delta = centerPoint.divide(baseRadius);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   402
                this.node_image = _raster;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   403
                this.node_image.__representation = _this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   404
                this.node_image.scale(this.circle_radius / baseRadius);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   405
                this.node_image.position = this.paper_coords.subtract(this.image_delta.multiply(this.circle_radius));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   406
                this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   407
                this.renderer.throttledPaperDraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   408
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   409
                var _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   410
                $(_image).on("load", function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   411
                    _this.showImage();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   412
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   413
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   414
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   415
        paperShift: function(_delta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   416
            if (this.options.editor_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   417
                if (!this.renkan.read_only) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   418
                    this.is_dragging = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   419
                    this.paper_coords = this.paper_coords.add(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   420
                    this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   421
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   422
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   423
                this.renderer.paperShift(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   424
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   425
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   426
        openEditor: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   427
            this.renderer.removeRepresentationsOfType("editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   428
            var _editor = this.renderer.addRepresentation("NodeEditor",null);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   429
            _editor.source_representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   430
            _editor.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   431
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   432
        select: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   433
            this.selected = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   434
            this.circle.strokeWidth = this.options.selected_node_stroke_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   435
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   436
                this.active_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   437
                    b.show();
175
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   438
                });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   439
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   440
            var _uri = this.model.get("uri");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   441
            if (_uri) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   442
                $('.Rk-Bin-Item').each(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   443
                    var _el = $(this);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   444
                    if (_el.attr("data-uri") == _uri) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   445
                        _el.addClass("selected");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   446
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   447
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   448
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   449
            if (!this.options.editor_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   450
                this.openEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   451
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   452
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   453
            if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   454
                this.minimap_circle.strokeWidth = this.options.minimap_highlight_weight;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   455
                this.minimap_circle.strokeColor = this.options.minimap_highlight_color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   456
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   457
            this._super("select");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   458
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   459
        unselect: function(_newTarget) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   460
            if (!_newTarget || _newTarget.source_representation !== this) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   461
                this.selected = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   462
                this.all_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   463
                    b.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   464
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   465
                this.circle.strokeWidth = this.options.node_stroke_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   466
                $('.Rk-Bin-Item').removeClass("selected");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   467
                if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   468
                    this.minimap_circle.strokeColor = undefined;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   469
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   470
                this._super("unselect");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   471
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   472
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   473
        highlight: function(textToReplace) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   474
            var hlvalue = textToReplace || true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   475
            if (this.highlighted === hlvalue) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   476
                return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   477
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   478
            this.highlighted = hlvalue;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   479
            this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   480
            this.renderer.throttledPaperDraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   481
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   482
        unhighlight: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   483
            if (!this.highlighted) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   484
                return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   485
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   486
            this.highlighted = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   487
            this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   488
            this.renderer.throttledPaperDraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   489
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   490
        saveCoords: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   491
            var _coords = this.renderer.toModelCoords(this.paper_coords),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   492
            _data = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   493
                position: {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   494
                    x: _coords.x,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   495
                    y: _coords.y
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   496
                }
199
aff7eb118f7d Added Standalone Renkan
veltr
parents: 198
diff changeset
   497
            };
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   498
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   499
                this.model.set(_data);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   500
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   501
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   502
        mousedown: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   503
            if (_isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   504
                this.renderer.unselectAll();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   505
                this.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   506
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   507
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   508
        mouseup: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   509
            if (this.renderer.is_dragging && this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   510
                this.saveCoords();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   511
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   512
                if (!_isTouch && !this.model.get("delete_scheduled")) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   513
                    this.openEditor();
175
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   514
                }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   515
                this.model.trigger("clicked");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   516
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   517
            this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   518
            this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   519
            this.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   520
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   521
        destroy: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   522
            this._super("destroy");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   523
            this.all_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   524
                b.destroy();
175
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   525
            });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   526
            this.circle.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   527
            this.title.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   528
            if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   529
                this.minimap_circle.remove();
175
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   530
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   531
            if (this.node_image) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   532
                this.node_image.remove();
175
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   533
            }
f636e2dcfb2c eGonomy image fragments support
veltr
parents: 174
diff changeset
   534
        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   535
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   536
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   537
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   538
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   539
    var Edge = Renderer.Edge = Rkns.Utils.inherit(_BaseRepresentation);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   540
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   541
    _(Edge.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   542
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   543
            this.renderer.edge_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   544
            this.type = "Edge";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   545
            this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   546
            this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   547
            this.bundle = this.renderer.addToBundles(this);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   548
            this.line = new paper.Path();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   549
            this.line.add([0,0],[0,0],[0,0]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   550
            this.line.__representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   551
            this.line.strokeWidth = this.options.edge_stroke_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   552
            this.arrow = new paper.Path();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   553
            this.arrow.add(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   554
                    [ 0, 0 ],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   555
                    [ this.options.edge_arrow_length, this.options.edge_arrow_width / 2 ],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   556
                    [ 0, this.options.edge_arrow_width ]
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   557
            );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   558
            this.arrow.__representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   559
            this.text = $('<div class="Rk-Label Rk-Edge-Label">').appendTo(this.renderer.labels_$);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   560
            this.arrow_angle = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   561
            if (this.options.editor_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   562
                this.normal_buttons = [
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   563
                                       new EdgeEditButton(this.renderer, null),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   564
                                       new EdgeRemoveButton(this.renderer, null)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   565
                                       ];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   566
                this.pending_delete_buttons = [
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   567
                                               new EdgeRevertButton(this.renderer, null)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   568
                                               ];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   569
                this.all_buttons = this.normal_buttons.concat(this.pending_delete_buttons);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   570
                for (var i = 0; i < this.all_buttons.length; i++) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   571
                    this.all_buttons[i].source_representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   572
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   573
                this.active_buttons = [];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   574
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   575
                this.active_buttons = this.all_buttons = [];
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
   576
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   577
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   578
            if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   579
                this.renderer.minimap.edge_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   580
                this.minimap_line = new paper.Path();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   581
                this.minimap_line.add([0,0],[0,0]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   582
                this.minimap_line.__representation = this.renderer.minimap.miniframe.__representation;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   583
                this.minimap_line.strokeWidth = 1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   584
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   585
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   586
        redraw: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   587
            var from = this.model.get("from"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   588
            to = this.model.get("to");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   589
            if (!from || !to) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   590
                return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   591
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   592
            this.from_representation = this.renderer.getRepresentationByModel(from);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   593
            this.to_representation = this.renderer.getRepresentationByModel(to);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   594
            if (typeof this.from_representation === "undefined" || typeof this.to_representation === "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   595
                return;
57
01f66ed90e32 Drag node/edge only saved at mouse up.
veltr
parents: 56
diff changeset
   596
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   597
            var _p0a = this.from_representation.paper_coords,
283
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   598
            _p1a = this.to_representation.paper_coords,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   599
            _v = _p1a.subtract(_p0a),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   600
            _r = _v.length,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   601
            _u = _v.divide(_r),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   602
            _ortho = new paper.Point([- _u.y, _u.x]),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   603
            _group_pos = this.bundle.getPosition(this),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   604
            _delta = _ortho.multiply( this.options.edge_gap_in_bundles * _group_pos ),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   605
            _p0b = _p0a.add(_delta), /* Adding a 4 px difference */
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   606
            _p1b = _p1a.add(_delta), /* to differentiate bundled links */
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   607
            _a = _v.angle,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   608
            _textdelta = _ortho.multiply(this.options.edge_label_distance),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   609
            _handle = _v.divide(3),
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
   610
            _color = this.model.get("color") || this.model.get("color") || (this.model.get("created_by") || Rkns.Utils._USER_PLACEHOLDER(this.renkan)).get("color"),
283
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
   611
            opacity = 1;
4
f5297dde9053 Can now add nodes/edges
veltr
parents: 3
diff changeset
   612
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   613
            if (this.model.get("delete_scheduled") || this.from_representation.model.get("delete_scheduled") || this.to_representation.model.get("delete_scheduled")) {
278
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
   614
                opacity = .5;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   615
                this.line.dashArray = [2, 2];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   616
            } else {
278
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
   617
                opacity = 1;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   618
                this.line.dashArray = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   619
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   620
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   621
            var old_act_btn = this.active_buttons;
2
3360c3f7fb18 Added Edge management to the rendering engine
veltr
parents: 1
diff changeset
   622
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   623
            this.active_buttons = this.model.get("delete_scheduled") ? this.pending_delete_buttons : this.normal_buttons;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   624
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   625
            if (this.selected && this.renderer.isEditable() && old_act_btn !== this.active_buttons) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   626
                old_act_btn.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   627
                    b.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   628
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   629
                this.active_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   630
                    b.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   631
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   632
            }
2
3360c3f7fb18 Added Edge management to the rendering engine
veltr
parents: 1
diff changeset
   633
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   634
            this.paper_coords = _p0b.add(_p1b).divide(2);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   635
            this.line.strokeColor = _color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   636
            this.line.opacity = opacity;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   637
            this.line.segments[0].point = _p0a;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   638
            this.line.segments[1].point = this.paper_coords;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   639
            this.line.segments[1].handleIn = _handle.multiply(-1);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   640
            this.line.segments[1].handleOut = _handle;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   641
            this.line.segments[2].point = _p1a;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   642
            this.arrow.rotate(_a - this.arrow_angle);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   643
            this.arrow.fillColor = _color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   644
            this.arrow.opacity = opacity;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   645
            this.arrow.position = this.paper_coords;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   646
            this.arrow_angle = _a;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   647
            if (_a > 90) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   648
                _a -= 180;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   649
                _textdelta = _textdelta.multiply(-1);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   650
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   651
            if (_a < -90) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   652
                _a += 180;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   653
                _textdelta = _textdelta.multiply(-1);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   654
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   655
            var _text = this.model.get("title") || this.renkan.translate(this.options.label_untitled_edges) || "";
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
   656
            _text = Rkns.Utils.shortenText(_text, this.options.node_label_max_length);
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   657
            this.text.text(_text);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   658
            var _textpos = this.paper_coords.add(_textdelta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   659
            this.text.css({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   660
                left: _textpos.x,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   661
                top: _textpos.y,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   662
                transform: "rotate(" + _a + "deg)",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   663
                "-moz-transform": "rotate(" + _a + "deg)",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   664
                "-webkit-transform": "rotate(" + _a + "deg)",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   665
                opacity: opacity
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   666
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   667
            this.text_angle = _a;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   668
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   669
            var _pc = this.paper_coords;
161
c7a503c80ef4 Two step deletion of nodes and edges
veltr
parents: 160
diff changeset
   670
            this.all_buttons.forEach(function(b) {
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   671
                b.moveTo(_pc);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   672
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   673
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   674
            if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   675
                this.minimap_line.strokeColor = _color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   676
                this.minimap_line.segments[0].point = this.renderer.toMinimapCoords(new paper.Point(this.from_representation.model.get("position")));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   677
                this.minimap_line.segments[1].point = this.renderer.toMinimapCoords(new paper.Point(this.to_representation.model.get("position")));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   678
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   679
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   680
        openEditor: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   681
            this.renderer.removeRepresentationsOfType("editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   682
            var _editor = this.renderer.addRepresentation("EdgeEditor",null);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   683
            _editor.source_representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   684
            _editor.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   685
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   686
        select: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   687
            this.selected = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   688
            this.line.strokeWidth = this.options.selected_edge_stroke_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   689
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   690
                this.active_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   691
                    b.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   692
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   693
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   694
            if (!this.options.editor_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   695
                this.openEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   696
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   697
            this._super("select");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   698
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   699
        unselect: function(_newTarget) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   700
            if (!_newTarget || _newTarget.source_representation !== this) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   701
                this.selected = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   702
                if (this.options.editor_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   703
                    this.all_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   704
                        b.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   705
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   706
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   707
                this.line.strokeWidth = this.options.edge_stroke_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   708
                this._super("unselect");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   709
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   710
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   711
        mousedown: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   712
            if (_isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   713
                this.renderer.unselectAll();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   714
                this.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   715
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   716
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   717
        mouseup: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   718
            if (!this.renkan.read_only && this.renderer.is_dragging) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   719
                this.from_representation.saveCoords();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   720
                this.to_representation.saveCoords();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   721
                this.from_representation.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   722
                this.to_representation.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   723
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   724
                if (!_isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   725
                    this.openEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   726
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   727
                this.model.trigger("clicked");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   728
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   729
            this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   730
            this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   731
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   732
        paperShift: function(_delta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   733
            if (this.options.editor_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   734
                if (!this.options.read_only) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   735
                    this.from_representation.paperShift(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   736
                    this.to_representation.paperShift(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   737
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   738
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   739
                this.renderer.paperShift(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   740
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   741
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   742
        destroy: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   743
            this._super("destroy");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   744
            this.line.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   745
            this.arrow.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   746
            this.text.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   747
            if (this.renderer.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   748
                this.minimap_line.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   749
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   750
            this.all_buttons.forEach(function(b) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   751
                b.destroy();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   752
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   753
            var _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   754
            this.bundle.edges = _(this.bundle.edges).reject(function(_edge) {
278
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
   755
                return _this === _edge;
161
c7a503c80ef4 Two step deletion of nodes and edges
veltr
parents: 160
diff changeset
   756
            });
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 113
diff changeset
   757
        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   758
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   759
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   760
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   761
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   762
    var TempEdge = Renderer.TempEdge = Rkns.Utils.inherit(_BaseRepresentation);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   763
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   764
    _(TempEdge.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   765
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   766
            this.renderer.edge_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   767
            this.type = "Temp-edge";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   768
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
   769
            var _color = (this.project.get("users").get(this.renkan.current_user) || Rkns.Utils._USER_PLACEHOLDER(this.renkan)).get("color");
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   770
            this.line = new paper.Path();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   771
            this.line.strokeColor = _color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   772
            this.line.dashArray = [4, 2];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   773
            this.line.strokeWidth = this.options.selected_edge_stroke_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   774
            this.line.add([0,0],[0,0]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   775
            this.line.__representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   776
            this.arrow = new paper.Path();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   777
            this.arrow.fillColor = _color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   778
            this.arrow.add(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   779
                    [ 0, 0 ],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   780
                    [ this.options.edge_arrow_length, this.options.edge_arrow_width / 2 ],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   781
                    [ 0, this.options.edge_arrow_width ]
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   782
            );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   783
            this.arrow.__representation = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   784
            this.arrow_angle = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   785
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   786
        redraw: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   787
            var _p0 = this.from_representation.paper_coords,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   788
            _p1 = this.end_pos,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   789
            _a = _p1.subtract(_p0).angle,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   790
            _c = _p0.add(_p1).divide(2);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   791
            this.line.segments[0].point = _p0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   792
            this.line.segments[1].point = _p1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   793
            this.arrow.rotate(_a - this.arrow_angle);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   794
            this.arrow.position = _c;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   795
            this.arrow_angle = _a;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   796
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   797
        paperShift: function(_delta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   798
            if (!this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   799
                this.renderer.removeRepresentation(_this);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   800
                paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   801
                return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   802
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   803
            this.end_pos = this.end_pos.add(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   804
            var _hitResult = paper.project.hitTest(this.end_pos);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   805
            this.renderer.findTarget(_hitResult);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   806
            this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   807
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   808
        mouseup: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   809
            var _hitResult = paper.project.hitTest(_event.point),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   810
            _model = this.from_representation.model,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   811
            _endDrag = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   812
            if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   813
                var _target = _hitResult.item.__representation;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   814
                if (_target.type.substr(0,4) === "Node") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   815
                    var _destmodel = _target.model || _target.source_representation.model;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   816
                    if (_model !== _destmodel) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   817
                        var _data = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   818
                                id: Rkns.Utils.getUID('edge'),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   819
                                created_by: this.renkan.current_user,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   820
                                from: _model,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   821
                                to: _destmodel
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   822
                        };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   823
                        if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   824
                            this.project.addEdge(_data);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   825
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   826
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   827
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   828
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   829
                if (_model === _target.model || (_target.source_representation && _target.source_representation.model === _model)) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   830
                    _endDrag = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   831
                    this.renderer.is_dragging = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   832
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   833
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   834
            if (_endDrag) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   835
                this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   836
                this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   837
                this.renderer.removeRepresentation(this);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   838
                paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   839
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   840
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   841
        destroy: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   842
            this.arrow.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   843
            this.line.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   844
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   845
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   846
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   847
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   848
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   849
    var _BaseEditor = Renderer._BaseEditor = Rkns.Utils.inherit(_BaseRepresentation);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   850
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   851
    _(_BaseEditor.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   852
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   853
            this.renderer.buttons_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   854
            this.type = "editor";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   855
            this.editor_block = new paper.Path();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   856
            var _pts = _(_.range(8)).map(function() {return [0,0];});
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   857
            this.editor_block.add.apply(this.editor_block, _pts);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   858
            this.editor_block.strokeWidth = this.options.tooltip_border_width;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   859
            this.editor_block.strokeColor = this.options.tooltip_border_color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   860
            this.editor_block.opacity = .8;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   861
            this.editor_$ = $('<div>')
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   862
            .appendTo(this.renderer.editor_$)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   863
            .css({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   864
                position: "absolute",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   865
                opacity: .8
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   866
            })
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   867
            .hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   868
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   869
        destroy: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   870
            this.editor_block.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   871
            this.editor_$.remove();
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
   872
        }
161
c7a503c80ef4 Two step deletion of nodes and edges
veltr
parents: 160
diff changeset
   873
    });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   874
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   875
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   876
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   877
    var NodeEditor = Renderer.NodeEditor = Rkns.Utils.inherit(_BaseEditor);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   878
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   879
    _(NodeEditor.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   880
        template: _.template(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   881
                '<h2><span class="Rk-CloseX">&times;</span><%-renkan.translate("Edit Node")%></span></h2>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   882
                + '<p><label><%-renkan.translate("Title:")%></label><input class="Rk-Edit-Title" type="text" value="<%-node.title%>"/></p>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   883
                + '<% if (options.show_node_editor_uri) { %><p><label><%-renkan.translate("URI:")%></label><input class="Rk-Edit-URI" type="text" value="<%-node.uri%>"/><a class="Rk-Edit-Goto" href="<%-node.uri%>" target="_blank"></a></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   884
                + '<% if (options.show_node_editor_description) { %><p><label><%-renkan.translate("Description:")%></label><textarea class="Rk-Edit-Description"><%-node.description%></textarea></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   885
                + '<% if (options.show_node_editor_size) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Size:")%></span><a href="#" class="Rk-Edit-Size-Down">-</a><span class="Rk-Edit-Size-Value"><%-node.size%></span><a href="#" class="Rk-Edit-Size-Up">+</a></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   886
                + '<% if (options.show_node_editor_color) { %><div class="Rk-Editor-p"><span class="Rk-Editor-Label"><%-renkan.translate("Node color:")%></span><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-Edit-Color" style="background:<%-node.color%>;"><span class="Rk-Edit-ColorTip"></span></span>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   887
                + '<%= renkan.colorPicker %><span class="Rk-Edit-ColorPicker-Text"><%- renkan.translate("Choose color") %></span></div></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   888
                + '<% if (options.show_node_editor_image) { %><div class="Rk-Edit-ImgWrap"><div class="Rk-Edit-ImgPreview"><img src="<%-node.image || node.image_placeholder%>" />'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   889
                + '<% if (node.clip_path) { %><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewbox="0 0 1 1" preserveAspectRatio="none"><path style="stroke-width: .02; stroke:red; fill-opacity:.3; fill:red;" d="<%- node.clip_path %>"/></svg><% }%>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   890
                + '</div></div><p><label><%-renkan.translate("Image URL:")%></label><input class="Rk-Edit-Image" type="text" value="<%-node.image%>"/></p>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   891
                + '<p><label><%-renkan.translate("Choose Image File:")%></label><input class="Rk-Edit-Image-File" type="file" accept="image/*"/></p><% } %>'    
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   892
                + '<% if (options.show_node_editor_creator && node.has_creator) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Created by:")%></span> <span class="Rk-UserColor" style="background:<%-node.created_by_color%>;"></span><%- shortenText(node.created_by_title, 25) %></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   893
        ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   894
        readOnlyTemplate: _.template(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   895
                '<h2><span class="Rk-CloseX">&times;</span><% if (options.show_node_tooltip_color) { %><span class="Rk-UserColor" style="background:<%-node.color%>;"></span><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   896
                + '<span class="Rk-Display-Title"><% if (node.uri) { %><a href="<%-node.uri%>" target="_blank"><% } %><%-node.title%><% if (node.uri) { %></a><% } %></span></h2>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   897
                + '<% if (node.uri && options.show_node_tooltip_uri) { %><p class="Rk-Display-URI"><a href="<%-node.uri%>" target="_blank"><%-node.short_uri%></a></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   898
                + '<% if (options.show_node_tooltip_description) { %><p class="Rk-Display-Description"><%-node.description%></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   899
                + '<% if (node.image && options.show_node_tooltip_image) { %><img class="Rk-Display-ImgPreview" src="<%-node.image%>" /><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   900
                + '<% if (node.has_creator && options.show_node_tooltip_creator) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-node.created_by_color%>;"></span><%- shortenText(node.created_by_title, 25) %></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   901
        ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   902
        draw: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   903
            var _model = this.source_representation.model,
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
   904
            _created_by = _model.get("created_by") || Rkns.Utils._USER_PLACEHOLDER(this.renkan),
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   905
            _template = (this.renderer.isEditable() ? this.template : this.readOnlyTemplate ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   906
            _image_placeholder = this.options.static_url + "img/image-placeholder.png",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   907
            _size = (_model.get("size") || 0);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   908
            this.editor_$
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   909
            .html(_template({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   910
                node: {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   911
                    has_creator: !!_model.get("created_by"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   912
                    title: _model.get("title"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   913
                    uri: _model.get("uri"),
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
   914
                    short_uri:  Rkns.Utils.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40),
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   915
                    description: _model.get("description"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   916
                    image: _model.get("image") || "",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   917
                    image_placeholder: _image_placeholder,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   918
                    color: _model.get("color") || _created_by.get("color"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   919
                    clip_path: _model.get("clip_path") || false,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   920
                    created_by_color: _created_by.get("color"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   921
                    created_by_title: _created_by.get("title"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   922
                    size: (_size > 0 ? "+" : "") + _size
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   923
                },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   924
                renkan: this.renkan,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   925
                options: this.options,
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
   926
                shortenText: Rkns.Utils.shortenText
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   927
            }));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   928
            this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   929
            var _this = this,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   930
            closeEditor = function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   931
                _this.renderer.removeRepresentation(_this);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   932
                paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   933
            };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   934
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   935
            this.editor_$.find(".Rk-CloseX").click(closeEditor);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   936
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   937
            this.editor_$.find(".Rk-Edit-Goto").click(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   938
                if (!_model.get("uri")) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   939
                    return false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   940
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   941
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   942
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   943
            if (this.renderer.isEditable()) {
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
   944
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   945
                var onFieldChange = _(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   946
                    _(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   947
                        if (_this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   948
                            var _data = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   949
                                    title: _this.editor_$.find(".Rk-Edit-Title").val()
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   950
                            };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   951
                            if (_this.options.show_node_editor_uri) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   952
                                _data.uri = _this.editor_$.find(".Rk-Edit-URI").val();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   953
                                _this.editor_$.find(".Rk-Edit-Goto").attr("href",_data.uri || "#");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   954
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   955
                            if (_this.options.show_node_editor_image) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   956
                                _data.image = _this.editor_$.find(".Rk-Edit-Image").val();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   957
                                _this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _data.image || _image_placeholder);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   958
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   959
                            if (_this.options.show_node_editor_description) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   960
                                _data.description = _this.editor_$.find(".Rk-Edit-Description").val();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   961
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   962
                            _model.set(_data);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   963
                            _this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   964
                        } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   965
                            closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   966
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   967
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   968
                    }).defer();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   969
                }).throttle(500);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   970
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   971
                this.editor_$.on("keyup", function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   972
                    if (_e.keyCode === 27) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   973
                        closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   974
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   975
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   976
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   977
                this.editor_$.find("input, textarea").on("change keyup paste", onFieldChange);
4
f5297dde9053 Can now add nodes/edges
veltr
parents: 3
diff changeset
   978
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   979
                this.editor_$.find(".Rk-Edit-Image-File").change(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   980
                    if (this.files.length) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   981
                        var f = this.files[0],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   982
                        fr = new FileReader();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   983
                        if (f.type.substr(0,5) !== "image") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   984
                            alert(_this.renkan.translate("This file is not an image"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   985
                            return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   986
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   987
                        if (f.size > (_this.options.uploaded_image_max_kb * 1024)) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   988
                            alert(_this.renkan.translate("Image size must be under ") + _this.options.uploaded_image_max_kb + _this.renkan.translate("KB"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   989
                            return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   990
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   991
                        fr.onload = function(e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   992
                            _this.editor_$.find(".Rk-Edit-Image").val(e.target.result);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   993
                            onFieldChange();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   994
                        };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   995
                        fr.readAsDataURL(f);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   996
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   997
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   998
                this.editor_$.find(".Rk-Edit-Title")[0].focus();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
   999
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1000
                var _picker = _this.editor_$.find(".Rk-Edit-ColorPicker");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1001
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1002
                this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1003
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1004
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1005
                            _picker.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1006
                        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1007
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1008
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1009
                            _picker.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1010
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1011
                );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1012
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1013
                _picker.find("li").hover(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1014
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1015
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1016
                            _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1017
                        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1018
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1019
                            _e.preventDefault();
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1020
                            _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Utils._USER_PLACEHOLDER(_this.renkan)).get("color"));
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1021
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1022
                ).click(function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1023
                    _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1024
                    if (_this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1025
                        _model.set("color", $(this).attr("data-color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1026
                        _picker.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1027
                        paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1028
                    } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1029
                        closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1030
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1031
                });
4
f5297dde9053 Can now add nodes/edges
veltr
parents: 3
diff changeset
  1032
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1033
                var shiftSize = function(n) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1034
                    if (_this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1035
                        var _newsize = n+(_model.get("size") || 0);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1036
                        _this.editor_$.find(".Rk-Edit-Size-Value").text((_newsize > 0 ? "+" : "") + _newsize);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1037
                        _model.set("size", _newsize);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1038
                        paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1039
                    } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1040
                        closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1041
                    }
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1042
                };
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1043
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1044
                this.editor_$.find(".Rk-Edit-Size-Down").click(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1045
                    shiftSize(-1);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1046
                    return false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1047
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1048
                this.editor_$.find(".Rk-Edit-Size-Up").click(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1049
                    shiftSize(1);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1050
                    return false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1051
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1052
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1053
                if (typeof this.source_representation.highlighted === "object") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1054
                    var titlehtml = this.source_representation.highlighted.replace(_(_model.get("title")).escape(),'<span class="Rk-Highlighted">$1</span>');
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1055
                    this.editor_$.find(".Rk-Display-Title" + (_model.get("uri") ? " a" : "")).html(titlehtml);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1056
                    if (this.options.show_node_tooltip_description) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1057
                        this.editor_$.find(".Rk-Display-Description").html(this.source_representation.highlighted.replace(_(_model.get("description")).escape(),'<span class="Rk-Highlighted">$1</span>'));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1058
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1059
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1060
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1061
            this.editor_$.find("img").load(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1062
                _this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1063
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1064
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1065
        redraw: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1066
            var _coords = this.source_representation.paper_coords;
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1067
            Rkns.Utils.drawEditBox(this.options, _coords, this.editor_block, this.source_representation.circle_radius * .75, this.editor_$);
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1068
            this.editor_$.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1069
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1070
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1071
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1072
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1073
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1074
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1075
    var EdgeEditor = Renderer.EdgeEditor = Rkns.Utils.inherit(_BaseEditor);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1076
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1077
    _(EdgeEditor.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1078
        template: _.template(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1079
                '<h2><span class="Rk-CloseX">&times;</span><%-renkan.translate("Edit Edge")%></span></h2>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1080
                + '<p><label><%-renkan.translate("Title:")%></label><input class="Rk-Edit-Title" type="text" value="<%-edge.title%>"/></p>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1081
                + '<% if (options.show_edge_editor_uri) { %><p><label><%-renkan.translate("URI:")%></label><input class="Rk-Edit-URI" type="text" value="<%-edge.uri%>"/><a class="Rk-Edit-Goto" href="<%-edge.uri%>" target="_blank"></a></p>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1082
                + '<% if (options.properties.length) { %><p><label><%-renkan.translate("Choose from vocabulary:")%></label><select class="Rk-Edit-Vocabulary">'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1083
                + '<% _(options.properties).each(function(ontology) { %><option class="Rk-Edit-Vocabulary-Class" value=""><%- renkan.translate(ontology.label) %></option>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1084
                + '<% _(ontology.properties).each(function(property) { var uri = ontology["base-uri"] + property.uri; %><option class="Rk-Edit-Vocabulary-Property" value="<%- uri %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1085
                + '"<% if (uri === edge.uri) { %> selected<% } %>><%- renkan.translate(property.label) %></option>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1086
                + '<% }) %><% }) %></select></p><% } } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1087
                + '<% if (options.show_edge_editor_color) { %><div class="Rk-Editor-p"><span class="Rk-Editor-Label"><%-renkan.translate("Edge color:")%></span><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-Edit-Color" style="background:<%-edge.color%>;"><span class="Rk-Edit-ColorTip"></span></span>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1088
                + '<%= renkan.colorPicker %><span class="Rk-Edit-ColorPicker-Text"><%- renkan.translate("Choose color") %></span></div></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1089
                + '<% if (options.show_edge_editor_direction) { %><p><span class="Rk-Edit-Direction"><%- renkan.translate("Change edge direction") %></span></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1090
                + '<% if (options.show_edge_editor_nodes) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("From:")%></span><span class="Rk-UserColor" style="background:<%-edge.from_color%>;"></span><%- shortenText(edge.from_title, 25) %></p>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1091
                + '<p><span class="Rk-Editor-Label"><%-renkan.translate("To:")%></span><span class="Rk-UserColor" style="background:<%-edge.to_color%>;"></span><%- shortenText(edge.to_title, 25) %></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1092
                + '<% if (options.show_edge_editor_creator && edge.has_creator) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-edge.created_by_color%>;"></span><%- shortenText(edge.created_by_title, 25) %></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1093
        ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1094
        readOnlyTemplate: _.template(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1095
                '<h2><span class="Rk-CloseX">&times;</span><% if (options.show_edge_tooltip_color) { %><span class="Rk-UserColor" style="background:<%-edge.color%>;"></span><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1096
                + '<span class="Rk-Display-Title"><% if (edge.uri) { %><a href="<%-edge.uri%>" target="_blank"><% } %><%-edge.title%><% if (edge.uri) { %></a><% } %></span></h2>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1097
                + '<% if (options.show_edge_tooltip_uri && edge.uri) { %><p class="Rk-Display-URI"><a href="<%-edge.uri%>" target="_blank"><%-edge.short_uri%></a></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1098
                + '<p><%-edge.description%></p>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1099
                + '<% if (options.show_edge_tooltip_nodes) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("From:")%></span><span class="Rk-UserColor" style="background:<%-edge.from_color%>;"></span><%- shortenText(edge.from_title, 25) %></p>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1100
                + '<p><span class="Rk-Editor-Label"><%-renkan.translate("To:")%></span><span class="Rk-UserColor" style="background:<%-edge.to_color%>;"></span><%- shortenText(edge.to_title, 25) %></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1101
                + '<% if (options.show_edge_tooltip_creator && edge.has_creator) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-edge.created_by_color%>;"></span><%- shortenText(edge.created_by_title, 25) %></p><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1102
        ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1103
        draw: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1104
            var _model = this.source_representation.model,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1105
            _from_model = _model.get("from"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1106
            _to_model = _model.get("to"),
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1107
            _created_by = _model.get("created_by") || Rkns.Utils._USER_PLACEHOLDER(this.renkan),
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1108
            _template = (this.renderer.isEditable() ? this.template : this.readOnlyTemplate);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1109
            this.editor_$
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1110
            .html(_template({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1111
                edge: {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1112
                    has_creator: !!_model.get("created_by"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1113
                    title: _model.get("title"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1114
                    uri: _model.get("uri"),
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1115
                    short_uri:  Rkns.Utils.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40),
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1116
                    description: _model.get("description"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1117
                    color: _model.get("color") || _created_by.get("color"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1118
                    from_title: _from_model.get("title"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1119
                    to_title: _to_model.get("title"),
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1120
                    from_color: _from_model.get("color") || (_from_model.get("created_by") || Rkns.Utils._USER_PLACEHOLDER(this.renkan)).get("color"),
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1121
                    to_color: _to_model.get("color") || (_to_model.get("created_by") || Rkns.Utils._USER_PLACEHOLDER(this.renkan)).get("color"),
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1122
                    created_by_color: _created_by.get("color"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1123
                    created_by_title: _created_by.get("title")
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1124
                },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1125
                renkan: this.renkan,
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1126
                shortenText: Rkns.Utils.shortenText,
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1127
                options: this.options
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1128
            }));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1129
            this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1130
            var _this = this,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1131
            closeEditor = function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1132
                _this.renderer.removeRepresentation(_this);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1133
                paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1134
            };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1135
            this.editor_$.find(".Rk-CloseX").click(closeEditor);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1136
            this.editor_$.find(".Rk-Edit-Goto").click(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1137
                if (!_model.get("uri")) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1138
                    return false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1139
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1140
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1141
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1142
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1143
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1144
                var onFieldChange = _(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1145
                    _(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1146
                        if (_this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1147
                            var _data = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1148
                                    title: _this.editor_$.find(".Rk-Edit-Title").val()
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1149
                            };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1150
                            if (_this.options.show_edge_editor_uri) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1151
                                _data.uri = _this.editor_$.find(".Rk-Edit-URI").val();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1152
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1153
                            _this.editor_$.find(".Rk-Edit-Goto").attr("href",_data.uri || "#");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1154
                            _model.set(_data);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1155
                            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1156
                        } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1157
                            closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1158
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1159
                    }).defer();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1160
                }).throttle(500);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1161
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1162
                this.editor_$.on("keyup", function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1163
                    if (_e.keyCode === 27) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1164
                        closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1165
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1166
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1167
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1168
                this.editor_$.find("input").on("keyup change paste", onFieldChange);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1169
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1170
                this.editor_$.find(".Rk-Edit-Vocabulary").change(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1171
                    var e = $(this),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1172
                    v = e.val();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1173
                    if (v) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1174
                        _this.editor_$.find(".Rk-Edit-Title").val(e.find(":selected").text());
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1175
                        _this.editor_$.find(".Rk-Edit-URI").val(v);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1176
                        onFieldChange();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1177
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1178
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1179
                this.editor_$.find(".Rk-Edit-Direction").click(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1180
                    if (_this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1181
                        _model.set({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1182
                            from: _model.get("to"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1183
                            to: _model.get("from")
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1184
                        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1185
                        _this.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1186
                    } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1187
                        closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1188
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1189
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1190
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1191
                var _picker = _this.editor_$.find(".Rk-Edit-ColorPicker");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1192
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1193
                this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1194
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1195
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1196
                            _picker.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1197
                        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1198
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1199
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1200
                            _picker.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1201
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1202
                );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1203
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1204
                _picker.find("li").hover(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1205
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1206
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1207
                            _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1208
                        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1209
                        function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1210
                            _e.preventDefault();
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1211
                            _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Utils._USER_PLACEHOLDER(_this.renkan)).get("color"));
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1212
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1213
                ).click(function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1214
                    _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1215
                    if (_this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1216
                        _model.set("color", $(this).attr("data-color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1217
                        _picker.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1218
                        paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1219
                    } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1220
                        closeEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1221
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1222
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1223
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1224
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1225
        redraw: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1226
            var _coords = this.source_representation.paper_coords;
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1227
            Rkns.Utils.drawEditBox(this.options, _coords, this.editor_block, 5, this.editor_$);
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1228
            this.editor_$.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1229
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1230
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1231
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1232
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1233
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1234
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1235
    var _NodeButton = Renderer._NodeButton = Rkns.Utils.inherit(_BaseButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1236
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1237
    _(_NodeButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1238
        setSectorSize: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1239
            var sectorInner = this.source_representation.circle_radius;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1240
            if (sectorInner !== this.lastSectorInner) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1241
                if (this.sector) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1242
                    this.sector.destroy();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1243
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1244
                this.sector = this.renderer.drawSector(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1245
                        this, 1 + sectorInner,
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1246
                        Rkns.Utils._NODE_BUTTON_WIDTH + sectorInner,
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1247
                        this.startAngle,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1248
                        this.endAngle,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1249
                        1,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1250
                        this.imageName,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1251
                        this.renkan.translate(this.text)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1252
                );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1253
                this.lastSectorInner = sectorInner;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1254
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1255
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1256
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1257
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1258
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1259
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1260
    var NodeEditButton = Renderer.NodeEditButton = Rkns.Utils.inherit(_NodeButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1261
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1262
    _(NodeEditButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1263
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1264
            this.type = "Node-edit-button";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1265
            this.lastSectorInner = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1266
            this.startAngle = -135;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1267
            this.endAngle = -45;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1268
            this.imageName = "edit";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1269
            this.text = "Edit";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1270
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1271
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1272
            if (!this.renderer.is_dragging) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1273
                this.source_representation.openEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1274
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1275
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1276
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1277
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1278
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1279
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1280
    var NodeRemoveButton = Renderer.NodeRemoveButton = Rkns.Utils.inherit(_NodeButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1281
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1282
    _(NodeRemoveButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1283
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1284
            this.type = "Node-remove-button";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1285
            this.lastSectorInner = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1286
            this.startAngle = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1287
            this.endAngle = 90;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1288
            this.imageName = "remove";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1289
            this.text = "Remove";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1290
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1291
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1292
            this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1293
            this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1294
            this.renderer.removeRepresentationsOfType("editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1295
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1296
                if (this.options.element_delete_delay) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1297
                    var delid = Rkns.Utils.getUID("delete");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1298
                    this.renderer.delete_list.push({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1299
                        id: delid,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1300
                        time: new Date().valueOf() + this.options.element_delete_delay
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1301
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1302
                    this.source_representation.model.set("delete_scheduled", delid);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1303
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1304
                    if (confirm(this.renkan.translate('Do you really wish to remove node ') + '"' + this.source_representation.model.get("title") + '"?')) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1305
                        this.project.removeNode(this.source_representation.model);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1306
                    }
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1307
                }
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1308
            }
4
f5297dde9053 Can now add nodes/edges
veltr
parents: 3
diff changeset
  1309
        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1310
    });
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
  1311
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1312
    /* */
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
  1313
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1314
    var NodeRevertButton = Renderer.NodeRevertButton = Rkns.Utils.inherit(_NodeButton);
5
67085e6281e5 Added basic node/edge editing
veltr
parents: 4
diff changeset
  1315
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1316
    _(NodeRevertButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1317
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1318
            this.type = "Node-revert-button";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1319
            this.lastSectorInner = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1320
            this.startAngle = -135;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1321
            this.endAngle = 135;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1322
            this.imageName = "revert";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1323
            this.text = "Cancel deletion";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1324
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1325
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1326
            this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1327
            this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1328
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1329
                this.source_representation.model.unset("delete_scheduled");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1330
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1331
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1332
    });
159
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  1333
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1334
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1335
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1336
    var NodeLinkButton = Renderer.NodeLinkButton = Rkns.Utils.inherit(_NodeButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1337
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1338
    _(NodeLinkButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1339
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1340
            this.type = "Node-link-button";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1341
            this.lastSectorInner = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1342
            this.startAngle = 90;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1343
            this.endAngle = 180;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1344
            this.imageName = "link";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1345
            this.text = "Link to another node";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1346
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1347
        mousedown: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1348
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1349
                var _off = this.renderer.canvas_$.offset(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1350
                _point = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1351
                                          _event.pageX - _off.left,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1352
                                          _event.pageY - _off.top
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1353
                                          ]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1354
                this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1355
                this.renderer.removeRepresentationsOfType("editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1356
                this.renderer.addTempEdge(this.source_representation, _point);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1357
            }
194
f53a7999ae7b Node link fix
veltr
parents: 193
diff changeset
  1358
        }
f53a7999ae7b Node link fix
veltr
parents: 193
diff changeset
  1359
    });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1360
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1361
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1362
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1363
    var NodeEnlargeButton = Renderer.NodeEnlargeButton = Rkns.Utils.inherit(_NodeButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1364
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1365
    _(NodeEnlargeButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1366
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1367
            this.type = "Node-enlarge-button";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1368
            this.lastSectorInner = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1369
            this.startAngle = -45;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1370
            this.endAngle = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1371
            this.imageName = "enlarge";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1372
            this.text = "Enlarge";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1373
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1374
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1375
            var _newsize = 1 + (this.source_representation.model.get("size") || 0);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1376
            this.source_representation.model.set("size", _newsize);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1377
            this.source_representation.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1378
            this.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1379
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1380
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1381
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1382
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1383
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1384
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1385
    var NodeShrinkButton = Renderer.NodeShrinkButton = Rkns.Utils.inherit(_NodeButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1386
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1387
    _(NodeShrinkButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1388
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1389
            this.type = "Node-shrink-button";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1390
            this.lastSectorInner = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1391
            this.startAngle = -180;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1392
            this.endAngle = -135;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1393
            this.imageName = "shrink";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1394
            this.text = "Shrink";
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1395
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1396
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1397
            var _newsize = -1 + (this.source_representation.model.get("size") || 0);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1398
            this.source_representation.model.set("size", _newsize);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1399
            this.source_representation.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1400
            this.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1401
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1402
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1403
    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1404
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1405
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1406
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1407
    var EdgeEditButton = Renderer.EdgeEditButton = Rkns.Utils.inherit(_BaseButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1408
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1409
    _(EdgeEditButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1410
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1411
            this.type = "Edge-edit-button";
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1412
            this.sector = this.renderer.drawSector(this, Rkns.Utils._EDGE_BUTTON_INNER, Rkns.Utils._EDGE_BUTTON_OUTER, -270, -90, 1, "edit", this.renkan.translate("Edit"));
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1413
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1414
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1415
            if (!this.renderer.is_dragging) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1416
                this.source_representation.openEditor();
114
110f99eb417e moved options to defaults.js and improved read-only switching
veltr
parents: 113
diff changeset
  1417
            }
194
f53a7999ae7b Node link fix
veltr
parents: 193
diff changeset
  1418
        }
f53a7999ae7b Node link fix
veltr
parents: 193
diff changeset
  1419
    });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1420
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1421
    /* */
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1422
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1423
    var EdgeRemoveButton = Renderer.EdgeRemoveButton = Rkns.Utils.inherit(_BaseButton);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1424
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1425
    _(EdgeRemoveButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1426
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1427
            this.type = "Edge-remove-button";
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1428
            this.sector = this.renderer.drawSector(this, Rkns.Utils._EDGE_BUTTON_INNER, Rkns.Utils._EDGE_BUTTON_OUTER, -90, 90, 1, "remove", this.renkan.translate("Remove"));
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1429
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1430
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1431
            this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1432
            this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1433
            this.renderer.removeRepresentationsOfType("editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1434
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1435
                if (this.options.element_delete_delay) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1436
                    var delid = Rkns.Utils.getUID("delete");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1437
                    this.renderer.delete_list.push({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1438
                        id: delid,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1439
                        time: new Date().valueOf() + this.options.element_delete_delay
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1440
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1441
                    this.source_representation.model.set("delete_scheduled", delid);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1442
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1443
                    if (confirm(this.renkan.translate('Do you really wish to remove edge ') + '"' + this.source_representation.model.get("title") + '"?')) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1444
                        this.project.removeEdge(this.source_representation.model);
173
009427475db2 Improvements for MDP and CG
veltr
parents: 170
diff changeset
  1445
                    }
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1446
                }
159
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  1447
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1448
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1449
    });
7
ae86ecebb1be Added Edit-Remove buttons
veltr
parents: 6
diff changeset
  1450
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1451
    /* */
7
ae86ecebb1be Added Edit-Remove buttons
veltr
parents: 6
diff changeset
  1452
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1453
    var EdgeRevertButton = Renderer.EdgeRevertButton = Rkns.Utils.inherit(_BaseButton);
132
860340d4c645 Improvements for CineCard
veltr
parents: 122
diff changeset
  1454
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1455
    _(EdgeRevertButton.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1456
        _init: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1457
            this.type = "Edge-revert-button";
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1458
            this.sector = this.renderer.drawSector(this, Rkns.Utils._EDGE_BUTTON_INNER, Rkns.Utils._EDGE_BUTTON_OUTER, -135, 135, 1, "revert", this.renkan.translate("Cancel deletion"));
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1459
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1460
        mouseup: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1461
            this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1462
            this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1463
            if (this.renderer.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1464
                this.source_representation.model.unset("delete_scheduled");
174
756cfa6570d2 Setting element_delete_delay now shows remove confirm dialog
veltr
parents: 173
diff changeset
  1465
            }
756cfa6570d2 Setting element_delete_delay now shows remove confirm dialog
veltr
parents: 173
diff changeset
  1466
        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1467
    });
7
ae86ecebb1be Added Edit-Remove buttons
veltr
parents: 6
diff changeset
  1468
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1469
    /* */
11
c73bfb5c0af6 UI Improvements before merge
veltr
parents: 10
diff changeset
  1470
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1471
    var MiniFrame = Renderer.MiniFrame = Rkns.Utils.inherit(_BaseRepresentation);
11
c73bfb5c0af6 UI Improvements before merge
veltr
parents: 10
diff changeset
  1472
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1473
    _(MiniFrame.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1474
        paperShift: function(_delta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1475
            this.renderer.offset = this.renderer.offset.subtract(_delta.divide(this.renderer.minimap.scale).multiply(this.renderer.scale));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1476
            this.renderer.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1477
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1478
        mouseup: function(_delta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1479
            this.renderer.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1480
            this.renderer.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1481
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1482
    });
132
860340d4c645 Improvements for CineCard
veltr
parents: 122
diff changeset
  1483
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1484
    /* */
15
de8528eb3662 Commit before merge
veltr
parents: 11
diff changeset
  1485
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1486
    var Scene = Renderer.Scene = function(_renkan) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1487
        this.renkan = _renkan;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1488
        this.$ = $(".Rk-Render");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1489
        this.representations = [];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1490
        this.$.html(this.template(_renkan));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1491
        this.onStatusChange();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1492
        this.canvas_$ = this.$.find(".Rk-Canvas");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1493
        this.labels_$ = this.$.find(".Rk-Labels");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1494
        this.editor_$ = this.$.find(".Rk-Editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1495
        this.notif_$ = this.$.find(".Rk-Notifications");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1496
        paper.setup(this.canvas_$[0]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1497
        this.scale = 1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1498
        this.initialScale = 1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1499
        this.offset = paper.view.center;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1500
        this.totalScroll = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1501
        this.mouse_down = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1502
        this.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1503
        this.selected_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1504
        this.edge_layer = new paper.Layer();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1505
        this.node_layer = new paper.Layer();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1506
        this.buttons_layer = new paper.Layer();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1507
        this.delete_list = [];
70
47b3125130a2 bookmarklet evolution
veltr
parents: 69
diff changeset
  1508
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1509
        if (_renkan.options.show_minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1510
            this.minimap = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1511
                    background_layer: new paper.Layer(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1512
                    edge_layer: new paper.Layer(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1513
                    node_layer: new paper.Layer(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1514
                    node_group: new paper.Group(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1515
                    size: new paper.Size( _renkan.options.minimap_width, _renkan.options.minimap_height )
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1516
            };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1517
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1518
            this.minimap.background_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1519
            this.minimap.topleft = paper.view.bounds.bottomRight.subtract(this.minimap.size);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1520
            this.minimap.rectangle = new paper.Path.Rectangle(this.minimap.topleft.subtract([2,2]), this.minimap.size.add([4,4]));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1521
            this.minimap.rectangle.fillColor = _renkan.options.minimap_background_color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1522
            this.minimap.rectangle.strokeColor = _renkan.options.minimap_border_color;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1523
            this.minimap.rectangle.strokeWidth = 4;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1524
            this.minimap.offset = new paper.Point(this.minimap.size.divide(2));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1525
            this.minimap.scale = .1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1526
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1527
            this.minimap.node_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1528
            this.minimap.cliprectangle = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1529
            this.minimap.node_group.addChild(this.minimap.cliprectangle);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1530
            this.minimap.node_group.clipped = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1531
            this.minimap.miniframe = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1532
            this.minimap.node_group.addChild(this.minimap.miniframe);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1533
            this.minimap.miniframe.fillColor = '#c0c0ff';
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1534
            this.minimap.miniframe.opacity = .3;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1535
            this.minimap.miniframe.strokeColor = '#000080';
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1536
            this.minimap.miniframe.strokeWidth = 3;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1537
            this.minimap.miniframe.__representation = new MiniFrame(this, null);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1538
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1539
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1540
        this.throttledPaperDraw = _(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1541
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1542
        }).throttle(100);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1543
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1544
        this.bundles = [];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1545
        this.click_mode = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1546
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1547
        var _this = this,
283
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1548
        _allowScroll = true,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1549
        _originalScale = 1,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1550
        _zooming = false,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1551
        _lastTapX = 0,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1552
        _lastTapY = 0;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1553
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1554
        this.image_cache = {};
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1555
        this.icon_cache = {};
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1556
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1557
        ['edit', 'remove', 'link', 'enlarge', 'shrink', 'revert' ].forEach(function(imgname) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1558
            var img = new Image();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1559
            img.src = _renkan.options.static_url + 'img/' + imgname + '.png';
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1560
            _this.icon_cache[imgname] = img;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1561
        });
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1562
        
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1563
        var throttledMouseMove = _.throttle(function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1564
            _this.onMouseMove(_event, _isTouch);
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1565
        }, Rkns.Utils._MOUSEMOVE_RATE);
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1566
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1567
        this.canvas_$.on({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1568
            mousedown: function(_event) {
211
d87f6bdee43d upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents: 207
diff changeset
  1569
                _event.preventDefault();
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1570
                _this.onMouseDown(_event, false);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1571
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1572
            mousemove: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1573
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1574
                throttledMouseMove(_event, false);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1575
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1576
            mouseup: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1577
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1578
                _this.onMouseUp(_event, false);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1579
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1580
            mousewheel: function(_event, _delta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1581
                if(_renkan.options.zoom_on_scroll) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1582
                    _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1583
                    if (_allowScroll) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1584
                        _this.onScroll(_event, _delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1585
                    }
211
d87f6bdee43d upgrade libs + add no minified versions of libs + improve build + allow disabling zoom on scroll
ymh <ymh.work@gmail.com>
parents: 207
diff changeset
  1586
                }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1587
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1588
            touchstart: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1589
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1590
                var _touches = _event.originalEvent.touches[0];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1591
                if (
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1592
                        _renkan.options.allow_double_click
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1593
                        && new Date() - _lastTap < Rkns.Utils._DOUBLETAP_DELAY
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1594
                        && ( Math.pow(_lastTapX - _touches.pageX, 2) + Math.pow(_lastTapY - _touches.pageY, 2) < Rkns.Utils._DOUBLETAP_DISTANCE )
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1595
                ) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1596
                    _lastTap = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1597
                    _this.onDoubleClick(_touches);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1598
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1599
                    _lastTap = new Date();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1600
                    _lastTapX = _touches.pageX;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1601
                    _lastTapY = _touches.pageY;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1602
                    _originalScale = _this.scale;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1603
                    _zooming = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1604
                    _this.onMouseDown(_touches, true);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1605
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1606
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1607
            touchmove: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1608
                _event.preventDefault();
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1609
                _lastTap = 0;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1610
                if (_event.originalEvent.touches.length == 1) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1611
                    _this.onMouseMove(_event.originalEvent.touches[0], true);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1612
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1613
                    if (!_zooming) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1614
                        _this.onMouseUp(_event.originalEvent.touches[0], true);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1615
                        _this.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1616
                        _this.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1617
                        _zooming = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1618
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1619
                    if (_event.originalEvent.scale === "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1620
                        return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1621
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1622
                    var _newScale = _event.originalEvent.scale * _originalScale,
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1623
                    _scaleRatio = _newScale / _this.scale,
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1624
                    _newOffset = new paper.Point([
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1625
                                                  _this.canvas_$.width(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1626
                                                  _this.canvas_$.height()
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1627
                                                  ]).multiply( .5 * ( 1 - _scaleRatio ) ).add(_this.offset.multiply( _scaleRatio ));
278
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
  1628
                    _this.setScale(_newScale, _newOffset);
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1629
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1630
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1631
            touchend: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1632
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1633
                _this.onMouseUp(_event.originalEvent.changedTouches[0], true);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1634
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1635
            dblclick: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1636
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1637
                if (_renkan.options.allow_double_click) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1638
                    _this.onDoubleClick(_event);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1639
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1640
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1641
            mouseleave: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1642
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1643
                _this.onMouseUp(_event, false);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1644
                _this.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1645
                _this.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1646
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1647
            dragover: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1648
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1649
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1650
            dragenter: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1651
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1652
                _allowScroll = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1653
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1654
            dragleave: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1655
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1656
                _allowScroll = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1657
            },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1658
            drop: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1659
                _event.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1660
                _allowScroll = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1661
                var res = {};
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1662
                _(_event.originalEvent.dataTransfer.types).each(function(t) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1663
                    try {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1664
                        res[t] = _event.originalEvent.dataTransfer.getData(t);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1665
                    } catch(e) {}
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1666
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1667
                var text = _event.originalEvent.dataTransfer.getData("Text");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1668
                if (typeof text === "string") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1669
                    switch(text[0]) {
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1670
                    case "{":
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1671
                    case "[":
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1672
                        try {
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1673
                            var data = JSON.parse(text);
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1674
                            _(res).extend(data);
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1675
                        }
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1676
                        catch(e) {
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1677
                            if (!res["text/plain"]) {
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1678
                                res["text/plain"] = text;
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1679
                            }
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1680
                        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1681
                        break;
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1682
                    case "<":
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1683
                        if (!res["text/html"]) {
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1684
                            res["text/html"] = text;
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1685
                        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1686
                        break;
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1687
                    default:
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1688
                        if (!res["text/plain"]) {
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1689
                            res["text/plain"] = text;
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1690
                        }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1691
                    }
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1692
                }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1693
                var url = _event.originalEvent.dataTransfer.getData("URL");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1694
                if (url && !res["text/uri-list"]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1695
                    res["text/uri-list"] = url;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1696
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1697
                _this.dropData(res, _event.originalEvent);
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1698
            }
190
a9040a7c47d9 Some changes for standalone app compatibility
veltr
parents: 189
diff changeset
  1699
        });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1700
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1701
        var bindClick = function(selector, fname) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1702
            _this.$.find(selector).click(function(evt) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1703
                _this[fname](evt);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1704
                return false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1705
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1706
        };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1707
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1708
        bindClick(".Rk-ZoomOut", "zoomOut");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1709
        bindClick(".Rk-ZoomIn", "zoomIn");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1710
        bindClick(".Rk-ZoomFit", "autoScale");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1711
        this.$.find(".Rk-ZoomSave").click( function() {
283
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1712
            // Save scale and offset point
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1713
            _this.renkan.project.addView( { zoom_level:_this.scale, offset_x:_this.offset.x, offset_y:_this.offset.y } );
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1714
        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1715
        this.$.find(".Rk-ZoomSetSaved").click( function() {
281
9ff388c9bc8d model cleanup for views
cavaliet
parents: 278
diff changeset
  1716
            var view = _this.renkan.project.get("views").last();
9ff388c9bc8d model cleanup for views
cavaliet
parents: 278
diff changeset
  1717
            if(view){
283
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1718
                _this.setScale(view.get("zoom_level"), new paper.Point(view.get("offset_x"), view.get("offset_y")));
281
9ff388c9bc8d model cleanup for views
cavaliet
parents: 278
diff changeset
  1719
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1720
        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1721
        if(this.renkan.read_only && !isNaN(parseInt(this.renkan.options.default_view))){
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1722
            this.$.find(".Rk-ZoomSetSaved").show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1723
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1724
        this.$.find(".Rk-CurrentUser").mouseenter(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1725
                function() { _this.$.find(".Rk-UserList").slideDown(); }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1726
        );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1727
        this.$.find(".Rk-Users").mouseleave(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1728
                function() { _this.$.find(".Rk-UserList").slideUp(); }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1729
        );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1730
        bindClick(".Rk-FullScreen-Button", "fullScreen");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1731
        bindClick(".Rk-AddNode-Button", "addNodeBtn");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1732
        bindClick(".Rk-AddEdge-Button", "addEdgeBtn");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1733
        bindClick(".Rk-Save-Button", "save");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1734
        bindClick(".Rk-Open-Button", "open");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1735
        this.$.find(".Rk-Bookmarklet-Button")
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  1736
        .attr("href","javascript:" + Rkns.Utils._BOOKMARKLET_CODE(_renkan))
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1737
        .click(function(){
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1738
            _this.notif_$
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1739
            .text(_renkan.translate("Drag this button to your bookmark bar. When on a third-party website, click it to enable drag-and-drop from the website to Renkan."))
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1740
            .fadeIn()
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1741
            .delay(5000)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1742
            .fadeOut();
160
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1743
            return false;
408da84d4dc0 Convert tabs added by ide configuration mistake
veltr
parents: 159
diff changeset
  1744
        });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1745
        this.$.find(".Rk-TopBar-Button").mouseover(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1746
            $(this).find(".Rk-TopBar-Tooltip").show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1747
        }).mouseout(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1748
            $(this).find(".Rk-TopBar-Tooltip").hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1749
        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1750
        bindClick(".Rk-Fold-Bins", "foldBins");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1751
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1752
        paper.view.onResize = function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1753
            // Because of paper bug which does not calculate the good height (and width a fortiori)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1754
            // We have to update manually the canvas's height
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1755
            paper.view._viewSize.height =  _event.size.height = _this.canvas_$.parent().height();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1756
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1757
            if (_this.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1758
                _this.minimap.topleft = paper.view.bounds.bottomRight.subtract(_this.minimap.size);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1759
                _this.minimap.rectangle.fitBounds(_this.minimap.topleft.subtract([2,2]), _this.minimap.size.add([4,4]));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1760
                _this.minimap.cliprectangle.fitBounds(_this.minimap.topleft, _this.minimap.size);
62
f9019462465a Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents: 57
diff changeset
  1761
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1762
            _this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1763
        };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1764
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1765
        var _thRedraw = _.throttle(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1766
            _this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1767
        },50);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1768
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1769
        this.addRepresentations("Node", this.renkan.project.get("nodes"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1770
        this.addRepresentations("Edge", this.renkan.project.get("edges"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1771
        this.renkan.project.on("change:title", function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1772
            _this.$.find(".Rk-PadTitle").val(_renkan.project.get("title"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1773
        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1774
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1775
        this.$.find(".Rk-PadTitle").on("keyup input paste", function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1776
            _renkan.project.set({"title": $(this).val()});
163
fca0475da9a7 Changes for metadataplayer compatibility
veltr
parents: 161
diff changeset
  1777
        });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1778
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1779
        var _thRedrawUsers = _.throttle(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1780
            _this.redrawUsers();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1781
        }, 100);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1782
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1783
        _thRedrawUsers();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1784
283
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1785
        // register model events
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1786
        this.renkan.project.on("add:users remove:users", _thRedrawUsers);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1787
283
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1788
        this.renkan.project.on("add:views remove:views", function(_node) {
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1789
            if(_this.renkan.project.get('views').length > 0) {
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1790
                _this.$.find(".Rk-ZoomSetSaved").show();
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1791
            }
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1792
            else {
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1793
                _this.$.find(".Rk-ZoomSetSaved").hide();
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1794
            }
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1795
        });
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1796
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1797
        this.renkan.project.on("add:nodes", function(_node) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1798
            _this.addRepresentation("Node", _node);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1799
            _thRedraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1800
        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1801
        this.renkan.project.on("add:edges", function(_edge) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1802
            _this.addRepresentation("Edge", _edge);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1803
            _thRedraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1804
        });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1805
        this.renkan.project.on("change:title", function(_model, _title) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1806
            var el = _this.$.find(".Rk-PadTitle");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1807
            if (el.is("input")) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1808
                if (el.val() !== _title) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1809
                    el.val(_title);
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
  1810
                }
196
2a2fcec209d0 Added in-graph search
veltr
parents: 195
diff changeset
  1811
            } else {
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1812
                el.text(_title);
196
2a2fcec209d0 Added in-graph search
veltr
parents: 195
diff changeset
  1813
            }
2a2fcec209d0 Added in-graph search
veltr
parents: 195
diff changeset
  1814
        });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1815
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1816
        if (_renkan.options.size_bug_fix) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1817
            var _delay = (
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1818
                    typeof _renkan.options.size_bug_fix === "number"
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1819
                        ? _renkan.options.size_bug_fix
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1820
                                : 500
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1821
            );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1822
            window.setTimeout(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1823
                    function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1824
                        _this.fixSize(true);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1825
                    },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1826
                    _delay
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1827
            );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1828
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1829
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1830
        if (_renkan.options.force_resize) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1831
            $(window).resize(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1832
                _this.fixSize(false);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1833
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1834
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1835
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1836
        if (_renkan.options.show_user_list && _renkan.options.user_color_editable) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1837
            var $cpwrapper = this.$.find(".Rk-Users .Rk-Edit-ColorPicker-Wrapper"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1838
            $cplist = this.$.find(".Rk-Users .Rk-Edit-ColorPicker");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1839
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1840
            $cpwrapper.hover(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1841
                    function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1842
                        if (_this.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1843
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1844
                            $cplist.show();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1845
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1846
                    },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1847
                    function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1848
                        _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1849
                        $cplist.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1850
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1851
            );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1852
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1853
            $cplist.find("li").mouseenter(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1854
                    function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1855
                        if (_this.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1856
                            _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1857
                            _this.$.find(".Rk-CurrentUser-Color").css("background", $(this).attr("data-color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1858
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1859
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1860
            );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1861
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1862
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1863
        if (_renkan.options.show_search_field) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1864
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1865
            var lastval = '';
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1866
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1867
            this.$.find(".Rk-GraphSearch-Field").on("keyup change paste input", function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1868
                var $this = $(this),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1869
                val = $this.val();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1870
                if (val === lastval) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1871
                    return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1872
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1873
                lastval = val;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1874
                if (val.length < 2) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1875
                    _renkan.project.get("nodes").each(function(n) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1876
                        _this.getRepresentationByModel(n).unhighlight();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1877
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1878
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1879
                    var rxs = Rkns.Utils.regexpFromTextOrArray(val);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1880
                    _renkan.project.get("nodes").each(function(n) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1881
                        if (rxs.test(n.get("title")) || rxs.test(n.get("description"))) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1882
                            _this.getRepresentationByModel(n).highlight(rxs);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1883
                        } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1884
                            _this.getRepresentationByModel(n).unhighlight(); 
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1885
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1886
                    });
161
c7a503c80ef4 Two step deletion of nodes and edges
veltr
parents: 160
diff changeset
  1887
                }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1888
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1889
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1890
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1891
        this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1892
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1893
        window.setInterval(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1894
            var _now = new Date().valueOf();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1895
            _this.delete_list.forEach(function(d) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1896
                if (_now >= d.time) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1897
                    var el = _renkan.project.get("nodes").findWhere({"delete_scheduled":d.id});
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1898
                    if (el) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1899
                        project.removeNode(el);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1900
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1901
                    el = _renkan.project.get("edges").findWhere({"delete_scheduled":d.id});
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1902
                    if (el) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1903
                        project.removeEdge(el);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1904
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1905
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1906
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1907
            _this.delete_list = _this.delete_list.filter(function(d) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1908
                return _renkan.project.get("nodes").findWhere({"delete_scheduled":d.id}) || _renkan.project.get("edges").findWhere({"delete_scheduled":d.id});
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1909
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1910
        }, 500);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1911
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1912
        if (this.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1913
            window.setInterval(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1914
                _this.rescaleMinimap();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1915
            }, 2000);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1916
        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1917
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1918
    };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1919
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1920
    _(Scene.prototype).extend({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1921
        template: _.template(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1922
                '<% if (options.show_top_bar) { %><div class="Rk-TopBar"><% if (!options.editor_mode) { %><h2 class="Rk-PadTitle"><%- project.get("title") || translate("Untitled project")%></h2>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1923
                + '<% } else { %><input type="text" class="Rk-PadTitle" value="<%- project.get("title") || "" %>" placeholder="<%-translate("Untitled project")%>" /><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1924
                + '<% if (options.show_user_list) { %><div class="Rk-Users"><div class="Rk-CurrentUser"><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-CurrentUser-Color"><% if (options.user_color_editable) { %><span class="Rk-Edit-ColorTip"></span><% } %></span>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1925
                + '<% if (options.user_color_editable) { print(colorPicker) } %></div><span class="Rk-CurrentUser-Name">&lt;unknown user&gt;</span></div><ul class="Rk-UserList"></ul></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1926
                + '<% if (options.home_button_url) {%><div class="Rk-TopBar-Separator"></div><a class="Rk-TopBar-Button Rk-Home-Button" href="<%- options.home_button_url %>"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Contents">'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1927
                + '<%- translate(options.home_button_title) %></div></div></a><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1928
                + '<% if (options.show_fullscreen_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-FullScreen-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Contents"><%-translate("Full Screen")%></div></div></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1929
                + '<% if (options.editor_mode) { %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1930
                + '<% if (options.show_addnode_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddNode-Button"><div class="Rk-TopBar-Tooltip">'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1931
                + '<div class="Rk-TopBar-Tooltip-Contents"><%-translate("Add Node")%></div></div></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1932
                + '<% if (options.show_addedge_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddEdge-Button"><div class="Rk-TopBar-Tooltip">'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1933
                + '<div class="Rk-TopBar-Tooltip-Contents"><%-translate("Add Edge")%></div></div></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1934
                + '<% if (options.show_save_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-Save-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Contents"> </div></div></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1935
                + '<% if (options.show_open_button) { %><div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-Open-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Contents"><%-translate("Open Project")%></div></div></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1936
                + '<% if (options.show_bookmarklet) { %><div class="Rk-TopBar-Separator"></div><a class="Rk-TopBar-Button Rk-Bookmarklet-Button" href="#"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Contents">'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1937
                + '<%-translate("Renkan \'Drag-to-Add\' bookmarklet")%></div></div></a><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1938
                + '<div class="Rk-TopBar-Separator"></div><% }; if (options.show_search_field) { %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1939
                + '<form action="#" class="Rk-GraphSearch-Form"><input type="search" class="Rk-GraphSearch-Field" placeholder="<%- translate("Search in graph") %>" /></form><div class="Rk-TopBar-Separator"></div><% } %></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1940
                + '<div class="Rk-Editing-Space<% if (!options.show_top_bar) { %> Rk-Editing-Space-Full<% } %>">'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1941
                + '<div class="Rk-Labels"></div><canvas class="Rk-Canvas" resize></canvas><div class="Rk-Notifications"></div><div class="Rk-Editor">'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1942
                + '<% if (options.show_bins) { %><div class="Rk-Fold-Bins">&laquo;</div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1943
                + '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%-translate("Zoom In")%>"></div><div class="Rk-ZoomFit" title="<%-translate("Zoom Fit")%>"></div><div class="Rk-ZoomOut" title="<%-translate("Zoom Out")%>"></div>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1944
                + '<% if (options.editor_mode) { %><div class="Rk-ZoomSave" title="<%-translate("Zoom Save")%>"></div><% } %>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1945
                + '<% if (options.editor_mode || !isNaN(parseInt(options.default_view))) { %><div class="Rk-ZoomSetSaved" title="<%-translate("View saved zoom")%>"></div><% } %></div>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1946
                + '</div></div>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1947
        ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1948
        fixSize: function(_autoscale) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1949
            var w = this.$.width(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1950
            h = this.$.height();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1951
            if (this.renkan.options.show_top_bar) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1952
                h -= this.$.find(".Rk-TopBar").height();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1953
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1954
            this.canvas_$.attr({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1955
                width: w,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1956
                height: h
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1957
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1958
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1959
            paper.view.viewSize = new paper.Size([w, h]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1960
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1961
            if (_autoscale) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1962
                // If _autoscale, we get the initial view (zoom+offset) set in the project datas.
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1963
                if(this.renkan.read_only && !isNaN(parseInt(this.renkan.options.default_view))){
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1964
                    this.autoScale(this.renkan.project.get("views")[parseInt(this.renkan.options.default_view)]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1965
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1966
                else{
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1967
                    this.autoScale();
161
c7a503c80ef4 Two step deletion of nodes and edges
veltr
parents: 160
diff changeset
  1968
                }
c7a503c80ef4 Two step deletion of nodes and edges
veltr
parents: 160
diff changeset
  1969
            }
159
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  1970
        },
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1971
        drawSector: function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1972
            var _options = this.renkan.options,
283
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1973
            _startRads = _startAngle * Math.PI / 180,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1974
            _endRads = _endAngle * Math.PI / 180,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1975
            _img = this.icon_cache[_imgname],
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1976
            _startdx = - Math.sin(_startRads),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1977
            _startdy = Math.cos(_startRads),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1978
            _startXIn = Math.cos(_startRads) * _inR + _padding * _startdx,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1979
            _startYIn = Math.sin(_startRads) * _inR + _padding * _startdy,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1980
            _startXOut = Math.cos(_startRads) * _outR + _padding * _startdx,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1981
            _startYOut = Math.sin(_startRads) * _outR + _padding * _startdy,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1982
            _enddx = - Math.sin(_endRads),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1983
            _enddy = Math.cos(_endRads),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1984
            _endXIn = Math.cos(_endRads) * _inR - _padding * _enddx,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1985
            _endYIn = Math.sin(_endRads) * _inR - _padding * _enddy,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1986
            _endXOut = Math.cos(_endRads) * _outR - _padding * _enddx,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1987
            _endYOut = Math.sin(_endRads) * _outR - _padding * _enddy,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1988
            _centerR = (_inR + _outR)/2,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1989
            _centerRads = (_startRads + _endRads) / 2,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1990
            _centerX = Math.cos(_centerRads) * _centerR,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1991
            _centerY = Math.sin(_centerRads) * _centerR,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1992
            _centerXIn = Math.cos(_centerRads) * _inR,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1993
            _centerXOut = Math.cos(_centerRads) * _outR,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1994
            _centerYIn = Math.sin(_centerRads) * _inR,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1995
            _centerYOut = Math.sin(_centerRads) * _outR,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1996
            _textX = Math.cos(_centerRads) * (_outR + 3),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  1997
            _textY = Math.sin(_centerRads) * (_outR + _options.buttons_label_font_size) + _options.buttons_label_font_size / 2;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1998
            this.buttons_layer.activate();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  1999
            var _path = new paper.Path();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2000
            _path.add([_startXIn, _startYIn]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2001
            _path.arcTo([_centerXIn, _centerYIn], [_endXIn, _endYIn]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2002
            _path.lineTo([_endXOut,  _endYOut]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2003
            _path.arcTo([_centerXOut, _centerYOut], [_startXOut, _startYOut]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2004
            _path.fillColor = _options.buttons_background;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2005
            _path.opacity = .5;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2006
            _path.closed = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2007
            _path.__representation = _repr;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2008
            var _text = new paper.PointText(_textX,_textY);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2009
            _text.characterStyle = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2010
                    fontSize: _options.buttons_label_font_size,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2011
                    fillColor: _options.buttons_label_color
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2012
            };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2013
            if (_textX > 2) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2014
                _text.paragraphStyle.justification = 'left';
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2015
            } else if (_textX < -2) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2016
                _text.paragraphStyle.justification = 'right';
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2017
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2018
                _text.paragraphStyle.justification = 'center';
159
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  2019
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2020
            _text.visible = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2021
            var _visible = false,
283
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2022
            _restPos = new paper.Point(-200, -200),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2023
            _grp = new paper.Group([_path, _text]),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2024
            _delta = _grp.position,
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2025
            _imgdelta = new paper.Point([_centerX, _centerY]),
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2026
            _currentPos = new paper.Point(0,0);
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2027
            _text.content = _caption;
159
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  2028
            _grp.visible = false;
1796e0220bef Bugfixes and improvements for Cinegift
veltr
parents: 157
diff changeset
  2029
            _grp.position = _restPos;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2030
            var _res = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2031
                    show: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2032
                        _visible = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2033
                        _grp.position = _currentPos.add(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2034
                        _grp.visible = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2035
                    },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2036
                    moveTo: function(_point) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2037
                        _currentPos = _point;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2038
                        if (_visible) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2039
                            _grp.position = _point.add(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2040
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2041
                    },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2042
                    hide: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2043
                        _visible = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2044
                        _grp.visible = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2045
                        _grp.position = _restPos;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2046
                    },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2047
                    select: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2048
                        _path.opacity = .8;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2049
                        _text.visible = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2050
                    },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2051
                    unselect: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2052
                        _path.opacity = .5;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2053
                        _text.visible = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2054
                    },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2055
                    destroy: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2056
                        _grp.remove();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2057
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2058
            };
278
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
  2059
            var showImage = function() {
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2060
                var _raster = new paper.Raster(_img);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2061
                _raster.position = _imgdelta.add(_grp.position).subtract(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2062
                _raster.locked = true; // Disable mouse events on icon
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2063
                _grp.addChild(_raster);
278
b45dda454dd6 remove as much warnings as possible.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
  2064
            };
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2065
            if (_img.width) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2066
                showImage();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2067
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2068
                $(_img).on("load",showImage);
31
5e37072ec7b7 Added multiple edges
veltr
parents: 30
diff changeset
  2069
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2070
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2071
            return _res;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2072
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2073
        addToBundles: function(_edgeRepr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2074
            var _bundle = _(this.bundles).find(function(_bundle) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2075
                return ( 
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2076
                        ( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation )
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2077
                        || ( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation )
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2078
                );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2079
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2080
            if (typeof _bundle !== "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2081
                _bundle.edges.push(_edgeRepr);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2082
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2083
                _bundle = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2084
                        from: _edgeRepr.from_representation,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2085
                        to: _edgeRepr.to_representation,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2086
                        edges: [ _edgeRepr ],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2087
                        getPosition: function(_er) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2088
                            var _dir = (_er.from_representation === this.from) ? 1 : -1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2089
                            return _dir * ( _(this.edges).indexOf(_er) - (this.edges.length - 1) / 2 );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2090
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2091
                };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2092
                this.bundles.push(_bundle);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2093
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2094
            return _bundle;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2095
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2096
        isEditable: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2097
            return (this.renkan.options.editor_mode && !this.renkan.read_only);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2098
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2099
        onStatusChange: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2100
            var savebtn = this.$.find(".Rk-Save-Button"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2101
            tip = savebtn.find(".Rk-TopBar-Tooltip-Contents");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2102
            if (this.renkan.read_only) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2103
                savebtn.removeClass("disabled Rk-Save-Online").addClass("Rk-Save-ReadOnly");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2104
                tip.text(this.renkan.translate("Connection lost"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2105
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2106
                if (this.renkan.options.snapshot_mode) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2107
                    savebtn.removeClass("Rk-Save-ReadOnly Rk-Save-Online");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2108
                    tip.text(this.renkan.translate("Save Project"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2109
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2110
                    savebtn.removeClass("disabled Rk-Save-ReadOnly").addClass("Rk-Save-Online");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2111
                    tip.text(this.renkan.translate("Auto-save enabled"));
198
d3737b90a66b Allow user name and color editing
veltr
parents: 197
diff changeset
  2112
                }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2113
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2114
            this.redrawUsers();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2115
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2116
        setScale: function(_newScale, _offset) {
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  2117
            if ((_newScale/this.initialScale) > Rkns.Utils._MIN_SCALE && (_newScale/this.initialScale) < Rkns.Utils._MAX_SCALE) {
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2118
                this.scale = _newScale;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2119
                if (_offset) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2120
                    this.offset = _offset;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2121
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2122
                this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2123
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2124
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2125
        autoScale: function(force_view) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2126
            var nodes = this.renkan.project.get("nodes");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2127
            if (nodes.length > 1) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2128
                var _xx = nodes.map(function(_node) { return _node.get("position").x; }),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2129
                _yy = nodes.map(function(_node) { return _node.get("position").y; }),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2130
                _minx = Math.min.apply(Math, _xx),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2131
                _miny = Math.min.apply(Math, _yy),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2132
                _maxx = Math.max.apply(Math, _xx),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2133
                _maxy = Math.max.apply(Math, _yy);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2134
                var _scale = Math.min( (paper.view.size.width - 2 * this.renkan.options.autoscale_padding) / (_maxx - _minx), (paper.view.size.height - 2 * this.renkan.options.autoscale_padding) / (_maxy - _miny));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2135
                this.initialScale = _scale;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2136
                // Override calculated scale if asked
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2137
                if((typeof force_view !== "undefined") && parseFloat(force_view.zoom_level)>0 && parseFloat(force_view.offset_x)>0 && parseFloat(force_view.offset_y)>0){
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2138
                    this.setScale(parseFloat(force_view.zoom_level), new paper.Point(parseFloat(force_view.offset_x), parseFloat(force_view.offset_y)));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2139
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2140
                else{
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2141
                    this.setScale(_scale, paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)));
198
d3737b90a66b Allow user name and color editing
veltr
parents: 197
diff changeset
  2142
                }
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
  2143
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2144
            if (nodes.length === 1) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2145
                this.setScale(1, paper.view.center.subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y])));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2146
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2147
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2148
        redrawMiniframe: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2149
            var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2150
            bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2151
            this.minimap.miniframe.fitBounds(topleft, bottomright);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2152
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2153
        rescaleMinimap: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2154
            var nodes = this.renkan.project.get("nodes");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2155
            if (nodes.length > 1) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2156
                var _xx = nodes.map(function(_node) { return _node.get("position").x; }),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2157
                _yy = nodes.map(function(_node) { return _node.get("position").y; }),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2158
                _minx = Math.min.apply(Math, _xx),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2159
                _miny = Math.min.apply(Math, _yy),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2160
                _maxx = Math.max.apply(Math, _xx),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2161
                _maxy = Math.max.apply(Math, _yy);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2162
                var _scale = Math.min(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2163
                        this.scale * .8 * this.renkan.options.minimap_width / paper.view.bounds.width,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2164
                        this.scale * .8 * this.renkan.options.minimap_height / paper.view.bounds.height,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2165
                        ( this.renkan.options.minimap_width - 2 * this.renkan.options.minimap_padding ) / (_maxx - _minx),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2166
                        ( this.renkan.options.minimap_height - 2 * this.renkan.options.minimap_padding ) / (_maxy - _miny)
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2167
                );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2168
                this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2169
                this.minimap.scale = _scale;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2170
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2171
            if (nodes.length === 1) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2172
                this.minimap.scale = .1;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2173
                this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y]).multiply(this.minimap.scale));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2174
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2175
            this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2176
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2177
        toPaperCoords: function(_point) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2178
            return _point.multiply(this.scale).add(this.offset);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2179
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2180
        toMinimapCoords: function(_point) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2181
            return _point.multiply(this.minimap.scale).add(this.minimap.offset).add(this.minimap.topleft);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2182
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2183
        toModelCoords: function(_point) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2184
            return _point.subtract(this.offset).divide(this.scale);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2185
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2186
        addRepresentation: function(_type, _model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2187
            var _repr = new Renderer[_type](this, _model);
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  2188
            console.log("REPR RENKAN",_repr);
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  2189
            console.log("REPR RENKAN",Renderer[_type]);
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2190
            this.representations.push(_repr);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2191
            return _repr;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2192
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2193
        addRepresentations: function(_type, _collection) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2194
            var _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2195
            _collection.forEach(function(_model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2196
                _this.addRepresentation(_type, _model);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2197
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2198
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2199
        userTemplate: _.template(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2200
                '<li class="Rk-User"><span class="Rk-UserColor" style="background:<%=background%>;"></span><%=name%></li>'
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2201
        ),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2202
        redrawUsers: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2203
            if (!this.renkan.options.show_user_list) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2204
                return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2205
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2206
            var allUsers = [].concat((this.renkan.project.current_user_list || {}).models || [], (this.renkan.project.get("users") || {}).models || []),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2207
            ulistHtml = '',
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2208
            $userpanel = this.$.find(".Rk-Users"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2209
            $name = $userpanel.find(".Rk-CurrentUser-Name"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2210
            $cpitems = $userpanel.find(".Rk-Edit-ColorPicker li"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2211
            $colorsquare = $userpanel.find(".Rk-CurrentUser-Color"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2212
            _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2213
            $name.off("click").text(this.renkan.translate("<unknown user>"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2214
            $cpitems.off("mouseleave click");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2215
            allUsers.forEach(function(_user) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2216
                if (_user.get("_id") === _this.renkan.current_user) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2217
                    $name.text(_user.get("title"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2218
                    $colorsquare.css("background", _user.get("color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2219
                    if (_this.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2220
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2221
                        if (_this.renkan.options.user_name_editable) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2222
                            $name.click(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2223
                                var $this = $(this),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2224
                                $input = $('<input>').val(_user.get("title")).blur(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2225
                                    _user.set("title", $(this).val());
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2226
                                    _this.redrawUsers();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2227
                                    _this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2228
                                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2229
                                $this.empty().html($input);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2230
                                $input.select();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2231
                            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2232
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2233
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2234
                        if (_this.renkan.options.user_color_editable) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2235
                            $cpitems.click(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2236
                                    function(_e) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2237
                                        _e.preventDefault();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2238
                                        if (_this.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2239
                                            _user.set("color", $(this).attr("data-color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2240
                                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2241
                                        $(this).parent().hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2242
                                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2243
                            ).mouseleave(function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2244
                                $colorsquare.css("background", _user.get("color"));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2245
                            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2246
                        }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2247
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2248
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2249
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2250
                    ulistHtml += _this.userTemplate({
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2251
                        name: _user.get("title"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2252
                        background: _user.get("color")
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2253
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2254
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2255
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2256
            $userpanel.find(".Rk-UserList").html(ulistHtml);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2257
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2258
        removeRepresentation: function(_representation) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2259
            _representation.destroy();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2260
            this.representations = _(this.representations).reject(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2261
                    function(_repr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2262
                        return _repr == _representation;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2263
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2264
            );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2265
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2266
        getRepresentationByModel: function(_model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2267
            if (!_model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2268
                return undefined;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2269
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2270
            return _(this.representations).find(function(_repr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2271
                return _repr.model === _model;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2272
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2273
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2274
        removeRepresentationsOfType: function(_type) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2275
            var _representations = _(this.representations).filter(function(_repr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2276
                return _repr.type == _type;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2277
            }),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2278
            _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2279
            _(_representations).each(function(_repr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2280
                _this.removeRepresentation(_repr);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2281
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2282
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2283
        highlightModel: function(_model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2284
            var _repr = this.getRepresentationByModel(_model);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2285
            if (_repr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2286
                _repr.highlight();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2287
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2288
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2289
        unhighlightAll: function(_model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2290
            _(this.representations).each(function(_repr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2291
                _repr.unhighlight();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2292
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2293
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2294
        unselectAll: function(_model) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2295
            _(this.representations).each(function(_repr) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2296
                _repr.unselect();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2297
            });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2298
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2299
        redraw: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2300
            _(this.representations).each(function(_representation) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2301
                _representation.redraw(true);
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
  2302
            });
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2303
            if (this.minimap) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2304
                this.redrawMiniframe();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2305
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2306
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2307
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2308
        addTempEdge: function(_from, _point) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2309
            var _tmpEdge = this.addRepresentation("TempEdge",null);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2310
            _tmpEdge.end_pos = _point;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2311
            _tmpEdge.from_representation = _from;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2312
            _tmpEdge.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2313
            this.click_target = _tmpEdge;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2314
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2315
        findTarget: function(_hitResult) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2316
            if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2317
                var _newTarget = _hitResult.item.__representation;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2318
                if (this.selected_target !== _hitResult.item.__representation) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2319
                    if (this.selected_target) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2320
                        this.selected_target.unselect(_newTarget);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2321
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2322
                    _newTarget.select(this.selected_target);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2323
                    this.selected_target = _newTarget;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2324
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2325
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2326
                if (this.selected_target) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2327
                    this.selected_target.unselect();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2328
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2329
                this.selected_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2330
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2331
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2332
        paperShift: function(_delta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2333
            this.offset = this.offset.add(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2334
            this.redraw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2335
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2336
        onMouseMove: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2337
            var _off = this.canvas_$.offset(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2338
            _point = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2339
                                      _event.pageX - _off.left,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2340
                                      _event.pageY - _off.top
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2341
                                      ]),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2342
                                      _delta = _point.subtract(this.last_point);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2343
            this.last_point = _point;
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  2344
            if (!this.is_dragging && this.mouse_down && _delta.length > Rkns.Utils._MIN_DRAG_DISTANCE) {
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2345
                this.is_dragging = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2346
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2347
            var _hitResult = paper.project.hitTest(_point);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2348
            if (this.is_dragging) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2349
                if (this.click_target && typeof this.click_target.paperShift === "function") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2350
                    this.click_target.paperShift(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2351
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2352
                    this.paperShift(_delta);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2353
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2354
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2355
                this.findTarget(_hitResult);
4
f5297dde9053 Can now add nodes/edges
veltr
parents: 3
diff changeset
  2356
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2357
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2358
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2359
        onMouseDown: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2360
            var _off = this.canvas_$.offset(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2361
            _point = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2362
                                      _event.pageX - _off.left,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2363
                                      _event.pageY - _off.top
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2364
                                      ]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2365
            this.last_point = _point;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2366
            this.mouse_down = true;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2367
            if (!this.click_target || this.click_target.type !== "Temp-edge") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2368
                this.removeRepresentationsOfType("editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2369
                this.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2370
                var _hitResult = paper.project.hitTest(_point);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2371
                if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2372
                    this.click_target = _hitResult.item.__representation;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2373
                    this.click_target.mousedown(_event, _isTouch);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2374
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2375
                    this.click_target = null;
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  2376
                    if (this.isEditable() && this.click_mode === Rkns.Utils._CLICKMODE_ADDNODE) {
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2377
                        var _coords = this.toModelCoords(_point),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2378
                        _data = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2379
                            id: Rkns.Utils.getUID('node'),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2380
                            created_by: this.renkan.current_user,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2381
                            position: {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2382
                                x: _coords.x,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2383
                                y: _coords.y
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2384
                            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2385
                        };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2386
                        _node = this.renkan.project.addNode(_data);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2387
                        this.getRepresentationByModel(_node).openEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2388
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2389
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2390
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2391
            if (this.click_mode) {
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  2392
                if (this.isEditable() && this.click_mode === Rkns.Utils._CLICKMODE_STARTEDGE && this.click_target && this.click_target.type === "Node") {
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2393
                    this.removeRepresentationsOfType("editor");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2394
                    this.addTempEdge(this.click_target, _point);
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  2395
                    this.click_mode = Rkns.Utils._CLICKMODE_ENDEDGE;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2396
                    this.notif_$.fadeOut(function() {
277
1a54f4e626df correct _renkan reference
ymh <ymh.work@gmail.com>
parents: 276
diff changeset
  2397
                        $(this).html(this.renkan.translate("Click on a second node to complete the edge")).fadeIn();
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2398
                    });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2399
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2400
                    this.notif_$.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2401
                    this.click_mode = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2402
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2403
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2404
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2405
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2406
        onMouseUp: function(_event, _isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2407
            this.mouse_down = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2408
            if (this.click_target) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2409
                var _off = this.canvas_$.offset();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2410
                this.click_target.mouseup(
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2411
                        {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2412
                            point: new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2413
                                                    _event.pageX - _off.left,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2414
                                                    _event.pageY - _off.top
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2415
                                                    ])
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2416
                        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2417
                        _isTouch
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2418
                );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2419
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2420
                this.click_target = null;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2421
                this.is_dragging = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2422
                if (_isTouch) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2423
                    this.unselectAll();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2424
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2425
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2426
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2427
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2428
        onScroll: function(_event, _scrolldelta) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2429
            this.totalScroll += _scrolldelta;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2430
            if (Math.abs(this.totalScroll) >= 1) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2431
                var _off = this.canvas_$.offset(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2432
                _delta = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2433
                                          _event.pageX - _off.left,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2434
                                          _event.pageY - _off.top
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2435
                                          ]).subtract(this.offset).multiply( Math.SQRT2 - 1 );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2436
                if (this.totalScroll > 0) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2437
                    this.setScale( this.scale * Math.SQRT2, this.offset.subtract(_delta) );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2438
                } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2439
                    this.setScale( this.scale * Math.SQRT1_2, this.offset.add(_delta.divide(Math.SQRT2)));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2440
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2441
                this.totalScroll = 0;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2442
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2443
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2444
        onDoubleClick: function(_event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2445
            if (!this.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2446
                return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2447
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2448
            var _off = this.canvas_$.offset(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2449
            _point = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2450
                                      _event.pageX - _off.left,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2451
                                      _event.pageY - _off.top
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2452
                                      ]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2453
            var _hitResult = paper.project.hitTest(_point);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2454
            if (this.isEditable() && (!_hitResult || typeof _hitResult.item.__representation === "undefined")) {
153
7fcb35795ff4 Now showing images in publish tooltips
veltr
parents: 152
diff changeset
  2455
                var _coords = this.toModelCoords(_point),
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2456
                _data = {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2457
                    id: Rkns.Utils.getUID('node'),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2458
                    created_by: this.renkan.current_user,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2459
                    position: {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2460
                        x: _coords.x,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2461
                        y: _coords.y
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2462
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2463
                },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2464
                _node = this.renkan.project.addNode(_data);
36
d249d36ecc37 Add Edge button, French translation and various bugfixes
veltr
parents: 35
diff changeset
  2465
                this.getRepresentationByModel(_node).openEditor();
d249d36ecc37 Add Edge button, French translation and various bugfixes
veltr
parents: 35
diff changeset
  2466
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2467
            paper.view.draw();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2468
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2469
        defaultDropHandler: function(_data) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2470
            var newNode = {};
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2471
            switch(_data["text/x-iri-specific-site"]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2472
            case "twitter":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2473
                var snippet = $('<div>').html(_data["text/x-iri-selected-html"]),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2474
                tweetdiv = snippet.find(".tweet");
277
1a54f4e626df correct _renkan reference
ymh <ymh.work@gmail.com>
parents: 276
diff changeset
  2475
                newNode.title = this.renkan.translate("Tweet by ") + tweetdiv.attr("data-name");
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2476
                newNode.uri = "http://twitter.com/" + tweetdiv.attr("data-screen-name") + "/status/" + tweetdiv.attr("data-tweet-id");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2477
                newNode.image = tweetdiv.find(".avatar").attr("src");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2478
                newNode.description = tweetdiv.find(".js-tweet-text:first").text();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2479
                break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2480
            case "google":
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2481
                var snippet = $('<div>').html(_data["text/x-iri-selected-html"]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2482
                newNode.title = snippet.find("h3:first").text().trim();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2483
                newNode.uri = snippet.find("h3 a").attr("href");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2484
                newNode.description = snippet.find(".st:first").text().trim();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2485
                break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2486
            case undefined:
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2487
            default:
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2488
                if (_data["text/x-iri-source-uri"]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2489
                    newNode.uri = _data["text/x-iri-source-uri"];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2490
                }
283
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2491
            if (_data["text/plain"] || _data["text/x-iri-selected-text"]) {
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2492
                newNode.description = (_data["text/plain"] || _data["text/x-iri-selected-text"]).replace(/[\s\n]+/gm,' ').trim();
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2493
            }
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2494
            if (_data["text/html"] || _data["text/x-iri-selected-html"]) {
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2495
                var snippet = $('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]);
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2496
                var _svgimgs = snippet.find("image");
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2497
                if (_svgimgs.length) {
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2498
                    newNode.image = _svgimgs.attr("xlink:href");
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2499
                }
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2500
                var _svgpaths = snippet.find("path");
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2501
                if (_svgpaths.length) {
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2502
                    newNode.clipPath = _svgpaths.attr("d");
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2503
                }
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2504
                var _imgs = snippet.find("img");
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2505
                if (_imgs.length) {
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2506
                    newNode.image = _imgs[0].src;
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2507
                }
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2508
                var _as = snippet.find("a");
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2509
                if (_as.length) {
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2510
                    newNode.uri = _as[0].href;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2511
                }
283
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2512
                newNode.title = snippet.find("[title]").attr("title") || newNode.title;
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2513
                newNode.description = snippet.text().replace(/[\s\n]+/gm,' ').trim();
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2514
            }
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2515
            if (_data["text/uri-list"]) {
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2516
                newNode.uri = _data["text/uri-list"];
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2517
            }
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2518
            if (_data["text/x-moz-url"] && !newNode.title) {
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2519
                newNode.title = (_data["text/x-moz-url"].split("\n")[1] || "").trim();
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2520
                if (newNode.title === newNode.uri) {
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2521
                    newNode.title = false;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2522
                }
283
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2523
            }
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2524
            if (_data["text/x-iri-source-title"] && !newNode.title) {
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2525
                newNode.title = _data["text/x-iri-source-title"];
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2526
            }
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2527
            if (_data["text/html"] || _data["text/x-iri-selected-html"]) {
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2528
                var snippet = $('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]);
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2529
                newNode.image = snippet.find("[data-image]").attr("data-image") || newNode.image;
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2530
                newNode.uri = snippet.find("[data-uri]").attr("data-uri") || newNode.uri;
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2531
                newNode.title = snippet.find("[data-title]").attr("data-title") || newNode.title;
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2532
                newNode.description = snippet.find("[data-description]").attr("data-description") || newNode.description;
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2533
                newNode.clipPath = snippet.find("[data-clip-path]").attr("data-clip-path") || newNode.clipPath;
67f3a24a7c01 make view save state button use the model
ymh <ymh.work@gmail.com>
parents: 282
diff changeset
  2534
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2535
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2536
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2537
            if(typeof this.renkan.options.drop_enhancer === "function"){
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2538
                newNode = this.renkan.options.drop_enhancer(newNode, _data);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2539
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2540
            return newNode;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2541
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2542
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2543
        dropData: function(_data, _event) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2544
            if (!this.isEditable()) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2545
                return;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2546
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2547
            if (_data["text/json"] || _data["application/json"]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2548
                try {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2549
                    var jsondata = JSON.parse(_data["text/json"] || _data["application/json"]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2550
                    _(_data).extend(jsondata);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2551
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2552
                catch(e) {}
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2553
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2554
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2555
            var newNode = (typeof this.renkan.options.drop_handler === "undefined")?this.defaultDropHandler(_data):this.renkan.options.drop_handler(_data);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2556
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2557
            if (!newNode.title) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2558
                newNode.title = this.renkan.translate("Dragged resource");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2559
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2560
            var fields = ["title", "description", "uri", "image"];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2561
            for (var i = 0; i < fields.length; i++) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2562
                var f = fields[i];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2563
                if (_data["text/x-iri-" + f] || _data[f]) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2564
                    newNode[f] = _data["text/x-iri-" + f] || _data[f];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2565
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2566
                if (newNode[f] === "none" || newNode[f] === "null") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2567
                    newNode[f] = undefined;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2568
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2569
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2570
            var _off = this.canvas_$.offset(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2571
            _point = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2572
                                      _event.pageX - _off.left,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2573
                                      _event.pageY - _off.top
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2574
                                      ]),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2575
                                      _coords = this.toModelCoords(_point),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2576
                                      _nodedata = {
23
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 21
diff changeset
  2577
                id: Rkns.Utils.getUID('node'),
70c8af9b44ec Rebased Rendering on Backbone Model
veltr
parents: 21
diff changeset
  2578
                created_by: this.renkan.current_user,
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2579
                uri: newNode.uri || "",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2580
                title: newNode.title || "",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2581
                description: newNode.description || "",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2582
                image: newNode.image || "",
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2583
                color: newNode.color || undefined,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2584
                clip_path: newNode.clipPath || undefined,
8
8e67c9f6da51 New node now opens editor
veltr
parents: 7
diff changeset
  2585
                position: {
8e67c9f6da51 New node now opens editor
veltr
parents: 7
diff changeset
  2586
                    x: _coords.x,
8e67c9f6da51 New node now opens editor
veltr
parents: 7
diff changeset
  2587
                    y: _coords.y
8e67c9f6da51 New node now opens editor
veltr
parents: 7
diff changeset
  2588
                }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2589
            };
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2590
            var _node = this.renkan.project.addNode(_nodedata),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2591
            _repr = this.getRepresentationByModel(_node);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2592
            if (_event.type === "drop") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2593
                _repr.openEditor();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2594
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2595
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2596
        fullScreen: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2597
            var _isFull = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2598
            _el = this.renkan.$[0],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2599
            _requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"],
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2600
            _cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"];
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2601
            if (_isFull) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2602
                for (var i = 0; i < _cancelMethods.length; i++) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2603
                    if (typeof document[_cancelMethods[i]] === "function") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2604
                        document[_cancelMethods[i]]();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2605
                        break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2606
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2607
                }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2608
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2609
                for (var i = 0; i < _requestMethods.length; i++) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2610
                    if (typeof _el[_requestMethods[i]] === "function") {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2611
                        _el[_requestMethods[i]]();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2612
                        break;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2613
                    }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2614
                }
155
7d5f722d76b2 iPad compatibility
veltr
parents: 154
diff changeset
  2615
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2616
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2617
        zoomOut: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2618
            var _newScale = this.scale * Math.SQRT1_2,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2619
            _offset = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2620
                                       this.canvas_$.width(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2621
                                       this.canvas_$.height()
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2622
                                       ]).multiply( .5 * ( 1 - Math.SQRT1_2 ) ).add(this.offset.multiply( Math.SQRT1_2 ));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2623
            this.setScale( _newScale, _offset );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2624
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2625
        zoomIn: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2626
            var _newScale = this.scale * Math.SQRT2,
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2627
            _offset = new paper.Point([
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2628
                                       this.canvas_$.width(),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2629
                                       this.canvas_$.height()
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2630
                                       ]).multiply( .5 * ( 1 - Math.SQRT2 ) ).add(this.offset.multiply( Math.SQRT2 ));
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2631
            this.setScale( _newScale, _offset );
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2632
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2633
        addNodeBtn: function() {
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  2634
            if (this.click_mode === Rkns.Utils._CLICKMODE_ADDNODE) {
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2635
                this.click_mode = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2636
                this.notif_$.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2637
            } else {
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  2638
                this.click_mode = Rkns.Utils._CLICKMODE_ADDNODE;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2639
                this.notif_$.text(this.renkan.translate("Click on the background canvas to add a node")).fadeIn();
190
a9040a7c47d9 Some changes for standalone app compatibility
veltr
parents: 189
diff changeset
  2640
            }
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2641
            return false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2642
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2643
        addEdgeBtn: function() {
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  2644
            if (this.click_mode === Rkns.Utils._CLICKMODE_STARTEDGE || this.click_mode === Rkns.Utils._CLICKMODE_ENDEDGE) {
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2645
                this.click_mode = false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2646
                this.notif_$.hide();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2647
            } else {
284
fa8035885814 build renderer with require js
cavaliet
parents: 283
diff changeset
  2648
                this.click_mode = Rkns.Utils._CLICKMODE_STARTEDGE;
276
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2649
                this.notif_$.text(this.renkan.translate("Click on a first node to start the edge")).fadeIn();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2650
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2651
            return false;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2652
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2653
        foldBins: function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2654
            var foldBinsButton = this.$.find(".Rk-Fold-Bins"),
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2655
            bins = this.renkan.$.find(".Rk-Bins");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2656
            if (bins.offset().left < 0) {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2657
                bins.animate({left: 0},250);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2658
                var _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2659
                this.$.animate({left: 300},250,function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2660
                    var w = _this.$.width();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2661
                    paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2662
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2663
                foldBinsButton.html("&laquo;");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2664
            } else {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2665
                bins.animate({left: -300},250);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2666
                var _this = this;
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2667
                this.$.animate({left: 0},250,function() {
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2668
                    var w = _this.$.width();
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2669
                    paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]);
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2670
                });
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2671
                foldBinsButton.html("&raquo;");
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2672
            }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2673
        },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2674
        save: function() { },
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2675
        open: function() { }
900467290a0a Correct drag and drop problem on renkan
ymh <ymh.work@gmail.com>
parents: 273
diff changeset
  2676
    });
195
15e048e00002 Better User List Management
veltr
parents: 194
diff changeset
  2677
})(window);
187
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
  2678
ba5022639c76 Some refactoring
veltr
parents: 185
diff changeset
  2679
/* END paper-renderer.js */