diff --git a/js/main.js b/js/main.js index fe93ef88d3f2c29c6110b632a501243949cf589d..85044f23d9755ff0363262ee6caacd395b1092bd 100644 --- a/js/main.js +++ b/js/main.js @@ -14,7 +14,7 @@ $(function(){ new ThreeView({model:window.three, lattice:lattice}); //setup ui - var appState = new AppState(); + var appState = new AppState({lattice:lattice}); new MenuWrapper({lattice:lattice, model:appState}); new NavBar({model:appState}); diff --git a/js/menus/ImportMenuView.js b/js/menus/ImportMenuView.js index c454f98d886c7737394b85c52a8251b83365b03b..835ac15b7a3bb2cacea7504b51b116330c80593f 100644 --- a/js/menus/ImportMenuView.js +++ b/js/menus/ImportMenuView.js @@ -18,12 +18,10 @@ ImportMenuView = Backbone.View.extend({ initialize: function(options){ this.lattice = options.lattice; + this.appState = options.appState; _.bindAll(this, "render", "_onMeshLoad"); - this.listenTo(this.model, "change", function(){ - if (options.appState.get("currentTab")!="import") return; - this.render(); - }); + this.listenTo(this.model, "change", this.render); // this.listenTo(this.model, "change:filename change:boundingBoxHelper", this.render);//boundingBoxHelper covers orientation @@ -72,8 +70,8 @@ ImportMenuView = Backbone.View.extend({ }, render: function(){ + if (this.appState.get("currentTab") != "import") return; this.$el.html(this.template(this.model.attributes)); - this.lattice.set("cellMode", "cell"); }, // makeDimensionString: function(){ diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index 396f6fc29f4ecc9910e834a4b48ee298dcb44ab0..4b0b7f3fe5438460f9122084d56e9b24c04ce531 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -15,13 +15,10 @@ LatticeMenuView = Backbone.View.extend({ initialize: function(options){ + this.appState = options.appState; + _.bindAll(this, "render"); - this.listenTo(this.model, "change", function(){ - if (options.appState.get("currentTab")!="lattice") return; - if(!this.model.hasChanged('cellMode')){//I want to ignore cellMode changes and listen to everything else - this.render(); - } - }); + this.listenTo(this.model, "change", this.render); }, _clearCells: function(e){ @@ -43,8 +40,8 @@ LatticeMenuView = Backbone.View.extend({ }, render: function(){ + if (this.appState.get("currentTab") != "lattice") return; this.$el.html(this.template(_.extend(this.model.attributes, this._formatData()))); - this.model.set("cellMode", "cell"); }, template: _.template('\ diff --git a/js/menus/PartMenuView.js b/js/menus/PartMenuView.js index a8c455db3155f3626841560f006b7c4461bffe29..664db0856b83e8568e3b7b1c70fdd0f393c90a57 100644 --- a/js/menus/PartMenuView.js +++ b/js/menus/PartMenuView.js @@ -9,19 +9,18 @@ PartMenuView = Backbone.View.extend({ events: { }, - initialize: function(){ + initialize: function(options){ + + this.appState = options.appState; _.bindAll(this, "render"); this.listenTo(this.model, "change:partType", this.render); -// this.listenTo(this.model, "change", function(){ -// if (options.appState.get("currentTab")!="part") return; -// this.render(); -// }); + }, render: function(){ + if (this.appState.get("currentTab") != "part") return; this.$el.html(this.template(this.model.attributes)); - this.model.set("cellMode", "parts"); }, template: _.template('\ diff --git a/js/menus/ScriptMenuView.js b/js/menus/ScriptMenuView.js index 9b8adf2877860190a634c0ec5882cc1e4be2ec2e..4dda3b65e9c306eff5b5eded5965e1d53459618f 100644 --- a/js/menus/ScriptMenuView.js +++ b/js/menus/ScriptMenuView.js @@ -9,12 +9,15 @@ ScriptMenuView = Backbone.View.extend({ events: { }, - initialize: function(){ + initialize: function(options){ + + this.appState = options.appState; _.bindAll(this, "render"); }, render: function(){ + if (this.appState.get("currentTab") != "script") return; this.$el.html(this.template()); }, diff --git a/js/menus/SketchMenuView.js b/js/menus/SketchMenuView.js index e146cb59abd049a251cd2aceabdfa9b81a8ec45f..f4a78b115a46566787ea861b934949ad6aec158d 100644 --- a/js/menus/SketchMenuView.js +++ b/js/menus/SketchMenuView.js @@ -10,18 +10,17 @@ SketchMenuView = Backbone.View.extend({ events: { }, - initialize: function(){ + initialize: function(options){ + + this.appState = options.appState; _.bindAll(this, "render"); -// this.listenTo(this.model, "change", function(){ -// if (options.appState.get("currentTab")!="sketch") return; -// this.render(); -// }); + }, render: function(){ + if (this.appState.get("currentTab") != "sketch") return; this.$el.html(this.template()); - this.model.set("cellMode", "cell"); }, template: _.template('\ diff --git a/js/models/AppState.js b/js/models/AppState.js index ddc65582aea1b42bcddfbe8f9970646512ed78e0..9a37734d05714e5d66c428e74853edccc9da3f2e 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -19,10 +19,12 @@ AppState = Backbone.Model.extend({ menuIsVisible: true }, - initialize: function(){ + initialize: function(options){ - this.listenTo(this, "change:currentTab", this._storeTab) + this.listenTo(this, "change:currentTab", this._storeTab); + this.listenTo(this, "change:currentTab", this._updateLatticeMode); + this.lattice = options.lattice; }, _storeTab: function(){ @@ -31,5 +33,14 @@ AppState = Backbone.Model.extend({ if (currentNav == "navDesign") this.set("lastDesignTab", currentTab); else if (currentNav == "navSim") this.set("lastSimulationTab", currentTab); else if (currentNav == "navAssemble") this.set("lastAssembleTab", currentTab); + }, + + _updateLatticeMode: function(){ + var currentTab = this.get("currentTab"); + if (currentTab == "lattice") this.lattice.set("cellMode", "cell"); + else if (currentTab == "import") this.lattice.set("cellMode", "cell"); + else if (currentTab == "sketch") this.lattice.set("cellMode", "cell"); + else if (currentTab == "part") this.lattice.set("cellMode", "parts"); } + }); \ No newline at end of file