234 this.renderer.node_layer.activate(); |
234 this.renderer.node_layer.activate(); |
235 this.type = "Node"; |
235 this.type = "Node"; |
236 this.circle = new paper.Path.Circle([0, 0], Rkns.Renderer._NODE_RADIUS); |
236 this.circle = new paper.Path.Circle([0, 0], Rkns.Renderer._NODE_RADIUS); |
237 this.circle.fillColor = '#ffffff'; |
237 this.circle.fillColor = '#ffffff'; |
238 this.circle.__representation = this; |
238 this.circle.__representation = this; |
|
239 this.circle.strokeWidth = 2; |
239 this.title = new paper.PointText([0,0]); |
240 this.title = new paper.PointText([0,0]); |
240 this.title.characterStyle = { |
241 this.title.characterStyle = { |
241 fontSize: Rkns.Renderer._NODE_FONT_SIZE, |
242 fontSize: Rkns.Renderer._NODE_FONT_SIZE, |
242 fillColor: 'black' |
243 fillColor: 'black' |
243 }; |
244 }; |
254 var _model_coords = new paper.Point(this.model.get("position")); |
255 var _model_coords = new paper.Point(this.model.get("position")); |
255 this.paper_coords = this.renderer.toPaperCoords(_model_coords); |
256 this.paper_coords = this.renderer.toPaperCoords(_model_coords); |
256 this.circle.position = this.paper_coords; |
257 this.circle.position = this.paper_coords; |
257 this.title.content = this.model.get("title"); |
258 this.title.content = this.model.get("title"); |
258 this.title.position = this.paper_coords.add([0, Rkns.Renderer._NODE_RADIUS + 1.5 *Rkns.Renderer._NODE_FONT_SIZE]); |
259 this.title.position = this.paper_coords.add([0, Rkns.Renderer._NODE_RADIUS + 1.5 *Rkns.Renderer._NODE_FONT_SIZE]); |
259 this.circle.strokeColor = this.model.get("created_by").get("color"); |
260 this.circle.strokeColor = this.model.get("color") || this.model.get("created_by").get("color") || "#000000"; |
260 this.edit_button.moveTo(this.paper_coords); |
261 this.edit_button.moveTo(this.paper_coords); |
261 this.remove_button.moveTo(this.paper_coords); |
262 this.remove_button.moveTo(this.paper_coords); |
262 this.link_button.moveTo(this.paper_coords); |
263 this.link_button.moveTo(this.paper_coords); |
263 var _img = this.model.get("image"); |
264 var _img = this.model.get("image"); |
264 if (_img && _img !== this.img) { |
265 if (_img && _img !== this.img) { |
315 _editor.node_representation = this; |
316 _editor.node_representation = this; |
316 _editor.draw(); |
317 _editor.draw(); |
317 } |
318 } |
318 |
319 |
319 Rkns.Renderer.Node.prototype.select = function() { |
320 Rkns.Renderer.Node.prototype.select = function() { |
320 this.circle.strokeWidth = 3; |
321 this.circle.strokeWidth = 4; |
321 this.edit_button.show(); |
322 this.edit_button.show(); |
322 this.remove_button.show(); |
323 this.remove_button.show(); |
323 this.link_button.show(); |
324 this.link_button.show(); |
324 var _uri = this.model.get("uri"); |
325 var _uri = this.model.get("uri"); |
325 Rkns.$('.Rk-Bin-Item').each(function() { |
326 Rkns.$('.Rk-Bin-Item').each(function() { |
333 Rkns.Renderer.Node.prototype.unselect = function(_newTarget) { |
334 Rkns.Renderer.Node.prototype.unselect = function(_newTarget) { |
334 if (!_newTarget || _newTarget.node_representation !== this) { |
335 if (!_newTarget || _newTarget.node_representation !== this) { |
335 this.edit_button.hide(); |
336 this.edit_button.hide(); |
336 this.remove_button.hide(); |
337 this.remove_button.hide(); |
337 this.link_button.hide(); |
338 this.link_button.hide(); |
338 this.circle.strokeWidth = 1; |
339 this.circle.strokeWidth = 2; |
339 Rkns.$('.Rk-Bin-Item').removeClass("selected"); |
340 Rkns.$('.Rk-Bin-Item').removeClass("selected"); |
340 } |
341 } |
341 } |
342 } |
342 |
343 |
343 Rkns.Renderer.Node.prototype.highlight = function() { |
344 Rkns.Renderer.Node.prototype.highlight = function() { |
385 this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to")); |
386 this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to")); |
386 this.bundle = this.renderer.addToBundles(this); |
387 this.bundle = this.renderer.addToBundles(this); |
387 this.line = new paper.Path(); |
388 this.line = new paper.Path(); |
388 this.line.add([0,0],[0,0],[0,0]); |
389 this.line.add([0,0],[0,0],[0,0]); |
389 this.line.__representation = this; |
390 this.line.__representation = this; |
|
391 this.line.strokeWidth = 2; |
390 this.arrow = new paper.Path(); |
392 this.arrow = new paper.Path(); |
391 this.arrow.add([0,0],[Rkns.Renderer._ARROW_LENGTH,Rkns.Renderer._ARROW_WIDTH / 2],[0,Rkns.Renderer._ARROW_WIDTH]); |
393 this.arrow.add([0,0],[Rkns.Renderer._ARROW_LENGTH,Rkns.Renderer._ARROW_WIDTH / 2],[0,Rkns.Renderer._ARROW_WIDTH]); |
392 this.arrow.__representation = this; |
394 this.arrow.__representation = this; |
393 this.text = new paper.PointText(); |
395 this.text = new paper.PointText(); |
394 this.text.characterStyle = { |
396 this.text.characterStyle = { |
414 _delta = new paper.Point([- _u.y, _u.x]).multiply( 12 * _group_pos ), |
416 _delta = new paper.Point([- _u.y, _u.x]).multiply( 12 * _group_pos ), |
415 _p0b = _p0a.add(_delta), /* Adding a 4 px difference */ |
417 _p0b = _p0a.add(_delta), /* Adding a 4 px difference */ |
416 _p1b = _p1a.add(_delta), /* to differentiate inbound and outbound links */ |
418 _p1b = _p1a.add(_delta), /* to differentiate inbound and outbound links */ |
417 _a = _v.angle, |
419 _a = _v.angle, |
418 _handle = _v.divide(3), |
420 _handle = _v.divide(3), |
419 _color = this.model.get("created_by").get("color"); |
421 _color = this.model.get("color") || this.model.get("created_by").get("color") || "#000000"; |
420 this.paper_coords = _p0b.add(_p1b).divide(2); |
422 this.paper_coords = _p0b.add(_p1b).divide(2); |
421 this.line.strokeColor = _color; |
423 this.line.strokeColor = _color; |
422 this.line.segments[0].point = _p0a; |
424 this.line.segments[0].point = _p0a; |
423 this.line.segments[1].point = this.paper_coords; |
425 this.line.segments[1].point = this.paper_coords; |
424 this.line.segments[1].handleIn = _handle.multiply(-1); |
426 this.line.segments[1].handleIn = _handle.multiply(-1); |
448 _editor.edge_representation = this; |
450 _editor.edge_representation = this; |
449 _editor.draw(); |
451 _editor.draw(); |
450 } |
452 } |
451 |
453 |
452 Rkns.Renderer.Edge.prototype.select = function() { |
454 Rkns.Renderer.Edge.prototype.select = function() { |
453 this.line.strokeWidth = 3; |
455 this.line.strokeWidth = 4; |
454 this.edit_button.show(); |
456 this.edit_button.show(); |
455 this.remove_button.show(); |
457 this.remove_button.show(); |
456 } |
458 } |
457 |
459 |
458 Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) { |
460 Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) { |
459 if (!_newTarget || _newTarget.edge_representation !== this) { |
461 if (!_newTarget || _newTarget.edge_representation !== this) { |
460 this.edit_button.hide(); |
462 this.edit_button.hide(); |
461 this.remove_button.hide(); |
463 this.remove_button.hide(); |
462 this.line.strokeWidth = 1; |
464 this.line.strokeWidth = 2; |
463 } |
465 } |
464 } |
466 } |
465 |
467 |
466 Rkns.Renderer.Edge.prototype.mouseup = function(_event) { |
468 Rkns.Renderer.Edge.prototype.mouseup = function(_event) { |
467 if (!this.renderer.is_dragging) { |
469 if (!this.renderer.is_dragging) { |
496 |
498 |
497 Rkns.Renderer.TempEdge.prototype._init = function() { |
499 Rkns.Renderer.TempEdge.prototype._init = function() { |
498 this.renderer.edge_layer.activate(); |
500 this.renderer.edge_layer.activate(); |
499 this.type = "temp-edge"; |
501 this.type = "temp-edge"; |
500 |
502 |
501 var _color = this.project.get("users").get(this.renderer.renkan.current_user).get("color"); |
503 var _color = this.project.get("users").get(this.renderer.renkan.current_user).get("color") || "#000000"; |
502 this.line = new paper.Path(); |
504 this.line = new paper.Path(); |
503 this.line.strokeColor = _color; |
505 this.line.strokeColor = _color; |
504 this.line.add([0,0],[0,0]); |
506 this.line.add([0,0],[0,0]); |
505 this.line.__representation = this; |
507 this.line.__representation = this; |
506 this.arrow = new paper.Path(); |
508 this.arrow = new paper.Path(); |
588 Rkns.Renderer.NodeEditor.prototype.template = Rkns._.template( |
590 Rkns.Renderer.NodeEditor.prototype.template = Rkns._.template( |
589 '<h2><span class="Rk-CloseX">×</span><%=l10n.edit_node%></span></h2>' |
591 '<h2><span class="Rk-CloseX">×</span><%=l10n.edit_node%></span></h2>' |
590 + '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=node.title%>"/></p>' |
592 + '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=node.title%>"/></p>' |
591 + '<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>' |
593 + '<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>' |
592 + '<p><label><%=l10n.edit_description%></label><textarea class="Rk-Edit-Description"><%=node.description%></textarea></p>' |
594 + '<p><label><%=l10n.edit_description%></label><textarea class="Rk-Edit-Description"><%=node.description%></textarea></p>' |
|
595 + '<div class="Rk-Editor-p"><label>Node color</label><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-Edit-Color" style="background:<%=node.color%>;"></span><ul class="Rk-Edit-ColorPicker">' |
|
596 + '<% print(Rkns.pickerColors.reduce(function(m,c) { return m + "<li data-color=\'" + c + "\' style=\'background: " + c + "\'></li>"},"")); %></ul></div></div>' |
593 + '<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>' |
597 + '<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>' |
594 + '<p><label><%=l10n.created_by%></label> <span class="Rk-UserColor" style="background:<%=node.created_by_color%>;"></span><%=node.created_by_title%></p>' |
598 + '<p><label><%=l10n.created_by%></label> <span class="Rk-UserColor" style="background:<%=node.created_by_color%>;"></span><%=node.created_by_title%></p>' |
595 ); |
599 ); |
596 |
600 |
597 Rkns.Renderer.NodeEditor.prototype.draw = function() { |
601 Rkns.Renderer.NodeEditor.prototype.draw = function() { |
601 node: { |
605 node: { |
602 title: _model.get("title"), |
606 title: _model.get("title"), |
603 uri: _model.get("uri"), |
607 uri: _model.get("uri"), |
604 description: _model.get("description"), |
608 description: _model.get("description"), |
605 image: _model.get("image") || "", |
609 image: _model.get("image") || "", |
|
610 color: _model.get("color") || _model.get("created_by").get("color") || "#000000", |
606 created_by_color: _model.get("created_by").get("color"), |
611 created_by_color: _model.get("created_by").get("color"), |
607 created_by_title: _model.get("created_by").get("title") |
612 created_by_title: _model.get("created_by").get("title") |
608 }, |
613 }, |
609 l10n: this.renderer.renkan.l10n |
614 l10n: this.renderer.renkan.l10n |
610 })); |
615 })); |
630 }); |
635 }); |
631 this.editor_$.find("img").load(function() { |
636 this.editor_$.find("img").load(function() { |
632 _this.redraw(); |
637 _this.redraw(); |
633 }) |
638 }) |
634 this.editor_$.find(".Rk-Edit-Title")[0].focus(); |
639 this.editor_$.find(".Rk-Edit-Title")[0].focus(); |
|
640 this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( |
|
641 function() { _this.editor_$.find(".Rk-Edit-ColorPicker").show(); }, |
|
642 function() { _this.editor_$.find(".Rk-Edit-ColorPicker").hide(); } |
|
643 ); |
|
644 this.editor_$.find(".Rk-Edit-ColorPicker li").hover( |
|
645 function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); }, |
|
646 function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || _model.get("created_by").get("color") || "#000000") } |
|
647 ).click(function() { |
|
648 _model.set("color", $(this).attr("data-color")); |
|
649 _this.redraw(); |
|
650 }); |
635 } |
651 } |
636 |
652 |
637 Rkns.Renderer.NodeEditor.prototype.redraw = function() { |
653 Rkns.Renderer.NodeEditor.prototype.redraw = function() { |
638 var _coords = this.node_representation.paper_coords; |
654 var _coords = this.node_representation.paper_coords; |
639 Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 20, this.editor_$); |
655 Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 20, this.editor_$); |
671 |
687 |
672 Rkns.Renderer.EdgeEditor.prototype.template = Rkns._.template( |
688 Rkns.Renderer.EdgeEditor.prototype.template = Rkns._.template( |
673 '<h2><span class="Rk-CloseX">×</span><%=l10n.edit_edge%></span></h2>' |
689 '<h2><span class="Rk-CloseX">×</span><%=l10n.edit_edge%></span></h2>' |
674 + '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=edge.title%>"/></p>' |
690 + '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=edge.title%>"/></p>' |
675 + '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=edge.uri%>"/><a class="Rk-Edit-Goto" href="<%=edge.uri%>" target="_blank"></a></p>' |
691 + '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=edge.uri%>"/><a class="Rk-Edit-Goto" href="<%=edge.uri%>" target="_blank"></a></p>' |
|
692 + '<div class="Rk-Editor-p"><label>Edge color:</label><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-Edit-Color" style="background:<%=edge.color%>;"></span><ul class="Rk-Edit-ColorPicker">' |
|
693 + '<% print(Rkns.pickerColors.reduce(function(m,c) { return m + "<li data-color=\'" + c + "\' style=\'background: " + c + "\'></li>"},"")); %></ul></div></div>' |
676 + '<p><label><%=l10n.edit_from%></label><span class="Rk-UserColor" style="background:<%=edge.from_created_by_color%>;"></span><%=edge.from_title%></p>' |
694 + '<p><label><%=l10n.edit_from%></label><span class="Rk-UserColor" style="background:<%=edge.from_created_by_color%>;"></span><%=edge.from_title%></p>' |
677 + '<p><label><%=l10n.edit_to%></label><span class="Rk-UserColor" style="background:<%=edge.to_created_by_color%>;"></span><%=edge.to_title%></p>' |
695 + '<p><label><%=l10n.edit_to%></label><span class="Rk-UserColor" style="background:<%=edge.to_created_by_color%>;"></span><%=edge.to_title%></p>' |
678 + '<p><label><%=l10n.created_by%> </label><span class="Rk-UserColor" style="background:<%=edge.created_by_color%>;"></span><%=edge.created_by_title%></p>' |
696 + '<p><label><%=l10n.created_by%> </label><span class="Rk-UserColor" style="background:<%=edge.created_by_color%>;"></span><%=edge.created_by_title%></p>' |
679 ); |
697 ); |
680 |
698 |
684 .html(this.template({ |
702 .html(this.template({ |
685 edge: { |
703 edge: { |
686 title: _model.get("title"), |
704 title: _model.get("title"), |
687 uri: _model.get("uri"), |
705 uri: _model.get("uri"), |
688 description: _model.get("description"), |
706 description: _model.get("description"), |
|
707 color: _model.get("color") || _model.get("created_by").get("color") || "#000000", |
689 from_title: _model.get("from").get("title"), |
708 from_title: _model.get("from").get("title"), |
690 to_title: _model.get("to").get("title"), |
709 to_title: _model.get("to").get("title"), |
691 from_created_by_color: _model.get("from").get("created_by").get("color"), |
710 from_created_by_color: _model.get("from").get("created_by").get("color"), |
692 to_created_by_color: _model.get("to").get("created_by").get("color"), |
711 to_created_by_color: _model.get("to").get("created_by").get("color"), |
693 created_by_color: _model.get("created_by").get("color"), |
712 created_by_color: _model.get("created_by").get("color"), |
706 var _data = { |
725 var _data = { |
707 title: _this.editor_$.find(".Rk-Edit-Title").val(), |
726 title: _this.editor_$.find(".Rk-Edit-Title").val(), |
708 uri: _this.editor_$.find(".Rk-Edit-URI").val() |
727 uri: _this.editor_$.find(".Rk-Edit-URI").val() |
709 } |
728 } |
710 _model.set(_data); |
729 _model.set(_data); |
|
730 _this.redraw(); |
|
731 }); |
|
732 this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( |
|
733 function() { _this.editor_$.find(".Rk-Edit-ColorPicker").show(); }, |
|
734 function() { _this.editor_$.find(".Rk-Edit-ColorPicker").hide(); } |
|
735 ); |
|
736 this.editor_$.find(".Rk-Edit-ColorPicker li").hover( |
|
737 function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); }, |
|
738 function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || _model.get("created_by").get("color") || "#000000") } |
|
739 ).click(function() { |
|
740 _model.set("color", $(this).attr("data-color")); |
711 _this.redraw(); |
741 _this.redraw(); |
712 }); |
742 }); |
713 } |
743 } |
714 Rkns.Renderer.EdgeEditor.prototype.redraw = function() { |
744 Rkns.Renderer.EdgeEditor.prototype.redraw = function() { |
715 var _coords = this.edge_representation.paper_coords; |
745 var _coords = this.edge_representation.paper_coords; |