| author | veltr |
| Thu, 28 Feb 2013 19:13:08 +0100 | |
| changeset 69 | f0873867143a |
| parent 68 | 803dbeb7c919 |
| child 70 | 47b3125130a2 |
| permissions | -rw-r--r-- |
| 28 | 1 |
Rkns.Renderer = { |
| 69 | 2 |
_MINIMAP_MARGIN_X: 20, |
3 |
_MINIMAP_MARGIN_Y: 20, |
|
| 28 | 4 |
_MIN_DRAG_DISTANCE: 2, |
| 67 | 5 |
_NODE_SIZE_BASE: 25, |
6 |
_NODE_BUTTON_WIDTH: 40, |
|
7 |
_EDGE_BUTTON_INNER: 2, |
|
| 31 | 8 |
_EDGE_BUTTON_OUTER: 40, |
| 28 | 9 |
_NODE_FONT_SIZE: 10, |
10 |
_EDGE_FONT_SIZE: 9, |
|
11 |
_NODE_MAX_CHAR: 50, |
|
12 |
_EDGE_MAX_CHAR: 40, |
|
13 |
_ARROW_LENGTH: 16, |
|
14 |
_ARROW_WIDTH: 8, |
|
| 5 | 15 |
_EDITOR_ARROW_LENGTH : 20, |
16 |
_EDITOR_ARROW_WIDTH : 40, |
|
17 |
_EDITOR_MARGIN : 15, |
|
18 |
_EDITOR_PADDING : 10, |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
19 |
_EDITOR_GRADIENT : new paper.Gradient(['#f0f0f0', '#d0d0d0']), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
20 |
_CLICKMODE_ADDNODE : 1, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
21 |
_CLICKMODE_STARTEDGE : 2, |
| 53 | 22 |
_CLICKMODE_ENDEDGE : 3, |
| 66 | 23 |
_IMAGE_MAX_KB : 500, |
| 67 | 24 |
_NODE_SIZE_STEP: Math.LN2/4, |
| 69 | 25 |
_MINIMAP_WIDTH: 160, |
26 |
_MINIMAP_HEIGHT: 120, |
|
| 53 | 27 |
_USER_PLACEHOLDER : { |
28 |
color: "#000000", |
|
29 |
title: "(unknown user)", |
|
30 |
get: function(attr) { |
|
31 |
return this[attr] || false; |
|
32 |
} |
|
33 |
} |
|
| 28 | 34 |
} |
35 |
||
36 |
Rkns.Renderer.Utils = { |
|
37 |
drawEditBox : function(_coords, _path, _width, _xmargin, _selector) { |
|
38 |
_selector.css({ |
|
39 |
width: (_width - 2* Rkns.Renderer._EDITOR_PADDING), |
|
40 |
}) |
|
41 |
var _height = _selector.outerHeight() + 2* Rkns.Renderer._EDITOR_PADDING, |
|
42 |
_isLeft = (_coords.x < paper.view.center.x ? 1 : -1), |
|
43 |
_left = _coords.x + _isLeft * ( _xmargin + Rkns.Renderer._EDITOR_ARROW_LENGTH ), |
|
44 |
_right = _coords.x + _isLeft * ( _xmargin + Rkns.Renderer._EDITOR_ARROW_LENGTH + _width ), |
|
| 5 | 45 |
_top = _coords.y - _height / 2; |
| 28 | 46 |
if (_top < Rkns.Renderer._EDITOR_MARGIN) { |
47 |
_top = Math.min( Rkns.Renderer._EDITOR_MARGIN, _coords.y - Rkns.Renderer._EDITOR_ARROW_WIDTH / 2 ); |
|
| 5 | 48 |
} |
49 |
var _bottom = _top + _height; |
|
| 28 | 50 |
if (_bottom > (paper.view.size.height - Rkns.Renderer._EDITOR_MARGIN)) { |
51 |
_bottom = Math.max( paper.view.size.height - Rkns.Renderer._EDITOR_MARGIN, _coords.y + Rkns.Renderer._EDITOR_ARROW_WIDTH / 2 ); |
|
| 5 | 52 |
_top = _bottom - _height; |
53 |
} |
|
54 |
_path.segments[0].point |
|
55 |
= _path.segments[7].point |
|
| 28 | 56 |
= _coords.add([_isLeft * _xmargin, 0]); |
| 5 | 57 |
_path.segments[1].point.x |
58 |
= _path.segments[2].point.x |
|
59 |
= _path.segments[5].point.x |
|
60 |
= _path.segments[6].point.x |
|
61 |
= _left; |
|
62 |
_path.segments[3].point.x |
|
63 |
= _path.segments[4].point.x |
|
64 |
= _right; |
|
65 |
_path.segments[2].point.y |
|
66 |
= _path.segments[3].point.y |
|
67 |
= _top; |
|
68 |
_path.segments[4].point.y |
|
69 |
= _path.segments[5].point.y |
|
70 |
= _bottom; |
|
| 28 | 71 |
_path.segments[1].point.y = _coords.y - Rkns.Renderer._EDITOR_ARROW_WIDTH / 2; |
72 |
_path.segments[6].point.y = _coords.y + Rkns.Renderer._EDITOR_ARROW_WIDTH / 2; |
|
73 |
_path.closed = true; |
|
74 |
_path.fillColor = new paper.GradientColor(Rkns.Renderer._EDITOR_GRADIENT, [0,_top], [0, _bottom]); |
|
75 |
_selector.css({ |
|
76 |
left: (Rkns.Renderer._EDITOR_PADDING + Math.min(_left, _right)), |
|
77 |
top: (Rkns.Renderer._EDITOR_PADDING + _top) |
|
78 |
}); |
|
| 7 | 79 |
}, |
| 38 | 80 |
sector : function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgsrc, _caption) { |
| 7 | 81 |
var _startRads = _startAngle * Math.PI / 180, |
82 |
_endRads = _endAngle * Math.PI / 180, |
|
83 |
_img = new Image(), |
|
84 |
_span = _endRads - _startRads, |
|
85 |
_k = .0879 * _span, |
|
86 |
_kin = _k * _inR, |
|
87 |
_kout = _k * _outR, |
|
88 |
_startdx = - Math.sin(_startRads), |
|
89 |
_startdy = Math.cos(_startRads), |
|
90 |
_startXIn = Math.cos(_startRads) * _inR + _padding * _startdx, |
|
91 |
_startYIn = Math.sin(_startRads) * _inR + _padding * _startdy, |
|
92 |
_startXOut = Math.cos(_startRads) * _outR + _padding * _startdx, |
|
93 |
_startYOut = Math.sin(_startRads) * _outR + _padding * _startdy, |
|
94 |
_enddx = - Math.sin(_endRads), |
|
95 |
_enddy = Math.cos(_endRads), |
|
96 |
_endXIn = Math.cos(_endRads) * _inR - _padding * _enddx, |
|
97 |
_endYIn = Math.sin(_endRads) * _inR - _padding * _enddy, |
|
98 |
_endXOut = Math.cos(_endRads) * _outR - _padding * _enddx, |
|
99 |
_endYOut = Math.sin(_endRads) * _outR - _padding * _enddy, |
|
100 |
_centerR = (_inR + _outR)/2, |
|
101 |
_centerRads = (_startRads + _endRads) / 2, |
|
102 |
_centerX = Math.cos(_centerRads) * _centerR, |
|
103 |
_centerY = Math.sin(_centerRads) * _centerR, |
|
| 67 | 104 |
_centerXIn = Math.cos(_centerRads) * _inR, |
105 |
_centerXOut = Math.cos(_centerRads) * _outR, |
|
106 |
_centerYIn = Math.sin(_centerRads) * _inR, |
|
107 |
_centerYOut = Math.sin(_centerRads) * _outR, |
|
| 38 | 108 |
_textX = Math.cos(_centerRads) * (_outR + 3), |
109 |
_textY = Math.sin(_centerRads) * (_outR + 3), |
|
| 7 | 110 |
_segments = []; |
| 69 | 111 |
_repr.renderer.buttons_layer.activate(); |
| 18 | 112 |
var _path = new paper.Path(); |
| 67 | 113 |
_path.add([_startXIn, _startYIn]); |
114 |
_path.arcTo([_centerXIn, _centerYIn], [_endXIn, _endYIn]); |
|
115 |
_path.lineTo([_endXOut, _endYOut]); |
|
116 |
_path.arcTo([_centerXOut, _centerYOut], [_startXOut, _startYOut]); |
|
| 7 | 117 |
_path.fillColor = "#333333"; |
| 15 | 118 |
_path.opacity = .5; |
| 7 | 119 |
_path.closed = true; |
| 23 | 120 |
_path.__representation = _repr; |
| 38 | 121 |
if (_textX >= -2 && _textX <= 2) { |
122 |
if (_textY > 0) { |
|
123 |
_textY += 6; |
|
124 |
} |
|
125 |
} |
|
126 |
var _text = new paper.PointText(_textX,_textY); |
|
127 |
_text.characterStyle = { |
|
128 |
fontSize: 9, |
|
129 |
fillColor: '#c000c0' |
|
130 |
}; |
|
131 |
if (_textX > 2) { |
|
132 |
_text.paragraphStyle.justification = 'left'; |
|
133 |
} else if (_textX < -2) { |
|
134 |
_text.paragraphStyle.justification = 'right'; |
|
135 |
} else { |
|
136 |
_text.paragraphStyle.justification = 'center'; |
|
137 |
} |
|
138 |
_text.visible = false; |
|
| 18 | 139 |
var _visible = false, |
140 |
_restPos = new paper.Point(-200, -200), |
|
| 38 | 141 |
_grp = new paper.Group([_path, _text]), |
| 18 | 142 |
_delta = _grp.position, |
143 |
_imgdelta = new paper.Point([_centerX, _centerY]), |
|
144 |
_currentPos = new paper.Point(0,0); |
|
| 38 | 145 |
_text.content = _caption; |
| 18 | 146 |
_grp.visible = false; |
147 |
_grp.position = _restPos; |
|
148 |
var _res = { |
|
149 |
show: function() { |
|
150 |
_visible = true; |
|
151 |
_grp.position = _currentPos.add(_delta); |
|
152 |
_grp.visible = true; |
|
153 |
}, |
|
154 |
moveTo: function(_point) { |
|
155 |
_currentPos = _point; |
|
156 |
if (_visible) { |
|
157 |
_grp.position = _point.add(_delta); |
|
158 |
} |
|
159 |
}, |
|
160 |
hide: function() { |
|
161 |
_visible = false; |
|
162 |
_grp.visible = false; |
|
163 |
_grp.position = _restPos; |
|
164 |
}, |
|
165 |
select: function() { |
|
166 |
_path.opacity = .8; |
|
| 38 | 167 |
_text.visible = true; |
| 18 | 168 |
}, |
169 |
unselect: function() { |
|
170 |
_path.opacity = .5; |
|
| 38 | 171 |
_text.visible = false; |
| 18 | 172 |
}, |
173 |
destroy: function() { |
|
174 |
_grp.remove(); |
|
| 7 | 175 |
} |
| 18 | 176 |
} |
| 7 | 177 |
_img.onload = function() { |
| 38 | 178 |
var _h = _img.height; |
| 7 | 179 |
var _raster = new paper.Raster(_img); |
| 18 | 180 |
_raster.position = _imgdelta.add(_grp.position).subtract(_delta); |
| 7 | 181 |
_grp.addChild(_raster); |
182 |
} |
|
183 |
_img.src = _imgsrc; |
|
184 |
return _res |
|
| 5 | 185 |
} |
186 |
} |
|
187 |
||
| 23 | 188 |
Rkns.Renderer._BaseRepresentation = function(_renderer, _model) { |
| 1 | 189 |
if (typeof _renderer !== "undefined") { |
| 23 | 190 |
this.renderer = _renderer; |
191 |
this.project = _renderer.renkan.project; |
|
192 |
this.model = _model; |
|
| 39 | 193 |
if (this.model) { |
194 |
var _this = this; |
|
195 |
this._changeBinding = function() { |
|
196 |
_this.redraw(); |
|
197 |
} |
|
198 |
this._removeBinding = function() { |
|
199 |
_renderer.removeRepresentation(_this); |
|
200 |
_renderer.redraw(); |
|
201 |
} |
|
202 |
this.model.on("change", this._changeBinding ); |
|
203 |
this.model.on("remove", this._removeBinding ); |
|
204 |
} |
|
| 1 | 205 |
} |
206 |
} |
|
207 |
||
| 39 | 208 |
Rkns.Renderer._BaseRepresentation.prototype.super = function(_func) { |
209 |
Rkns.Renderer._BaseRepresentation.prototype[_func].apply(this, Array.prototype.slice.call(arguments, 1)); |
|
210 |
} |
|
211 |
||
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
212 |
Rkns.Renderer._BaseRepresentation.prototype.moveTo = function() {} |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
213 |
|
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
214 |
Rkns.Renderer._BaseRepresentation.prototype.show = function() {} |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
215 |
|
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
216 |
Rkns.Renderer._BaseRepresentation.prototype.hide = function() {} |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
217 |
|
| 23 | 218 |
Rkns.Renderer._BaseRepresentation.prototype.select = function() {} |
| 4 | 219 |
|
| 23 | 220 |
Rkns.Renderer._BaseRepresentation.prototype.unselect = function() {} |
| 7 | 221 |
|
| 26 | 222 |
Rkns.Renderer._BaseRepresentation.prototype.highlight = function() {} |
223 |
||
224 |
Rkns.Renderer._BaseRepresentation.prototype.unhighlight = function() {} |
|
225 |
||
| 23 | 226 |
Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() {} |
| 4 | 227 |
|
| 39 | 228 |
Rkns.Renderer._BaseRepresentation.prototype.destroy = function() { |
229 |
if (this.model) { |
|
230 |
this.model.off("change", this._changeBinding ); |
|
231 |
this.model.off("remove", this._removeBinding ); |
|
232 |
} |
|
233 |
} |
|
| 5 | 234 |
|
| 57 | 235 |
Rkns.Renderer._BaseRepresentation.prototype.resetCoords = function() { |
236 |
this.paper_coords = undefined; |
|
237 |
} |
|
238 |
||
| 23 | 239 |
Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 1 | 240 |
|
| 7 | 241 |
Rkns.Renderer.Node.prototype._init = function() { |
| 23 | 242 |
this.renderer.node_layer.activate(); |
| 20 | 243 |
this.type = "Node"; |
| 67 | 244 |
this.circle = new paper.Path.Circle([0, 0], 1); |
| 7 | 245 |
this.circle.fillColor = '#ffffff'; |
| 23 | 246 |
this.circle.__representation = this; |
| 52 | 247 |
this.circle.strokeWidth = 2; |
| 7 | 248 |
this.title = new paper.PointText([0,0]); |
249 |
this.title.characterStyle = { |
|
| 28 | 250 |
fontSize: Rkns.Renderer._NODE_FONT_SIZE, |
| 2 | 251 |
fillColor: 'black' |
252 |
}; |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
253 |
if (this.renderer.renkan.read_only) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
254 |
this.edit_button = new Rkns.Renderer._BaseRepresentation(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
255 |
this.remove_button = new Rkns.Renderer._BaseRepresentation(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
256 |
this.link_button = new Rkns.Renderer._BaseRepresentation(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
257 |
} else { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
258 |
this.edit_button = new Rkns.Renderer.NodeEditButton(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
259 |
this.edit_button.node_representation = this; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
260 |
this.remove_button = new Rkns.Renderer.NodeRemoveButton(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
261 |
this.remove_button.node_representation = this; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
262 |
this.link_button = new Rkns.Renderer.NodeLinkButton(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
263 |
this.link_button.node_representation = this; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
264 |
} |
| 67 | 265 |
this.last_circle_radius = 1; |
| 7 | 266 |
this.title.paragraphStyle.justification = 'center'; |
| 69 | 267 |
|
268 |
this.renderer.minimap.node_layer.activate(); |
|
269 |
this.minimap_circle = new paper.Path.Circle([0, 0], 1); |
|
270 |
this.renderer.minimap.node_group.addChild(this.minimap_circle); |
|
| 1 | 271 |
} |
272 |
||
| 7 | 273 |
Rkns.Renderer.Node.prototype.redraw = function() { |
| 69 | 274 |
var _model_coords = new paper.Point(this.model.get("position")), |
275 |
_baseRadius = Rkns.Renderer._NODE_SIZE_BASE * Math.exp((this.model.get("size") || 0) * Rkns.Renderer._NODE_SIZE_STEP); |
|
| 57 | 276 |
if (!this.paper_coords) { |
277 |
this.paper_coords = this.renderer.toPaperCoords(_model_coords); |
|
278 |
} |
|
| 69 | 279 |
this.circle_radius = _baseRadius * this.renderer.scale; |
| 67 | 280 |
if (this.last_circle_radius !== this.circle_radius) { |
281 |
if (!this.renderer.renkan.read_only) { |
|
282 |
this.edit_button.setSectorSize(); |
|
283 |
this.remove_button.setSectorSize(); |
|
284 |
this.link_button.setSectorSize(); |
|
285 |
} |
|
286 |
var square = new paper.Size(this.circle_radius, this.circle_radius), |
|
287 |
topleft = this.paper_coords.subtract(square), |
|
288 |
bounds = new paper.Rectangle(topleft, square.multiply(2)); |
|
289 |
this.circle.fitBounds(bounds); |
|
290 |
if (this.node_image) { |
|
291 |
this.node_image.fitBounds(bounds); |
|
292 |
} |
|
293 |
} else { |
|
294 |
this.circle.position = this.paper_coords; |
|
295 |
if (this.node_image) { |
|
296 |
this.node_image.position = this.paper_coords; |
|
297 |
} |
|
298 |
} |
|
| 68 | 299 |
this.last_circle_radius = this.circle_radius; |
| 67 | 300 |
|
| 68 | 301 |
this.title.content = this.model.get("title") || this.renderer.renkan.translate("(untitled)"); |
| 67 | 302 |
this.title.position = this.paper_coords.add([0, this.circle_radius + 1.5 *Rkns.Renderer._NODE_FONT_SIZE]); |
| 69 | 303 |
var _color = this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"); |
304 |
this.circle.strokeColor = _color; |
|
| 7 | 305 |
this.edit_button.moveTo(this.paper_coords); |
306 |
this.remove_button.moveTo(this.paper_coords); |
|
| 11 | 307 |
this.link_button.moveTo(this.paper_coords); |
| 37 | 308 |
var _img = this.model.get("image"); |
309 |
if (_img && _img !== this.img) { |
|
310 |
var _image = new Image(), |
|
311 |
_this = this; |
|
312 |
_image.onload = function() { |
|
313 |
if (_this.node_image) { |
|
314 |
_this.node_image.remove(); |
|
315 |
} |
|
316 |
_this.renderer.node_layer.activate(); |
|
| 68 | 317 |
var _ratio = Math.min(2 / _image.width, 2 / _image.height ); |
| 37 | 318 |
var _raster = new paper.Raster(_image); |
| 68 | 319 |
var _clip = new paper.Path.Circle([0, 0], 1); |
| 37 | 320 |
_raster.scale(_ratio); |
321 |
_this.node_image = new paper.Group(_clip, _raster); |
|
322 |
_this.node_image.opacity = .9; |
|
| 38 | 323 |
/* This is a workaround to allow clipping at group level |
324 |
* If opacity was set to 1, paper.js would merge all clipping groups in one (known bug). |
|
325 |
*/ |
|
| 37 | 326 |
_this.node_image.clipped = true; |
327 |
_this.node_image.__representation = _this; |
|
| 68 | 328 |
var square = new paper.Size(_this.circle_radius, _this.circle_radius), |
329 |
topleft = _this.paper_coords.subtract(square), |
|
330 |
bounds = new paper.Rectangle(topleft, square.multiply(2)); |
|
331 |
_this.node_image.fitBounds(bounds); |
|
| 38 | 332 |
_clip.__representation = _this; |
| 37 | 333 |
paper.view.draw(); |
334 |
} |
|
335 |
_image.src = _img; |
|
336 |
} |
|
337 |
this.img = _img; |
|
| 67 | 338 |
if (this.node_image && !this.img) { |
339 |
this.node_image.remove(); |
|
340 |
delete this.node_image; |
|
| 37 | 341 |
} |
| 69 | 342 |
|
343 |
this.minimap_circle.fillColor = _color; |
|
344 |
var minipos = this.renderer.toMinimapCoords(_model_coords), |
|
345 |
miniradius = this.renderer.minimap.scale * _baseRadius, |
|
346 |
minisize = new paper.Size([miniradius, miniradius]); |
|
347 |
this.minimap_circle.fitBounds(minipos.subtract(minisize), minisize.multiply(2)); |
|
| 56 | 348 |
|
349 |
Rkns._.each(this.project.get("edges").filter(function (ed) { return ((ed.to === this.model) || (ed.from === this.model));}), function(edge, index, list){ |
|
350 |
var repr = this.renderer.getRepresentationByModel(edge); |
|
351 |
if(repr != null && typeof repr.from_representation.paper_coords !== "undefined" && typeof repr.to_representation.paper_coords !== "undefined") { |
|
352 |
repr.redraw(); |
|
353 |
} |
|
354 |
}, this); |
|
| 1 | 355 |
} |
356 |
||
| 7 | 357 |
Rkns.Renderer.Node.prototype.paperShift = function(_delta) { |
| 57 | 358 |
this.paper_coords = this.paper_coords.add(_delta); |
359 |
this.redraw(); |
|
| 2 | 360 |
} |
361 |
||
| 8 | 362 |
Rkns.Renderer.Node.prototype.openEditor = function() { |
| 23 | 363 |
this.renderer.removeRepresentationsOfType("editor"); |
364 |
var _editor = this.renderer.addRepresentation("NodeEditor",null); |
|
365 |
_editor.node_representation = this; |
|
| 37 | 366 |
_editor.draw(); |
| 8 | 367 |
} |
368 |
||
| 7 | 369 |
Rkns.Renderer.Node.prototype.select = function() { |
| 52 | 370 |
this.circle.strokeWidth = 4; |
| 7 | 371 |
this.edit_button.show(); |
372 |
this.remove_button.show(); |
|
| 11 | 373 |
this.link_button.show(); |
| 26 | 374 |
var _uri = this.model.get("uri"); |
375 |
Rkns.$('.Rk-Bin-Item').each(function() { |
|
376 |
var _el = Rkns.$(this); |
|
377 |
if (_el.attr("data-uri") == _uri) { |
|
378 |
_el.addClass("selected"); |
|
379 |
} |
|
380 |
}); |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
381 |
if (this.renderer.renkan.read_only) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
382 |
this.openEditor(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
383 |
} |
| 69 | 384 |
this.minimap_circle.fillColor = "#ff00fc"; |
| 7 | 385 |
} |
386 |
||
387 |
Rkns.Renderer.Node.prototype.unselect = function(_newTarget) { |
|
| 35 | 388 |
if (!_newTarget || _newTarget.node_representation !== this) { |
| 7 | 389 |
this.edit_button.hide(); |
390 |
this.remove_button.hide(); |
|
| 11 | 391 |
this.link_button.hide(); |
| 52 | 392 |
this.circle.strokeWidth = 2; |
| 35 | 393 |
Rkns.$('.Rk-Bin-Item').removeClass("selected"); |
| 69 | 394 |
this.minimap_circle.fillColor = this.circle.strokeColor; |
| 7 | 395 |
} |
| 26 | 396 |
} |
397 |
||
398 |
Rkns.Renderer.Node.prototype.highlight = function() { |
|
| 37 | 399 |
this.circle.fillColor = "#ffff80"; |
400 |
if (this.node_image) { |
|
401 |
this.node_image.opacity = .5; |
|
402 |
} |
|
| 26 | 403 |
} |
404 |
||
405 |
Rkns.Renderer.Node.prototype.unhighlight = function(_newTarget) { |
|
406 |
this.circle.fillColor = "#ffffff"; |
|
| 37 | 407 |
if (this.node_image) { |
408 |
this.node_image.opacity = .9; |
|
409 |
} |
|
| 4 | 410 |
} |
411 |
||
| 57 | 412 |
Rkns.Renderer.Node.prototype.saveCoords = function() { |
413 |
var _coords = this.renderer.toModelCoords(this.paper_coords), |
|
414 |
_data = { |
|
415 |
position: { |
|
416 |
x: _coords.x, |
|
417 |
y: _coords.y |
|
418 |
} |
|
419 |
}; |
|
420 |
this.model.set(_data); |
|
421 |
} |
|
422 |
||
| 7 | 423 |
Rkns.Renderer.Node.prototype.mouseup = function(_event) { |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
424 |
if (!this.renderer.renkan.read_only) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
425 |
if (this.renderer.is_dragging) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
426 |
this.saveCoords(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
427 |
} |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
428 |
else { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
429 |
this.openEditor(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
430 |
} |
| 7 | 431 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
432 |
this.renderer.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
433 |
this.renderer.is_dragging = false; |
| 7 | 434 |
} |
435 |
||
436 |
Rkns.Renderer.Node.prototype.destroy = function(_event) { |
|
| 39 | 437 |
this.super("destroy"); |
| 7 | 438 |
this.edit_button.destroy(); |
439 |
this.remove_button.destroy(); |
|
| 26 | 440 |
this.link_button.destroy(); |
| 7 | 441 |
this.circle.remove(); |
442 |
this.title.remove(); |
|
| 69 | 443 |
this.minimap_circle.remove(); |
| 37 | 444 |
if (this.node_image) { |
445 |
this.node_image.remove(); |
|
446 |
} |
|
| 4 | 447 |
} |
448 |
||
| 2 | 449 |
/* */ |
450 |
||
| 23 | 451 |
Rkns.Renderer.Edge = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 2 | 452 |
|
| 7 | 453 |
Rkns.Renderer.Edge.prototype._init = function() { |
| 23 | 454 |
this.renderer.edge_layer.activate(); |
| 20 | 455 |
this.type = "Edge"; |
| 23 | 456 |
this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from")); |
457 |
this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to")); |
|
| 31 | 458 |
this.bundle = this.renderer.addToBundles(this); |
| 7 | 459 |
this.line = new paper.Path(); |
| 31 | 460 |
this.line.add([0,0],[0,0],[0,0]); |
| 23 | 461 |
this.line.__representation = this; |
| 52 | 462 |
this.line.strokeWidth = 2; |
| 7 | 463 |
this.arrow = new paper.Path(); |
| 28 | 464 |
this.arrow.add([0,0],[Rkns.Renderer._ARROW_LENGTH,Rkns.Renderer._ARROW_WIDTH / 2],[0,Rkns.Renderer._ARROW_WIDTH]); |
| 23 | 465 |
this.arrow.__representation = this; |
| 7 | 466 |
this.text = new paper.PointText(); |
467 |
this.text.characterStyle = { |
|
| 28 | 468 |
fontSize: Rkns.Renderer._EDGE_FONT_SIZE, |
| 2 | 469 |
fillColor: 'black' |
470 |
}; |
|
| 7 | 471 |
this.text.paragraphStyle.justification = 'center'; |
472 |
this.text_angle = 0; |
|
473 |
this.arrow_angle = 0; |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
474 |
if (this.renderer.renkan.read_only) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
475 |
this.edit_button = new Rkns.Renderer._BaseRepresentation(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
476 |
this.remove_button = new Rkns.Renderer._BaseRepresentation(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
477 |
} else { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
478 |
this.edit_button = new Rkns.Renderer.EdgeEditButton(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
479 |
this.edit_button.edge_representation = this; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
480 |
this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
481 |
this.remove_button.edge_representation = this; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
482 |
} |
| 2 | 483 |
} |
484 |
||
| 7 | 485 |
Rkns.Renderer.Edge.prototype.redraw = function() { |
| 31 | 486 |
var _p0a = this.from_representation.paper_coords, |
487 |
_p1a = this.to_representation.paper_coords, |
|
488 |
_v = _p1a.subtract(_p0a), |
|
| 15 | 489 |
_r = _v.length, |
| 18 | 490 |
_u = _v.divide(_r), |
| 31 | 491 |
_group_pos = this.bundle.getPosition(this), |
492 |
_delta = new paper.Point([- _u.y, _u.x]).multiply( 12 * _group_pos ), |
|
493 |
_p0b = _p0a.add(_delta), /* Adding a 4 px difference */ |
|
494 |
_p1b = _p1a.add(_delta), /* to differentiate inbound and outbound links */ |
|
| 15 | 495 |
_a = _v.angle, |
| 31 | 496 |
_handle = _v.divide(3), |
| 56 | 497 |
_color = this.model.get("color") || this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"); |
| 31 | 498 |
this.paper_coords = _p0b.add(_p1b).divide(2); |
| 7 | 499 |
this.line.strokeColor = _color; |
| 31 | 500 |
this.line.segments[0].point = _p0a; |
501 |
this.line.segments[1].point = this.paper_coords; |
|
502 |
this.line.segments[1].handleIn = _handle.multiply(-1); |
|
503 |
this.line.segments[1].handleOut = _handle; |
|
504 |
this.line.segments[2].point = _p1a; |
|
| 7 | 505 |
this.arrow.rotate(_a - this.arrow_angle); |
506 |
this.arrow.fillColor = _color; |
|
| 18 | 507 |
this.arrow.position = this.paper_coords.subtract(_u.multiply(4)); |
| 7 | 508 |
this.arrow_angle = _a; |
| 2 | 509 |
if (_a > 90) { |
510 |
_a -= 180; |
|
511 |
} |
|
512 |
if (_a < -90) { |
|
513 |
_a += 180; |
|
514 |
} |
|
| 7 | 515 |
this.text.rotate(_a - this.text_angle); |
| 23 | 516 |
this.text.content = this.model.get("title"); |
| 15 | 517 |
this.text.position = this.paper_coords; |
| 7 | 518 |
this.text_angle = _a; |
| 15 | 519 |
this.edit_button.moveTo(this.paper_coords); |
520 |
this.remove_button.moveTo(this.paper_coords); |
|
| 7 | 521 |
} |
522 |
||
| 18 | 523 |
Rkns.Renderer.Edge.prototype.openEditor = function() { |
| 23 | 524 |
this.renderer.removeRepresentationsOfType("editor"); |
525 |
var _editor = this.renderer.addRepresentation("EdgeEditor",null); |
|
526 |
_editor.edge_representation = this; |
|
| 37 | 527 |
_editor.draw(); |
| 18 | 528 |
} |
529 |
||
| 7 | 530 |
Rkns.Renderer.Edge.prototype.select = function() { |
| 52 | 531 |
this.line.strokeWidth = 4; |
| 15 | 532 |
this.edit_button.show(); |
533 |
this.remove_button.show(); |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
534 |
if (this.renderer.renkan.read_only) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
535 |
this.openEditor(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
536 |
} |
| 7 | 537 |
} |
538 |
||
539 |
Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) { |
|
| 35 | 540 |
if (!_newTarget || _newTarget.edge_representation !== this) { |
| 15 | 541 |
this.edit_button.hide(); |
542 |
this.remove_button.hide(); |
|
| 52 | 543 |
this.line.strokeWidth = 2; |
| 15 | 544 |
} |
| 4 | 545 |
} |
546 |
||
| 7 | 547 |
Rkns.Renderer.Edge.prototype.mouseup = function(_event) { |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
548 |
if (!this.renderer.renkan.read_only) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
549 |
if (this.renderer.is_dragging) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
550 |
this.from_representation.saveCoords(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
551 |
this.to_representation.saveCoords(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
552 |
} else { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
553 |
this.openEditor(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
554 |
} |
| 7 | 555 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
556 |
this.renderer.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
557 |
this.renderer.is_dragging = false; |
| 4 | 558 |
} |
559 |
||
| 7 | 560 |
Rkns.Renderer.Edge.prototype.paperShift = function(_delta) { |
| 23 | 561 |
this.from_representation.paperShift(_delta); |
562 |
this.to_representation.paperShift(_delta); |
|
| 2 | 563 |
} |
564 |
||
| 7 | 565 |
Rkns.Renderer.Edge.prototype.destroy = function() { |
| 39 | 566 |
this.super("destroy"); |
| 7 | 567 |
this.line.remove(); |
568 |
this.arrow.remove(); |
|
569 |
this.text.remove(); |
|
| 15 | 570 |
this.edit_button.destroy(); |
571 |
this.remove_button.destroy(); |
|
| 31 | 572 |
var _this = this; |
573 |
this.bundle.edges = Rkns._(this.bundle.edges).reject(function(_edge) { |
|
574 |
return _edge === _this; |
|
575 |
}); |
|
| 2 | 576 |
} |
| 5 | 577 |
|
| 4 | 578 |
/* */ |
579 |
||
| 23 | 580 |
Rkns.Renderer.TempEdge = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 4 | 581 |
|
| 7 | 582 |
Rkns.Renderer.TempEdge.prototype._init = function() { |
| 23 | 583 |
this.renderer.edge_layer.activate(); |
| 4 | 584 |
this.type = "temp-edge"; |
| 23 | 585 |
|
| 64 | 586 |
var _color = (this.project.get("users").get(this.renderer.renkan.current_user) || Rkns.Renderer._USER_PLACEHOLDER).get("color"); |
| 7 | 587 |
this.line = new paper.Path(); |
588 |
this.line.strokeColor = _color; |
|
589 |
this.line.add([0,0],[0,0]); |
|
| 23 | 590 |
this.line.__representation = this; |
| 7 | 591 |
this.arrow = new paper.Path(); |
592 |
this.arrow.fillColor = _color; |
|
| 28 | 593 |
this.arrow.add([0,0],[Rkns.Renderer._ARROW_LENGTH,Rkns.Renderer._ARROW_WIDTH / 2],[0,Rkns.Renderer._ARROW_WIDTH]); |
| 23 | 594 |
this.arrow.__representation = this; |
| 7 | 595 |
this.arrow_angle = 0; |
| 4 | 596 |
} |
597 |
||
| 7 | 598 |
Rkns.Renderer.TempEdge.prototype.redraw = function() { |
| 23 | 599 |
var _p0 = this.from_representation.paper_coords, |
| 4 | 600 |
_p1 = this.end_pos, |
601 |
_a = _p1.subtract(_p0).angle, |
|
602 |
_c = _p0.add(_p1).divide(2); |
|
| 7 | 603 |
this.line.segments[0].point = _p0; |
604 |
this.line.segments[1].point = _p1; |
|
605 |
this.arrow.rotate(_a - this.arrow_angle); |
|
606 |
this.arrow.position = _c; |
|
607 |
this.arrow_angle = _a; |
|
| 4 | 608 |
} |
609 |
||
| 7 | 610 |
Rkns.Renderer.TempEdge.prototype.paperShift = function(_delta) { |
| 4 | 611 |
this.end_pos = this.end_pos.add(_delta); |
| 21 | 612 |
var _hitResult = paper.project.hitTest(this.end_pos); |
| 23 | 613 |
this.renderer.findTarget(_hitResult); |
| 4 | 614 |
this.redraw(); |
615 |
} |
|
616 |
||
| 7 | 617 |
Rkns.Renderer.TempEdge.prototype.mouseup = function(_event) { |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
618 |
var _hitResult = paper.project.hitTest(_event.point), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
619 |
_model = this.from_representation.model, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
620 |
_endDrag = true; |
| 23 | 621 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
622 |
var _target = _hitResult.item.__representation; |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
623 |
if (_target.type === "Node" && _model !== _target.model) { |
| 23 | 624 |
var _data = { |
625 |
id: Rkns.Utils.getUID('edge'), |
|
626 |
created_by: this.renderer.renkan.current_user, |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
627 |
from: _model.get("_id"), |
| 30 | 628 |
to: _target.model.get("_id") |
| 23 | 629 |
}; |
630 |
this.project.addEdge(_data); |
|
| 4 | 631 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
632 |
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
|
633 |
_endDrag = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
634 |
this.renderer.is_dragging = true; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
635 |
} |
| 4 | 636 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
637 |
if (_endDrag) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
638 |
this.renderer.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
639 |
this.renderer.is_dragging = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
640 |
this.renderer.removeRepresentation(this); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
641 |
paper.view.draw(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
642 |
} |
| 5 | 643 |
} |
644 |
||
| 7 | 645 |
Rkns.Renderer.TempEdge.prototype.destroy = function() { |
646 |
this.arrow.remove(); |
|
647 |
this.line.remove(); |
|
| 5 | 648 |
} |
649 |
||
650 |
/* */ |
|
651 |
||
| 23 | 652 |
Rkns.Renderer.NodeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 5 | 653 |
|
| 7 | 654 |
Rkns.Renderer.NodeEditor.prototype._init = function() { |
| 67 | 655 |
this.renderer.buttons_layer.activate(); |
| 5 | 656 |
this.type = "editor"; |
657 |
this.editor_block = new paper.Path(); |
|
658 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
659 |
this.editor_block.add.apply(this.editor_block, _pts); |
|
660 |
this.editor_block.strokeWidth = 2; |
|
661 |
this.editor_block.strokeColor = "#999999"; |
|
662 |
this.editor_block.fillColor = "#e0e0e0"; |
|
663 |
this.editor_block.opacity = .8; |
|
664 |
this.editor_$ = Rkns.$('<div>') |
|
| 23 | 665 |
.appendTo(this.renderer.editor_$) |
| 5 | 666 |
.css({ |
667 |
position: "absolute", |
|
668 |
opacity: .8 |
|
669 |
}) |
|
670 |
.hide(); |
|
671 |
} |
|
672 |
||
| 7 | 673 |
Rkns.Renderer.NodeEditor.prototype.template = Rkns._.template( |
| 66 | 674 |
'<h2><span class="Rk-CloseX">×</span><%-translate("Edit Node")%></span></h2>' |
675 |
+ '<p><label><%-translate("Title:")%></label><input class="Rk-Edit-Title" type="text" value="<%=node.title%>"/></p>' |
|
676 |
+ '<p><label><%-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>' |
|
677 |
+ '<p><label><%-translate("Description:")%></label><textarea class="Rk-Edit-Description"><%=node.description%></textarea></p>' |
|
| 67 | 678 |
+ '<p><span class="Rk-Editor-Label"><%-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>' |
| 66 | 679 |
+ '<div class="Rk-Editor-p"><span class="Rk-Editor-Label"><%-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><ul class="Rk-Edit-ColorPicker">' |
| 68 | 680 |
+ '<% _(Rkns.pickerColors).each(function(c) { %><li data-color="<%=c%>" style="background: <%=c%>"></li><% }); %></ul><span class="Rk-Edit-ColorPicker-Text">Choose color</span></div></div>' |
| 66 | 681 |
+ '<img class="Rk-Edit-ImgPreview" src="<%=node.image || node.image_placeholder%>" />' |
682 |
+ '<p><label><%-translate("Image URL:")%></label><input class="Rk-Edit-Image" type="text" value="<%=node.image%>"/></p>' |
|
| 68 | 683 |
+ '<p><label><%-translate("Choose Image File:")%></label><input class="Rk-Edit-Image-File" type="file" accept="image/*"/></p>' |
| 66 | 684 |
+ '<p><span class="Rk-Editor-Label"><%-translate("Created by:")%></span> <span class="Rk-UserColor" style="background:<%=node.created_by_color%>;"></span><%=node.created_by_title%></p>' |
| 5 | 685 |
); |
686 |
||
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
687 |
Rkns.Renderer.NodeEditor.prototype.readOnlyTemplate = Rkns._.template( |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
688 |
'<h2><span class="Rk-CloseX">×</span><span class="Rk-UserColor" style="background:<%=node.color%>;"></span><%-node.title%></span></h2>' |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
689 |
+ '<p><a href="<%-node.uri%>" target="_blank"><%-node.uri%></a></p>' |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
690 |
+ '<p><%-node.description%></p>' |
| 67 | 691 |
+ '<p><span class="Rk-Editor-Label"><%-translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%=node.created_by_color%>;"></span><%=node.created_by_title%></p>' |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
692 |
); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
693 |
|
| 37 | 694 |
Rkns.Renderer.NodeEditor.prototype.draw = function() { |
| 53 | 695 |
var _model = this.node_representation.model, |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
696 |
_created_by = _model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER, |
| 67 | 697 |
_template = (this.renderer.renkan.read_only ? this.readOnlyTemplate : this.template), |
698 |
_image_placeholder = this.renderer.renkan.static_url + "img/image-placeholder.png", |
|
699 |
_size = (_model.get("size") || 0); |
|
| 5 | 700 |
this.editor_$ |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
701 |
.html(_template({ |
| 23 | 702 |
node: { |
703 |
title: _model.get("title"), |
|
704 |
uri: _model.get("uri"), |
|
705 |
description: _model.get("description"), |
|
| 37 | 706 |
image: _model.get("image") || "", |
| 67 | 707 |
image_placeholder: _image_placeholder, |
| 53 | 708 |
color: _model.get("color") || _created_by.get("color"), |
709 |
created_by_color: _created_by.get("color"), |
|
| 67 | 710 |
created_by_title: _created_by.get("title"), |
711 |
size: (_size > 0 ? "+" : "") + _size |
|
| 23 | 712 |
}, |
| 66 | 713 |
translate: this.renderer.renkan.translate |
| 37 | 714 |
})); |
715 |
this.redraw(); |
|
| 5 | 716 |
var _this = this; |
717 |
this.editor_$.find(".Rk-CloseX").click(function() { |
|
| 23 | 718 |
_this.renderer.removeRepresentation(_this); |
| 5 | 719 |
paper.view.draw(); |
720 |
}); |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
721 |
if (!this.renderer.renkan.read_only) { |
| 66 | 722 |
|
723 |
var onFieldChange = Rkns._(function() { |
|
724 |
Rkns._(function() { |
|
725 |
var _uri = _this.editor_$.find(".Rk-Edit-URI").val(), |
|
726 |
_image = _this.editor_$.find(".Rk-Edit-Image").val(); |
|
| 67 | 727 |
_this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _image || _image_placeholder); |
| 66 | 728 |
_this.editor_$.find(".Rk-Edit-Goto").attr("href",_uri); |
729 |
var _data = { |
|
730 |
title: _this.editor_$.find(".Rk-Edit-Title").val(), |
|
731 |
description: _this.editor_$.find(".Rk-Edit-Description").val(), |
|
732 |
uri: _uri, |
|
733 |
image: _image |
|
734 |
} |
|
735 |
_model.set(_data); |
|
736 |
_this.redraw(); |
|
737 |
}).defer(); |
|
738 |
}).throttle(500); |
|
739 |
|
|
740 |
this.editor_$.find("input, textarea").bind("change keyup paste", onFieldChange); |
|
741 |
|
|
742 |
this.editor_$.find(".Rk-Edit-Image-File").bind("change", function() { |
|
743 |
if (this.files.length) { |
|
744 |
var f = this.files[0], |
|
745 |
fr = new FileReader(); |
|
746 |
if (f.type.substr(0,5) !== "image") { |
|
747 |
alert(_this.renderer.renkan.translate("This file is not an image")); |
|
748 |
return; |
|
749 |
} |
|
750 |
if (f.size > (Rkns.Renderer._IMAGE_MAX_KB * 1024)) { |
|
751 |
alert(_this.renderer.renkan.translate("Image size must be under ")+Rkns.Renderer._IMAGE_MAX_KB+_this.renderer.renkan.translate("KB")); |
|
752 |
return; |
|
753 |
} |
|
754 |
fr.onload = function(e) { |
|
755 |
_this.editor_$.find(".Rk-Edit-Image").val(e.target.result); |
|
756 |
onFieldChange(); |
|
757 |
} |
|
758 |
fr.readAsDataURL(f); |
|
759 |
} |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
760 |
}); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
761 |
this.editor_$.find(".Rk-Edit-Title")[0].focus(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
762 |
this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
763 |
function() { _this.editor_$.find(".Rk-Edit-ColorPicker").show(); }, |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
764 |
function() { _this.editor_$.find(".Rk-Edit-ColorPicker").hide(); } |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
765 |
); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
766 |
this.editor_$.find(".Rk-Edit-ColorPicker li").hover( |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
767 |
function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); }, |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
768 |
function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color")) } |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
769 |
).click(function() { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
770 |
_model.set("color", $(this).attr("data-color")); |
| 67 | 771 |
}); |
772 |
|
|
773 |
function shiftSize(n) { |
|
774 |
var _newsize = n+(_model.get("size") || 0); |
|
775 |
_this.editor_$.find(".Rk-Edit-Size-Value").text((_newsize > 0 ? "+" : "") + _newsize); |
|
776 |
_model.set("size", _newsize); |
|
| 68 | 777 |
paper.view.draw(); |
| 67 | 778 |
} |
779 |
|
|
780 |
this.editor_$.find(".Rk-Edit-Size-Down").click(function() { |
|
781 |
shiftSize(-1); |
|
782 |
return false; |
|
783 |
}); |
|
784 |
this.editor_$.find(".Rk-Edit-Size-Up").click(function() { |
|
785 |
shiftSize(1); |
|
786 |
return false; |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
787 |
}); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
788 |
} |
| 38 | 789 |
this.editor_$.find("img").load(function() { |
790 |
_this.redraw(); |
|
| 52 | 791 |
}); |
| 37 | 792 |
} |
793 |
||
794 |
Rkns.Renderer.NodeEditor.prototype.redraw = function() { |
|
795 |
var _coords = this.node_representation.paper_coords; |
|
796 |
Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 20, this.editor_$); |
|
797 |
this.editor_$.show(); |
|
| 23 | 798 |
paper.view.draw(); |
| 5 | 799 |
} |
800 |
||
| 7 | 801 |
Rkns.Renderer.NodeEditor.prototype.destroy = function() { |
| 5 | 802 |
this.editor_block.remove(); |
803 |
this.editor_$.detach(); |
|
804 |
} |
|
805 |
||
806 |
/* */ |
|
807 |
||
| 23 | 808 |
Rkns.Renderer.EdgeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 5 | 809 |
|
| 7 | 810 |
Rkns.Renderer.EdgeEditor.prototype._init = function() { |
| 67 | 811 |
this.renderer.buttons_layer.activate(); |
| 5 | 812 |
this.type = "editor"; |
813 |
this.editor_block = new paper.Path(); |
|
814 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
815 |
this.editor_block.add.apply(this.editor_block, _pts); |
|
816 |
this.editor_block.strokeWidth = 2; |
|
817 |
this.editor_block.strokeColor = "#999999"; |
|
818 |
this.editor_block.fillColor = "#e0e0e0"; |
|
819 |
this.editor_block.opacity = .8; |
|
820 |
this.editor_$ = Rkns.$('<div>') |
|
| 23 | 821 |
.appendTo(this.renderer.editor_$) |
| 5 | 822 |
.css({ |
823 |
position: "absolute", |
|
824 |
opacity: .8 |
|
825 |
}) |
|
826 |
.hide(); |
|
827 |
} |
|
828 |
||
| 7 | 829 |
Rkns.Renderer.EdgeEditor.prototype.template = Rkns._.template( |
| 66 | 830 |
'<h2><span class="Rk-CloseX">×</span><%-translate("Edit Edge")%></span></h2>' |
831 |
+ '<p><label><%-translate("Title:")%></label><input class="Rk-Edit-Title" type="text" value="<%=edge.title%>"/></p>' |
|
832 |
+ '<p><label><%-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>' |
|
| 68 | 833 |
+ '<% if (properties.length) { %><p><label><%-translate("Choose from vocabulary:")%></label><select class="Rk-Edit-Vocabulary">' |
834 |
+ '<% _(properties).each(function(ontology) { %><option class="Rk-Edit-Vocabulary-Class" value=""><%- translate(ontology.label) %></option>' |
|
835 |
+ '<% _(ontology.properties).each(function(property) { var uri = ontology["base-uri"] + property.uri; %><option class="Rk-Edit-Vocabulary-Property" value="<%- uri %>' |
|
836 |
+ '"<% if (uri === edge.uri) { %> selected<% } %>><%- translate(property.label) %></option>' |
|
837 |
+ '<% }) %><% }) %></select></p><% } %>' |
|
| 66 | 838 |
+ '<div class="Rk-Editor-p"><span class="Rk-Editor-Label"><%-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><ul class="Rk-Edit-ColorPicker">' |
| 68 | 839 |
+ '<% _(Rkns.pickerColors).each(function(c) { %><li data-color="<%=c%>" style="background: <%=c%>"></li><% }); %></ul><span class="Rk-Edit-ColorPicker-Text">Choose color</span></div></div>' |
| 66 | 840 |
+ '<p><span class="Rk-Editor-Label"><%-translate("From:")%></span><span class="Rk-UserColor" style="background:<%=edge.from_color%>;"></span><%=edge.from_title%></p>' |
841 |
+ '<p><span class="Rk-Editor-Label"><%-translate("To:")%></span><span class="Rk-UserColor" style="background:<%=edge.to_color%>;"></span><%=edge.to_title%></p>' |
|
842 |
+ '<p><span class="Rk-Editor-Label"><%-translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%=edge.created_by_color%>;"></span><%=edge.created_by_title%></p>' |
|
| 5 | 843 |
); |
844 |
||
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
845 |
Rkns.Renderer.EdgeEditor.prototype.readOnlyTemplate = Rkns._.template( |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
846 |
'<h2><span class="Rk-CloseX">×</span><span class="Rk-UserColor" style="background:<%=edge.color%>;"></span><%- edge.title %></span></h2>' |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
847 |
+ '<p><a href="<%-edge.uri%>" target="_blank"><%-edge.uri%></a></p>' |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
848 |
+ '<p><%-edge.description%></p>' |
| 66 | 849 |
+ '<p><span class="Rk-Editor-Label"><%-translate("From:")%></span><span class="Rk-UserColor" style="background:<%=edge.from_color%>;"></span><%=edge.from_title%></p>' |
850 |
+ '<p><span class="Rk-Editor-Label"><%-translate("To:")%></span><span class="Rk-UserColor" style="background:<%=edge.to_color%>;"></span><%=edge.to_title%></p>' |
|
851 |
+ '<p><span class="Rk-Editor-Label"><%-translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%=edge.created_by_color%>;"></span><%=edge.created_by_title%></p>' |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
852 |
); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
853 |
|
| 37 | 854 |
Rkns.Renderer.EdgeEditor.prototype.draw = function() { |
| 53 | 855 |
var _model = this.edge_representation.model, |
856 |
_from_model = _model.get("from"), |
|
857 |
_to_model = _model.get("to"), |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
858 |
_created_by = _model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER, |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
859 |
_template = (this.renderer.renkan.read_only ? this.readOnlyTemplate : this.template); |
| 5 | 860 |
this.editor_$ |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
861 |
.html(_template({ |
| 25 | 862 |
edge: { |
863 |
title: _model.get("title"), |
|
864 |
uri: _model.get("uri"), |
|
865 |
description: _model.get("description"), |
|
| 53 | 866 |
color: _model.get("color") || _created_by.get("color"), |
867 |
from_title: _from_model.get("title"), |
|
868 |
to_title: _to_model.get("title"), |
|
869 |
from_color: _from_model.get("color") || (_from_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"), |
|
870 |
to_color: _to_model.get("color") || (_to_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"), |
|
871 |
created_by_color: _created_by.get("color"), |
|
872 |
created_by_title: _created_by.get("title") |
|
| 25 | 873 |
}, |
| 68 | 874 |
translate: this.renderer.renkan.translate, |
875 |
properties: this.renderer.renkan.properties |
|
| 37 | 876 |
})); |
877 |
this.redraw(); |
|
| 5 | 878 |
var _this = this; |
879 |
this.editor_$.find(".Rk-CloseX").click(function() { |
|
| 23 | 880 |
_this.renderer.removeRepresentation(_this); |
| 5 | 881 |
paper.view.draw(); |
882 |
}); |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
883 |
if (!this.renderer.renkan.read_only) { |
| 66 | 884 |
|
885 |
var onFieldChange = Rkns._(function() { |
|
886 |
Rkns._(function() { |
|
887 |
_this.editor_$.find(".Rk-Edit-Goto").attr("href",_this.editor_$.find(".Rk-Edit-URI").val()); |
|
888 |
var _data = { |
|
889 |
title: _this.editor_$.find(".Rk-Edit-Title").val(), |
|
890 |
uri: _this.editor_$.find(".Rk-Edit-URI").val() |
|
891 |
} |
|
892 |
_model.set(_data); |
|
| 68 | 893 |
_this.edge_representation.redraw(); |
894 |
paper.view.draw(); |
|
| 66 | 895 |
}).defer(); |
896 |
}).throttle(500); |
|
897 |
|
|
| 68 | 898 |
this.editor_$.find("input").bind("keyup change paste", onFieldChange); |
899 |
this.editor_$.find(".Rk-Edit-Vocabulary").change(function() { |
|
900 |
var e = $(this), |
|
901 |
v = e.val(); |
|
902 |
if (v) { |
|
903 |
_this.editor_$.find(".Rk-Edit-Title").val(e.find(":selected").text()); |
|
904 |
_this.editor_$.find(".Rk-Edit-URI").val(v); |
|
905 |
onFieldChange(); |
|
906 |
} |
|
907 |
}); |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
908 |
this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
909 |
function() { _this.editor_$.find(".Rk-Edit-ColorPicker").show(); }, |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
910 |
function() { _this.editor_$.find(".Rk-Edit-ColorPicker").hide(); } |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
911 |
); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
912 |
this.editor_$.find(".Rk-Edit-ColorPicker li").hover( |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
913 |
function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); }, |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
914 |
function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color")); } |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
915 |
).click(function() { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
916 |
_model.set("color", $(this).attr("data-color")); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
917 |
_this.redraw(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
918 |
}); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
919 |
} |
| 37 | 920 |
} |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
921 |
|
| 37 | 922 |
Rkns.Renderer.EdgeEditor.prototype.redraw = function() { |
923 |
var _coords = this.edge_representation.paper_coords; |
|
924 |
Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 5, this.editor_$); |
|
925 |
this.editor_$.show(); |
|
| 23 | 926 |
paper.view.draw(); |
| 5 | 927 |
} |
928 |
||
| 7 | 929 |
Rkns.Renderer.EdgeEditor.prototype.destroy = function() { |
| 5 | 930 |
this.editor_block.remove(); |
931 |
this.editor_$.detach(); |
|
| 4 | 932 |
} |
| 2 | 933 |
|
934 |
/* */ |
|
| 1 | 935 |
|
| 23 | 936 |
Rkns.Renderer.NodeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 7 | 937 |
|
938 |
Rkns.Renderer.NodeEditButton.prototype._init = function() { |
|
| 20 | 939 |
this.type = "Node-edit-button"; |
| 67 | 940 |
this.lastSectorInner = 0; |
941 |
} |
|
942 |
||
943 |
Rkns.Renderer.NodeEditButton.prototype.setSectorSize = function() { |
|
944 |
var sectorInner = this.node_representation.circle_radius; |
|
945 |
if (sectorInner !== this.lastSectorInner) { |
|
946 |
if (this.sector) { |
|
947 |
this.sector.destroy(); |
|
948 |
} |
|
949 |
this.sector = Rkns.Renderer.Utils.sector(this, 1 + sectorInner, Rkns.Renderer._NODE_BUTTON_WIDTH + sectorInner, - 90, 30, 1, this.renderer.renkan.static_url+'img/edit.png', this.renderer.renkan.translate("Edit")); |
|
950 |
this.lastSectorInner = sectorInner; |
|
951 |
} |
|
| 7 | 952 |
} |
953 |
||
954 |
Rkns.Renderer.NodeEditButton.prototype.moveTo = function(_pos) { |
|
| 18 | 955 |
this.sector.moveTo(_pos); |
| 7 | 956 |
} |
957 |
||
958 |
Rkns.Renderer.NodeEditButton.prototype.show = function() { |
|
| 18 | 959 |
this.sector.show(); |
| 7 | 960 |
} |
961 |
||
962 |
Rkns.Renderer.NodeEditButton.prototype.hide = function() { |
|
| 18 | 963 |
this.sector.hide(); |
| 7 | 964 |
} |
965 |
||
966 |
Rkns.Renderer.NodeEditButton.prototype.select = function() { |
|
| 18 | 967 |
this.sector.select(); |
| 7 | 968 |
} |
969 |
||
| 35 | 970 |
Rkns.Renderer.NodeEditButton.prototype.unselect = function(_newTarget) { |
| 18 | 971 |
this.sector.unselect(); |
| 35 | 972 |
if (!_newTarget || (_newTarget !== this.node_representation && _newTarget.node_representation !== this.node_representation)) { |
973 |
this.node_representation.unselect(); |
|
974 |
} |
|
| 7 | 975 |
} |
976 |
||
977 |
Rkns.Renderer.NodeEditButton.prototype.mouseup = function() { |
|
| 23 | 978 |
if (!this.renderer.is_dragging) { |
979 |
this.node_representation.openEditor(); |
|
| 7 | 980 |
} |
981 |
} |
|
982 |
||
983 |
Rkns.Renderer.NodeEditButton.prototype.destroy = function() { |
|
| 18 | 984 |
this.sector.destroy(); |
| 7 | 985 |
} |
986 |
||
987 |
/* */ |
|
988 |
||
| 23 | 989 |
Rkns.Renderer.NodeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 7 | 990 |
|
991 |
Rkns.Renderer.NodeRemoveButton.prototype._init = function() { |
|
| 20 | 992 |
this.type = "Node-remove-button"; |
| 67 | 993 |
this.lastSectorInner = 0; |
994 |
} |
|
995 |
||
996 |
Rkns.Renderer.NodeRemoveButton.prototype.setSectorSize = function() { |
|
997 |
var sectorInner = this.node_representation.circle_radius; |
|
998 |
if (sectorInner !== this.lastSectorInner) { |
|
999 |
if (this.sector) { |
|
1000 |
this.sector.destroy(); |
|
1001 |
} |
|
1002 |
this.sector = Rkns.Renderer.Utils.sector(this, 1 + sectorInner, Rkns.Renderer._NODE_BUTTON_WIDTH + sectorInner, - 210, - 90, 1, this.renderer.renkan.static_url+'img/remove.png', this.renderer.renkan.translate("Remove")); |
|
1003 |
this.lastSectorInner = sectorInner; |
|
1004 |
} |
|
| 7 | 1005 |
} |
1006 |
||
1007 |
Rkns.Renderer.NodeRemoveButton.prototype.moveTo = function(_pos) { |
|
| 18 | 1008 |
this.sector.moveTo(_pos); |
| 7 | 1009 |
} |
1010 |
||
1011 |
Rkns.Renderer.NodeRemoveButton.prototype.show = function() { |
|
| 18 | 1012 |
this.sector.show(); |
| 7 | 1013 |
} |
1014 |
||
1015 |
Rkns.Renderer.NodeRemoveButton.prototype.hide = function() { |
|
| 18 | 1016 |
this.sector.hide(); |
| 7 | 1017 |
} |
1018 |
||
1019 |
Rkns.Renderer.NodeRemoveButton.prototype.select = function() { |
|
| 18 | 1020 |
this.sector.select(); |
| 7 | 1021 |
} |
1022 |
||
| 35 | 1023 |
Rkns.Renderer.NodeRemoveButton.prototype.unselect = function(_newTarget) { |
| 18 | 1024 |
this.sector.unselect(); |
| 35 | 1025 |
if (!_newTarget || (_newTarget !== this.node_representation && _newTarget.node_representation !== this.node_representation)) { |
1026 |
this.node_representation.unselect(); |
|
1027 |
} |
|
| 7 | 1028 |
} |
1029 |
||
1030 |
Rkns.Renderer.NodeRemoveButton.prototype.mouseup = function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1031 |
this.renderer.removeRepresentationsOfType("editor"); |
| 66 | 1032 |
if (confirm(this.renderer.renkan.translate('Do you really wish to remove node ') + '"' + this.node_representation.model.get("title") + '"?')) { |
| 23 | 1033 |
this.project.removeNode(this.node_representation.model); |
| 10 | 1034 |
} |
| 7 | 1035 |
} |
1036 |
||
1037 |
Rkns.Renderer.NodeRemoveButton.prototype.destroy = function() { |
|
| 18 | 1038 |
this.sector.destroy(); |
| 7 | 1039 |
} |
1040 |
||
1041 |
/* */ |
|
1042 |
||
| 23 | 1043 |
Rkns.Renderer.NodeLinkButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 11 | 1044 |
|
1045 |
Rkns.Renderer.NodeLinkButton.prototype._init = function() { |
|
| 20 | 1046 |
this.type = "Node-link-button"; |
| 67 | 1047 |
this.lastSectorInner = 0; |
1048 |
} |
|
1049 |
||
1050 |
Rkns.Renderer.NodeLinkButton.prototype.setSectorSize = function() { |
|
1051 |
var sectorInner = this.node_representation.circle_radius; |
|
1052 |
if (sectorInner !== this.lastSectorInner) { |
|
1053 |
if (this.sector) { |
|
1054 |
this.sector.destroy(); |
|
1055 |
} |
|
1056 |
this.sector = Rkns.Renderer.Utils.sector(this, 1 + sectorInner, Rkns.Renderer._NODE_BUTTON_WIDTH + sectorInner, 30, 150, 1, this.renderer.renkan.static_url+'img/link.png', this.renderer.renkan.translate("Link to another node")); |
|
1057 |
this.lastSectorInner = sectorInner; |
|
1058 |
} |
|
| 11 | 1059 |
} |
1060 |
||
1061 |
Rkns.Renderer.NodeLinkButton.prototype.moveTo = function(_pos) { |
|
| 18 | 1062 |
this.sector.moveTo(_pos); |
| 11 | 1063 |
} |
1064 |
||
1065 |
Rkns.Renderer.NodeLinkButton.prototype.show = function() { |
|
| 18 | 1066 |
this.sector.show(); |
| 11 | 1067 |
} |
1068 |
||
1069 |
Rkns.Renderer.NodeLinkButton.prototype.hide = function() { |
|
| 18 | 1070 |
this.sector.hide(); |
| 11 | 1071 |
} |
1072 |
||
1073 |
Rkns.Renderer.NodeLinkButton.prototype.select = function() { |
|
| 18 | 1074 |
this.sector.select(); |
| 11 | 1075 |
} |
1076 |
||
| 35 | 1077 |
Rkns.Renderer.NodeLinkButton.prototype.unselect = function(_newTarget) { |
| 18 | 1078 |
this.sector.unselect(); |
| 35 | 1079 |
if (!_newTarget || (_newTarget !== this.node_representation && _newTarget.node_representation !== this.node_representation)) { |
1080 |
this.node_representation.unselect(); |
|
1081 |
} |
|
| 11 | 1082 |
} |
1083 |
||
1084 |
Rkns.Renderer.NodeLinkButton.prototype.destroy = function() { |
|
| 18 | 1085 |
this.sector.destroy(); |
| 11 | 1086 |
} |
1087 |
||
1088 |
/* */ |
|
1089 |
||
| 23 | 1090 |
Rkns.Renderer.EdgeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 15 | 1091 |
|
1092 |
Rkns.Renderer.EdgeEditButton.prototype._init = function() { |
|
| 20 | 1093 |
this.type = "Edge-edit-button"; |
| 66 | 1094 |
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.translate("Edit")); |
| 15 | 1095 |
} |
1096 |
||
1097 |
Rkns.Renderer.EdgeEditButton.prototype.moveTo = function(_pos) { |
|
| 18 | 1098 |
this.sector.moveTo(_pos); |
| 15 | 1099 |
} |
1100 |
||
1101 |
Rkns.Renderer.EdgeEditButton.prototype.show = function() { |
|
| 18 | 1102 |
this.sector.show(); |
| 15 | 1103 |
} |
1104 |
||
1105 |
Rkns.Renderer.EdgeEditButton.prototype.hide = function() { |
|
| 18 | 1106 |
this.sector.hide(); |
| 15 | 1107 |
} |
1108 |
||
1109 |
Rkns.Renderer.EdgeEditButton.prototype.select = function() { |
|
| 18 | 1110 |
this.sector.select(); |
| 15 | 1111 |
} |
1112 |
||
| 35 | 1113 |
Rkns.Renderer.EdgeEditButton.prototype.unselect = function(_newTarget) { |
| 18 | 1114 |
this.sector.unselect(); |
| 35 | 1115 |
if (!_newTarget || (_newTarget !== this.edge_representation && _newTarget.edge_representation !== this.edge_representation)) { |
1116 |
this.edge_representation.unselect(); |
|
1117 |
} |
|
| 15 | 1118 |
} |
1119 |
||
1120 |
Rkns.Renderer.EdgeEditButton.prototype.mouseup = function() { |
|
| 23 | 1121 |
if (!this.renderer.is_dragging) { |
1122 |
this.edge_representation.openEditor(); |
|
| 15 | 1123 |
} |
1124 |
} |
|
1125 |
||
1126 |
Rkns.Renderer.EdgeEditButton.prototype.destroy = function() { |
|
| 18 | 1127 |
this.sector.destroy(); |
| 15 | 1128 |
} |
1129 |
||
1130 |
/* */ |
|
1131 |
||
| 23 | 1132 |
Rkns.Renderer.EdgeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 15 | 1133 |
|
1134 |
Rkns.Renderer.EdgeRemoveButton.prototype._init = function() { |
|
| 20 | 1135 |
this.type = "Edge-remove-button"; |
| 66 | 1136 |
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.translate("Remove")); |
| 15 | 1137 |
} |
1138 |
Rkns.Renderer.EdgeRemoveButton.prototype.moveTo = function(_pos) { |
|
| 18 | 1139 |
this.sector.moveTo(_pos); |
| 15 | 1140 |
} |
1141 |
||
1142 |
Rkns.Renderer.EdgeRemoveButton.prototype.show = function() { |
|
| 18 | 1143 |
this.sector.show(); |
| 15 | 1144 |
} |
1145 |
||
1146 |
Rkns.Renderer.EdgeRemoveButton.prototype.hide = function() { |
|
| 18 | 1147 |
this.sector.hide(); |
| 15 | 1148 |
} |
1149 |
||
1150 |
Rkns.Renderer.EdgeRemoveButton.prototype.select = function() { |
|
| 18 | 1151 |
this.sector.select(); |
| 15 | 1152 |
} |
1153 |
||
| 35 | 1154 |
Rkns.Renderer.EdgeRemoveButton.prototype.unselect = function(_newTarget) { |
| 18 | 1155 |
this.sector.unselect(); |
| 35 | 1156 |
if (!_newTarget || (_newTarget !== this.edge_representation && _newTarget.edge_representation !== this.edge_representation)) { |
1157 |
this.edge_representation.unselect(); |
|
1158 |
} |
|
| 15 | 1159 |
} |
1160 |
||
1161 |
Rkns.Renderer.EdgeRemoveButton.prototype.mouseup = function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1162 |
this.renderer.removeRepresentationsOfType("editor"); |
| 66 | 1163 |
if (confirm(this.renderer.renkan.translate('Do you really wish to remove edge ') + '"' + this.edge_representation.model.get("title") + '"?')) { |
| 23 | 1164 |
this.project.removeEdge(this.edge_representation.model); |
| 15 | 1165 |
} |
1166 |
} |
|
1167 |
||
1168 |
Rkns.Renderer.EdgeRemoveButton.prototype.destroy = function() { |
|
| 18 | 1169 |
this.sector.destroy(); |
| 15 | 1170 |
} |
1171 |
||
1172 |
/* */ |
|
1173 |
||
| 23 | 1174 |
Rkns.Renderer.Scene = function(_renkan) { |
1175 |
this.renkan = _renkan; |
|
| 20 | 1176 |
this.$ = Rkns.$(".Rk-Render"); |
| 23 | 1177 |
this.representations = []; |
| 44 | 1178 |
this.$.html(this.template(_renkan)); |
| 20 | 1179 |
this.canvas_$ = this.$.find(".Rk-Canvas"); |
1180 |
this.editor_$ = this.$.find(".Rk-Editor"); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1181 |
this.notif_$ = this.$.find(".Rk-Notifications"); |
| 20 | 1182 |
paper.setup(this.canvas_$[0]); |
| 2 | 1183 |
this.scale = 1; |
1184 |
this.offset = paper.view.center; |
|
1185 |
this.totalScroll = 0; |
|
| 5 | 1186 |
this.click_target = null; |
| 4 | 1187 |
this.selected_target = null; |
| 2 | 1188 |
this.edge_layer = new paper.Layer(); |
1189 |
this.node_layer = new paper.Layer(); |
|
| 67 | 1190 |
this.buttons_layer = new paper.Layer(); |
| 69 | 1191 |
|
1192 |
this.minimap = { |
|
1193 |
background_layer: new paper.Layer(), |
|
1194 |
node_layer: new paper.Layer(), |
|
1195 |
node_group: new paper.Group(), |
|
1196 |
size: new paper.Size( Rkns.Renderer._MINIMAP_WIDTH, Rkns.Renderer._MINIMAP_HEIGHT ) |
|
1197 |
} |
|
1198 |
|
|
1199 |
this.minimap.background_layer.activate(); |
|
1200 |
this.minimap.topleft = paper.view.bounds.bottomRight.subtract(this.minimap.size); |
|
1201 |
this.minimap.rectangle = new paper.Path.Rectangle(this.minimap.topleft.subtract([2,2]), this.minimap.size.add([4,4])); |
|
1202 |
this.minimap.rectangle.fillColor = '#ffffff'; |
|
1203 |
this.minimap.rectangle.strokeColor = '#cccccc'; |
|
1204 |
this.minimap.rectangle.strokeWidth = 4; |
|
1205 |
this.minimap.offset = new paper.Point(this.minimap.size.divide(2)); |
|
1206 |
this.minimap.scale = .25; |
|
1207 |
|
|
1208 |
this.node_layer.activate(); |
|
1209 |
this.minimap.cliprectangle = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size); |
|
1210 |
this.minimap.node_group.addChild(this.minimap.cliprectangle); |
|
1211 |
this.minimap.node_group.clipped = true; |
|
1212 |
this.minimap.miniframe = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size); |
|
1213 |
this.minimap.node_group.addChild(this.minimap.miniframe); |
|
1214 |
this.minimap.miniframe.fillColor = '#f0f0ff'; |
|
1215 |
this.minimap.miniframe.strokeColor = '#8080ff'; |
|
1216 |
this.minimap.miniframe.strokeWidth = 2; |
|
1217 |
|
|
| 31 | 1218 |
this.bundles = []; |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1219 |
this.click_mode = false; |
| 2 | 1220 |
var _tool = new paper.Tool(), |
1221 |
_this = this; |
|
| 28 | 1222 |
_tool.minDistance = Rkns.Renderer._MIN_DRAG_DISTANCE; |
| 4 | 1223 |
_tool.onMouseMove = function(_event) { |
1224 |
_this.onMouseMove(_event); |
|
1225 |
} |
|
| 2 | 1226 |
_tool.onMouseDown = function(_event) { |
1227 |
_this.onMouseDown(_event); |
|
1228 |
} |
|
1229 |
_tool.onMouseDrag = function(_event) { |
|
1230 |
_this.onMouseDrag(_event); |
|
1231 |
} |
|
| 21 | 1232 |
this.canvas_$.mouseup(function(_event) { |
| 4 | 1233 |
_this.onMouseUp(_event); |
| 21 | 1234 |
}); |
| 20 | 1235 |
this.canvas_$.mousewheel(function(_event, _delta) { |
| 2 | 1236 |
_this.onScroll(_event, _delta); |
| 21 | 1237 |
}); |
| 20 | 1238 |
this.canvas_$.dblclick(function(_event) { |
| 4 | 1239 |
_this.onDoubleClick(_event); |
| 11 | 1240 |
}); |
| 66 | 1241 |
this.canvas_$.on("dragover", function(_event) { |
1242 |
_event.stopPropagation(); |
|
1243 |
_event.preventDefault(); |
|
1244 |
}) |
|
1245 |
this.canvas_$.on("drop", function(_event) { |
|
1246 |
_event.stopPropagation(); |
|
1247 |
_event.preventDefault(); |
|
| 69 | 1248 |
if (_this.renkan.read_only) { |
1249 |
return; |
|
1250 |
} |
|
| 66 | 1251 |
var res = {} |
1252 |
Rkns._(_event.originalEvent.dataTransfer.types).each(function(t) { |
|
1253 |
return res[t] = _event.originalEvent.dataTransfer.getData(t); |
|
1254 |
}); |
|
1255 |
var newNode = {}; |
|
| 69 | 1256 |
if (res["text/x-iri-source-uri"]) { |
1257 |
newNode.uri = res["text/x-iri-source-uri"]; |
|
1258 |
} |
|
| 66 | 1259 |
if (res["text/plain"]) { |
1260 |
newNode.description = res["text/plain"].replace(/[\s\n]+/gm,' ').trim(); |
|
1261 |
} |
|
1262 |
if (res["text/html"]) { |
|
1263 |
var snippet = Rkns.$('<div>').html(res["text/html"]); |
|
1264 |
newNode.image = snippet.find("img").attr("src") || ''; |
|
| 69 | 1265 |
newNode.uri = snippet.find("a").attr("href") || newNode.uri; |
| 68 | 1266 |
newNode.title = snippet.find("[title]").attr("title"); |
| 66 | 1267 |
} |
1268 |
if (res["text/uri-list"]) { |
|
1269 |
newNode.uri = res["text/uri-list"]; |
|
1270 |
} |
|
| 69 | 1271 |
if (res["text/x-moz-url"] && !newNode.title) { |
| 66 | 1272 |
newNode.title = (res["text/x-moz-url"].split("\n")[1] || "").trim(); |
1273 |
if (newNode.title === newNode.uri) { |
|
| 69 | 1274 |
newNode.title = false; |
| 66 | 1275 |
} |
1276 |
} |
|
| 69 | 1277 |
if (res["text/x-iri-source-title"] && !newNode.title) { |
1278 |
newNode.title = res["text/x-iri-source-title"]; |
|
1279 |
} |
|
| 68 | 1280 |
var fields = ["title", "description", "uri", "image"]; |
1281 |
for (var i = 0; i < fields.length; i++) { |
|
1282 |
var f = fields[i]; |
|
1283 |
if (res["text/x-iri-" + f]) { |
|
1284 |
newNode[f] = res["text/x-iri-" + f]; |
|
1285 |
} |
|
1286 |
} |
|
| 66 | 1287 |
if (newNode.title || newNode.description || newNode.uri) { |
1288 |
var _off = _this.canvas_$.offset(), |
|
1289 |
_point = new paper.Point([ |
|
1290 |
_event.originalEvent.pageX - _off.left, |
|
1291 |
_event.originalEvent.pageY - _off.top |
|
1292 |
]), |
|
1293 |
_coords = _this.toModelCoords(_point), |
|
1294 |
_data = { |
|
1295 |
id: Rkns.Utils.getUID('node'), |
|
1296 |
created_by: _this.renkan.current_user, |
|
1297 |
uri: newNode.uri || "", |
|
1298 |
title: newNode.title || _this.renkan.translate("Dragged resource"), |
|
1299 |
description: newNode.description || "", |
|
1300 |
image: newNode.image || "", |
|
1301 |
position: { |
|
1302 |
x: _coords.x, |
|
1303 |
y: _coords.y |
|
1304 |
} |
|
1305 |
}; |
|
1306 |
var _node = _this.renkan.project.addNode(_data); |
|
1307 |
_this.getRepresentationByModel(_node).openEditor(); |
|
1308 |
} |
|
1309 |
}) |
|
| 11 | 1310 |
this.editor_$.find(".Rk-ZoomOut").click(function() { |
1311 |
_this.offset = new paper.Point([ |
|
| 20 | 1312 |
_this.canvas_$.width(), |
1313 |
_this.canvas_$.height() |
|
| 11 | 1314 |
]).multiply( .5 * ( 1 - Math.SQRT1_2 ) ).add(_this.offset.multiply( Math.SQRT1_2 )); |
| 28 | 1315 |
_this.setScale( _this.scale * Math.SQRT1_2 ); |
| 11 | 1316 |
_this.redraw(); |
1317 |
}); |
|
1318 |
this.editor_$.find(".Rk-ZoomIn").click(function() { |
|
1319 |
_this.offset = new paper.Point([ |
|
| 20 | 1320 |
_this.canvas_$.width(), |
1321 |
_this.canvas_$.height() |
|
| 11 | 1322 |
]).multiply( .5 * ( 1 - Math.SQRT2 ) ).add(_this.offset.multiply( Math.SQRT2 )); |
| 28 | 1323 |
_this.setScale( _this.scale * Math.SQRT2 ); |
| 11 | 1324 |
_this.redraw(); |
1325 |
}); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1326 |
this.$.find(".Rk-CurrentUser").mouseenter( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1327 |
function() { _this.$.find(".Rk-UserList").slideDown() } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1328 |
); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1329 |
this.$.find(".Rk-Users").mouseleave( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1330 |
function() { _this.$.find(".Rk-UserList").slideUp(); } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1331 |
); |
| 34 | 1332 |
this.$.find(".Rk-FullScreen-Button").click(function() { |
1333 |
var _isFull = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen, |
|
1334 |
_el = _this.renkan.$[0], |
|
1335 |
_requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"], |
|
1336 |
_cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"]; |
|
1337 |
if (_isFull) { |
|
1338 |
for (var i = 0; i < _cancelMethods.length; i++) { |
|
1339 |
if (typeof document[_cancelMethods[i]] === "function") { |
|
1340 |
document[_cancelMethods[i]](); |
|
1341 |
break; |
|
1342 |
} |
|
1343 |
} |
|
1344 |
} else { |
|
1345 |
for (var i = 0; i < _requestMethods.length; i++) { |
|
1346 |
if (typeof _el[_requestMethods[i]] === "function") { |
|
1347 |
_el[_requestMethods[i]](); |
|
1348 |
break; |
|
1349 |
} |
|
1350 |
} |
|
1351 |
} |
|
1352 |
}); |
|
1353 |
this.$.find(".Rk-AddNode-Button").click(function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1354 |
if (_this.click_mode === Rkns.Renderer._CLICKMODE_ADDNODE) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1355 |
_this.click_mode = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1356 |
_this.notif_$.hide(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1357 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1358 |
_this.click_mode = Rkns.Renderer._CLICKMODE_ADDNODE; |
| 69 | 1359 |
_this.notif_$.text(_renkan.translate("Click on the background canvas to add a node")).fadeIn(); |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1360 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1361 |
}); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1362 |
this.$.find(".Rk-AddEdge-Button").click(function() { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1363 |
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
|
1364 |
_this.click_mode = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1365 |
_this.notif_$.hide(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1366 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1367 |
_this.click_mode = Rkns.Renderer._CLICKMODE_STARTEDGE; |
| 69 | 1368 |
_this.notif_$.text(_renkan.translate("Click on a first node to start the edge")).fadeIn(); |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1369 |
} |
| 34 | 1370 |
}); |
| 69 | 1371 |
this.$.find(".Rk-Bookmarklet-Button").click(function(){ |
1372 |
_this.notif_$ |
|
1373 |
.text(_renkan.translate("Drag this bookmarklet to your bookmark bar. When on a third-party website, click it to enable drag-and-drop from the website to Renkan.")) |
|
1374 |
.fadeIn() |
|
1375 |
.delay(5000) |
|
1376 |
.fadeOut(); |
|
1377 |
return false; |
|
1378 |
}); |
|
| 34 | 1379 |
this.$.find(".Rk-TopBar-Button").mouseover(function() { |
1380 |
Rkns.$(this).find(".Rk-TopBar-Tooltip").show(); |
|
1381 |
}).mouseout(function() { |
|
1382 |
Rkns.$(this).find(".Rk-TopBar-Tooltip").hide(); |
|
1383 |
}); |
|
1384 |
|
|
| 2 | 1385 |
paper.view.onResize = function(_event) { |
1386 |
_this.offset = _this.offset.add(_event.delta.divide(2)); |
|
| 57 | 1387 |
_this.resetCoords(); |
| 69 | 1388 |
_this.minimap.topleft = paper.view.bounds.bottomRight.subtract(_this.minimap.size) |
1389 |
_this.minimap.rectangle.fitBounds(_this.minimap.topleft.subtract([2,2]), _this.minimap.size.add([4,4])); |
|
1390 |
_this.minimap.cliprectangle.fitBounds(_this.minimap.topleft, _this.minimap.size); |
|
| 2 | 1391 |
_this.redraw(); |
1392 |
} |
|
| 23 | 1393 |
|
1394 |
var _thRedraw = Rkns._.throttle(function() { |
|
1395 |
_this.redraw(); |
|
1396 |
},50); |
|
1397 |
|
|
1398 |
this.addRepresentations("Node", this.renkan.project.get("nodes")); |
|
1399 |
this.addRepresentations("Edge", this.renkan.project.get("edges")); |
|
| 44 | 1400 |
this.renkan.project.on("change:title", function() { |
1401 |
_this.$.find(".Rk-PadTitle").val(_renkan.project.get("title")); |
|
1402 |
}); |
|
1403 |
|
|
1404 |
this.$.find(".Rk-PadTitle").on("keyup input paste", function() { |
|
1405 |
_renkan.project.set({"title": $(this).val()}); |
|
1406 |
}) |
|
1407 |
|
|
| 34 | 1408 |
this.renkan.project.get("users").each(function(_user) { |
1409 |
_this.addUser(_user); |
|
| 44 | 1410 |
}); |
| 23 | 1411 |
|
| 34 | 1412 |
this.renkan.project.on("add:users", function(_user) { |
1413 |
_this.addUser(_user); |
|
1414 |
}); |
|
| 23 | 1415 |
this.renkan.project.on("add:nodes", function(_node) { |
1416 |
_this.addRepresentation("Node", _node); |
|
1417 |
_thRedraw(); |
|
1418 |
}); |
|
1419 |
this.renkan.project.on("add:edges", function(_edge) { |
|
1420 |
_this.addRepresentation("Edge", _edge); |
|
1421 |
_thRedraw(); |
|
1422 |
}); |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1423 |
this.renkan.project.on("change:title", function(_model, _title) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1424 |
var el = $(".Rk-PadTitle"); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1425 |
if (el.is("input")) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1426 |
if (el.val() !== _title) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1427 |
el.val(_title); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1428 |
} |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1429 |
} else { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1430 |
el.text(_title); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1431 |
} |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1432 |
}); |
| 23 | 1433 |
|
1434 |
this.redraw(); |
|
| 69 | 1435 |
window.setInterval(function() { |
1436 |
_this.rescaleMinimap() |
|
1437 |
}, 2000); |
|
| 2 | 1438 |
} |
1439 |
||
| 20 | 1440 |
Rkns.Renderer.Scene.prototype.template = Rkns._.template( |
| 66 | 1441 |
'<div class="Rk-TopBar"><% if (read_only) { %><h2 class="Rk-PadTitle"><%- project.get("title") || translate("Untitled project")%></h2>' |
1442 |
+ '<% } else { %><input type="text" class="Rk-PadTitle" value="<%- project.get("title") || "" %>" placeholder="<%-translate("Untitled project")%>" /><% } %>' |
|
| 34 | 1443 |
+ '<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>' |
| 66 | 1444 |
+ '<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"><%-translate("Full Screen")%></div></div></div>' |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1445 |
+ '<% if (!read_only) { %>' |
| 66 | 1446 |
+ '<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"><%-translate("Add Node")%></div></div></div>' |
1447 |
+ '<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"><%-translate("Add Edge")%></div></div></div>' |
|
1448 |
+ '<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"><%-translate("Archive Project")%></div></div></div>' |
|
| 69 | 1449 |
+ '<div class="Rk-TopBar-Separator"></div><a class="Rk-TopBar-Button Rk-Bookmarklet-Button" href="javascript:(function(){a=document;' |
1450 |
+ 'b=function(c){d=a.createElement(\'script\');d.type=\'text/javascript\';d.src=c;a.getElementsByTagName(\'head\')[0].appendChild(d);};' |
|
1451 |
+ 'b(\'<%- bookmarklet_url %>\');})();"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents">' |
|
1452 |
+ '<%-translate("Renkan \'Drag and Add\' bookmarklet")%></div></div></a>' |
|
| 34 | 1453 |
+ '<div class="Rk-TopBar-Separator"></div></div>' |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1454 |
+ '<% } %>' |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1455 |
+ '<canvas class="Rk-Canvas" resize></canvas><div class="Rk-Editor"><div class="Rk-Notifications"></div>' |
| 66 | 1456 |
+ '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%-translate("Zoom In")%>"></div><div class="Rk-ZoomOut" title="<%-translate("Zoom Out")%>"></div></div>' |
| 20 | 1457 |
+ '</div>' |
| 11 | 1458 |
); |
1459 |
||
| 31 | 1460 |
Rkns.Renderer.Scene.prototype.addToBundles = function(_edgeRepr) { |
1461 |
var _bundle = Rkns._(this.bundles).find(function(_bundle) { |
|
1462 |
return ( |
|
1463 |
( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation ) |
|
1464 |
|| ( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation ) |
|
1465 |
); |
|
1466 |
}); |
|
1467 |
if (typeof _bundle !== "undefined") { |
|
1468 |
_bundle.edges.push(_edgeRepr) |
|
1469 |
} else { |
|
1470 |
_bundle = { |
|
1471 |
from: _edgeRepr.from_representation, |
|
1472 |
to: _edgeRepr.to_representation, |
|
1473 |
edges: [ _edgeRepr ], |
|
1474 |
getPosition: function(_er) { |
|
1475 |
var _dir = (_er.from_representation === this.from) ? 1 : -1; |
|
1476 |
return _dir * ( Rkns._(this.edges).indexOf(_er) - (this.edges.length - 1) / 2 ); |
|
1477 |
} |
|
1478 |
} |
|
1479 |
this.bundles.push(_bundle); |
|
1480 |
} |
|
1481 |
return _bundle; |
|
1482 |
} |
|
1483 |
||
| 28 | 1484 |
Rkns.Renderer.Scene.prototype.setScale = function(_newScale) { |
1485 |
this.scale = _newScale; |
|
| 57 | 1486 |
this.resetCoords(); |
| 28 | 1487 |
this.redraw(); |
1488 |
} |
|
| 69 | 1489 |
|
1490 |
Rkns.Renderer.Scene.prototype.redrawMiniframe = function() { |
|
1491 |
var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))), |
|
1492 |
bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight)); |
|
1493 |
this.minimap.miniframe.fitBounds(topleft, bottomright); |
|
1494 |
} |
|
1495 |
||
1496 |
Rkns.Renderer.Scene.prototype.rescaleMinimap = function() { |
|
| 43 | 1497 |
var nodes = this.renkan.project.get("nodes") |
1498 |
if (nodes.length > 1) { |
|
1499 |
var _xx = nodes.map(function(_node) { return _node.get("position").x }), |
|
1500 |
_yy = nodes.map(function(_node) { return _node.get("position").y }), |
|
| 26 | 1501 |
_minx = Math.min.apply(Math, _xx), |
1502 |
_miny = Math.min.apply(Math, _yy), |
|
1503 |
_maxx = Math.max.apply(Math, _xx), |
|
1504 |
_maxy = Math.max.apply(Math, _yy); |
|
| 69 | 1505 |
var _scale = Math.min(this.scale * .8 * Rkns.Renderer._MINIMAP_WIDTH / paper.view.bounds.width, this.scale * .8 * Rkns.Renderer._MINIMAP_HEIGHT / paper.view.bounds.height, (Rkns.Renderer._MINIMAP_WIDTH - 2 * Rkns.Renderer._MINIMAP_MARGIN_X) / (_maxx - _minx), (Rkns.Renderer._MINIMAP_HEIGHT - 2 * Rkns.Renderer._MINIMAP_MARGIN_Y) / (_maxy - _miny)); |
1506 |
this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)); |
|
1507 |
this.minimap.scale = _scale; |
|
| 26 | 1508 |
} |
| 43 | 1509 |
if (nodes.length === 1) { |
| 69 | 1510 |
this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y])); |
1511 |
this.minimap.scale = .25; |
|
| 43 | 1512 |
} |
| 69 | 1513 |
this.redraw(); |
| 25 | 1514 |
} |
| 69 | 1515 |
|
| 57 | 1516 |
Rkns.Renderer.Scene.prototype.resetCoords = function(_point) { |
1517 |
_(this.representations).each(function(r) { |
|
1518 |
r.resetCoords(); |
|
1519 |
}); |
|
1520 |
} |
|
1521 |
||
| 7 | 1522 |
Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) { |
| 2 | 1523 |
return _point.multiply(this.scale).add(this.offset); |
1524 |
} |
|
1525 |
||
| 69 | 1526 |
Rkns.Renderer.Scene.prototype.toMinimapCoords = function(_point) { |
1527 |
return _point.multiply(this.minimap.scale).add(this.minimap.offset).add(this.minimap.topleft); |
|
1528 |
} |
|
| 2 | 1529 |
|
| 7 | 1530 |
Rkns.Renderer.Scene.prototype.toModelCoords = function(_point) { |
| 2 | 1531 |
return _point.subtract(this.offset).divide(this.scale); |
| 1 | 1532 |
} |
1533 |
||
| 23 | 1534 |
Rkns.Renderer.Scene.prototype.addRepresentation = function(_type, _model) { |
1535 |
var _repr = new Rkns.Renderer[_type](this, _model); |
|
1536 |
this.representations.push(_repr); |
|
1537 |
return _repr; |
|
1538 |
} |
|
1539 |
||
1540 |
Rkns.Renderer.Scene.prototype.addRepresentations = function(_type, _collection) { |
|
1541 |
var _this = this; |
|
1542 |
_collection.forEach(function(_model) { |
|
1543 |
_this.addRepresentation(_type, _model); |
|
| 1 | 1544 |
}); |
1545 |
} |
|
1546 |
||
| 34 | 1547 |
Rkns.Renderer.Scene.prototype.userTemplate = Rkns._.template( |
1548 |
'<li class="Rk-User"><span class="Rk-UserColor" style="background:<%=background%>;"></span><%=name%></li>' |
|
1549 |
); |
|
1550 |
||
1551 |
Rkns.Renderer.Scene.prototype.addUser = function(_user) { |
|
1552 |
if (_user.get("_id") === this.renkan.current_user) { |
|
1553 |
this.$.find(".Rk-CurrentUser-Name").text(_user.get("title")); |
|
1554 |
this.$.find(".Rk-CurrentUser-Color").css("background", _user.get("color")); |
|
1555 |
} else { |
|
1556 |
this.$.find(".Rk-UserList").append( |
|
1557 |
Rkns.$( |
|
1558 |
this.userTemplate({ |
|
1559 |
name: _user.get("title"), |
|
1560 |
background: _user.get("color") |
|
1561 |
}) |
|
1562 |
) |
|
1563 |
); |
|
1564 |
} |
|
1565 |
} |
|
1566 |
||
| 23 | 1567 |
Rkns.Renderer.Scene.prototype.removeRepresentation = function(_representation) { |
1568 |
_representation.destroy(); |
|
1569 |
this.representations = Rkns._(this.representations).reject( |
|
1570 |
function(_repr) { |
|
1571 |
return _repr == _representation |
|
1572 |
} |
|
1573 |
); |
|
| 4 | 1574 |
} |
1575 |
||
| 23 | 1576 |
Rkns.Renderer.Scene.prototype.getRepresentationByModel = function(_model) { |
1577 |
return Rkns._(this.representations).find(function(_repr) { |
|
1578 |
return _repr.model === _model; |
|
1579 |
}); |
|
| 5 | 1580 |
} |
1581 |
||
| 23 | 1582 |
Rkns.Renderer.Scene.prototype.removeRepresentationsOfType = function(_type) { |
1583 |
var _representations = Rkns._(this.representations).filter(function(_repr) { |
|
1584 |
return _repr.type == _type; |
|
| 5 | 1585 |
}), |
1586 |
_this = this; |
|
| 23 | 1587 |
Rkns._(_representations).each(function(_repr) { |
1588 |
_this.removeRepresentation(_repr); |
|
| 5 | 1589 |
}); |
1590 |
} |
|
1591 |
||
| 26 | 1592 |
Rkns.Renderer.Scene.prototype.highlightModel = function(_model) { |
1593 |
var _repr = this.getRepresentationByModel(_model); |
|
1594 |
if (_repr) { |
|
1595 |
_repr.highlight(); |
|
1596 |
} |
|
1597 |
} |
|
1598 |
||
1599 |
Rkns.Renderer.Scene.prototype.unhighlightAll = function(_model) { |
|
1600 |
Rkns._(this.representations).each(function(_repr) { |
|
1601 |
_repr.unhighlight(); |
|
1602 |
}); |
|
1603 |
} |
|
1604 |
||
| 7 | 1605 |
Rkns.Renderer.Scene.prototype.redraw = function() { |
| 23 | 1606 |
Rkns._(this.representations).each(function(_representation) { |
1607 |
_representation.redraw(); |
|
| 2 | 1608 |
}); |
| 69 | 1609 |
this.redrawMiniframe(); |
| 2 | 1610 |
paper.view.draw(); |
1611 |
} |
|
1612 |
||
| 11 | 1613 |
Rkns.Renderer.Scene.prototype.addTempEdge = function(_from, _point) { |
| 23 | 1614 |
var _tmpEdge = this.addRepresentation("TempEdge",null); |
| 11 | 1615 |
_tmpEdge.end_pos = _point; |
| 23 | 1616 |
_tmpEdge.from_representation = _from; |
| 11 | 1617 |
_tmpEdge.redraw(); |
1618 |
this.click_target = _tmpEdge; |
|
1619 |
} |
|
1620 |
||
| 21 | 1621 |
Rkns.Renderer.Scene.prototype.findTarget = function(_hitResult) { |
| 23 | 1622 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
1623 |
var _newTarget = _hitResult.item.__representation; |
|
1624 |
if (this.selected_target !== _hitResult.item.__representation) { |
|
| 4 | 1625 |
if (this.selected_target) { |
| 7 | 1626 |
this.selected_target.unselect(_newTarget); |
| 4 | 1627 |
} |
| 7 | 1628 |
_newTarget.select(this.selected_target); |
1629 |
this.selected_target = _newTarget; |
|
| 4 | 1630 |
} |
1631 |
} else { |
|
1632 |
if (this.selected_target) { |
|
| 7 | 1633 |
this.selected_target.unselect(null); |
| 4 | 1634 |
} |
1635 |
this.selected_target = null; |
|
1636 |
} |
|
1637 |
} |
|
1638 |
||
| 21 | 1639 |
Rkns.Renderer.Scene.prototype.onMouseMove = function(_event) { |
1640 |
var _hitResult = paper.project.hitTest(_event.point); |
|
1641 |
if (this.is_dragging) { |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1642 |
if (this.click_target && typeof this.click_target.paperShift === "function" && !this.renkan.read_only) { |
| 21 | 1643 |
this.click_target.paperShift(_event.delta); |
1644 |
} else { |
|
1645 |
this.offset = this.offset.add(_event.delta); |
|
| 57 | 1646 |
this.resetCoords(); |
| 21 | 1647 |
this.redraw(); |
1648 |
} |
|
1649 |
} else { |
|
1650 |
this.findTarget(_hitResult); |
|
1651 |
} |
|
1652 |
} |
|
1653 |
||
| 7 | 1654 |
Rkns.Renderer.Scene.prototype.onMouseDown = function(_event) { |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1655 |
if (!this.click_target || this.click_target.type !== "temp-edge") { |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1656 |
this.removeRepresentationsOfType("editor"); |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1657 |
this.is_dragging = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1658 |
var _hitResult = paper.project.hitTest(_event.point); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1659 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1660 |
this.click_target = _hitResult.item.__representation; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1661 |
if (this.click_target.type === "Node-link-button") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1662 |
this.removeRepresentationsOfType("editor"); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1663 |
this.addTempEdge(this.click_target.node_representation, _event.point); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1664 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1665 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1666 |
this.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1667 |
if (this.click_mode === Rkns.Renderer._CLICKMODE_ADDNODE) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1668 |
var _coords = this.toModelCoords(_event.point), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1669 |
_data = { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1670 |
id: Rkns.Utils.getUID('node'), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1671 |
created_by: this.renkan.current_user, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1672 |
position: { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1673 |
x: _coords.x, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1674 |
y: _coords.y |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1675 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1676 |
}; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1677 |
_node = this.renkan.project.addNode(_data); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1678 |
this.getRepresentationByModel(_node).openEditor(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1679 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1680 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1681 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1682 |
if (this.click_mode) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1683 |
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
|
1684 |
this.removeRepresentationsOfType("editor"); |
| 11 | 1685 |
this.addTempEdge(this.click_target, _event.point); |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1686 |
this.click_mode = Rkns.Renderer._CLICKMODE_ENDEDGE; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1687 |
this.notif_$.fadeOut(function() { |
| 66 | 1688 |
Rkns.$(this).html(_renkan.translate("Click on a second node to complete the edge")).fadeIn(); |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1689 |
}); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1690 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1691 |
this.notif_$.hide(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1692 |
this.click_mode = false; |
| 11 | 1693 |
} |
| 2 | 1694 |
} |
| 1 | 1695 |
} |
| 2 | 1696 |
|
| 7 | 1697 |
Rkns.Renderer.Scene.prototype.onMouseDrag = function(_event) { |
| 5 | 1698 |
this.is_dragging = true; |
| 21 | 1699 |
this.onMouseMove(_event); |
| 2 | 1700 |
} |
1701 |
||
| 7 | 1702 |
Rkns.Renderer.Scene.prototype.onMouseUp = function(_event) { |
| 5 | 1703 |
if (this.click_target) { |
| 21 | 1704 |
var _off = this.canvas_$.offset(); |
1705 |
this.click_target.mouseup( |
|
1706 |
{ |
|
1707 |
point: new paper.Point([ |
|
1708 |
_event.pageX - _off.left, |
|
1709 |
_event.pageY - _off.top |
|
1710 |
]) |
|
1711 |
} |
|
1712 |
); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1713 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1714 |
this.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1715 |
this.is_dragging = false; |
| 4 | 1716 |
} |
1717 |
} |
|
1718 |
||
| 7 | 1719 |
Rkns.Renderer.Scene.prototype.onScroll = function(_event, _scrolldelta) { |
| 3 | 1720 |
this.totalScroll += _scrolldelta; |
| 2 | 1721 |
if (Math.abs(this.totalScroll) >= 1) { |
| 20 | 1722 |
var _off = this.canvas_$.offset(), |
| 3 | 1723 |
_delta = new paper.Point([ |
1724 |
_event.pageX - _off.left, |
|
1725 |
_event.pageY - _off.top |
|
1726 |
]).subtract(this.offset).multiply( Math.SQRT2 - 1 ); |
|
| 2 | 1727 |
if (this.totalScroll > 0) { |
| 3 | 1728 |
this.offset = this.offset.subtract(_delta); |
| 28 | 1729 |
this.setScale( this.scale * Math.SQRT2 ); |
| 2 | 1730 |
} else { |
| 3 | 1731 |
this.offset = this.offset.add(_delta.divide( Math.SQRT2 )); |
| 28 | 1732 |
this.setScale( this.scale * Math.SQRT1_2); |
| 2 | 1733 |
} |
1734 |
this.totalScroll = 0; |
|
1735 |
this.redraw(); |
|
1736 |
} |
|
1737 |
} |
|
| 4 | 1738 |
|
| 7 | 1739 |
Rkns.Renderer.Scene.prototype.onDoubleClick = function(_event) { |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1740 |
if (this.renkan.read_only) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1741 |
return; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1742 |
} |
| 20 | 1743 |
var _off = this.canvas_$.offset(), |
| 4 | 1744 |
_point = new paper.Point([ |
1745 |
_event.pageX - _off.left, |
|
1746 |
_event.pageY - _off.top |
|
1747 |
]); |
|
1748 |
var _hitResult = paper.project.hitTest(_point); |
|
| 23 | 1749 |
if (!_hitResult || typeof _hitResult.item.__representation === "undefined") { |
| 8 | 1750 |
var _coords = this.toModelCoords(_point), |
| 23 | 1751 |
_data = { |
1752 |
id: Rkns.Utils.getUID('node'), |
|
1753 |
created_by: this.renkan.current_user, |
|
| 8 | 1754 |
position: { |
1755 |
x: _coords.x, |
|
1756 |
y: _coords.y |
|
1757 |
} |
|
| 23 | 1758 |
}; |
1759 |
_node = this.renkan.project.addNode(_data); |
|
1760 |
this.getRepresentationByModel(_node).openEditor(); |
|
| 4 | 1761 |
} |
1762 |
paper.view.draw(); |
|
1763 |
} |