client/js/paper-renderer.js
changeset 26 2fad193bae98
parent 25 b5ada3bb8e53
child 28 805d85b3f390
equal deleted inserted replaced
25:b5ada3bb8e53 26:2fad193bae98
   152 
   152 
   153 Rkns.Renderer._BaseRepresentation.prototype.select = function() {}
   153 Rkns.Renderer._BaseRepresentation.prototype.select = function() {}
   154 
   154 
   155 Rkns.Renderer._BaseRepresentation.prototype.unselect = function() {}
   155 Rkns.Renderer._BaseRepresentation.prototype.unselect = function() {}
   156 
   156 
       
   157 Rkns.Renderer._BaseRepresentation.prototype.highlight = function() {}
       
   158 
       
   159 Rkns.Renderer._BaseRepresentation.prototype.unhighlight = function() {}
       
   160 
   157 Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() {}
   161 Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() {}
   158 
   162 
   159 Rkns.Renderer._BaseRepresentation.prototype.destroy = function() {}
   163 Rkns.Renderer._BaseRepresentation.prototype.destroy = function() {}
   160 
   164 
   161 Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
   165 Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
   215 Rkns.Renderer.Node.prototype.select = function() {
   219 Rkns.Renderer.Node.prototype.select = function() {
   216     this.circle.strokeWidth = 3;
   220     this.circle.strokeWidth = 3;
   217     this.edit_button.show();
   221     this.edit_button.show();
   218     this.remove_button.show();
   222     this.remove_button.show();
   219     this.link_button.show();
   223     this.link_button.show();
       
   224     var _uri = this.model.get("uri");
       
   225     Rkns.$('.Rk-Bin-Item').each(function() {
       
   226         var _el = Rkns.$(this);
       
   227         if (_el.attr("data-uri") == _uri) {
       
   228             _el.addClass("selected");
       
   229         }
       
   230     });
   220 }
   231 }
   221 
   232 
   222 Rkns.Renderer.Node.prototype.unselect = function(_newTarget) {
   233 Rkns.Renderer.Node.prototype.unselect = function(_newTarget) {
   223     if (!_newTarget || (_newTarget !== this.edit_button && _newTarget !== this.remove_button && _newTarget !== this.link_button)) {
   234     if (!_newTarget || (_newTarget !== this.edit_button && _newTarget !== this.remove_button && _newTarget !== this.link_button)) {
   224         this.edit_button.hide();
   235         this.edit_button.hide();
   225         this.remove_button.hide();
   236         this.remove_button.hide();
   226         this.link_button.hide();
   237         this.link_button.hide();
   227     }
   238     }
   228     this.circle.strokeWidth = 1;
   239     this.circle.strokeWidth = 1;
       
   240     Rkns.$('.Rk-Bin-Item').removeClass("selected");
       
   241 }
       
   242 
       
   243 Rkns.Renderer.Node.prototype.highlight = function() {
       
   244     this.circle.fillColor = "#ffffc0";
       
   245 }
       
   246 
       
   247 Rkns.Renderer.Node.prototype.unhighlight = function(_newTarget) {
       
   248     this.circle.fillColor = "#ffffff";
   229 }
   249 }
   230 
   250 
   231 Rkns.Renderer.Node.prototype.mouseup = function(_event) {
   251 Rkns.Renderer.Node.prototype.mouseup = function(_event) {
   232     if (!this.renderer.is_dragging) {
   252     if (!this.renderer.is_dragging) {
   233         this.openEditor();
   253         this.openEditor();
   235 }
   255 }
   236 
   256 
   237 Rkns.Renderer.Node.prototype.destroy = function(_event) {
   257 Rkns.Renderer.Node.prototype.destroy = function(_event) {
   238     this.edit_button.destroy();
   258     this.edit_button.destroy();
   239     this.remove_button.destroy();
   259     this.remove_button.destroy();
       
   260     this.link_button.destroy();
   240     this.circle.remove();
   261     this.circle.remove();
   241     this.title.remove();
   262     this.title.remove();
   242 }
   263 }
   243 
   264 
   244 /* */
   265 /* */
   430 }
   451 }
   431 
   452 
   432 Rkns.Renderer.NodeEditor.prototype.template = Rkns._.template(
   453 Rkns.Renderer.NodeEditor.prototype.template = Rkns._.template(
   433     '<h2><span class="Rk-CloseX">&times;</span><%=l10n.edit_node%></span></h2>'
   454     '<h2><span class="Rk-CloseX">&times;</span><%=l10n.edit_node%></span></h2>'
   434     + '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=node.title%>"/></p>'
   455     + '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=node.title%>"/></p>'
   435     + '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=node.uri%>"/></p>'
   456     + '<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>'
   436     + '<p><label><%=l10n.edit_description%></label><textarea class="Rk-Edit-Description"><%=node.description%></textarea></p>'
   457     + '<p><label><%=l10n.edit_description%></label><textarea class="Rk-Edit-Description"><%=node.description%></textarea></p>'
   437     + '<p><label><%=l10n.created_by%></label> <span class="Rk-UserColor" style="background:<%=node.created_by_color%>;"></span><%=node.created_by_title%></p>'
   458     + '<p><label><%=l10n.created_by%></label> <span class="Rk-UserColor" style="background:<%=node.created_by_color%>;"></span><%=node.created_by_title%></p>'
   438 );
   459 );
   439 
   460 
   440 Rkns.Renderer.NodeEditor.prototype.redraw = function() {
   461 Rkns.Renderer.NodeEditor.prototype.redraw = function() {
   458     this.editor_$.find(".Rk-CloseX").click(function() {
   479     this.editor_$.find(".Rk-CloseX").click(function() {
   459         _this.renderer.removeRepresentation(_this);
   480         _this.renderer.removeRepresentation(_this);
   460         paper.view.draw();
   481         paper.view.draw();
   461     });
   482     });
   462     this.editor_$.find("input, textarea").bind("keyup change", function() {
   483     this.editor_$.find("input, textarea").bind("keyup change", function() {
       
   484         _this.editor_$.find(".Rk-Edit-Goto").attr("href",_this.editor_$.find(".Rk-Edit-URI").val());
   463         var _data = {
   485         var _data = {
   464             title: _this.editor_$.find(".Rk-Edit-Title").val(),
   486             title: _this.editor_$.find(".Rk-Edit-Title").val(),
   465             description: _this.editor_$.find(".Rk-Edit-Description").val(),
   487             description: _this.editor_$.find(".Rk-Edit-Description").val(),
   466             uri: _this.editor_$.find(".Rk-Edit-URI").val()
   488             uri: _this.editor_$.find(".Rk-Edit-URI").val()
   467         }
   489         }
   501 }
   523 }
   502 
   524 
   503 Rkns.Renderer.EdgeEditor.prototype.template = Rkns._.template(
   525 Rkns.Renderer.EdgeEditor.prototype.template = Rkns._.template(
   504     '<h2><span class="Rk-CloseX">&times;</span><%=l10n.edit_edge%></span></h2>'
   526     '<h2><span class="Rk-CloseX">&times;</span><%=l10n.edit_edge%></span></h2>'
   505     + '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=edge.title%>"/></p>'
   527     + '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=edge.title%>"/></p>'
   506     + '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=edge.uri%>"/></p>'
   528     + '<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>'
   507     + '<p><label><%=l10n.edit_from%></label><span class="Rk-UserColor" style="background:<%=edge.from_created_by_color%>;"></span><%=edge.from_title%></p>'
   529     + '<p><label><%=l10n.edit_from%></label><span class="Rk-UserColor" style="background:<%=edge.from_created_by_color%>;"></span><%=edge.from_title%></p>'
   508     + '<p><label><%=l10n.edit_to%></label><span class="Rk-UserColor" style="background:<%=edge.to_created_by_color%>;"></span><%=edge.to_title%></p>'
   530     + '<p><label><%=l10n.edit_to%></label><span class="Rk-UserColor" style="background:<%=edge.to_created_by_color%>;"></span><%=edge.to_title%></p>'
   509     + '<p><label><%=l10n.created_by%> </label><span class="Rk-UserColor" style="background:<%=edge.created_by_color%>;"></span><%=edge.created_by_title%></p>'
   531     + '<p><label><%=l10n.created_by%> </label><span class="Rk-UserColor" style="background:<%=edge.created_by_color%>;"></span><%=edge.created_by_title%></p>'
   510 );
   532 );
   511 
   533 
   848     + '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%=l10n.zoom_in%>"></div><div class="Rk-ZoomOut" title="<%=l10n.zoom_out%>"></div></div>'
   870     + '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%=l10n.zoom_in%>"></div><div class="Rk-ZoomOut" title="<%=l10n.zoom_out%>"></div></div>'
   849     + '</div>'
   871     + '</div>'
   850 );
   872 );
   851 
   873 
   852 Rkns.Renderer.Scene.prototype.autoScale = function() {
   874 Rkns.Renderer.Scene.prototype.autoScale = function() {
   853     var _xx = this.renkan.project.get("nodes").map(function(_node) { return _node.get("position").x }),
   875     if (this.renkan.project.get("nodes").length) {
   854         _yy = this.renkan.project.get("nodes").map(function(_node) { return _node.get("position").y }),
   876         var _xx = this.renkan.project.get("nodes").map(function(_node) { return _node.get("position").x }),
   855         _minx = Math.min.apply(Math, _xx),
   877             _yy = this.renkan.project.get("nodes").map(function(_node) { return _node.get("position").y }),
   856         _miny = Math.min.apply(Math, _yy),
   878             _minx = Math.min.apply(Math, _xx),
   857         _maxx = Math.max.apply(Math, _xx),
   879             _miny = Math.min.apply(Math, _yy),
   858         _maxy = Math.max.apply(Math, _yy);
   880             _maxx = Math.max.apply(Math, _xx),
   859     this.scale = Math.min((paper.view.size.width - 2 * this._MARGIN_X) / (_maxx - _minx), (paper.view.size.height - 2 * this._MARGIN_Y) / (_maxy - _miny));
   881             _maxy = Math.max.apply(Math, _yy);
   860     this.offset = paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(this.scale));
   882         this.scale = Math.min((paper.view.size.width - 2 * this._MARGIN_X) / (_maxx - _minx), (paper.view.size.height - 2 * this._MARGIN_Y) / (_maxy - _miny));
   861     this.redraw();
   883         this.offset = paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(this.scale));
       
   884         this.redraw();
       
   885     }
   862 }
   886 }
   863 
   887 
   864 Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) {
   888 Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) {
   865     return _point.multiply(this.scale).add(this.offset);
   889     return _point.multiply(this.scale).add(this.offset);
   866 }
   890 }
   913             return _repr.type == _type;
   937             return _repr.type == _type;
   914         }),
   938         }),
   915         _this = this;
   939         _this = this;
   916     Rkns._(_representations).each(function(_repr) {
   940     Rkns._(_representations).each(function(_repr) {
   917         _this.removeRepresentation(_repr);
   941         _this.removeRepresentation(_repr);
       
   942     });
       
   943 }
       
   944 
       
   945 Rkns.Renderer.Scene.prototype.highlightModel = function(_model) {
       
   946     var _repr = this.getRepresentationByModel(_model);
       
   947     if (_repr) {
       
   948         _repr.highlight();
       
   949     }
       
   950 }
       
   951 
       
   952 Rkns.Renderer.Scene.prototype.unhighlightAll = function(_model) {
       
   953     Rkns._(this.representations).each(function(_repr) {
       
   954         _repr.unhighlight();
   918     });
   955     });
   919 }
   956 }
   920 
   957 
   921 Rkns.Renderer.Scene.prototype.redraw = function() {
   958 Rkns.Renderer.Scene.prototype.redraw = function() {
   922     Rkns._(this.representations).each(function(_representation) {
   959     Rkns._(this.representations).each(function(_representation) {