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