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