# HG changeset patch
# User cavaliet
# Date 1398694281 -7200
# Node ID 9ff388c9bc8d8993ca19e6580bac098f8df6b90b
# Parent 1be105c235c566883819e42bbf874726547590ef
model cleanup for views
diff -r 1be105c235c5 -r 9ff388c9bc8d client/js/models.js
--- a/client/js/models.js Sat Apr 26 21:28:54 2014 +0200
+++ b/client/js/models.js Mon Apr 28 16:11:21 2014 +0200
@@ -1,7 +1,7 @@
(function() {
"use strict";
var root = this;
-
+
var Backbone = root.Backbone;
var Models = root.Rkns.Models = {};
@@ -136,6 +136,18 @@
};
}
});
+
+ // View
+ var View = Models.View = RenkanModel.extend({
+ type: "view",
+ relations: [
+ {
+ type: Backbone.HasOne,
+ key: "created_by",
+ relatedModel: User
+ }
+ ],
+ });
// PROJECT
var Project = Models.Project = RenkanModel.extend({
@@ -167,6 +179,15 @@
key: 'project',
includeInJSON: '_id'
}
+ },
+ {
+ type: Backbone.HasMany,
+ key: "views",
+ relatedModel: View,
+ reverseRelation: {
+ key: 'project',
+ includeInJSON: '_id'
+ }
}
],
addUser: function(_props, _options) {
@@ -187,6 +208,14 @@
this.get("edges").push(_edge, _options);
return _edge;
},
+ addView: function(_props, _options) {
+ _props.project = this;
+ // TODO: check if need to replace with create only
+ var _view = View.findOrCreate(_props);
+ // TODO: Should we remember only one view?
+ this.get("views").push(_view, _options);
+ return _view;
+ },
removeNode: function(_model) {
this.get("nodes").remove(_model);
},
diff -r 1be105c235c5 -r 9ff388c9bc8d client/js/paper-renderer.js
--- a/client/js/paper-renderer.js Sat Apr 26 21:28:54 2014 +0200
+++ b/client/js/paper-renderer.js Mon Apr 28 16:11:21 2014 +0200
@@ -2,7 +2,7 @@
"use strict";
(function(root) {
-
+
var Rkns = root.Rkns,
_ = Rkns._,
$ = Rkns.$;
@@ -1796,12 +1796,15 @@
bindClick(".Rk-ZoomIn", "zoomIn");
bindClick(".Rk-ZoomFit", "autoScale");
this.$.find(".Rk-ZoomSave").click( function() {
- _this.renkan.project.set("views", [{id:Rkns.Utils.getUID('view'), zoom_level:_this.scale, offset_x:_this.offset.x, offset_y:_this.offset.y}]); // Save scale
+ // Save scale and offset point
+ _this.renkan.project.addView( { id:Rkns.Utils.getUID('view'), zoom_level:_this.scale, offset_x:_this.offset.x, offset_y:_this.offset.y } );
_this.$.find(".Rk-ZoomSetSaved").show();
});
this.$.find(".Rk-ZoomSetSaved").click( function() {
- var view = _this.renkan.project.get("views")[0];
- _this.setScale(view.zoom_level, new paper.Point(view.offset_x, view.offset_y));
+ var view = _this.renkan.project.get("views").last();
+ if(view){
+ _this.setScale(view.get("zoom_level"), new paper.Point(view.get("offset_x"), view.get("offset_y")));
+ }
});
if(this.renkan.read_only && !isNaN(parseInt(this.renkan.options.default_view))){
this.$.find(".Rk-ZoomSetSaved").show();
diff -r 1be105c235c5 -r 9ff388c9bc8d client/test/publish-test-min.html
--- a/client/test/publish-test-min.html Sat Apr 26 21:28:54 2014 +0200
+++ b/client/test/publish-test-min.html Mon Apr 28 16:11:21 2014 +0200
@@ -14,9 +14,8 @@