--- a/server/python/django/renkanmanager/static/renkanmanager/lib/renkan/js/renkan.js Sat Mar 28 04:28:21 2015 +0100
+++ b/server/python/django/renkanmanager/static/renkanmanager/lib/renkan/js/renkan.js Mon Mar 30 09:53:48 2015 +0200
@@ -598,13 +598,14 @@
var Models = root.Rkns.Models = {};
-
Models.getUID = function(obj) {
- var guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
- var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
- return v.toString(16);
- });
- if(typeof obj !== 'undefined') {
+ var guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
+ function(c) {
+ var r = Math.random() * 16 | 0, v = c === 'x' ? r
+ : (r & 0x3 | 0x8);
+ return v.toString(16);
+ });
+ if (typeof obj !== 'undefined') {
return obj.type + "-" + guid;
}
else {
@@ -612,10 +613,9 @@
}
};
-
var RenkanModel = Backbone.RelationalModel.extend({
idAttribute : "_id",
- constructor: function(options) {
+ constructor : function(options) {
if (typeof options !== "undefined") {
options._id = options._id || options.id || Models.getUID(this);
@@ -623,220 +623,218 @@
options.description = options.description || "";
options.uri = options.uri || "";
- if(typeof this.prepare === "function") {
+ if (typeof this.prepare === "function") {
options = this.prepare(options);
}
}
Backbone.RelationalModel.prototype.constructor.call(this, options);
},
- validate: function() {
- if(!this.type) {
+ validate : function() {
+ if (!this.type) {
return "object has no type";
}
},
addReference : function(_options, _propName, _list, _id, _default) {
var _element = _list.get(_id);
- if (typeof _element === "undefined" && typeof _default !== "undefined") {
- _options[_propName ] = _default;
+ if (typeof _element === "undefined" &&
+ typeof _default !== "undefined") {
+ _options[_propName] = _default;
}
else {
- _options[_propName ] = _element;
+ _options[_propName] = _element;
}
}
});
// USER
var User = Models.User = RenkanModel.extend({
- type: "user",
- prepare: function(options) {
+ type : "user",
+ prepare : function(options) {
options.color = options.color || "#666666";
return options;
},
- toJSON: function() {
+ toJSON : function() {
return {
- _id: this.get("_id"),
- title: this.get("title"),
- uri: this.get("uri"),
- description: this.get("description"),
- color: this.get("color")
+ _id : this.get("_id"),
+ title : this.get("title"),
+ uri : this.get("uri"),
+ description : this.get("description"),
+ color : this.get("color")
};
}
});
// NODE
var Node = Models.Node = RenkanModel.extend({
- type: "node",
- relations: [{
- type: Backbone.HasOne,
- key: "created_by",
- relatedModel: User
- }],
- prepare: function(options) {
+ type : "node",
+ relations : [ {
+ type : Backbone.HasOne,
+ key : "created_by",
+ relatedModel : User
+ } ],
+ prepare : function(options) {
var project = options.project;
- this.addReference(options, "created_by", project.get("users"), options.created_by, project.current_user);
+ this.addReference(options, "created_by", project.get("users"),
+ options.created_by, project.current_user);
options.description = options.description || "";
return options;
},
- toJSON: function() {
+ toJSON : function() {
return {
- _id: this.get("_id"),
- title: this.get("title"),
- uri: this.get("uri"),
- description: this.get("description"),
- position: this.get("position"),
- image: this.get("image"),
- color: this.get("color"),
- created_by: this.get("created_by") ? this.get("created_by").get("_id") : null,
- size: this.get("size"),
- clip_path: this.get("clip_path"),
- shape: this.get("shape")
+ _id : this.get("_id"),
+ title : this.get("title"),
+ uri : this.get("uri"),
+ description : this.get("description"),
+ position : this.get("position"),
+ image : this.get("image"),
+ color : this.get("color"),
+ created_by : this.get("created_by") ? this.get("created_by")
+ .get("_id") : null,
+ size : this.get("size"),
+ clip_path : this.get("clip_path"),
+ shape : this.get("shape")
};
}
});
// EDGE
var Edge = Models.Edge = RenkanModel.extend({
- type: "edge",
- relations: [
- {
- type: Backbone.HasOne,
- key: "created_by",
- relatedModel: User
- },
- {
- type: Backbone.HasOne,
- key: "from",
- relatedModel: Node
- },
- {
- type: Backbone.HasOne,
- key: "to",
- relatedModel: Node
- }
- ],
- prepare: function(options) {
+ type : "edge",
+ relations : [ {
+ type : Backbone.HasOne,
+ key : "created_by",
+ relatedModel : User
+ }, {
+ type : Backbone.HasOne,
+ key : "from",
+ relatedModel : Node
+ }, {
+ type : Backbone.HasOne,
+ key : "to",
+ relatedModel : Node
+ } ],
+ prepare : function(options) {
var project = options.project;
- this.addReference(options, "created_by", project.get("users"), options.created_by, project.current_user);
- this.addReference(options, "from", project.get("nodes"), options.from);
+ this.addReference(options, "created_by", project.get("users"),
+ options.created_by, project.current_user);
+ this.addReference(options, "from", project.get("nodes"),
+ options.from);
this.addReference(options, "to", project.get("nodes"), options.to);
return options;
},
- toJSON: function() {
+ toJSON : function() {
return {
- _id: this.get("_id"),
- title: this.get("title"),
- uri: this.get("uri"),
- description: this.get("description"),
- from: this.get("from") ? this.get("from").get("_id") : null,
- to: this.get("to") ? this.get("to").get("_id") : null,
- color: this.get("color"),
- created_by: this.get("created_by") ? this.get("created_by").get("_id") : null
+ _id : this.get("_id"),
+ title : this.get("title"),
+ uri : this.get("uri"),
+ description : this.get("description"),
+ from : this.get("from") ? this.get("from").get("_id") : null,
+ to : this.get("to") ? this.get("to").get("_id") : null,
+ color : this.get("color"),
+ created_by : this.get("created_by") ? this.get("created_by")
+ .get("_id") : null
};
}
});
// View
var View = Models.View = RenkanModel.extend({
- type: "view",
- relations: [
- {
- type: Backbone.HasOne,
- key: "created_by",
- relatedModel: User
- }
- ],
- prepare: function(options) {
+ type : "view",
+ relations : [ {
+ type : Backbone.HasOne,
+ key : "created_by",
+ relatedModel : User
+ } ],
+ prepare : function(options) {
var project = options.project;
- this.addReference(options, "created_by", project.get("users"), options.created_by, project.current_user);
+ this.addReference(options, "created_by", project.get("users"),
+ options.created_by, project.current_user);
options.description = options.description || "";
- if(typeof options.offset !== "undefined") {
+ if (typeof options.offset !== "undefined") {
var offset = {};
if (Array.isArray(options.offset)) {
- offset.x = options.offset[0];
- offset.y = options.offset.length > 1 ? options.offset[1] : options.offset[0];
+ offset.x = options.offset[0];
+ offset.y = options.offset.length > 1 ? options.offset[1]
+ : options.offset[0];
}
else if (options.offset.x != null) {
- offset.x = options.offset.x;
- offset.y = options.offset.y;
+ offset.x = options.offset.x;
+ offset.y = options.offset.y;
}
options.offset = offset;
}
return options;
},
- toJSON: function() {
+ toJSON : function() {
return {
- _id: this.get("_id"),
- zoom_level: this.get("zoom_level"),
- offset: this.get("offset"),
- title: this.get("title"),
- description: this.get("description"),
- created_by: this.get("created_by") ? this.get("created_by").get("_id") : null
- // Don't need project id
+ _id : this.get("_id"),
+ zoom_level : this.get("zoom_level"),
+ offset : this.get("offset"),
+ title : this.get("title"),
+ description : this.get("description"),
+ created_by : this.get("created_by") ? this.get("created_by")
+ .get("_id") : null
+ // Don't need project id
};
}
});
// PROJECT
var Project = Models.Project = RenkanModel.extend({
- type: "project",
- blacklist: ['save_status',],
- relations: [
- {
- type: Backbone.HasMany,
- key: "users",
- relatedModel: User,
- reverseRelation: {
- key: 'project',
- includeInJSON: '_id'
+ type : "project",
+ blacklist : [ 'save_status', ],
+ relations : [ {
+ type : Backbone.HasMany,
+ key : "users",
+ relatedModel : User,
+ reverseRelation : {
+ key : 'project',
+ includeInJSON : '_id'
}
- },
- {
- type: Backbone.HasMany,
- key: "nodes",
- relatedModel: Node,
- reverseRelation: {
- key: 'project',
- includeInJSON: '_id'
+ }, {
+ type : Backbone.HasMany,
+ key : "nodes",
+ relatedModel : Node,
+ reverseRelation : {
+ key : 'project',
+ includeInJSON : '_id'
}
- },
- {
- type: Backbone.HasMany,
- key: "edges",
- relatedModel: Edge,
- reverseRelation: {
- key: 'project',
- includeInJSON: '_id'
+ }, {
+ type : Backbone.HasMany,
+ key : "edges",
+ relatedModel : Edge,
+ reverseRelation : {
+ key : 'project',
+ includeInJSON : '_id'
}
- },
- {
- type: Backbone.HasMany,
- key: "views",
- relatedModel: View,
- reverseRelation: {
- key: 'project',
- includeInJSON: '_id'
+ }, {
+ type : Backbone.HasMany,
+ key : "views",
+ relatedModel : View,
+ reverseRelation : {
+ key : 'project',
+ includeInJSON : '_id'
}
- }
- ],
- addUser: function(_props, _options) {
+ } ],
+ addUser : function(_props, _options) {
_props.project = this;
var _user = User.findOrCreate(_props);
this.get("users").push(_user, _options);
return _user;
},
- addNode: function(_props, _options) {
+ addNode : function(_props, _options) {
_props.project = this;
var _node = Node.findOrCreate(_props);
this.get("nodes").push(_node, _options);
return _node;
},
- addEdge: function(_props, _options) {
+ addEdge : function(_props, _options) {
_props.project = this;
var _edge = Edge.findOrCreate(_props);
this.get("edges").push(_edge, _options);
return _edge;
},
- addView: function(_props, _options) {
+ addView : function(_props, _options) {
_props.project = this;
// TODO: check if need to replace with create only
var _view = View.findOrCreate(_props);
@@ -844,92 +842,100 @@
this.get("views").push(_view, _options);
return _view;
},
- removeNode: function(_model) {
+ removeNode : function(_model) {
this.get("nodes").remove(_model);
},
- removeEdge: function(_model) {
+ removeEdge : function(_model) {
this.get("edges").remove(_model);
},
- validate: function(options) {
+ validate : function(options) {
var _project = this;
- _([].concat(options.users, options.nodes, options.edges, options.views)).each(function(_item) {
- if(_item) {
+ _(
+ [].concat(options.users, options.nodes, options.edges,
+ options.views)).each(function(_item) {
+ if (_item) {
_item.project = _project;
}
});
},
// Add event handler to remove edges when a node is removed
- initialize: function() {
+ initialize : function() {
var _this = this;
this.on("remove:nodes", function(_node) {
_this.get("edges").remove(
- _this.get("edges").filter(function(_edge) {
- return _edge.get("from") === _node || _edge.get("to") === _node;
- })
- );
+ _this.get("edges").filter(
+ function(_edge) {
+ return _edge.get("from") === _node ||
+ _edge.get("to") === _node;
+ }));
});
},
- toJSON: function(){
- var json = _.clone(this.attributes);
- for(var attr in json) {
- if((json[attr] instanceof Backbone.Model) || (json[attr] instanceof Backbone.Collection) || (json[attr] instanceof RenkanModel)) {
- json[attr] = json[attr].toJSON();
- }
- }
- return _.omit(json, this.blacklist);
+ toJSON : function() {
+ var json = _.clone(this.attributes);
+ for ( var attr in json) {
+ if ((json[attr] instanceof Backbone.Model) ||
+ (json[attr] instanceof Backbone.Collection) ||
+ (json[attr] instanceof RenkanModel)) {
+ json[attr] = json[attr].toJSON();
+ }
+ }
+ return _.omit(json, this.blacklist);
}
});
- var RosterUser = Models.RosterUser = Backbone.Model.extend({
- type: "roster_user",
- idAttribute : "_id",
-
- constructor: function(options) {
-
- if (typeof options !== "undefined") {
- options._id = options._id || options.id || Models.getUID(this);
- options.title = options.title || "(untitled " + this.type + ")";
- options.description = options.description || "";
- options.uri = options.uri || "";
- options.project = options.project || null;
- options.site_id = options.site_id || 0;
-
- if(typeof this.prepare === "function") {
- options = this.prepare(options);
+ var RosterUser = Models.RosterUser = Backbone.Model
+ .extend({
+ type : "roster_user",
+ idAttribute : "_id",
+
+ constructor : function(options) {
+
+ if (typeof options !== "undefined") {
+ options._id = options._id ||
+ options.id ||
+ Models.getUID(this);
+ options.title = options.title || "(untitled " + this.type + ")";
+ options.description = options.description || "";
+ options.uri = options.uri || "";
+ options.project = options.project || null;
+ options.site_id = options.site_id || 0;
+
+ if (typeof this.prepare === "function") {
+ options = this.prepare(options);
+ }
+ }
+ Backbone.Model.prototype.constructor.call(this, options);
+ },
+
+ validate : function() {
+ if (!this.type) {
+ return "object has no type";
+ }
+ },
+
+ prepare : function(options) {
+ options.color = options.color || "#666666";
+ return options;
+ },
+
+ toJSON : function() {
+ return {
+ _id : this.get("_id"),
+ title : this.get("title"),
+ uri : this.get("uri"),
+ description : this.get("description"),
+ color : this.get("color"),
+ project : (this.get("project") != null) ? this.get(
+ "project").get("id") : null,
+ site_id : this.get("site_id")
+ };
}
- }
- Backbone.Model.prototype.constructor.call(this, options);
- },
-
- validate: function() {
- if(!this.type) {
- return "object has no type";
- }
- },
-
- prepare: function(options) {
- options.color = options.color || "#666666";
- return options;
- },
-
- toJSON: function() {
- return {
- _id: this.get("_id"),
- title: this.get("title"),
- uri: this.get("uri"),
- description: this.get("description"),
- color: this.get("color"),
- project: (this.get("project") != null)?this.get("project").get("id"):null,
- site_id: this.get("site_id")
- };
- }
- });
+ });
var UsersList = Models.UsersList = Backbone.Collection.extend({
- model: RosterUser
+ model : RosterUser
});
-
}).call(window);
Rkns.defaults = {
@@ -975,8 +981,10 @@
/* zoom options */
show_zoom: true,
/* show zoom buttons */
+ save_view: true,
+ /* show buttons to save view */
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... */
+ /* Allows to load default view (zoom+offset) at start on read_only mode, instead of autoScale. the default_view will be the last */
/* TOP BAR BUTTONS */
@@ -1201,35 +1209,46 @@
}
var _load = function() {
_renkan.renderer.redrawActive = false;
- _proj.set({loading_status:true});
+ _proj.set({
+ loading_status : true
+ });
Rkns.$.getJSON(_opts.url, function(_data) {
- _proj.set(_data, {validate: true});
- _proj.set({loading_status:false});
- _proj.set({save_status:0});
+ _proj.set(_data, {
+ validate : true
+ });
+ _proj.set({
+ loading_status : false
+ });
+ _proj.set({
+ save_status : 0
+ });
_renkan.renderer.redrawActive = true;
- _renkan.renderer.autoScale();
+ _renkan.renderer.fixSize();
});
};
var _save = function() {
- _proj.set({save_status:2});
+ _proj.set({
+ save_status : 2
+ });
var _data = _proj.toJSON();
if (!_renkan.read_only) {
Rkns.$.ajax({
- type: _opts.http_method,
- url: _opts.url,
- contentType: "application/json",
- data: JSON.stringify(_data),
- success: function(data, textStatus, jqXHR) {
- _proj.set({save_status:0});
+ type : _opts.http_method,
+ url : _opts.url,
+ contentType : "application/json",
+ data : JSON.stringify(_data),
+ success : function(data, textStatus, jqXHR) {
+ _proj.set({
+ save_status : 0
+ });
}
});
}
};
- var _thrSave = Rkns._.throttle(
- function() {
- setTimeout(_save, 100);
- }, 1000);
+ var _thrSave = Rkns._.throttle(function() {
+ setTimeout(_save, 100);
+ }, 1000);
_proj.on("add:nodes add:edges add:users add:views", function(_model) {
_model.on("change remove", function(_model) {
_thrSave();
@@ -1237,9 +1256,10 @@
_thrSave();
});
_proj.on("change", function() {
- if(!(_proj.changedAttributes.length === 1 && _proj.hasChanged('save_status'))) {
- _thrSave();
- }
+ if (!(_proj.changedAttributes.length === 1 && _proj
+ .hasChanged('save_status'))) {
+ _thrSave();
+ }
});
_load();
@@ -3916,7 +3936,7 @@
_this.setScale(view.get("zoom_level"), new paper.Point(view.get("offset")));
}
});
- if(this.renkan.project.get("views").length > 0 && !isNaN(parseInt(this.renkan.options.default_view))){
+ if(this.renkan.project.get("views").length > 0 && this.renkan.options.save_view){
this.$.find(".Rk-ZoomSetSaved").show();
}
this.$.find(".Rk-CurrentUser").mouseenter(
@@ -4066,7 +4086,7 @@
);
window.setTimeout(
function() {
- _this.fixSize(true);
+ _this.fixSize();
},
_delay
);
@@ -4074,7 +4094,7 @@
if (_renkan.options.force_resize) {
$(window).resize(function() {
- _this.fixSize(false);
+ _this.autoScale();
});
}
@@ -4190,20 +4210,17 @@
'<div class="Rk-Labels"></div><canvas class="Rk-Canvas" <% if (options.resize) { %> resize="" <% } %>></canvas><div class="Rk-Notifications"></div><div class="Rk-Editor">' +
'<% if (options.show_bins) { %><div class="Rk-Fold-Bins">«</div><% } %>' +
'<% if (options.show_zoom) { %><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>' +
- '<% if (options.editor_mode && !isNaN(parseInt(options.default_view))) { %><div class="Rk-ZoomSave" title="<%-translate("Zoom Save")%>"></div><% } %>' +
- '<% if (!isNaN(parseInt(options.default_view))) { %><div class="Rk-ZoomSetSaved" title="<%-translate("View saved zoom")%>"></div><% } %></div><% } %>' +
+ '<% if (options.editor_mode && options.save_view) { %><div class="Rk-ZoomSave" title="<%-translate("Zoom Save")%>"></div><% } %>' +
+ '<% if (options.save_view) { %><div class="Rk-ZoomSetSaved" title="<%-translate("View saved zoom")%>"></div><% } %></div><% } %>' +
'</div></div>'
),
- fixSize: function(_autoscale) {
-
- if (_autoscale) {
- // 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();
- }
+ fixSize: function() {
+ if( this.renkan.options.default_view && this.renkan.project.get("views").length > 0) {
+ var view = this.renkan.project.get("views").last();
+ this.setScale(view.get("zoom_level"), new paper.Point(view.get("offset")));
+ }
+ else{
+ this.autoScale();
}
},
drawSector: function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) {