From cf45fb091da488b1dbc950e3602ba75d0ae7997f Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Tue, 27 Jan 2015 01:59:00 -0500 Subject: [PATCH] menu event binding --- js/fea/dmaCell.js | 3 +-- js/menus/LatticeMenuView.js | 11 ++++++++++- js/menus/MenuWrapper.js | 9 +++++++++ js/menus/PartMenuView.js | 4 ++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/js/fea/dmaCell.js b/js/fea/dmaCell.js index 859904e7..93e07b0f 100644 --- a/js/fea/dmaCell.js +++ b/js/fea/dmaCell.js @@ -27,8 +27,6 @@ this.position = position; this.drawForMode(mode, position); - this._draw(); - // this.parts = this._createParts(nodes, config); } @@ -38,6 +36,7 @@ // parts.push(new Part(nodes[i], config[i])); // } // return parts; + return null; }; Cell.prototype._buildCellMesh = function(position){//abstract mesh representation of cell diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index 61fd323b..28286ebb 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -12,10 +12,17 @@ LatticeMenuView = Backbone.View.extend({ }, + currentlySelected: false, + initialize: function(){ _.bindAll(this, "render"); - this.listenTo(this.model, "change", this.render); + this.listenTo(this.model, "change", function(){ + if (!this.currentlySelected) return; + if(!this.model.hasChanged('cellMode')){//I want to ignore cellMode changes and listen to everything else + this.render(); + } + }); }, _clearCells: function(e){ @@ -30,7 +37,9 @@ LatticeMenuView = Backbone.View.extend({ }, render: function(){ + this.currentlySelected = true;//if this causes a change, render must have been called from menu wrapper this.$el.html(this.template(_.extend(this.model.attributes, this._formatData()))); + this.model.set("cellMode", "cell"); }, template: _.template('\ diff --git a/js/menus/MenuWrapper.js b/js/menus/MenuWrapper.js index f46f089f..674e4d71 100644 --- a/js/menus/MenuWrapper.js +++ b/js/menus/MenuWrapper.js @@ -26,6 +26,7 @@ function MenuWrapper(args){ }); $this.parent().addClass("active"); + deselectAllMenus(); var tabName = $this.parent().data('name'); if (tabName == "lattice"){ latticeMenu.render(); @@ -43,6 +44,14 @@ function MenuWrapper(args){ } }); + function deselectAllMenus(){ + latticeMenu.currentlySelected = false; +// importMenu.currentlySelected = false; +// sketchMenu.currentlySelected = false; + partMenu.currentlySelected = false; +// scriptMenu.currentlySelected = false; + } + function init(){ latticeMenu.render();//init with lattice menu open } diff --git a/js/menus/PartMenuView.js b/js/menus/PartMenuView.js index 602b9bca..fd43d717 100644 --- a/js/menus/PartMenuView.js +++ b/js/menus/PartMenuView.js @@ -9,6 +9,8 @@ PartMenuView = Backbone.View.extend({ events: { }, + currentlySelected: false, + initialize: function(){ _.bindAll(this, "render"); @@ -16,7 +18,9 @@ PartMenuView = Backbone.View.extend({ }, render: function(){ + this.currentlySelected = true;//if this causes a change, render must have been called from menu wrapper this.$el.html(this.template(this.model.attributes)); + this.model.set("cellMode", "parts"); }, template: _.template('\ -- GitLab