# HG changeset patch # User ymh # Date 1432509492 -7200 # Node ID 4c7ab16e58459ca9a16a3cbfe4d576b8824c538f # Parent adb907bba95656bacfc9090eb250819c122b0653 best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export add the schema version to export, to prepare for schema migrations. diff -r adb907bba956 -r 4c7ab16e5845 client/js/full-json.js --- a/client/js/full-json.js Fri May 22 17:48:14 2015 +0200 +++ b/client/js/full-json.js Mon May 25 01:18:12 2015 +0200 @@ -8,17 +8,17 @@ var _load = function() { _renkan.renderer.redrawActive = false; _proj.set({ - loading_status : true + loadingStatus : true }); Rkns.$.getJSON(_opts.url, function(_data) { _proj.set(_data, { validate : true }); _proj.set({ - loading_status : false + loadingStatus : false }); _proj.set({ - save_status : 0 + saveStatus : 0 }); _renkan.renderer.redrawActive = true; _renkan.renderer.fixSize(); @@ -26,7 +26,7 @@ }; var _save = function() { _proj.set({ - save_status : 2 + saveStatus : 2 }); var _data = _proj.toJSON(); if (!_renkan.read_only) { @@ -37,7 +37,7 @@ data : JSON.stringify(_data), success : function(data, textStatus, jqXHR) { _proj.set({ - save_status : 0 + saveStatus : 0 }); } }); @@ -55,7 +55,7 @@ }); _proj.on("change", function() { if (!(_proj.changedAttributes.length === 1 && _proj - .hasChanged('save_status'))) { + .hasChanged('saveStatus'))) { _thrSave(); } }); diff -r adb907bba956 -r 4c7ab16e5845 client/js/models.js --- a/client/js/models.js Fri May 22 17:48:14 2015 +0200 +++ b/client/js/models.js Mon May 25 01:18:12 2015 +0200 @@ -191,8 +191,9 @@ // PROJECT var Project = Models.Project = RenkanModel.extend({ + schemaVersion : 1, type : "project", - blacklist : [ 'save_status', ], + blacklist : [ 'saveStatus', 'loadingStatus',], relations : [ { type : Backbone.HasMany, key : "users", @@ -269,6 +270,19 @@ } ); }, + getSchemaVersion : function(data) { + var t = data; + if(typeof(t) === "undefined") { + t = this; + } + var version = t.schemaVersion; + if(!version) { + return 1; + } + else { + return version; + } + }, // Add event handler to remove edges when a node is removed initialize : function() { var _this = this; @@ -283,6 +297,7 @@ }, toJSON : function() { var json = _.clone(this.attributes); + json.schema_version = this.schemaVersion; for ( var attr in json) { if ((json[attr] instanceof Backbone.Model) || (json[attr] instanceof Backbone.Collection) || diff -r adb907bba956 -r 4c7ab16e5845 client/js/renderer/scene.js --- a/client/js/renderer/scene.js Fri May 22 17:48:14 2015 +0200 +++ b/client/js/renderer/scene.js Mon May 25 01:18:12 2015 +0200 @@ -321,8 +321,8 @@ _thRedrawUsers(); // register model events - this.renkan.project.on("change:save_status", function(){ - switch (_this.renkan.project.get("save_status")) { + this.renkan.project.on("change:saveStatus", function(){ + switch (_this.renkan.project.get("saveStatus")) { case 0: //clean _this.$.find(".Rk-Save-Button").removeClass("to-save"); _this.$.find(".Rk-Save-Button").removeClass("saving"); @@ -341,8 +341,8 @@ } }); - this.renkan.project.on("change:loading_status", function(){ - if (_this.renkan.project.get("loading_status")){ + this.renkan.project.on("change:loadingStatus", function(){ + if (_this.renkan.project.get("loadingStatus")){ var animate = _this.$.find(".loader").addClass("run"); var timer = setTimeout(function(){ _this.$.find(".loader").hide(250); @@ -363,13 +363,13 @@ this.renkan.project.on("add:nodes", function(_node) { _this.addRepresentation("Node", _node); - if (!_this.renkan.project.get("loading_status")){ + if (!_this.renkan.project.get("loadingStatus")){ _thRedraw(); } }); this.renkan.project.on("add:edges", function(_edge) { _this.addRepresentation("Edge", _edge); - if (!_this.renkan.project.get("loading_status")){ + if (!_this.renkan.project.get("loadingStatus")){ _thRedraw(); } }); diff -r adb907bba956 -r 4c7ab16e5845 client/js/save-once.js --- a/client/js/save-once.js Fri May 22 17:48:14 2015 +0200 +++ b/client/js/save-once.js Mon May 25 01:18:12 2015 +0200 @@ -20,13 +20,13 @@ url: _opts.url, data: getdata, beforeSend: function(){ - _proj.set({loading_status:true}); + _proj.set({loadingStatus:true}); }, success: function(_data) { _proj.set(_data, {validate: true}); - _proj.set({loading_status:false}); - _proj.set({save_status:0}); - _renkan.renderer.autoScale(); + _proj.set({loadingStatus:false}); + _proj.set({saveStatus:0}); + _renkan.renderer.autoScale(); } }); }; @@ -39,20 +39,20 @@ contentType: "application/json", data: JSON.stringify(_data), beforeSend: function(){ - _proj.set({save_status:2}); + _proj.set({saveStatus:2}); }, success: function(data, textStatus, jqXHR) { $(window).off("beforeunload", _onLeave); _saveWarn = false; - _proj.set({save_status:0}); + _proj.set({saveStatus:0}); //document.location.hash = "#id=" + data.id; //$(".Rk-Notifications").text("Saved as "+document.location.href).fadeIn().delay(2000).fadeOut(); } }); }; var _checkLeave = function() { - _proj.set({save_status:1}); - + _proj.set({saveStatus:1}); + var title = _proj.get("title"); if (title && _proj.get("nodes").length) { $(".Rk-Save-Button").removeClass("disabled"); @@ -70,11 +70,11 @@ _load(); _proj.on("add:nodes add:edges add:users change", function(_model) { _model.on("change remove", function(_model) { - if(!(_model.changedAttributes.length === 1 && _model.hasChanged('save_status'))) { + if(!(_model.changedAttributes.length === 1 && _model.hasChanged('saveStatus'))) { _checkLeave(); } }); - if(!(_proj.changedAttributes.length === 1 && _proj.hasChanged('save_status'))) { + if(!(_proj.changedAttributes.length === 1 && _proj.hasChanged('saveStatus'))) { _checkLeave(); } });