From 529f0266bacf7585919bdbbeda10f6ce138a038f Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Thu, 29 Jan 2015 21:18:46 -0500 Subject: [PATCH] cell mode logic in one place --- js/main.js | 2 +- js/menus/ImportMenuView.js | 8 +++----- js/menus/LatticeMenuView.js | 11 ++++------- js/menus/PartMenuView.js | 11 +++++------ js/menus/ScriptMenuView.js | 5 ++++- js/menus/SketchMenuView.js | 11 +++++------ js/models/AppState.js | 15 +++++++++++++-- 7 files changed, 35 insertions(+), 28 deletions(-) diff --git a/js/main.js b/js/main.js index fe93ef88..85044f23 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 c454f98d..835ac15b 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 396f6fc2..4b0b7f3f 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 a8c455db..664db085 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 9b8adf28..4dda3b65 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 e146cb59..f4a78b11 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 ddc65582..9a37734d 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 -- GitLab