| author | veltr |
| Wed, 13 Feb 2013 13:41:19 +0100 | |
| changeset 57 | 01f66ed90e32 |
| parent 56 | a9b9e6c7be63 |
| child 62 | f9019462465a |
| permissions | -rw-r--r-- |
| 28 | 1 |
Rkns.Renderer = { |
2 |
_MARGIN_X: 80, |
|
3 |
_MARGIN_Y: 50, |
|
4 |
_MIN_DRAG_DISTANCE: 2, |
|
| 37 | 5 |
_NODE_RADIUS: 25, |
6 |
_NODE_BUTTON_INNER: 26, |
|
7 |
_NODE_BUTTON_OUTER: 60, |
|
| 35 | 8 |
_EDGE_BUTTON_INNER: 1, |
| 31 | 9 |
_EDGE_BUTTON_OUTER: 40, |
| 28 | 10 |
_NODE_FONT_SIZE: 10, |
11 |
_EDGE_FONT_SIZE: 9, |
|
12 |
_NODE_MAX_CHAR: 50, |
|
13 |
_EDGE_MAX_CHAR: 40, |
|
14 |
_ARROW_LENGTH: 16, |
|
15 |
_ARROW_WIDTH: 8, |
|
| 5 | 16 |
_EDITOR_ARROW_LENGTH : 20, |
17 |
_EDITOR_ARROW_WIDTH : 40, |
|
18 |
_EDITOR_MARGIN : 15, |
|
19 |
_EDITOR_PADDING : 10, |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
20 |
_EDITOR_GRADIENT : new paper.Gradient(['#f0f0f0', '#d0d0d0']), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
21 |
_CLICKMODE_ADDNODE : 1, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
22 |
_CLICKMODE_STARTEDGE : 2, |
| 53 | 23 |
_CLICKMODE_ENDEDGE : 3, |
24 |
_USER_PLACEHOLDER : { |
|
25 |
color: "#000000", |
|
26 |
title: "(unknown user)", |
|
27 |
get: function(attr) { |
|
28 |
return this[attr] || false; |
|
29 |
} |
|
30 |
} |
|
| 28 | 31 |
} |
32 |
||
33 |
Rkns.Renderer.Utils = { |
|
34 |
drawEditBox : function(_coords, _path, _width, _xmargin, _selector) { |
|
35 |
_selector.css({ |
|
36 |
width: (_width - 2* Rkns.Renderer._EDITOR_PADDING), |
|
37 |
}) |
|
38 |
var _height = _selector.outerHeight() + 2* Rkns.Renderer._EDITOR_PADDING, |
|
39 |
_isLeft = (_coords.x < paper.view.center.x ? 1 : -1), |
|
40 |
_left = _coords.x + _isLeft * ( _xmargin + Rkns.Renderer._EDITOR_ARROW_LENGTH ), |
|
41 |
_right = _coords.x + _isLeft * ( _xmargin + Rkns.Renderer._EDITOR_ARROW_LENGTH + _width ), |
|
| 5 | 42 |
_top = _coords.y - _height / 2; |
| 28 | 43 |
if (_top < Rkns.Renderer._EDITOR_MARGIN) { |
44 |
_top = Math.min( Rkns.Renderer._EDITOR_MARGIN, _coords.y - Rkns.Renderer._EDITOR_ARROW_WIDTH / 2 ); |
|
| 5 | 45 |
} |
46 |
var _bottom = _top + _height; |
|
| 28 | 47 |
if (_bottom > (paper.view.size.height - Rkns.Renderer._EDITOR_MARGIN)) { |
48 |
_bottom = Math.max( paper.view.size.height - Rkns.Renderer._EDITOR_MARGIN, _coords.y + Rkns.Renderer._EDITOR_ARROW_WIDTH / 2 ); |
|
| 5 | 49 |
_top = _bottom - _height; |
50 |
} |
|
51 |
_path.segments[0].point |
|
52 |
= _path.segments[7].point |
|
| 28 | 53 |
= _coords.add([_isLeft * _xmargin, 0]); |
| 5 | 54 |
_path.segments[1].point.x |
55 |
= _path.segments[2].point.x |
|
56 |
= _path.segments[5].point.x |
|
57 |
= _path.segments[6].point.x |
|
58 |
= _left; |
|
59 |
_path.segments[3].point.x |
|
60 |
= _path.segments[4].point.x |
|
61 |
= _right; |
|
62 |
_path.segments[2].point.y |
|
63 |
= _path.segments[3].point.y |
|
64 |
= _top; |
|
65 |
_path.segments[4].point.y |
|
66 |
= _path.segments[5].point.y |
|
67 |
= _bottom; |
|
| 28 | 68 |
_path.segments[1].point.y = _coords.y - Rkns.Renderer._EDITOR_ARROW_WIDTH / 2; |
69 |
_path.segments[6].point.y = _coords.y + Rkns.Renderer._EDITOR_ARROW_WIDTH / 2; |
|
70 |
_path.closed = true; |
|
71 |
_path.fillColor = new paper.GradientColor(Rkns.Renderer._EDITOR_GRADIENT, [0,_top], [0, _bottom]); |
|
72 |
_selector.css({ |
|
73 |
left: (Rkns.Renderer._EDITOR_PADDING + Math.min(_left, _right)), |
|
74 |
top: (Rkns.Renderer._EDITOR_PADDING + _top) |
|
75 |
}); |
|
| 7 | 76 |
}, |
| 38 | 77 |
sector : function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgsrc, _caption) { |
| 7 | 78 |
var _startRads = _startAngle * Math.PI / 180, |
79 |
_endRads = _endAngle * Math.PI / 180, |
|
80 |
_img = new Image(), |
|
81 |
_span = _endRads - _startRads, |
|
82 |
_k = .0879 * _span, |
|
83 |
_kin = _k * _inR, |
|
84 |
_kout = _k * _outR, |
|
85 |
_startdx = - Math.sin(_startRads), |
|
86 |
_startdy = Math.cos(_startRads), |
|
87 |
_startXIn = Math.cos(_startRads) * _inR + _padding * _startdx, |
|
88 |
_startYIn = Math.sin(_startRads) * _inR + _padding * _startdy, |
|
89 |
_startXOut = Math.cos(_startRads) * _outR + _padding * _startdx, |
|
90 |
_startYOut = Math.sin(_startRads) * _outR + _padding * _startdy, |
|
91 |
_enddx = - Math.sin(_endRads), |
|
92 |
_enddy = Math.cos(_endRads), |
|
93 |
_endXIn = Math.cos(_endRads) * _inR - _padding * _enddx, |
|
94 |
_endYIn = Math.sin(_endRads) * _inR - _padding * _enddy, |
|
95 |
_endXOut = Math.cos(_endRads) * _outR - _padding * _enddx, |
|
96 |
_endYOut = Math.sin(_endRads) * _outR - _padding * _enddy, |
|
97 |
_centerR = (_inR + _outR)/2, |
|
98 |
_centerRads = (_startRads + _endRads) / 2, |
|
99 |
_centerX = Math.cos(_centerRads) * _centerR, |
|
100 |
_centerY = Math.sin(_centerRads) * _centerR, |
|
| 38 | 101 |
_textX = Math.cos(_centerRads) * (_outR + 3), |
102 |
_textY = Math.sin(_centerRads) * (_outR + 3), |
|
| 7 | 103 |
_segments = []; |
104 |
_segments.push([[_startXIn, _startYIn], [0, 0], [ _kin * _startdx, _kin * _startdy ]]); |
|
105 |
for (var i = 1; i < 4; i++) { |
|
106 |
var _rads = i * _span / 4 + _startRads, |
|
107 |
_dx = - Math.sin(_rads), |
|
108 |
_dy = Math.cos(_rads), |
|
109 |
_x = Math.cos(_rads) * _inR, |
|
110 |
_y = Math.sin(_rads) * _inR; |
|
111 |
_segments.push([[_x, _y], [ - _kin * _dx, - _kin * _dy], [ _kin * _dx, _kin * _dy ]]); |
|
112 |
} |
|
113 |
_segments.push([[_endXIn, _endYIn], [ - _kin * _enddx, - _kin * _enddy ], [0,0]]); |
|
114 |
_segments.push([[_endXOut, _endYOut], [ 0,0 ], [ - _kout * _enddx, - _kout * _enddy ]]); |
|
115 |
for (var i = 3; i > 0; i--) { |
|
116 |
var _rads = i * _span / 4 + _startRads, |
|
117 |
_dx = - Math.sin(_rads), |
|
118 |
_dy = Math.cos(_rads), |
|
119 |
_x = Math.cos(_rads) * _outR, |
|
120 |
_y = Math.sin(_rads) * _outR; |
|
121 |
_segments.push([[_x, _y], [ _kout * _dx, _kout * _dy], [ - _kout * _dx, - _kout * _dy ]]); |
|
122 |
} |
|
123 |
_segments.push([[_startXOut, _startYOut], [ _kout * _startdx, _kout * _startdy ], [0, 0]]); |
|
| 18 | 124 |
var _path = new paper.Path(); |
| 7 | 125 |
_path.add.apply(_path, _segments); |
126 |
_path.fillColor = "#333333"; |
|
| 15 | 127 |
_path.opacity = .5; |
| 7 | 128 |
_path.closed = true; |
| 23 | 129 |
_path.__representation = _repr; |
| 38 | 130 |
if (_textX >= -2 && _textX <= 2) { |
131 |
if (_textY > 0) { |
|
132 |
_textY += 6; |
|
133 |
} |
|
134 |
} |
|
135 |
var _text = new paper.PointText(_textX,_textY); |
|
136 |
_text.characterStyle = { |
|
137 |
fontSize: 9, |
|
138 |
fillColor: '#c000c0' |
|
139 |
}; |
|
140 |
if (_textX > 2) { |
|
141 |
_text.paragraphStyle.justification = 'left'; |
|
142 |
} else if (_textX < -2) { |
|
143 |
_text.paragraphStyle.justification = 'right'; |
|
144 |
} else { |
|
145 |
_text.paragraphStyle.justification = 'center'; |
|
146 |
} |
|
147 |
_text.visible = false; |
|
| 18 | 148 |
var _visible = false, |
149 |
_restPos = new paper.Point(-200, -200), |
|
| 38 | 150 |
_grp = new paper.Group([_path, _text]), |
| 18 | 151 |
_delta = _grp.position, |
152 |
_imgdelta = new paper.Point([_centerX, _centerY]), |
|
153 |
_currentPos = new paper.Point(0,0); |
|
| 38 | 154 |
_text.content = _caption; |
| 18 | 155 |
_grp.visible = false; |
156 |
_grp.position = _restPos; |
|
157 |
var _res = { |
|
158 |
show: function() { |
|
159 |
_visible = true; |
|
160 |
_grp.position = _currentPos.add(_delta); |
|
161 |
_grp.visible = true; |
|
162 |
}, |
|
163 |
moveTo: function(_point) { |
|
164 |
_currentPos = _point; |
|
165 |
if (_visible) { |
|
166 |
_grp.position = _point.add(_delta); |
|
167 |
} |
|
168 |
}, |
|
169 |
hide: function() { |
|
170 |
_visible = false; |
|
171 |
_grp.visible = false; |
|
172 |
_grp.position = _restPos; |
|
173 |
}, |
|
174 |
select: function() { |
|
175 |
_path.opacity = .8; |
|
| 38 | 176 |
_text.visible = true; |
| 18 | 177 |
}, |
178 |
unselect: function() { |
|
179 |
_path.opacity = .5; |
|
| 38 | 180 |
_text.visible = false; |
| 18 | 181 |
}, |
182 |
destroy: function() { |
|
183 |
_grp.remove(); |
|
| 7 | 184 |
} |
| 18 | 185 |
} |
| 7 | 186 |
_img.onload = function() { |
| 38 | 187 |
var _h = _img.height; |
| 7 | 188 |
var _raster = new paper.Raster(_img); |
| 18 | 189 |
_raster.position = _imgdelta.add(_grp.position).subtract(_delta); |
| 7 | 190 |
_grp.addChild(_raster); |
191 |
} |
|
192 |
_img.src = _imgsrc; |
|
193 |
return _res |
|
| 5 | 194 |
} |
195 |
} |
|
196 |
||
| 23 | 197 |
Rkns.Renderer._BaseRepresentation = function(_renderer, _model) { |
| 1 | 198 |
if (typeof _renderer !== "undefined") { |
| 23 | 199 |
this.renderer = _renderer; |
200 |
this.project = _renderer.renkan.project; |
|
201 |
this.model = _model; |
|
| 39 | 202 |
if (this.model) { |
203 |
var _this = this; |
|
204 |
this._changeBinding = function() { |
|
205 |
_this.redraw(); |
|
206 |
} |
|
207 |
this._removeBinding = function() { |
|
208 |
_renderer.removeRepresentation(_this); |
|
209 |
_renderer.redraw(); |
|
210 |
} |
|
211 |
this.model.on("change", this._changeBinding ); |
|
212 |
this.model.on("remove", this._removeBinding ); |
|
213 |
} |
|
| 1 | 214 |
} |
215 |
} |
|
216 |
||
| 39 | 217 |
Rkns.Renderer._BaseRepresentation.prototype.super = function(_func) { |
218 |
Rkns.Renderer._BaseRepresentation.prototype[_func].apply(this, Array.prototype.slice.call(arguments, 1)); |
|
219 |
} |
|
220 |
||
| 23 | 221 |
Rkns.Renderer._BaseRepresentation.prototype.select = function() {} |
| 4 | 222 |
|
| 23 | 223 |
Rkns.Renderer._BaseRepresentation.prototype.unselect = function() {} |
| 7 | 224 |
|
| 26 | 225 |
Rkns.Renderer._BaseRepresentation.prototype.highlight = function() {} |
226 |
||
227 |
Rkns.Renderer._BaseRepresentation.prototype.unhighlight = function() {} |
|
228 |
||
| 23 | 229 |
Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() {} |
| 4 | 230 |
|
| 39 | 231 |
Rkns.Renderer._BaseRepresentation.prototype.destroy = function() { |
232 |
if (this.model) { |
|
233 |
this.model.off("change", this._changeBinding ); |
|
234 |
this.model.off("remove", this._removeBinding ); |
|
235 |
} |
|
236 |
} |
|
| 5 | 237 |
|
| 57 | 238 |
Rkns.Renderer._BaseRepresentation.prototype.resetCoords = function() { |
239 |
this.paper_coords = undefined; |
|
240 |
} |
|
241 |
||
| 23 | 242 |
Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 1 | 243 |
|
| 7 | 244 |
Rkns.Renderer.Node.prototype._init = function() { |
| 23 | 245 |
this.renderer.node_layer.activate(); |
| 20 | 246 |
this.type = "Node"; |
| 28 | 247 |
this.circle = new paper.Path.Circle([0, 0], Rkns.Renderer._NODE_RADIUS); |
| 7 | 248 |
this.circle.fillColor = '#ffffff'; |
| 23 | 249 |
this.circle.__representation = this; |
| 52 | 250 |
this.circle.strokeWidth = 2; |
| 7 | 251 |
this.title = new paper.PointText([0,0]); |
252 |
this.title.characterStyle = { |
|
| 28 | 253 |
fontSize: Rkns.Renderer._NODE_FONT_SIZE, |
| 2 | 254 |
fillColor: 'black' |
255 |
}; |
|
| 39 | 256 |
this.edit_button = new Rkns.Renderer.NodeEditButton(this.renderer, null); |
| 23 | 257 |
this.edit_button.node_representation = this; |
| 39 | 258 |
this.remove_button = new Rkns.Renderer.NodeRemoveButton(this.renderer, null); |
| 23 | 259 |
this.remove_button.node_representation = this; |
| 39 | 260 |
this.link_button = new Rkns.Renderer.NodeLinkButton(this.renderer, null); |
| 23 | 261 |
this.link_button.node_representation = this; |
| 7 | 262 |
this.title.paragraphStyle.justification = 'center'; |
| 1 | 263 |
} |
264 |
||
| 7 | 265 |
Rkns.Renderer.Node.prototype.redraw = function() { |
| 57 | 266 |
if (!this.paper_coords) { |
267 |
var _model_coords = new paper.Point(this.model.get("position")); |
|
268 |
this.paper_coords = this.renderer.toPaperCoords(_model_coords); |
|
269 |
} |
|
| 7 | 270 |
this.circle.position = this.paper_coords; |
| 23 | 271 |
this.title.content = this.model.get("title"); |
| 37 | 272 |
this.title.position = this.paper_coords.add([0, Rkns.Renderer._NODE_RADIUS + 1.5 *Rkns.Renderer._NODE_FONT_SIZE]); |
| 53 | 273 |
this.circle.strokeColor = this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"); |
| 7 | 274 |
this.edit_button.moveTo(this.paper_coords); |
275 |
this.remove_button.moveTo(this.paper_coords); |
|
| 11 | 276 |
this.link_button.moveTo(this.paper_coords); |
| 37 | 277 |
var _img = this.model.get("image"); |
278 |
if (_img && _img !== this.img) { |
|
279 |
var _image = new Image(), |
|
280 |
_this = this; |
|
281 |
_image.onload = function() { |
|
282 |
if (_this.node_image) { |
|
283 |
_this.node_image.remove(); |
|
284 |
} |
|
285 |
_this.renderer.node_layer.activate(); |
|
286 |
var _ratio = Math.min(1, 2 * Rkns.Renderer._NODE_RADIUS / _image.width, 2 * Rkns.Renderer._NODE_RADIUS / _image.height ); |
|
287 |
var _raster = new paper.Raster(_image); |
|
288 |
var _clip = new paper.Path.Circle([0, 0], Rkns.Renderer._NODE_RADIUS); |
|
289 |
_raster.scale(_ratio); |
|
290 |
_this.node_image = new paper.Group(_clip, _raster); |
|
291 |
_this.node_image.opacity = .9; |
|
| 38 | 292 |
/* This is a workaround to allow clipping at group level |
293 |
* If opacity was set to 1, paper.js would merge all clipping groups in one (known bug). |
|
294 |
*/ |
|
| 37 | 295 |
_this.node_image.clipped = true; |
296 |
_this.node_image.position = _this.paper_coords; |
|
297 |
_this.node_image.__representation = _this; |
|
| 38 | 298 |
_clip.__representation = _this; |
| 37 | 299 |
paper.view.draw(); |
300 |
} |
|
301 |
_image.src = _img; |
|
302 |
} |
|
303 |
this.img = _img; |
|
304 |
if (this.node_image) { |
|
305 |
if (!this.img) { |
|
306 |
this.node_image.remove(); |
|
307 |
delete this.node_image; |
|
308 |
} else { |
|
309 |
this.node_image.position = this.paper_coords; |
|
310 |
} |
|
311 |
} |
|
| 56 | 312 |
|
313 |
Rkns._.each(this.project.get("edges").filter(function (ed) { return ((ed.to === this.model) || (ed.from === this.model));}), function(edge, index, list){ |
|
314 |
var repr = this.renderer.getRepresentationByModel(edge); |
|
315 |
if(repr != null && typeof repr.from_representation.paper_coords !== "undefined" && typeof repr.to_representation.paper_coords !== "undefined") { |
|
316 |
repr.redraw(); |
|
317 |
} |
|
318 |
}, this); |
|
| 1 | 319 |
} |
320 |
||
| 7 | 321 |
Rkns.Renderer.Node.prototype.paperShift = function(_delta) { |
| 57 | 322 |
this.paper_coords = this.paper_coords.add(_delta); |
323 |
this.redraw(); |
|
| 2 | 324 |
} |
325 |
||
| 8 | 326 |
Rkns.Renderer.Node.prototype.openEditor = function() { |
| 23 | 327 |
this.renderer.removeRepresentationsOfType("editor"); |
328 |
var _editor = this.renderer.addRepresentation("NodeEditor",null); |
|
329 |
_editor.node_representation = this; |
|
| 37 | 330 |
_editor.draw(); |
| 8 | 331 |
} |
332 |
||
| 7 | 333 |
Rkns.Renderer.Node.prototype.select = function() { |
| 52 | 334 |
this.circle.strokeWidth = 4; |
| 7 | 335 |
this.edit_button.show(); |
336 |
this.remove_button.show(); |
|
| 11 | 337 |
this.link_button.show(); |
| 26 | 338 |
var _uri = this.model.get("uri"); |
339 |
Rkns.$('.Rk-Bin-Item').each(function() { |
|
340 |
var _el = Rkns.$(this); |
|
341 |
if (_el.attr("data-uri") == _uri) { |
|
342 |
_el.addClass("selected"); |
|
343 |
} |
|
344 |
}); |
|
| 7 | 345 |
} |
346 |
||
347 |
Rkns.Renderer.Node.prototype.unselect = function(_newTarget) { |
|
| 35 | 348 |
if (!_newTarget || _newTarget.node_representation !== this) { |
| 7 | 349 |
this.edit_button.hide(); |
350 |
this.remove_button.hide(); |
|
| 11 | 351 |
this.link_button.hide(); |
| 52 | 352 |
this.circle.strokeWidth = 2; |
| 35 | 353 |
Rkns.$('.Rk-Bin-Item').removeClass("selected"); |
| 7 | 354 |
} |
| 26 | 355 |
} |
356 |
||
357 |
Rkns.Renderer.Node.prototype.highlight = function() { |
|
| 37 | 358 |
this.circle.fillColor = "#ffff80"; |
359 |
if (this.node_image) { |
|
360 |
this.node_image.opacity = .5; |
|
361 |
} |
|
| 26 | 362 |
} |
363 |
||
364 |
Rkns.Renderer.Node.prototype.unhighlight = function(_newTarget) { |
|
365 |
this.circle.fillColor = "#ffffff"; |
|
| 37 | 366 |
if (this.node_image) { |
367 |
this.node_image.opacity = .9; |
|
368 |
} |
|
| 4 | 369 |
} |
370 |
||
| 57 | 371 |
Rkns.Renderer.Node.prototype.saveCoords = function() { |
372 |
var _coords = this.renderer.toModelCoords(this.paper_coords), |
|
373 |
_data = { |
|
374 |
position: { |
|
375 |
x: _coords.x, |
|
376 |
y: _coords.y |
|
377 |
} |
|
378 |
}; |
|
379 |
this.model.set(_data); |
|
380 |
} |
|
381 |
||
| 7 | 382 |
Rkns.Renderer.Node.prototype.mouseup = function(_event) { |
| 57 | 383 |
if (this.renderer.is_dragging) { |
384 |
this.saveCoords(); |
|
385 |
} |
|
386 |
else { |
|
| 8 | 387 |
this.openEditor(); |
| 7 | 388 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
389 |
this.renderer.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
390 |
this.renderer.is_dragging = false; |
| 7 | 391 |
} |
392 |
||
393 |
Rkns.Renderer.Node.prototype.destroy = function(_event) { |
|
| 39 | 394 |
this.super("destroy"); |
| 7 | 395 |
this.edit_button.destroy(); |
396 |
this.remove_button.destroy(); |
|
| 26 | 397 |
this.link_button.destroy(); |
| 7 | 398 |
this.circle.remove(); |
399 |
this.title.remove(); |
|
| 37 | 400 |
if (this.node_image) { |
401 |
this.node_image.remove(); |
|
402 |
} |
|
| 4 | 403 |
} |
404 |
||
| 2 | 405 |
/* */ |
406 |
||
| 23 | 407 |
Rkns.Renderer.Edge = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 2 | 408 |
|
| 7 | 409 |
Rkns.Renderer.Edge.prototype._init = function() { |
| 23 | 410 |
this.renderer.edge_layer.activate(); |
| 20 | 411 |
this.type = "Edge"; |
| 23 | 412 |
this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from")); |
413 |
this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to")); |
|
| 31 | 414 |
this.bundle = this.renderer.addToBundles(this); |
| 7 | 415 |
this.line = new paper.Path(); |
| 31 | 416 |
this.line.add([0,0],[0,0],[0,0]); |
| 23 | 417 |
this.line.__representation = this; |
| 52 | 418 |
this.line.strokeWidth = 2; |
| 7 | 419 |
this.arrow = new paper.Path(); |
| 28 | 420 |
this.arrow.add([0,0],[Rkns.Renderer._ARROW_LENGTH,Rkns.Renderer._ARROW_WIDTH / 2],[0,Rkns.Renderer._ARROW_WIDTH]); |
| 23 | 421 |
this.arrow.__representation = this; |
| 7 | 422 |
this.text = new paper.PointText(); |
423 |
this.text.characterStyle = { |
|
| 28 | 424 |
fontSize: Rkns.Renderer._EDGE_FONT_SIZE, |
| 2 | 425 |
fillColor: 'black' |
426 |
}; |
|
| 7 | 427 |
this.text.paragraphStyle.justification = 'center'; |
428 |
this.text_angle = 0; |
|
429 |
this.arrow_angle = 0; |
|
| 39 | 430 |
this.edit_button = new Rkns.Renderer.EdgeEditButton(this.renderer, null); |
| 23 | 431 |
this.edit_button.edge_representation = this; |
| 39 | 432 |
this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this.renderer, null); |
| 23 | 433 |
this.remove_button.edge_representation = this; |
| 2 | 434 |
} |
435 |
||
| 7 | 436 |
Rkns.Renderer.Edge.prototype.redraw = function() { |
| 31 | 437 |
var _p0a = this.from_representation.paper_coords, |
438 |
_p1a = this.to_representation.paper_coords, |
|
439 |
_v = _p1a.subtract(_p0a), |
|
| 15 | 440 |
_r = _v.length, |
| 18 | 441 |
_u = _v.divide(_r), |
| 31 | 442 |
_group_pos = this.bundle.getPosition(this), |
443 |
_delta = new paper.Point([- _u.y, _u.x]).multiply( 12 * _group_pos ), |
|
444 |
_p0b = _p0a.add(_delta), /* Adding a 4 px difference */ |
|
445 |
_p1b = _p1a.add(_delta), /* to differentiate inbound and outbound links */ |
|
| 15 | 446 |
_a = _v.angle, |
| 31 | 447 |
_handle = _v.divide(3), |
| 56 | 448 |
_color = this.model.get("color") || this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"); |
| 31 | 449 |
this.paper_coords = _p0b.add(_p1b).divide(2); |
| 7 | 450 |
this.line.strokeColor = _color; |
| 31 | 451 |
this.line.segments[0].point = _p0a; |
452 |
this.line.segments[1].point = this.paper_coords; |
|
453 |
this.line.segments[1].handleIn = _handle.multiply(-1); |
|
454 |
this.line.segments[1].handleOut = _handle; |
|
455 |
this.line.segments[2].point = _p1a; |
|
| 7 | 456 |
this.arrow.rotate(_a - this.arrow_angle); |
457 |
this.arrow.fillColor = _color; |
|
| 18 | 458 |
this.arrow.position = this.paper_coords.subtract(_u.multiply(4)); |
| 7 | 459 |
this.arrow_angle = _a; |
| 2 | 460 |
if (_a > 90) { |
461 |
_a -= 180; |
|
462 |
} |
|
463 |
if (_a < -90) { |
|
464 |
_a += 180; |
|
465 |
} |
|
| 7 | 466 |
this.text.rotate(_a - this.text_angle); |
| 23 | 467 |
this.text.content = this.model.get("title"); |
| 15 | 468 |
this.text.position = this.paper_coords; |
| 7 | 469 |
this.text_angle = _a; |
| 15 | 470 |
this.edit_button.moveTo(this.paper_coords); |
471 |
this.remove_button.moveTo(this.paper_coords); |
|
| 7 | 472 |
} |
473 |
||
| 18 | 474 |
Rkns.Renderer.Edge.prototype.openEditor = function() { |
| 23 | 475 |
this.renderer.removeRepresentationsOfType("editor"); |
476 |
var _editor = this.renderer.addRepresentation("EdgeEditor",null); |
|
477 |
_editor.edge_representation = this; |
|
| 37 | 478 |
_editor.draw(); |
| 18 | 479 |
} |
480 |
||
| 7 | 481 |
Rkns.Renderer.Edge.prototype.select = function() { |
| 52 | 482 |
this.line.strokeWidth = 4; |
| 15 | 483 |
this.edit_button.show(); |
484 |
this.remove_button.show(); |
|
| 7 | 485 |
} |
486 |
||
487 |
Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) { |
|
| 35 | 488 |
if (!_newTarget || _newTarget.edge_representation !== this) { |
| 15 | 489 |
this.edit_button.hide(); |
490 |
this.remove_button.hide(); |
|
| 52 | 491 |
this.line.strokeWidth = 2; |
| 15 | 492 |
} |
| 4 | 493 |
} |
494 |
||
| 7 | 495 |
Rkns.Renderer.Edge.prototype.mouseup = function(_event) { |
| 57 | 496 |
if (this.renderer.is_dragging) { |
497 |
this.from_representation.saveCoords(); |
|
498 |
this.to_representation.saveCoords(); |
|
499 |
} else { |
|
| 18 | 500 |
this.openEditor(); |
| 7 | 501 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
502 |
this.renderer.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
503 |
this.renderer.is_dragging = false; |
| 4 | 504 |
} |
505 |
||
| 7 | 506 |
Rkns.Renderer.Edge.prototype.paperShift = function(_delta) { |
| 23 | 507 |
this.from_representation.paperShift(_delta); |
508 |
this.to_representation.paperShift(_delta); |
|
| 2 | 509 |
} |
510 |
||
| 7 | 511 |
Rkns.Renderer.Edge.prototype.destroy = function() { |
| 39 | 512 |
this.super("destroy"); |
| 7 | 513 |
this.line.remove(); |
514 |
this.arrow.remove(); |
|
515 |
this.text.remove(); |
|
| 15 | 516 |
this.edit_button.destroy(); |
517 |
this.remove_button.destroy(); |
|
| 31 | 518 |
var _this = this; |
519 |
this.bundle.edges = Rkns._(this.bundle.edges).reject(function(_edge) { |
|
520 |
return _edge === _this; |
|
521 |
}); |
|
| 2 | 522 |
} |
| 5 | 523 |
|
| 4 | 524 |
/* */ |
525 |
||
| 23 | 526 |
Rkns.Renderer.TempEdge = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 4 | 527 |
|
| 7 | 528 |
Rkns.Renderer.TempEdge.prototype._init = function() { |
| 23 | 529 |
this.renderer.edge_layer.activate(); |
| 4 | 530 |
this.type = "temp-edge"; |
| 23 | 531 |
|
| 52 | 532 |
var _color = this.project.get("users").get(this.renderer.renkan.current_user).get("color") || "#000000"; |
| 7 | 533 |
this.line = new paper.Path(); |
534 |
this.line.strokeColor = _color; |
|
535 |
this.line.add([0,0],[0,0]); |
|
| 23 | 536 |
this.line.__representation = this; |
| 7 | 537 |
this.arrow = new paper.Path(); |
538 |
this.arrow.fillColor = _color; |
|
| 28 | 539 |
this.arrow.add([0,0],[Rkns.Renderer._ARROW_LENGTH,Rkns.Renderer._ARROW_WIDTH / 2],[0,Rkns.Renderer._ARROW_WIDTH]); |
| 23 | 540 |
this.arrow.__representation = this; |
| 7 | 541 |
this.arrow_angle = 0; |
| 4 | 542 |
} |
543 |
||
| 7 | 544 |
Rkns.Renderer.TempEdge.prototype.redraw = function() { |
| 23 | 545 |
var _p0 = this.from_representation.paper_coords, |
| 4 | 546 |
_p1 = this.end_pos, |
547 |
_a = _p1.subtract(_p0).angle, |
|
548 |
_c = _p0.add(_p1).divide(2); |
|
| 7 | 549 |
this.line.segments[0].point = _p0; |
550 |
this.line.segments[1].point = _p1; |
|
551 |
this.arrow.rotate(_a - this.arrow_angle); |
|
552 |
this.arrow.position = _c; |
|
553 |
this.arrow_angle = _a; |
|
| 4 | 554 |
} |
555 |
||
| 7 | 556 |
Rkns.Renderer.TempEdge.prototype.paperShift = function(_delta) { |
| 4 | 557 |
this.end_pos = this.end_pos.add(_delta); |
| 21 | 558 |
var _hitResult = paper.project.hitTest(this.end_pos); |
| 23 | 559 |
this.renderer.findTarget(_hitResult); |
| 4 | 560 |
this.redraw(); |
561 |
} |
|
562 |
||
| 7 | 563 |
Rkns.Renderer.TempEdge.prototype.mouseup = function(_event) { |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
564 |
var _hitResult = paper.project.hitTest(_event.point), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
565 |
_model = this.from_representation.model, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
566 |
_endDrag = true; |
| 23 | 567 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
568 |
var _target = _hitResult.item.__representation; |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
569 |
if (_target.type === "Node" && _model !== _target.model) { |
| 23 | 570 |
var _data = { |
571 |
id: Rkns.Utils.getUID('edge'), |
|
572 |
created_by: this.renderer.renkan.current_user, |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
573 |
from: _model.get("_id"), |
| 30 | 574 |
to: _target.model.get("_id") |
| 23 | 575 |
}; |
576 |
this.project.addEdge(_data); |
|
| 4 | 577 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
578 |
if (_model === _target.model || (_target.node_representation && _target.node_representation.model === _model)) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
579 |
_endDrag = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
580 |
this.renderer.is_dragging = true; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
581 |
} |
| 4 | 582 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
583 |
if (_endDrag) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
584 |
this.renderer.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
585 |
this.renderer.is_dragging = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
586 |
this.renderer.removeRepresentation(this); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
587 |
paper.view.draw(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
588 |
} |
| 5 | 589 |
} |
590 |
||
| 7 | 591 |
Rkns.Renderer.TempEdge.prototype.destroy = function() { |
592 |
this.arrow.remove(); |
|
593 |
this.line.remove(); |
|
| 5 | 594 |
} |
595 |
||
596 |
/* */ |
|
597 |
||
| 23 | 598 |
Rkns.Renderer.NodeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 5 | 599 |
|
| 7 | 600 |
Rkns.Renderer.NodeEditor.prototype._init = function() { |
| 23 | 601 |
this.renderer.overlay_layer.activate(); |
| 5 | 602 |
this.type = "editor"; |
603 |
this.editor_block = new paper.Path(); |
|
604 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
605 |
this.editor_block.add.apply(this.editor_block, _pts); |
|
606 |
this.editor_block.strokeWidth = 2; |
|
607 |
this.editor_block.strokeColor = "#999999"; |
|
608 |
this.editor_block.fillColor = "#e0e0e0"; |
|
609 |
this.editor_block.opacity = .8; |
|
610 |
this.editor_$ = Rkns.$('<div>') |
|
| 23 | 611 |
.appendTo(this.renderer.editor_$) |
| 5 | 612 |
.css({ |
613 |
position: "absolute", |
|
614 |
opacity: .8 |
|
615 |
}) |
|
616 |
.hide(); |
|
617 |
} |
|
618 |
||
| 7 | 619 |
Rkns.Renderer.NodeEditor.prototype.template = Rkns._.template( |
| 5 | 620 |
'<h2><span class="Rk-CloseX">×</span><%=l10n.edit_node%></span></h2>' |
621 |
+ '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=node.title%>"/></p>' |
|
| 26 | 622 |
+ '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=node.uri%>"/><a class="Rk-Edit-Goto" href="<%=node.uri%>" target="_blank"></a></p>' |
| 5 | 623 |
+ '<p><label><%=l10n.edit_description%></label><textarea class="Rk-Edit-Description"><%=node.description%></textarea></p>' |
| 53 | 624 |
+ '<div class="Rk-Editor-p"><label>Node color</label><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-Edit-Color" style="background:<%=node.color%>;"><span class="Rk-Edit-ColorTip"></span></span><ul class="Rk-Edit-ColorPicker">' |
625 |
+ '<% print(Rkns.pickerColors.reduce(function(m,c) { return m + "<li data-color=\'" + c + "\' style=\'background: " + c + "\'></li>"},"")); %></ul><span class="Rk-Edit-ColorPicker-Text">Choose color</span></div></div>' |
|
| 37 | 626 |
+ '<p><label><%=l10n.edit_image%></label><input class="Rk-Edit-Image" type="text" value="<%=node.image%>"/><img class="Rk-Edit-ImgPreview" src="<%=node.image%>" /></p>' |
| 25 | 627 |
+ '<p><label><%=l10n.created_by%></label> <span class="Rk-UserColor" style="background:<%=node.created_by_color%>;"></span><%=node.created_by_title%></p>' |
| 5 | 628 |
); |
629 |
||
| 37 | 630 |
Rkns.Renderer.NodeEditor.prototype.draw = function() { |
| 53 | 631 |
var _model = this.node_representation.model, |
632 |
_created_by = _model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER; |
|
| 5 | 633 |
this.editor_$ |
634 |
.html(this.template({ |
|
| 23 | 635 |
node: { |
636 |
title: _model.get("title"), |
|
637 |
uri: _model.get("uri"), |
|
638 |
description: _model.get("description"), |
|
| 37 | 639 |
image: _model.get("image") || "", |
| 53 | 640 |
color: _model.get("color") || _created_by.get("color"), |
641 |
created_by_color: _created_by.get("color"), |
|
642 |
created_by_title: _created_by.get("title") |
|
| 23 | 643 |
}, |
644 |
l10n: this.renderer.renkan.l10n |
|
| 37 | 645 |
})); |
646 |
this.redraw(); |
|
| 5 | 647 |
var _this = this; |
648 |
this.editor_$.find(".Rk-CloseX").click(function() { |
|
| 23 | 649 |
_this.renderer.removeRepresentation(_this); |
| 5 | 650 |
paper.view.draw(); |
651 |
}); |
|
652 |
this.editor_$.find("input, textarea").bind("keyup change", function() { |
|
| 37 | 653 |
var _uri = _this.editor_$.find(".Rk-Edit-URI").val(), |
654 |
_image = _this.editor_$.find(".Rk-Edit-Image").val(); |
|
655 |
_this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _image); |
|
656 |
_this.editor_$.find(".Rk-Edit-Goto").attr("href",_uri); |
|
| 5 | 657 |
var _data = { |
658 |
title: _this.editor_$.find(".Rk-Edit-Title").val(), |
|
659 |
description: _this.editor_$.find(".Rk-Edit-Description").val(), |
|
| 37 | 660 |
uri: _uri, |
661 |
image: _image |
|
| 5 | 662 |
} |
| 23 | 663 |
_model.set(_data); |
| 37 | 664 |
_this.redraw(); |
| 5 | 665 |
}); |
| 38 | 666 |
this.editor_$.find("img").load(function() { |
667 |
_this.redraw(); |
|
668 |
}) |
|
| 8 | 669 |
this.editor_$.find(".Rk-Edit-Title")[0].focus(); |
| 52 | 670 |
this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( |
671 |
function() { _this.editor_$.find(".Rk-Edit-ColorPicker").show(); }, |
|
672 |
function() { _this.editor_$.find(".Rk-Edit-ColorPicker").hide(); } |
|
673 |
); |
|
674 |
this.editor_$.find(".Rk-Edit-ColorPicker li").hover( |
|
675 |
function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); }, |
|
| 53 | 676 |
function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color")) } |
| 52 | 677 |
).click(function() { |
678 |
_model.set("color", $(this).attr("data-color")); |
|
679 |
_this.redraw(); |
|
680 |
}); |
|
| 37 | 681 |
} |
682 |
||
683 |
Rkns.Renderer.NodeEditor.prototype.redraw = function() { |
|
684 |
var _coords = this.node_representation.paper_coords; |
|
685 |
Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 20, this.editor_$); |
|
686 |
this.editor_$.show(); |
|
| 23 | 687 |
paper.view.draw(); |
| 5 | 688 |
} |
689 |
||
| 7 | 690 |
Rkns.Renderer.NodeEditor.prototype.destroy = function() { |
| 5 | 691 |
this.editor_block.remove(); |
692 |
this.editor_$.detach(); |
|
693 |
} |
|
694 |
||
695 |
/* */ |
|
696 |
||
| 23 | 697 |
Rkns.Renderer.EdgeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 5 | 698 |
|
| 7 | 699 |
Rkns.Renderer.EdgeEditor.prototype._init = function() { |
| 23 | 700 |
this.renderer.overlay_layer.activate(); |
| 5 | 701 |
this.type = "editor"; |
702 |
this.editor_block = new paper.Path(); |
|
703 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
704 |
this.editor_block.add.apply(this.editor_block, _pts); |
|
705 |
this.editor_block.strokeWidth = 2; |
|
706 |
this.editor_block.strokeColor = "#999999"; |
|
707 |
this.editor_block.fillColor = "#e0e0e0"; |
|
708 |
this.editor_block.opacity = .8; |
|
709 |
this.editor_$ = Rkns.$('<div>') |
|
| 23 | 710 |
.appendTo(this.renderer.editor_$) |
| 5 | 711 |
.css({ |
712 |
position: "absolute", |
|
713 |
opacity: .8 |
|
714 |
}) |
|
715 |
.hide(); |
|
716 |
} |
|
717 |
||
| 7 | 718 |
Rkns.Renderer.EdgeEditor.prototype.template = Rkns._.template( |
| 5 | 719 |
'<h2><span class="Rk-CloseX">×</span><%=l10n.edit_edge%></span></h2>' |
720 |
+ '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=edge.title%>"/></p>' |
|
| 26 | 721 |
+ '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=edge.uri%>"/><a class="Rk-Edit-Goto" href="<%=edge.uri%>" target="_blank"></a></p>' |
| 53 | 722 |
+ '<div class="Rk-Editor-p"><label>Edge color:</label><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-Edit-Color" style="background:<%=edge.color%>;"><span class="Rk-Edit-ColorTip"></span></span><ul class="Rk-Edit-ColorPicker">' |
723 |
+ '<% print(Rkns.pickerColors.reduce(function(m,c) { return m + "<li data-color=\'" + c + "\' style=\'background: " + c + "\'></li>"},"")); %></ul><span class="Rk-Edit-ColorPicker-Text">Choose color</span></div></div>' |
|
724 |
+ '<p><label><%=l10n.edit_from%></label><span class="Rk-UserColor" style="background:<%=edge.from_color%>;"></span><%=edge.from_title%></p>' |
|
725 |
+ '<p><label><%=l10n.edit_to%></label><span class="Rk-UserColor" style="background:<%=edge.to_color%>;"></span><%=edge.to_title%></p>' |
|
| 25 | 726 |
+ '<p><label><%=l10n.created_by%> </label><span class="Rk-UserColor" style="background:<%=edge.created_by_color%>;"></span><%=edge.created_by_title%></p>' |
| 5 | 727 |
); |
728 |
||
| 37 | 729 |
Rkns.Renderer.EdgeEditor.prototype.draw = function() { |
| 53 | 730 |
var _model = this.edge_representation.model, |
731 |
_from_model = _model.get("from"), |
|
732 |
_to_model = _model.get("to"), |
|
733 |
_created_by = _model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER; |
|
| 5 | 734 |
this.editor_$ |
735 |
.html(this.template({ |
|
| 25 | 736 |
edge: { |
737 |
title: _model.get("title"), |
|
738 |
uri: _model.get("uri"), |
|
739 |
description: _model.get("description"), |
|
| 53 | 740 |
color: _model.get("color") || _created_by.get("color"), |
741 |
from_title: _from_model.get("title"), |
|
742 |
to_title: _to_model.get("title"), |
|
743 |
from_color: _from_model.get("color") || (_from_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"), |
|
744 |
to_color: _to_model.get("color") || (_to_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"), |
|
745 |
created_by_color: _created_by.get("color"), |
|
746 |
created_by_title: _created_by.get("title") |
|
| 25 | 747 |
}, |
| 23 | 748 |
l10n: this.renderer.renkan.l10n |
| 37 | 749 |
})); |
750 |
this.redraw(); |
|
| 5 | 751 |
var _this = this; |
752 |
this.editor_$.find(".Rk-CloseX").click(function() { |
|
| 23 | 753 |
_this.renderer.removeRepresentation(_this); |
| 5 | 754 |
paper.view.draw(); |
755 |
}); |
|
756 |
this.editor_$.find("input, textarea").bind("keyup change", function() { |
|
| 28 | 757 |
_this.editor_$.find(".Rk-Edit-Goto").attr("href",_this.editor_$.find(".Rk-Edit-URI").val()); |
| 5 | 758 |
var _data = { |
759 |
title: _this.editor_$.find(".Rk-Edit-Title").val(), |
|
760 |
uri: _this.editor_$.find(".Rk-Edit-URI").val() |
|
761 |
} |
|
| 23 | 762 |
_model.set(_data); |
| 37 | 763 |
_this.redraw(); |
| 5 | 764 |
}); |
| 52 | 765 |
this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( |
766 |
function() { _this.editor_$.find(".Rk-Edit-ColorPicker").show(); }, |
|
767 |
function() { _this.editor_$.find(".Rk-Edit-ColorPicker").hide(); } |
|
768 |
); |
|
769 |
this.editor_$.find(".Rk-Edit-ColorPicker li").hover( |
|
770 |
function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); }, |
|
| 53 | 771 |
function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color")); } |
| 52 | 772 |
).click(function() { |
773 |
_model.set("color", $(this).attr("data-color")); |
|
774 |
_this.redraw(); |
|
775 |
}); |
|
| 37 | 776 |
} |
777 |
Rkns.Renderer.EdgeEditor.prototype.redraw = function() { |
|
778 |
var _coords = this.edge_representation.paper_coords; |
|
779 |
Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 5, this.editor_$); |
|
780 |
this.editor_$.show(); |
|
| 23 | 781 |
paper.view.draw(); |
| 5 | 782 |
} |
783 |
||
| 7 | 784 |
Rkns.Renderer.EdgeEditor.prototype.destroy = function() { |
| 5 | 785 |
this.editor_block.remove(); |
786 |
this.editor_$.detach(); |
|
| 4 | 787 |
} |
| 2 | 788 |
|
789 |
/* */ |
|
| 1 | 790 |
|
| 23 | 791 |
Rkns.Renderer.NodeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 7 | 792 |
|
793 |
Rkns.Renderer.NodeEditButton.prototype._init = function() { |
|
| 35 | 794 |
this.renderer.overlay_layer.activate(); |
| 20 | 795 |
this.type = "Node-edit-button"; |
| 56 | 796 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._NODE_BUTTON_INNER, Rkns.Renderer._NODE_BUTTON_OUTER, - 90, 30, 1, this.renderer.renkan.static_url+'img/edit.png', this.renderer.renkan.l10n.caption_edit); |
| 7 | 797 |
} |
798 |
||
799 |
Rkns.Renderer.NodeEditButton.prototype.moveTo = function(_pos) { |
|
| 18 | 800 |
this.sector.moveTo(_pos); |
| 7 | 801 |
} |
802 |
||
803 |
Rkns.Renderer.NodeEditButton.prototype.show = function() { |
|
| 18 | 804 |
this.sector.show(); |
| 7 | 805 |
} |
806 |
||
807 |
Rkns.Renderer.NodeEditButton.prototype.hide = function() { |
|
| 18 | 808 |
this.sector.hide(); |
| 7 | 809 |
} |
810 |
||
811 |
Rkns.Renderer.NodeEditButton.prototype.select = function() { |
|
| 18 | 812 |
this.sector.select(); |
| 7 | 813 |
} |
814 |
||
| 35 | 815 |
Rkns.Renderer.NodeEditButton.prototype.unselect = function(_newTarget) { |
| 18 | 816 |
this.sector.unselect(); |
| 35 | 817 |
if (!_newTarget || (_newTarget !== this.node_representation && _newTarget.node_representation !== this.node_representation)) { |
818 |
this.node_representation.unselect(); |
|
819 |
} |
|
| 7 | 820 |
} |
821 |
||
822 |
Rkns.Renderer.NodeEditButton.prototype.mouseup = function() { |
|
| 23 | 823 |
if (!this.renderer.is_dragging) { |
824 |
this.node_representation.openEditor(); |
|
| 7 | 825 |
} |
826 |
} |
|
827 |
||
828 |
Rkns.Renderer.NodeEditButton.prototype.destroy = function() { |
|
| 18 | 829 |
this.sector.destroy(); |
| 7 | 830 |
} |
831 |
||
832 |
/* */ |
|
833 |
||
| 23 | 834 |
Rkns.Renderer.NodeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 7 | 835 |
|
836 |
Rkns.Renderer.NodeRemoveButton.prototype._init = function() { |
|
| 35 | 837 |
this.renderer.overlay_layer.activate(); |
| 20 | 838 |
this.type = "Node-remove-button"; |
| 56 | 839 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._NODE_BUTTON_INNER, Rkns.Renderer._NODE_BUTTON_OUTER, -210, -90, 1, this.renderer.renkan.static_url+'img/remove.png', this.renderer.renkan.l10n.caption_remove); |
| 7 | 840 |
} |
841 |
||
842 |
Rkns.Renderer.NodeRemoveButton.prototype.moveTo = function(_pos) { |
|
| 18 | 843 |
this.sector.moveTo(_pos); |
| 7 | 844 |
} |
845 |
||
846 |
Rkns.Renderer.NodeRemoveButton.prototype.show = function() { |
|
| 18 | 847 |
this.sector.show(); |
| 7 | 848 |
} |
849 |
||
850 |
Rkns.Renderer.NodeRemoveButton.prototype.hide = function() { |
|
| 18 | 851 |
this.sector.hide(); |
| 7 | 852 |
} |
853 |
||
854 |
Rkns.Renderer.NodeRemoveButton.prototype.select = function() { |
|
| 18 | 855 |
this.sector.select(); |
| 7 | 856 |
} |
857 |
||
| 35 | 858 |
Rkns.Renderer.NodeRemoveButton.prototype.unselect = function(_newTarget) { |
| 18 | 859 |
this.sector.unselect(); |
| 35 | 860 |
if (!_newTarget || (_newTarget !== this.node_representation && _newTarget.node_representation !== this.node_representation)) { |
861 |
this.node_representation.unselect(); |
|
862 |
} |
|
| 7 | 863 |
} |
864 |
||
865 |
Rkns.Renderer.NodeRemoveButton.prototype.mouseup = function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
866 |
this.renderer.removeRepresentationsOfType("editor"); |
| 23 | 867 |
if (confirm('Do you really wish to remove node "' + this.node_representation.model.get("title") + '"?')) { |
868 |
this.project.removeNode(this.node_representation.model); |
|
| 10 | 869 |
} |
| 7 | 870 |
} |
871 |
||
872 |
Rkns.Renderer.NodeRemoveButton.prototype.destroy = function() { |
|
| 18 | 873 |
this.sector.destroy(); |
| 7 | 874 |
} |
875 |
||
876 |
/* */ |
|
877 |
||
| 23 | 878 |
Rkns.Renderer.NodeLinkButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 11 | 879 |
|
880 |
Rkns.Renderer.NodeLinkButton.prototype._init = function() { |
|
| 35 | 881 |
this.renderer.overlay_layer.activate(); |
| 20 | 882 |
this.type = "Node-link-button"; |
| 56 | 883 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._NODE_BUTTON_INNER, Rkns.Renderer._NODE_BUTTON_OUTER, 30, 150, 1, this.renderer.renkan.static_url+'img/link.png', this.renderer.renkan.l10n.caption_link); |
| 11 | 884 |
} |
885 |
||
886 |
Rkns.Renderer.NodeLinkButton.prototype.moveTo = function(_pos) { |
|
| 18 | 887 |
this.sector.moveTo(_pos); |
| 11 | 888 |
} |
889 |
||
890 |
Rkns.Renderer.NodeLinkButton.prototype.show = function() { |
|
| 18 | 891 |
this.sector.show(); |
| 11 | 892 |
} |
893 |
||
894 |
Rkns.Renderer.NodeLinkButton.prototype.hide = function() { |
|
| 18 | 895 |
this.sector.hide(); |
| 11 | 896 |
} |
897 |
||
898 |
Rkns.Renderer.NodeLinkButton.prototype.select = function() { |
|
| 18 | 899 |
this.sector.select(); |
| 11 | 900 |
} |
901 |
||
| 35 | 902 |
Rkns.Renderer.NodeLinkButton.prototype.unselect = function(_newTarget) { |
| 18 | 903 |
this.sector.unselect(); |
| 35 | 904 |
if (!_newTarget || (_newTarget !== this.node_representation && _newTarget.node_representation !== this.node_representation)) { |
905 |
this.node_representation.unselect(); |
|
906 |
} |
|
| 11 | 907 |
} |
908 |
||
909 |
Rkns.Renderer.NodeLinkButton.prototype.destroy = function() { |
|
| 18 | 910 |
this.sector.destroy(); |
| 11 | 911 |
} |
912 |
||
913 |
/* */ |
|
914 |
||
| 23 | 915 |
Rkns.Renderer.EdgeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 15 | 916 |
|
917 |
Rkns.Renderer.EdgeEditButton.prototype._init = function() { |
|
| 35 | 918 |
this.renderer.overlay_layer.activate(); |
| 20 | 919 |
this.type = "Edge-edit-button"; |
| 56 | 920 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, - 90, 90, 1, this.renderer.renkan.static_url+'img/edit.png', this.renderer.renkan.l10n.caption_edit); |
| 15 | 921 |
} |
922 |
||
923 |
Rkns.Renderer.EdgeEditButton.prototype.moveTo = function(_pos) { |
|
| 18 | 924 |
this.sector.moveTo(_pos); |
| 15 | 925 |
} |
926 |
||
927 |
Rkns.Renderer.EdgeEditButton.prototype.show = function() { |
|
| 18 | 928 |
this.sector.show(); |
| 15 | 929 |
} |
930 |
||
931 |
Rkns.Renderer.EdgeEditButton.prototype.hide = function() { |
|
| 18 | 932 |
this.sector.hide(); |
| 15 | 933 |
} |
934 |
||
935 |
Rkns.Renderer.EdgeEditButton.prototype.select = function() { |
|
| 18 | 936 |
this.sector.select(); |
| 15 | 937 |
} |
938 |
||
| 35 | 939 |
Rkns.Renderer.EdgeEditButton.prototype.unselect = function(_newTarget) { |
| 18 | 940 |
this.sector.unselect(); |
| 35 | 941 |
if (!_newTarget || (_newTarget !== this.edge_representation && _newTarget.edge_representation !== this.edge_representation)) { |
942 |
this.edge_representation.unselect(); |
|
943 |
} |
|
| 15 | 944 |
} |
945 |
||
946 |
Rkns.Renderer.EdgeEditButton.prototype.mouseup = function() { |
|
| 23 | 947 |
if (!this.renderer.is_dragging) { |
948 |
this.edge_representation.openEditor(); |
|
| 15 | 949 |
} |
950 |
} |
|
951 |
||
952 |
Rkns.Renderer.EdgeEditButton.prototype.destroy = function() { |
|
| 18 | 953 |
this.sector.destroy(); |
| 15 | 954 |
} |
955 |
||
956 |
/* */ |
|
957 |
||
| 23 | 958 |
Rkns.Renderer.EdgeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 15 | 959 |
|
960 |
Rkns.Renderer.EdgeRemoveButton.prototype._init = function() { |
|
| 35 | 961 |
this.renderer.overlay_layer.activate(); |
| 20 | 962 |
this.type = "Edge-remove-button"; |
| 56 | 963 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, - 270, -90, 1, this.renderer.renkan.static_url+'img/remove.png', this.renderer.renkan.l10n.caption_remove); |
| 15 | 964 |
} |
965 |
Rkns.Renderer.EdgeRemoveButton.prototype.moveTo = function(_pos) { |
|
| 18 | 966 |
this.sector.moveTo(_pos); |
| 15 | 967 |
} |
968 |
||
969 |
Rkns.Renderer.EdgeRemoveButton.prototype.show = function() { |
|
| 18 | 970 |
this.sector.show(); |
| 15 | 971 |
} |
972 |
||
973 |
Rkns.Renderer.EdgeRemoveButton.prototype.hide = function() { |
|
| 18 | 974 |
this.sector.hide(); |
| 15 | 975 |
} |
976 |
||
977 |
Rkns.Renderer.EdgeRemoveButton.prototype.select = function() { |
|
| 18 | 978 |
this.sector.select(); |
| 15 | 979 |
} |
980 |
||
| 35 | 981 |
Rkns.Renderer.EdgeRemoveButton.prototype.unselect = function(_newTarget) { |
| 18 | 982 |
this.sector.unselect(); |
| 35 | 983 |
if (!_newTarget || (_newTarget !== this.edge_representation && _newTarget.edge_representation !== this.edge_representation)) { |
984 |
this.edge_representation.unselect(); |
|
985 |
} |
|
| 15 | 986 |
} |
987 |
||
988 |
Rkns.Renderer.EdgeRemoveButton.prototype.mouseup = function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
989 |
this.renderer.removeRepresentationsOfType("editor"); |
| 23 | 990 |
if (confirm('Do you really wish to remove edge "' + this.edge_representation.model.get("title") + '"?')) { |
991 |
this.project.removeEdge(this.edge_representation.model); |
|
| 15 | 992 |
} |
993 |
} |
|
994 |
||
995 |
Rkns.Renderer.EdgeRemoveButton.prototype.destroy = function() { |
|
| 18 | 996 |
this.sector.destroy(); |
| 15 | 997 |
} |
998 |
||
999 |
/* */ |
|
1000 |
||
| 23 | 1001 |
Rkns.Renderer.Scene = function(_renkan) { |
1002 |
this.renkan = _renkan; |
|
| 20 | 1003 |
this.$ = Rkns.$(".Rk-Render"); |
| 23 | 1004 |
this.representations = []; |
| 44 | 1005 |
this.$.html(this.template(_renkan)); |
| 20 | 1006 |
this.canvas_$ = this.$.find(".Rk-Canvas"); |
1007 |
this.editor_$ = this.$.find(".Rk-Editor"); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1008 |
this.notif_$ = this.$.find(".Rk-Notifications"); |
| 20 | 1009 |
paper.setup(this.canvas_$[0]); |
| 2 | 1010 |
this.scale = 1; |
1011 |
this.offset = paper.view.center; |
|
1012 |
this.totalScroll = 0; |
|
| 5 | 1013 |
this.click_target = null; |
| 4 | 1014 |
this.selected_target = null; |
| 2 | 1015 |
this.edge_layer = new paper.Layer(); |
1016 |
this.node_layer = new paper.Layer(); |
|
| 5 | 1017 |
this.overlay_layer = new paper.Layer(); |
| 31 | 1018 |
this.bundles = []; |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1019 |
this.click_mode = false; |
| 2 | 1020 |
var _tool = new paper.Tool(), |
1021 |
_this = this; |
|
| 28 | 1022 |
_tool.minDistance = Rkns.Renderer._MIN_DRAG_DISTANCE; |
| 4 | 1023 |
_tool.onMouseMove = function(_event) { |
1024 |
_this.onMouseMove(_event); |
|
1025 |
} |
|
| 2 | 1026 |
_tool.onMouseDown = function(_event) { |
1027 |
_this.onMouseDown(_event); |
|
1028 |
} |
|
1029 |
_tool.onMouseDrag = function(_event) { |
|
1030 |
_this.onMouseDrag(_event); |
|
1031 |
} |
|
| 21 | 1032 |
this.canvas_$.mouseup(function(_event) { |
| 4 | 1033 |
_this.onMouseUp(_event); |
| 21 | 1034 |
}); |
| 20 | 1035 |
this.canvas_$.mousewheel(function(_event, _delta) { |
| 2 | 1036 |
_this.onScroll(_event, _delta); |
| 21 | 1037 |
}); |
| 20 | 1038 |
this.canvas_$.dblclick(function(_event) { |
| 4 | 1039 |
_this.onDoubleClick(_event); |
| 11 | 1040 |
}); |
| 21 | 1041 |
this.canvas_$.mouseenter(function(_event) { |
1042 |
_this.onMouseEnter(_event); |
|
1043 |
}); |
|
| 11 | 1044 |
this.editor_$.find(".Rk-ZoomOut").click(function() { |
1045 |
_this.offset = new paper.Point([ |
|
| 20 | 1046 |
_this.canvas_$.width(), |
1047 |
_this.canvas_$.height() |
|
| 11 | 1048 |
]).multiply( .5 * ( 1 - Math.SQRT1_2 ) ).add(_this.offset.multiply( Math.SQRT1_2 )); |
| 28 | 1049 |
_this.setScale( _this.scale * Math.SQRT1_2 ); |
| 11 | 1050 |
_this.redraw(); |
1051 |
}); |
|
1052 |
this.editor_$.find(".Rk-ZoomIn").click(function() { |
|
1053 |
_this.offset = new paper.Point([ |
|
| 20 | 1054 |
_this.canvas_$.width(), |
1055 |
_this.canvas_$.height() |
|
| 11 | 1056 |
]).multiply( .5 * ( 1 - Math.SQRT2 ) ).add(_this.offset.multiply( Math.SQRT2 )); |
| 28 | 1057 |
_this.setScale( _this.scale * Math.SQRT2 ); |
| 11 | 1058 |
_this.redraw(); |
1059 |
}); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1060 |
this.$.find(".Rk-CurrentUser").mouseenter( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1061 |
function() { _this.$.find(".Rk-UserList").slideDown() } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1062 |
); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1063 |
this.$.find(".Rk-Users").mouseleave( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1064 |
function() { _this.$.find(".Rk-UserList").slideUp(); } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1065 |
); |
| 34 | 1066 |
this.$.find(".Rk-FullScreen-Button").click(function() { |
1067 |
var _isFull = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen, |
|
1068 |
_el = _this.renkan.$[0], |
|
1069 |
_requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"], |
|
1070 |
_cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"]; |
|
1071 |
if (_isFull) { |
|
1072 |
for (var i = 0; i < _cancelMethods.length; i++) { |
|
1073 |
if (typeof document[_cancelMethods[i]] === "function") { |
|
1074 |
document[_cancelMethods[i]](); |
|
1075 |
break; |
|
1076 |
} |
|
1077 |
} |
|
1078 |
} else { |
|
1079 |
for (var i = 0; i < _requestMethods.length; i++) { |
|
1080 |
if (typeof _el[_requestMethods[i]] === "function") { |
|
1081 |
_el[_requestMethods[i]](); |
|
1082 |
break; |
|
1083 |
} |
|
1084 |
} |
|
1085 |
} |
|
1086 |
}); |
|
1087 |
this.$.find(".Rk-AddNode-Button").click(function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1088 |
if (_this.click_mode === Rkns.Renderer._CLICKMODE_ADDNODE) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1089 |
_this.click_mode = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1090 |
_this.notif_$.hide(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1091 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1092 |
_this.click_mode = Rkns.Renderer._CLICKMODE_ADDNODE; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1093 |
_this.notif_$.html(_renkan.l10n.notif_add_node).fadeIn(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1094 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1095 |
}); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1096 |
this.$.find(".Rk-AddEdge-Button").click(function() { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1097 |
if (_this.click_mode === Rkns.Renderer._CLICKMODE_STARTEDGE || _this.click_mode === Rkns.Renderer._CLICKMODE_ENDEDGE) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1098 |
_this.click_mode = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1099 |
_this.notif_$.hide(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1100 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1101 |
_this.click_mode = Rkns.Renderer._CLICKMODE_STARTEDGE; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1102 |
_this.notif_$.html(_renkan.l10n.notif_start_edge).fadeIn(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1103 |
} |
| 34 | 1104 |
}); |
1105 |
this.$.find(".Rk-TopBar-Button").mouseover(function() { |
|
1106 |
Rkns.$(this).find(".Rk-TopBar-Tooltip").show(); |
|
1107 |
}).mouseout(function() { |
|
1108 |
Rkns.$(this).find(".Rk-TopBar-Tooltip").hide(); |
|
1109 |
}); |
|
1110 |
|
|
| 2 | 1111 |
paper.view.onResize = function(_event) { |
1112 |
_this.offset = _this.offset.add(_event.delta.divide(2)); |
|
| 57 | 1113 |
_this.resetCoords(); |
| 2 | 1114 |
_this.redraw(); |
1115 |
} |
|
| 23 | 1116 |
|
1117 |
var _thRedraw = Rkns._.throttle(function() { |
|
1118 |
_this.redraw(); |
|
1119 |
},50); |
|
1120 |
|
|
1121 |
this.addRepresentations("Node", this.renkan.project.get("nodes")); |
|
1122 |
this.addRepresentations("Edge", this.renkan.project.get("edges")); |
|
| 44 | 1123 |
this.renkan.project.on("change:title", function() { |
1124 |
_this.$.find(".Rk-PadTitle").val(_renkan.project.get("title")); |
|
1125 |
}); |
|
1126 |
|
|
1127 |
this.$.find(".Rk-PadTitle").on("keyup input paste", function() { |
|
1128 |
_renkan.project.set({"title": $(this).val()}); |
|
1129 |
}) |
|
1130 |
|
|
| 34 | 1131 |
this.renkan.project.get("users").each(function(_user) { |
1132 |
_this.addUser(_user); |
|
| 44 | 1133 |
}); |
| 23 | 1134 |
|
| 34 | 1135 |
this.renkan.project.on("add:users", function(_user) { |
1136 |
_this.addUser(_user); |
|
1137 |
}); |
|
| 23 | 1138 |
this.renkan.project.on("add:nodes", function(_node) { |
1139 |
_this.addRepresentation("Node", _node); |
|
1140 |
_thRedraw(); |
|
1141 |
}); |
|
1142 |
this.renkan.project.on("add:edges", function(_edge) { |
|
1143 |
_this.addRepresentation("Edge", _edge); |
|
1144 |
_thRedraw(); |
|
1145 |
}); |
|
1146 |
|
|
1147 |
this.redraw(); |
|
| 2 | 1148 |
} |
1149 |
||
| 20 | 1150 |
Rkns.Renderer.Scene.prototype.template = Rkns._.template( |
| 44 | 1151 |
'<div class="Rk-TopBar"><input type="text" class="Rk-PadTitle" value="<%- project.get("title") || "" %>" placeholder="<%=l10n.untitled_project%>" />' |
| 34 | 1152 |
+ '<div class="Rk-Users"><div class="Rk-CurrentUser"><span class="Rk-CurrentUser-Color"></span><span class="Rk-CurrentUser-Name"><unknown user></span></div><ul class="Rk-UserList"></ul></div>' |
1153 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-FullScreen-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%=l10n.full_screen%></div></div></div>' |
|
1154 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddNode-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%=l10n.add_node%></div></div></div>' |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1155 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddEdge-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%=l10n.add_edge%></div></div></div>' |
| 44 | 1156 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-Save-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%=l10n.save_project%></div></div></div>' |
| 34 | 1157 |
+ '<div class="Rk-TopBar-Separator"></div></div>' |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1158 |
+ '<canvas class="Rk-Canvas" resize></canvas><div class="Rk-Editor"><div class="Rk-Notifications"></div>' |
| 20 | 1159 |
+ '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%=l10n.zoom_in%>"></div><div class="Rk-ZoomOut" title="<%=l10n.zoom_out%>"></div></div>' |
1160 |
+ '</div>' |
|
| 11 | 1161 |
); |
1162 |
||
| 31 | 1163 |
Rkns.Renderer.Scene.prototype.addToBundles = function(_edgeRepr) { |
1164 |
var _bundle = Rkns._(this.bundles).find(function(_bundle) { |
|
1165 |
return ( |
|
1166 |
( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation ) |
|
1167 |
|| ( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation ) |
|
1168 |
); |
|
1169 |
}); |
|
1170 |
if (typeof _bundle !== "undefined") { |
|
1171 |
_bundle.edges.push(_edgeRepr) |
|
1172 |
} else { |
|
1173 |
_bundle = { |
|
1174 |
from: _edgeRepr.from_representation, |
|
1175 |
to: _edgeRepr.to_representation, |
|
1176 |
edges: [ _edgeRepr ], |
|
1177 |
getPosition: function(_er) { |
|
1178 |
var _dir = (_er.from_representation === this.from) ? 1 : -1; |
|
1179 |
return _dir * ( Rkns._(this.edges).indexOf(_er) - (this.edges.length - 1) / 2 ); |
|
1180 |
} |
|
1181 |
} |
|
1182 |
this.bundles.push(_bundle); |
|
1183 |
} |
|
1184 |
return _bundle; |
|
1185 |
} |
|
1186 |
||
| 28 | 1187 |
Rkns.Renderer.Scene.prototype.setScale = function(_newScale) { |
1188 |
this.scale = _newScale; |
|
| 57 | 1189 |
this.resetCoords(); |
| 28 | 1190 |
this.redraw(); |
1191 |
} |
|
1192 |
||
| 25 | 1193 |
Rkns.Renderer.Scene.prototype.autoScale = function() { |
| 43 | 1194 |
var nodes = this.renkan.project.get("nodes") |
1195 |
if (nodes.length > 1) { |
|
1196 |
var _xx = nodes.map(function(_node) { return _node.get("position").x }), |
|
1197 |
_yy = nodes.map(function(_node) { return _node.get("position").y }), |
|
| 26 | 1198 |
_minx = Math.min.apply(Math, _xx), |
1199 |
_miny = Math.min.apply(Math, _yy), |
|
1200 |
_maxx = Math.max.apply(Math, _xx), |
|
1201 |
_maxy = Math.max.apply(Math, _yy); |
|
| 28 | 1202 |
var _scale = Math.min((paper.view.size.width - 2 * Rkns.Renderer._MARGIN_X) / (_maxx - _minx), (paper.view.size.height - 2 * Rkns.Renderer._MARGIN_Y) / (_maxy - _miny)); |
1203 |
this.offset = paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)); |
|
1204 |
this.setScale(_scale); |
|
| 26 | 1205 |
} |
| 43 | 1206 |
if (nodes.length === 1) { |
| 44 | 1207 |
this.offset = paper.view.center.subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y])); |
| 43 | 1208 |
this.setScale(1); |
1209 |
} |
|
| 25 | 1210 |
} |
1211 |
||
| 57 | 1212 |
Rkns.Renderer.Scene.prototype.resetCoords = function(_point) { |
1213 |
_(this.representations).each(function(r) { |
|
1214 |
r.resetCoords(); |
|
1215 |
}); |
|
1216 |
} |
|
1217 |
||
| 7 | 1218 |
Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) { |
| 2 | 1219 |
return _point.multiply(this.scale).add(this.offset); |
1220 |
} |
|
1221 |
||
1222 |
||
| 7 | 1223 |
Rkns.Renderer.Scene.prototype.toModelCoords = function(_point) { |
| 2 | 1224 |
return _point.subtract(this.offset).divide(this.scale); |
| 1 | 1225 |
} |
1226 |
||
| 23 | 1227 |
Rkns.Renderer.Scene.prototype.addRepresentation = function(_type, _model) { |
1228 |
var _repr = new Rkns.Renderer[_type](this, _model); |
|
1229 |
this.representations.push(_repr); |
|
1230 |
return _repr; |
|
1231 |
} |
|
1232 |
||
1233 |
Rkns.Renderer.Scene.prototype.addRepresentations = function(_type, _collection) { |
|
1234 |
var _this = this; |
|
1235 |
_collection.forEach(function(_model) { |
|
1236 |
_this.addRepresentation(_type, _model); |
|
| 1 | 1237 |
}); |
1238 |
} |
|
1239 |
||
| 34 | 1240 |
Rkns.Renderer.Scene.prototype.userTemplate = Rkns._.template( |
1241 |
'<li class="Rk-User"><span class="Rk-UserColor" style="background:<%=background%>;"></span><%=name%></li>' |
|
1242 |
); |
|
1243 |
||
1244 |
Rkns.Renderer.Scene.prototype.addUser = function(_user) { |
|
1245 |
if (_user.get("_id") === this.renkan.current_user) { |
|
1246 |
this.$.find(".Rk-CurrentUser-Name").text(_user.get("title")); |
|
1247 |
this.$.find(".Rk-CurrentUser-Color").css("background", _user.get("color")); |
|
1248 |
} else { |
|
1249 |
this.$.find(".Rk-UserList").append( |
|
1250 |
Rkns.$( |
|
1251 |
this.userTemplate({ |
|
1252 |
name: _user.get("title"), |
|
1253 |
background: _user.get("color") |
|
1254 |
}) |
|
1255 |
) |
|
1256 |
); |
|
1257 |
} |
|
1258 |
} |
|
1259 |
||
| 23 | 1260 |
Rkns.Renderer.Scene.prototype.removeRepresentation = function(_representation) { |
1261 |
_representation.destroy(); |
|
1262 |
this.representations = Rkns._(this.representations).reject( |
|
1263 |
function(_repr) { |
|
1264 |
return _repr == _representation |
|
1265 |
} |
|
1266 |
); |
|
| 4 | 1267 |
} |
1268 |
||
| 23 | 1269 |
Rkns.Renderer.Scene.prototype.getRepresentationByModel = function(_model) { |
1270 |
return Rkns._(this.representations).find(function(_repr) { |
|
1271 |
return _repr.model === _model; |
|
1272 |
}); |
|
| 5 | 1273 |
} |
1274 |
||
| 23 | 1275 |
Rkns.Renderer.Scene.prototype.removeRepresentationsOfType = function(_type) { |
1276 |
var _representations = Rkns._(this.representations).filter(function(_repr) { |
|
1277 |
return _repr.type == _type; |
|
| 5 | 1278 |
}), |
1279 |
_this = this; |
|
| 23 | 1280 |
Rkns._(_representations).each(function(_repr) { |
1281 |
_this.removeRepresentation(_repr); |
|
| 5 | 1282 |
}); |
1283 |
} |
|
1284 |
||
| 26 | 1285 |
Rkns.Renderer.Scene.prototype.highlightModel = function(_model) { |
1286 |
var _repr = this.getRepresentationByModel(_model); |
|
1287 |
if (_repr) { |
|
1288 |
_repr.highlight(); |
|
1289 |
} |
|
1290 |
} |
|
1291 |
||
1292 |
Rkns.Renderer.Scene.prototype.unhighlightAll = function(_model) { |
|
1293 |
Rkns._(this.representations).each(function(_repr) { |
|
1294 |
_repr.unhighlight(); |
|
1295 |
}); |
|
1296 |
} |
|
1297 |
||
| 7 | 1298 |
Rkns.Renderer.Scene.prototype.redraw = function() { |
| 23 | 1299 |
Rkns._(this.representations).each(function(_representation) { |
1300 |
_representation.redraw(); |
|
| 2 | 1301 |
}); |
1302 |
paper.view.draw(); |
|
1303 |
} |
|
1304 |
||
| 11 | 1305 |
Rkns.Renderer.Scene.prototype.addTempEdge = function(_from, _point) { |
| 23 | 1306 |
var _tmpEdge = this.addRepresentation("TempEdge",null); |
| 11 | 1307 |
_tmpEdge.end_pos = _point; |
| 23 | 1308 |
_tmpEdge.from_representation = _from; |
| 11 | 1309 |
_tmpEdge.redraw(); |
1310 |
this.click_target = _tmpEdge; |
|
1311 |
} |
|
1312 |
||
| 21 | 1313 |
Rkns.Renderer.Scene.prototype.findTarget = function(_hitResult) { |
| 23 | 1314 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
1315 |
var _newTarget = _hitResult.item.__representation; |
|
1316 |
if (this.selected_target !== _hitResult.item.__representation) { |
|
| 4 | 1317 |
if (this.selected_target) { |
| 7 | 1318 |
this.selected_target.unselect(_newTarget); |
| 4 | 1319 |
} |
| 7 | 1320 |
_newTarget.select(this.selected_target); |
1321 |
this.selected_target = _newTarget; |
|
| 4 | 1322 |
} |
1323 |
} else { |
|
1324 |
if (this.selected_target) { |
|
| 7 | 1325 |
this.selected_target.unselect(null); |
| 4 | 1326 |
} |
1327 |
this.selected_target = null; |
|
1328 |
} |
|
1329 |
} |
|
1330 |
||
| 21 | 1331 |
Rkns.Renderer.Scene.prototype.onMouseMove = function(_event) { |
1332 |
var _hitResult = paper.project.hitTest(_event.point); |
|
1333 |
if (this.is_dragging) { |
|
1334 |
if (this.click_target && typeof this.click_target.paperShift === "function") { |
|
1335 |
this.click_target.paperShift(_event.delta); |
|
1336 |
} else { |
|
1337 |
this.offset = this.offset.add(_event.delta); |
|
| 57 | 1338 |
this.resetCoords(); |
| 21 | 1339 |
this.redraw(); |
1340 |
} |
|
1341 |
} else { |
|
1342 |
this.findTarget(_hitResult); |
|
1343 |
} |
|
1344 |
} |
|
1345 |
||
| 7 | 1346 |
Rkns.Renderer.Scene.prototype.onMouseDown = function(_event) { |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1347 |
if (!this.click_target || this.click_target.type !== "temp-edge") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1348 |
this.is_dragging = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1349 |
var _hitResult = paper.project.hitTest(_event.point); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1350 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1351 |
this.click_target = _hitResult.item.__representation; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1352 |
if (this.click_target.type === "Node-link-button") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1353 |
this.removeRepresentationsOfType("editor"); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1354 |
this.addTempEdge(this.click_target.node_representation, _event.point); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1355 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1356 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1357 |
this.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1358 |
if (this.click_mode === Rkns.Renderer._CLICKMODE_ADDNODE) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1359 |
var _coords = this.toModelCoords(_event.point), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1360 |
_data = { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1361 |
id: Rkns.Utils.getUID('node'), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1362 |
created_by: this.renkan.current_user, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1363 |
position: { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1364 |
x: _coords.x, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1365 |
y: _coords.y |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1366 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1367 |
}; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1368 |
_node = this.renkan.project.addNode(_data); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1369 |
this.getRepresentationByModel(_node).openEditor(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1370 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1371 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1372 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1373 |
if (this.click_mode) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1374 |
if (this.click_mode === Rkns.Renderer._CLICKMODE_STARTEDGE && this.click_target && this.click_target.type === "Node") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1375 |
this.removeRepresentationsOfType("editor"); |
| 11 | 1376 |
this.addTempEdge(this.click_target, _event.point); |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1377 |
this.click_mode = Rkns.Renderer._CLICKMODE_ENDEDGE; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1378 |
this.notif_$.fadeOut(function() { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1379 |
Rkns.$(this).html(_renkan.l10n.notif_end_edge).fadeIn(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1380 |
}); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1381 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1382 |
this.notif_$.hide(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1383 |
this.click_mode = false; |
| 11 | 1384 |
} |
| 2 | 1385 |
} |
| 1 | 1386 |
} |
| 2 | 1387 |
|
| 7 | 1388 |
Rkns.Renderer.Scene.prototype.onMouseDrag = function(_event) { |
| 5 | 1389 |
this.is_dragging = true; |
| 21 | 1390 |
this.onMouseMove(_event); |
| 2 | 1391 |
} |
1392 |
||
| 7 | 1393 |
Rkns.Renderer.Scene.prototype.onMouseUp = function(_event) { |
| 5 | 1394 |
if (this.click_target) { |
| 21 | 1395 |
var _off = this.canvas_$.offset(); |
1396 |
this.click_target.mouseup( |
|
1397 |
{ |
|
1398 |
point: new paper.Point([ |
|
1399 |
_event.pageX - _off.left, |
|
1400 |
_event.pageY - _off.top |
|
1401 |
]) |
|
1402 |
} |
|
1403 |
); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1404 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1405 |
this.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1406 |
this.is_dragging = false; |
| 4 | 1407 |
} |
1408 |
} |
|
1409 |
||
| 7 | 1410 |
Rkns.Renderer.Scene.prototype.onScroll = function(_event, _scrolldelta) { |
| 3 | 1411 |
this.totalScroll += _scrolldelta; |
| 2 | 1412 |
if (Math.abs(this.totalScroll) >= 1) { |
| 20 | 1413 |
var _off = this.canvas_$.offset(), |
| 3 | 1414 |
_delta = new paper.Point([ |
1415 |
_event.pageX - _off.left, |
|
1416 |
_event.pageY - _off.top |
|
1417 |
]).subtract(this.offset).multiply( Math.SQRT2 - 1 ); |
|
| 2 | 1418 |
if (this.totalScroll > 0) { |
| 3 | 1419 |
this.offset = this.offset.subtract(_delta); |
| 28 | 1420 |
this.setScale( this.scale * Math.SQRT2 ); |
| 2 | 1421 |
} else { |
| 3 | 1422 |
this.offset = this.offset.add(_delta.divide( Math.SQRT2 )); |
| 28 | 1423 |
this.setScale( this.scale * Math.SQRT1_2); |
| 2 | 1424 |
} |
1425 |
this.totalScroll = 0; |
|
1426 |
this.redraw(); |
|
1427 |
} |
|
1428 |
} |
|
| 4 | 1429 |
|
| 7 | 1430 |
Rkns.Renderer.Scene.prototype.onDoubleClick = function(_event) { |
| 20 | 1431 |
var _off = this.canvas_$.offset(), |
| 4 | 1432 |
_point = new paper.Point([ |
1433 |
_event.pageX - _off.left, |
|
1434 |
_event.pageY - _off.top |
|
1435 |
]); |
|
1436 |
var _hitResult = paper.project.hitTest(_point); |
|
| 23 | 1437 |
if (!_hitResult || typeof _hitResult.item.__representation === "undefined") { |
| 8 | 1438 |
var _coords = this.toModelCoords(_point), |
| 23 | 1439 |
_data = { |
1440 |
id: Rkns.Utils.getUID('node'), |
|
1441 |
created_by: this.renkan.current_user, |
|
| 8 | 1442 |
position: { |
1443 |
x: _coords.x, |
|
1444 |
y: _coords.y |
|
1445 |
} |
|
| 23 | 1446 |
}; |
1447 |
_node = this.renkan.project.addNode(_data); |
|
1448 |
this.getRepresentationByModel(_node).openEditor(); |
|
| 4 | 1449 |
} |
1450 |
paper.view.draw(); |
|
1451 |
} |
|
| 21 | 1452 |
|
1453 |
Rkns.Renderer.Scene.prototype.onMouseEnter = function(_event) { |
|
1454 |
var _newEl = this.renkan.selected_bin_item; |
|
1455 |
if (_newEl) { |
|
1456 |
var _off = this.canvas_$.offset(), |
|
1457 |
_point = new paper.Point([ |
|
1458 |
_event.pageX - _off.left, |
|
1459 |
_event.pageY - _off.top |
|
1460 |
]), |
|
1461 |
_coords = this.toModelCoords(_point), |
|
| 23 | 1462 |
_data = { |
1463 |
id: Rkns.Utils.getUID('node'), |
|
1464 |
created_by: this.renkan.current_user, |
|
| 21 | 1465 |
uri: _newEl.uri, |
1466 |
title: _newEl.title, |
|
1467 |
description: _newEl.description, |
|
| 37 | 1468 |
image: _newEl.image, |
| 21 | 1469 |
position: { |
1470 |
x: _coords.x, |
|
1471 |
y: _coords.y |
|
1472 |
} |
|
| 23 | 1473 |
}; |
1474 |
var _node = this.renkan.project.addNode(_data); |
|
1475 |
this.renkan.selected_bin_item = null; |
|
| 21 | 1476 |
this.is_dragging = true; |
| 23 | 1477 |
this.click_target = this.getRepresentationByModel(_node); |
| 21 | 1478 |
} |
1479 |
} |