set default view on read only mode.
--- a/client/data/example-cinema.json Mon Feb 17 17:58:39 2014 +0100
+++ b/client/data/example-cinema.json Tue Feb 18 16:54:41 2014 +0100
@@ -619,5 +619,13 @@
"anonymous": true
}
],
- "space_id": "17f968e4-2640-4319-aa61-b5b8b527ebb4"
+ "space_id": "17f968e4-2640-4319-aa61-b5b8b527ebb4",
+ "views": [
+ {
+ "id": "view-2014-02-18-628af15b-12ad-457a-8ac0-a28c8998cc3b-0001",
+ "zoom_level": 0.8275032552816195,
+ "offset_x": 832.0104075533723,
+ "offset_y": 402.8917139487223
+ }
+ ]
}
\ No newline at end of file
--- a/client/js/defaults.js Mon Feb 17 17:58:39 2014 +0100
+++ b/client/js/defaults.js Tue Feb 18 16:54:41 2014 +0100
@@ -36,6 +36,8 @@
/* Delay between clicking on the bin on an element and really deleting it
Set to 0 for delete confirm */
autoscale_padding: 50,
+ default_view: false,
+ /* Allows to load default view (zoom+offset) at start on read_only mode, instead of autoScale. default_view has to be an integer 0,1,2... */
/* TOP BAR BUTTONS */
show_search_field: true,
--- a/client/js/paper-renderer.js Mon Feb 17 17:58:39 2014 +0100
+++ b/client/js/paper-renderer.js Tue Feb 18 16:54:41 2014 +0100
@@ -1803,6 +1803,9 @@
var view = _this.renkan.project.get("views")[0];
_this.setScale(view.zoom_level, new paper.Point(view.offset_x, view.offset_y));
});
+ if(this.renkan.read_only && !isNaN(parseInt(this.renkan.options.default_view))){
+ this.$.find(".Rk-ZoomSetSaved").show();
+ }
this.$.find(".Rk-CurrentUser").mouseenter(
function() { _this.$.find(".Rk-UserList").slideDown(); }
);
@@ -2013,7 +2016,8 @@
+ '<div class="Rk-Labels"></div><canvas class="Rk-Canvas" resize></canvas><div class="Rk-Notifications"></div><div class="Rk-Editor">'
+ '<% if (options.show_bins) { %><div class="Rk-Fold-Bins">«</div><% } %>'
+ '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%-translate("Zoom In")%>"></div><div class="Rk-ZoomFit" title="<%-translate("Zoom Fit")%>"></div><div class="Rk-ZoomOut" title="<%-translate("Zoom Out")%>"></div>'
- + '<div class="Rk-ZoomSave" title="<%-translate("Zoom Save")%>"></div><div class="Rk-ZoomSetSaved" title="<%-translate("View saved zoom")%>"></div></div>'
+ + '<% if (options.editor_mode) { %><div class="Rk-ZoomSave" title="<%-translate("Zoom Save")%>"></div><% } %>'
+ + '<% if (options.editor_mode || !isNaN(parseInt(options.default_view))) { %><div class="Rk-ZoomSetSaved" title="<%-translate("View saved zoom")%>"></div><% } %></div>'
+ '</div></div>'
),
fixSize: function(_autoscale) {
@@ -2031,8 +2035,13 @@
paper.view.viewSize = new paper.Size([w, h]);
if (_autoscale) {
- // If _autoscale, we get the initial zoom level set in the project datas.
- this.autoScale(this.renkan.project.get("zoom_level"));
+ // If _autoscale, we get the initial view (zoom+offset) set in the project datas.
+ if(this.renkan.read_only && !isNaN(parseInt(this.renkan.options.default_view))){
+ this.autoScale(this.renkan.project.get("views")[parseInt(this.renkan.options.default_view)]);
+ }
+ else{
+ this.autoScale();
+ }
}
},
drawSector: function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) {
@@ -2191,8 +2200,8 @@
this.redraw();
}
},
-autoScale: function(force_scale) {
- console.log("autoScale", force_scale);
+autoScale: function(force_view) {
+ console.log("autoScale", force_view);
var nodes = this.renkan.project.get("nodes");
if (nodes.length > 1) {
var _xx = nodes.map(function(_node) { return _node.get("position").x; }),
@@ -2204,10 +2213,12 @@
var _scale = Math.min( (paper.view.size.width - 2 * this.renkan.options.autoscale_padding) / (_maxx - _minx), (paper.view.size.height - 2 * this.renkan.options.autoscale_padding) / (_maxy - _miny));
this.initialScale = _scale;
// Override calculated scale if asked
- if((typeof force_scale !== "undefined") && parseFloat(force_scale)>0){
- _scale = parseFloat(force_scale);
+ if((typeof force_view !== "undefined") && parseFloat(force_view.zoom_level)>0 && parseFloat(force_view.offset_x)>0 && parseFloat(force_view.offset_y)>0){
+ this.setScale(parseFloat(force_view.zoom_level), new paper.Point(parseFloat(force_view.offset_x), parseFloat(force_view.offset_y)));
}
- this.setScale(_scale, paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)));
+ else{
+ this.setScale(_scale, paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)));
+ }
}
if (nodes.length === 1) {
this.setScale(1, paper.view.center.subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y])));
--- a/client/test/test-readonly-div.html Mon Feb 17 17:58:39 2014 +0100
+++ b/client/test/test-readonly-div.html Tue Feb 18 16:54:41 2014 +0100
@@ -12,14 +12,23 @@
<script src="../lib/backbone.js"></script>
<script src="../lib/backbone-relational.js"></script>
<script src="../lib/paper.js"></script>
- <script src="../../build/renkan.js"></script>
+ <script src="../js/main.js"></script>
+ <script src="../js/defaults.js"></script>
+ <script src="../js/i18n.js"></script>
+ <script src="../js/models.js"></script>
+ <script src="../js/full-json.js"></script>
+ <script src="../js/list-bin.js"></script>
+ <script src="../js/ldtjson-bin.js"></script>
+ <script src="../js/wikipedia-bin.js"></script>
+ <script src="../js/paper-renderer.js"></script>
<script type="text/javascript">
var _renkan;
$(function() {
_renkan = new Rkns.Renkan({
editor_mode: false,
show_bins: false,
- static_url: "../"
+ static_url: "../",
+ default_view:0
});
Rkns.jsonIO(_renkan, {
url: "../data/example-cinema.json"