203 this.remove_button = new Rkns.Renderer.NodeRemoveButton(this.renderer, {}); |
203 this.remove_button = new Rkns.Renderer.NodeRemoveButton(this.renderer, {}); |
204 this.remove_button.node_representation = this; |
204 this.remove_button.node_representation = this; |
205 this.link_button = new Rkns.Renderer.NodeLinkButton(this.renderer, {}); |
205 this.link_button = new Rkns.Renderer.NodeLinkButton(this.renderer, {}); |
206 this.link_button.node_representation = this; |
206 this.link_button.node_representation = this; |
207 this.title.paragraphStyle.justification = 'center'; |
207 this.title.paragraphStyle.justification = 'center'; |
208 this.title.__representation = this; |
|
209 } |
208 } |
210 |
209 |
211 Rkns.Renderer.Node.prototype.redraw = function() { |
210 Rkns.Renderer.Node.prototype.redraw = function() { |
212 var _model_coords = new paper.Point(this.model.get("position")); |
211 var _model_coords = new paper.Point(this.model.get("position")); |
213 this.paper_coords = this.renderer.toPaperCoords(_model_coords); |
212 this.paper_coords = this.renderer.toPaperCoords(_model_coords); |
214 this.circle.position = this.paper_coords; |
213 this.circle.position = this.paper_coords; |
215 this.title.content = this.model.get("title"); |
214 this.title.content = this.model.get("title"); |
216 this.title.position = this.paper_coords.add([0, 2 * Rkns.Renderer._NODE_RADIUS]); |
215 this.title.position = this.paper_coords.add([0, Rkns.Renderer._NODE_RADIUS + 1.5 *Rkns.Renderer._NODE_FONT_SIZE]); |
217 this.circle.strokeColor = this.model.get("created_by").get("color"); |
216 this.circle.strokeColor = this.model.get("created_by").get("color"); |
218 this.edit_button.moveTo(this.paper_coords); |
217 this.edit_button.moveTo(this.paper_coords); |
219 this.remove_button.moveTo(this.paper_coords); |
218 this.remove_button.moveTo(this.paper_coords); |
220 this.link_button.moveTo(this.paper_coords); |
219 this.link_button.moveTo(this.paper_coords); |
|
220 var _img = this.model.get("image"); |
|
221 if (_img && _img !== this.img) { |
|
222 var _image = new Image(), |
|
223 _this = this; |
|
224 _image.onload = function() { |
|
225 if (_this.node_image) { |
|
226 _this.node_image.remove(); |
|
227 } |
|
228 _this.renderer.node_layer.activate(); |
|
229 var _ratio = Math.min(1, 2 * Rkns.Renderer._NODE_RADIUS / _image.width, 2 * Rkns.Renderer._NODE_RADIUS / _image.height ); |
|
230 var _raster = new paper.Raster(_image); |
|
231 var _clip = new paper.Path.Circle([0, 0], Rkns.Renderer._NODE_RADIUS); |
|
232 _raster.scale(_ratio); |
|
233 _this.node_image = new paper.Group(_clip, _raster); |
|
234 _this.node_image.opacity = .9; |
|
235 /* This is a workaround to allow clipping at group level */ |
|
236 _this.node_image.clipped = true; |
|
237 _this.node_image.position = _this.paper_coords; |
|
238 _this.node_image.__representation = _this; |
|
239 paper.view.draw(); |
|
240 } |
|
241 _image.src = _img; |
|
242 } |
|
243 this.img = _img; |
|
244 if (this.node_image) { |
|
245 if (!this.img) { |
|
246 this.node_image.remove(); |
|
247 delete this.node_image; |
|
248 } else { |
|
249 this.node_image.position = this.paper_coords; |
|
250 } |
|
251 } |
221 } |
252 } |
222 |
253 |
223 Rkns.Renderer.Node.prototype.paperShift = function(_delta) { |
254 Rkns.Renderer.Node.prototype.paperShift = function(_delta) { |
224 var _coords = this.renderer.toModelCoords(this.paper_coords.add(_delta)), |
255 var _coords = this.renderer.toModelCoords(this.paper_coords.add(_delta)), |
225 _data = { |
256 _data = { |
262 Rkns.$('.Rk-Bin-Item').removeClass("selected"); |
293 Rkns.$('.Rk-Bin-Item').removeClass("selected"); |
263 } |
294 } |
264 } |
295 } |
265 |
296 |
266 Rkns.Renderer.Node.prototype.highlight = function() { |
297 Rkns.Renderer.Node.prototype.highlight = function() { |
267 this.circle.fillColor = "#ffffc0"; |
298 this.circle.fillColor = "#ffff80"; |
|
299 if (this.node_image) { |
|
300 this.node_image.opacity = .5; |
|
301 } |
268 } |
302 } |
269 |
303 |
270 Rkns.Renderer.Node.prototype.unhighlight = function(_newTarget) { |
304 Rkns.Renderer.Node.prototype.unhighlight = function(_newTarget) { |
271 this.circle.fillColor = "#ffffff"; |
305 this.circle.fillColor = "#ffffff"; |
|
306 if (this.node_image) { |
|
307 this.node_image.opacity = .9; |
|
308 } |
272 } |
309 } |
273 |
310 |
274 Rkns.Renderer.Node.prototype.mouseup = function(_event) { |
311 Rkns.Renderer.Node.prototype.mouseup = function(_event) { |
275 if (!this.renderer.is_dragging) { |
312 if (!this.renderer.is_dragging) { |
276 this.openEditor(); |
313 this.openEditor(); |
307 this.text.characterStyle = { |
347 this.text.characterStyle = { |
308 fontSize: Rkns.Renderer._EDGE_FONT_SIZE, |
348 fontSize: Rkns.Renderer._EDGE_FONT_SIZE, |
309 fillColor: 'black' |
349 fillColor: 'black' |
310 }; |
350 }; |
311 this.text.paragraphStyle.justification = 'center'; |
351 this.text.paragraphStyle.justification = 'center'; |
312 this.text.__representation = this; |
|
313 this.text_angle = 0; |
352 this.text_angle = 0; |
314 this.arrow_angle = 0; |
353 this.arrow_angle = 0; |
315 this.edit_button = new Rkns.Renderer.EdgeEditButton(this.renderer, {}); |
354 this.edit_button = new Rkns.Renderer.EdgeEditButton(this.renderer, {}); |
316 this.edit_button.edge_representation = this; |
355 this.edit_button.edge_representation = this; |
317 this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this.renderer, {}); |
356 this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this.renderer, {}); |
501 Rkns.Renderer.NodeEditor.prototype.template = Rkns._.template( |
540 Rkns.Renderer.NodeEditor.prototype.template = Rkns._.template( |
502 '<h2><span class="Rk-CloseX">×</span><%=l10n.edit_node%></span></h2>' |
541 '<h2><span class="Rk-CloseX">×</span><%=l10n.edit_node%></span></h2>' |
503 + '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=node.title%>"/></p>' |
542 + '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=node.title%>"/></p>' |
504 + '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=node.uri%>"/><a class="Rk-Edit-Goto" href="<%=node.uri%>" target="_blank"></a></p>' |
543 + '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=node.uri%>"/><a class="Rk-Edit-Goto" href="<%=node.uri%>" target="_blank"></a></p>' |
505 + '<p><label><%=l10n.edit_description%></label><textarea class="Rk-Edit-Description"><%=node.description%></textarea></p>' |
544 + '<p><label><%=l10n.edit_description%></label><textarea class="Rk-Edit-Description"><%=node.description%></textarea></p>' |
|
545 + '<p><label><%=l10n.edit_image%></label><input class="Rk-Edit-Image" type="text" value="<%=node.image%>"/><img class="Rk-Edit-ImgPreview" src="<%=node.image%>" /></p>' |
506 + '<p><label><%=l10n.created_by%></label> <span class="Rk-UserColor" style="background:<%=node.created_by_color%>;"></span><%=node.created_by_title%></p>' |
546 + '<p><label><%=l10n.created_by%></label> <span class="Rk-UserColor" style="background:<%=node.created_by_color%>;"></span><%=node.created_by_title%></p>' |
507 ); |
547 ); |
508 |
548 |
509 Rkns.Renderer.NodeEditor.prototype.redraw = function() { |
549 Rkns.Renderer.NodeEditor.prototype.draw = function() { |
510 var _coords = this.node_representation.paper_coords, |
550 var _model = this.node_representation.model; |
511 _model = this.node_representation.model; |
|
512 this.editor_$ |
551 this.editor_$ |
513 .html(this.template({ |
552 .html(this.template({ |
514 node: { |
553 node: { |
515 title: _model.get("title"), |
554 title: _model.get("title"), |
516 uri: _model.get("uri"), |
555 uri: _model.get("uri"), |
517 description: _model.get("description"), |
556 description: _model.get("description"), |
|
557 image: _model.get("image") || "", |
518 created_by_color: _model.get("created_by").get("color"), |
558 created_by_color: _model.get("created_by").get("color"), |
519 created_by_title: _model.get("created_by").get("title") |
559 created_by_title: _model.get("created_by").get("title") |
520 }, |
560 }, |
521 l10n: this.renderer.renkan.l10n |
561 l10n: this.renderer.renkan.l10n |
522 })) |
562 })); |
523 .show(); |
563 this.redraw(); |
524 Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 20, this.editor_$); |
|
525 var _this = this; |
564 var _this = this; |
526 this.editor_$.find(".Rk-CloseX").click(function() { |
565 this.editor_$.find(".Rk-CloseX").click(function() { |
527 _this.renderer.removeRepresentation(_this); |
566 _this.renderer.removeRepresentation(_this); |
528 paper.view.draw(); |
567 paper.view.draw(); |
529 }); |
568 }); |
530 this.editor_$.find("input, textarea").bind("keyup change", function() { |
569 this.editor_$.find("input, textarea").bind("keyup change", function() { |
531 _this.editor_$.find(".Rk-Edit-Goto").attr("href",_this.editor_$.find(".Rk-Edit-URI").val()); |
570 var _uri = _this.editor_$.find(".Rk-Edit-URI").val(), |
|
571 _image = _this.editor_$.find(".Rk-Edit-Image").val(); |
|
572 _this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _image); |
|
573 _this.editor_$.find(".Rk-Edit-Goto").attr("href",_uri); |
532 var _data = { |
574 var _data = { |
533 title: _this.editor_$.find(".Rk-Edit-Title").val(), |
575 title: _this.editor_$.find(".Rk-Edit-Title").val(), |
534 description: _this.editor_$.find(".Rk-Edit-Description").val(), |
576 description: _this.editor_$.find(".Rk-Edit-Description").val(), |
535 uri: _this.editor_$.find(".Rk-Edit-URI").val() |
577 uri: _uri, |
|
578 image: _image |
536 } |
579 } |
537 _model.set(_data); |
580 _model.set(_data); |
538 paper.view.draw(); |
581 _this.redraw(); |
539 }); |
582 }); |
540 this.editor_$.find(".Rk-Edit-Title")[0].focus(); |
583 this.editor_$.find(".Rk-Edit-Title")[0].focus(); |
|
584 } |
|
585 |
|
586 Rkns.Renderer.NodeEditor.prototype.redraw = function() { |
|
587 var _coords = this.node_representation.paper_coords; |
|
588 Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 20, this.editor_$); |
|
589 this.editor_$.show(); |
541 paper.view.draw(); |
590 paper.view.draw(); |
542 } |
591 } |
543 |
592 |
544 Rkns.Renderer.NodeEditor.prototype.destroy = function() { |
593 Rkns.Renderer.NodeEditor.prototype.destroy = function() { |
545 this.editor_block.remove(); |
594 this.editor_block.remove(); |
576 + '<p><label><%=l10n.edit_from%></label><span class="Rk-UserColor" style="background:<%=edge.from_created_by_color%>;"></span><%=edge.from_title%></p>' |
625 + '<p><label><%=l10n.edit_from%></label><span class="Rk-UserColor" style="background:<%=edge.from_created_by_color%>;"></span><%=edge.from_title%></p>' |
577 + '<p><label><%=l10n.edit_to%></label><span class="Rk-UserColor" style="background:<%=edge.to_created_by_color%>;"></span><%=edge.to_title%></p>' |
626 + '<p><label><%=l10n.edit_to%></label><span class="Rk-UserColor" style="background:<%=edge.to_created_by_color%>;"></span><%=edge.to_title%></p>' |
578 + '<p><label><%=l10n.created_by%> </label><span class="Rk-UserColor" style="background:<%=edge.created_by_color%>;"></span><%=edge.created_by_title%></p>' |
627 + '<p><label><%=l10n.created_by%> </label><span class="Rk-UserColor" style="background:<%=edge.created_by_color%>;"></span><%=edge.created_by_title%></p>' |
579 ); |
628 ); |
580 |
629 |
581 Rkns.Renderer.EdgeEditor.prototype.redraw = function() { |
630 Rkns.Renderer.EdgeEditor.prototype.draw = function() { |
582 var _coords = this.edge_representation.paper_coords, |
631 var _model = this.edge_representation.model; |
583 _model = this.edge_representation.model; |
|
584 this.editor_$ |
632 this.editor_$ |
585 .html(this.template({ |
633 .html(this.template({ |
586 edge: { |
634 edge: { |
587 title: _model.get("title"), |
635 title: _model.get("title"), |
588 uri: _model.get("uri"), |
636 uri: _model.get("uri"), |
593 to_created_by_color: _model.get("to").get("created_by").get("color"), |
641 to_created_by_color: _model.get("to").get("created_by").get("color"), |
594 created_by_color: _model.get("created_by").get("color"), |
642 created_by_color: _model.get("created_by").get("color"), |
595 created_by_title: _model.get("created_by").get("title") |
643 created_by_title: _model.get("created_by").get("title") |
596 }, |
644 }, |
597 l10n: this.renderer.renkan.l10n |
645 l10n: this.renderer.renkan.l10n |
598 })) |
646 })); |
599 .show(); |
647 this.redraw(); |
600 Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 5, this.editor_$); |
|
601 var _this = this; |
648 var _this = this; |
602 this.editor_$.find(".Rk-CloseX").click(function() { |
649 this.editor_$.find(".Rk-CloseX").click(function() { |
603 _this.renderer.removeRepresentation(_this); |
650 _this.renderer.removeRepresentation(_this); |
604 paper.view.draw(); |
651 paper.view.draw(); |
605 }); |
652 }); |