diff -r cf48c6d69717 -r f9019462465a client/js/paper-renderer.js --- a/client/js/paper-renderer.js Thu Feb 14 12:25:58 2013 +0100 +++ b/client/js/paper-renderer.js Thu Feb 14 17:39:52 2013 +0100 @@ -218,6 +218,12 @@ Rkns.Renderer._BaseRepresentation.prototype[_func].apply(this, Array.prototype.slice.call(arguments, 1)); } +Rkns.Renderer._BaseRepresentation.prototype.moveTo = function() {} + +Rkns.Renderer._BaseRepresentation.prototype.show = function() {} + +Rkns.Renderer._BaseRepresentation.prototype.hide = function() {} + Rkns.Renderer._BaseRepresentation.prototype.select = function() {} Rkns.Renderer._BaseRepresentation.prototype.unselect = function() {} @@ -253,12 +259,19 @@ fontSize: Rkns.Renderer._NODE_FONT_SIZE, fillColor: 'black' }; - this.edit_button = new Rkns.Renderer.NodeEditButton(this.renderer, null); - this.edit_button.node_representation = this; - this.remove_button = new Rkns.Renderer.NodeRemoveButton(this.renderer, null); - this.remove_button.node_representation = this; - this.link_button = new Rkns.Renderer.NodeLinkButton(this.renderer, null); - this.link_button.node_representation = this; + if (this.renderer.renkan.read_only) { + this.edit_button = new Rkns.Renderer._BaseRepresentation(this.renderer, null); + this.remove_button = new Rkns.Renderer._BaseRepresentation(this.renderer, null); + this.link_button = new Rkns.Renderer._BaseRepresentation(this.renderer, null); + } else { + this.edit_button = new Rkns.Renderer.NodeEditButton(this.renderer, null); + this.edit_button.node_representation = this; + this.remove_button = new Rkns.Renderer.NodeRemoveButton(this.renderer, null); + this.remove_button.node_representation = this; + this.link_button = new Rkns.Renderer.NodeLinkButton(this.renderer, null); + this.link_button.node_representation = this; + } + this.title.paragraphStyle.justification = 'center'; } @@ -342,6 +355,9 @@ _el.addClass("selected"); } }); + if (this.renderer.renkan.read_only) { + this.openEditor(); + } } Rkns.Renderer.Node.prototype.unselect = function(_newTarget) { @@ -380,11 +396,13 @@ } Rkns.Renderer.Node.prototype.mouseup = function(_event) { - if (this.renderer.is_dragging) { - this.saveCoords(); - } - else { - this.openEditor(); + if (!this.renderer.renkan.read_only) { + if (this.renderer.is_dragging) { + this.saveCoords(); + } + else { + this.openEditor(); + } } this.renderer.click_target = null; this.renderer.is_dragging = false; @@ -427,10 +445,15 @@ this.text.paragraphStyle.justification = 'center'; this.text_angle = 0; this.arrow_angle = 0; - this.edit_button = new Rkns.Renderer.EdgeEditButton(this.renderer, null); - this.edit_button.edge_representation = this; - this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this.renderer, null); - this.remove_button.edge_representation = this; + if (this.renderer.renkan.read_only) { + this.edit_button = new Rkns.Renderer._BaseRepresentation(this.renderer, null); + this.remove_button = new Rkns.Renderer._BaseRepresentation(this.renderer, null); + } else { + this.edit_button = new Rkns.Renderer.EdgeEditButton(this.renderer, null); + this.edit_button.edge_representation = this; + this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this.renderer, null); + this.remove_button.edge_representation = this; + } } Rkns.Renderer.Edge.prototype.redraw = function() { @@ -482,6 +505,9 @@ this.line.strokeWidth = 4; this.edit_button.show(); this.remove_button.show(); + if (this.renderer.renkan.read_only) { + this.openEditor(); + } } Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) { @@ -493,11 +519,13 @@ } Rkns.Renderer.Edge.prototype.mouseup = function(_event) { - if (this.renderer.is_dragging) { - this.from_representation.saveCoords(); - this.to_representation.saveCoords(); - } else { - this.openEditor(); + if (!this.renderer.renkan.read_only) { + if (this.renderer.is_dragging) { + this.from_representation.saveCoords(); + this.to_representation.saveCoords(); + } else { + this.openEditor(); + } } this.renderer.click_target = null; this.renderer.is_dragging = false; @@ -627,11 +655,19 @@ + '
<%=node.created_by_title%>
' ); +Rkns.Renderer.NodeEditor.prototype.readOnlyTemplate = Rkns._.template( + '<%-node.description%>
' + + '<%=node.created_by_title%>
' +); + Rkns.Renderer.NodeEditor.prototype.draw = function() { var _model = this.node_representation.model, - _created_by = _model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER; + _created_by = _model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER, + _template = (this.renderer.renkan.read_only ? this.readOnlyTemplate : this.template); this.editor_$ - .html(this.template({ + .html(_template({ node: { title: _model.get("title"), uri: _model.get("uri"), @@ -649,34 +685,36 @@ _this.renderer.removeRepresentation(_this); paper.view.draw(); }); - this.editor_$.find("input, textarea").bind("keyup change", function() { - var _uri = _this.editor_$.find(".Rk-Edit-URI").val(), - _image = _this.editor_$.find(".Rk-Edit-Image").val(); - _this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _image); - _this.editor_$.find(".Rk-Edit-Goto").attr("href",_uri); - var _data = { - title: _this.editor_$.find(".Rk-Edit-Title").val(), - description: _this.editor_$.find(".Rk-Edit-Description").val(), - uri: _uri, - image: _image - } - _model.set(_data); - _this.redraw(); - }); + if (!this.renderer.renkan.read_only) { + this.editor_$.find("input, textarea").bind("keyup change", function() { + var _uri = _this.editor_$.find(".Rk-Edit-URI").val(), + _image = _this.editor_$.find(".Rk-Edit-Image").val(); + _this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _image); + _this.editor_$.find(".Rk-Edit-Goto").attr("href",_uri); + var _data = { + title: _this.editor_$.find(".Rk-Edit-Title").val(), + description: _this.editor_$.find(".Rk-Edit-Description").val(), + uri: _uri, + image: _image + } + _model.set(_data); + _this.redraw(); + }); + this.editor_$.find(".Rk-Edit-Title")[0].focus(); + this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( + function() { _this.editor_$.find(".Rk-Edit-ColorPicker").show(); }, + function() { _this.editor_$.find(".Rk-Edit-ColorPicker").hide(); } + ); + this.editor_$.find(".Rk-Edit-ColorPicker li").hover( + function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); }, + function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color")) } + ).click(function() { + _model.set("color", $(this).attr("data-color")); + _this.redraw(); + }); + } this.editor_$.find("img").load(function() { _this.redraw(); - }) - this.editor_$.find(".Rk-Edit-Title")[0].focus(); - this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( - function() { _this.editor_$.find(".Rk-Edit-ColorPicker").show(); }, - function() { _this.editor_$.find(".Rk-Edit-ColorPicker").hide(); } - ); - this.editor_$.find(".Rk-Edit-ColorPicker li").hover( - function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); }, - function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color")) } - ).click(function() { - _model.set("color", $(this).attr("data-color")); - _this.redraw(); }); } @@ -726,13 +764,23 @@ + '<%=edge.created_by_title%>
' ); +Rkns.Renderer.EdgeEditor.prototype.readOnlyTemplate = Rkns._.template( + '<%-edge.description%>
' + + '<%=edge.from_title%>
' + + '<%=edge.to_title%>
' + + '<%=edge.created_by_title%>
' +); + Rkns.Renderer.EdgeEditor.prototype.draw = function() { var _model = this.edge_representation.model, _from_model = _model.get("from"), _to_model = _model.get("to"), - _created_by = _model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER; + _created_by = _model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER, + _template = (this.renderer.renkan.read_only ? this.readOnlyTemplate : this.template); this.editor_$ - .html(this.template({ + .html(_template({ edge: { title: _model.get("title"), uri: _model.get("uri"), @@ -753,27 +801,30 @@ _this.renderer.removeRepresentation(_this); paper.view.draw(); }); - this.editor_$.find("input, textarea").bind("keyup change", function() { - _this.editor_$.find(".Rk-Edit-Goto").attr("href",_this.editor_$.find(".Rk-Edit-URI").val()); - var _data = { - title: _this.editor_$.find(".Rk-Edit-Title").val(), - uri: _this.editor_$.find(".Rk-Edit-URI").val() - } - _model.set(_data); - _this.redraw(); - }); - this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( - function() { _this.editor_$.find(".Rk-Edit-ColorPicker").show(); }, - function() { _this.editor_$.find(".Rk-Edit-ColorPicker").hide(); } - ); - this.editor_$.find(".Rk-Edit-ColorPicker li").hover( - function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); }, - function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color")); } - ).click(function() { - _model.set("color", $(this).attr("data-color")); - _this.redraw(); - }); + if (!this.renderer.renkan.read_only) { + this.editor_$.find("input, textarea").bind("keyup change", function() { + _this.editor_$.find(".Rk-Edit-Goto").attr("href",_this.editor_$.find(".Rk-Edit-URI").val()); + var _data = { + title: _this.editor_$.find(".Rk-Edit-Title").val(), + uri: _this.editor_$.find(".Rk-Edit-URI").val() + } + _model.set(_data); + _this.redraw(); + }); + this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( + function() { _this.editor_$.find(".Rk-Edit-ColorPicker").show(); }, + function() { _this.editor_$.find(".Rk-Edit-ColorPicker").hide(); } + ); + this.editor_$.find(".Rk-Edit-ColorPicker li").hover( + function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); }, + function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color")); } + ).click(function() { + _model.set("color", $(this).attr("data-color")); + _this.redraw(); + }); + } } + Rkns.Renderer.EdgeEditor.prototype.redraw = function() { var _coords = this.edge_representation.paper_coords; Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 5, this.editor_$); @@ -1143,18 +1194,31 @@ _this.addRepresentation("Edge", _edge); _thRedraw(); }); + this.renkan.project.on("change:title", function(_model, _title) { + var el = $(".Rk-PadTitle"); + if (el.is("input")) { + if (el.val() !== _title) { + el.val(_title); + } + } else { + el.text(_title); + } + }); this.redraw(); } Rkns.Renderer.Scene.prototype.template = Rkns._.template( - '