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