From f18dc6d49b19e8ca8ef092cf94ca8e7b98557e57 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Mon, 25 May 2015 14:23:11 -0700
Subject: [PATCH] script menu

---
 js/menus/MenuWrapperView.js |  5 ++--
 js/menus/PartMenuView.js    | 53 ++++++-------------------------------
 2 files changed, 10 insertions(+), 48 deletions(-)

diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js
index 89527038..e90df643 100644
--- a/js/menus/MenuWrapperView.js
+++ b/js/menus/MenuWrapperView.js
@@ -22,7 +22,6 @@ MenuWrapper = Backbone.View.extend({
 
         //init all tab view controllers
         this.sketchMenu = new SketchMenuView({model:lattice, appState:this.model});
-        this.partMenu = new PartMenuView({model:this.model, lattice:lattice});
         this.scriptMenu = new ScriptMenuView({model:this.model});
         this.physicsMenu = new PhysicsMenuView({model:this.model});
         this.materialMenu = new MaterialMenuView({model:this.model});
@@ -43,13 +42,11 @@ MenuWrapper = Backbone.View.extend({
 
 
     _onKeyUp: function(e){
-
         if ($("input").is(":focus") && e.keyCode == 13) {//enter key
             $(e.target).blur();
             this._renderTab();
             return;
         }
-
         if ($(".floatInput").is(":focus")) this._updateFloat(e);
         if ($(".intInput").is(":focus")) this._updateInt(e);
     },
@@ -85,6 +82,7 @@ MenuWrapper = Backbone.View.extend({
         var key = $target.data("key");
         if (key){
             if ($target.hasClass("lattice")) globals.lattice.get(property)[key] = newVal;
+            globals.lattice.trigger("change:"+property);
             return;
         }
         if ($target.hasClass("lattice")) globals.lattice.set(property, newVal);
@@ -137,6 +135,7 @@ MenuWrapper = Backbone.View.extend({
         } else if (tabName == "sketch"){
             this.sketchMenu.render();
         } else if (tabName == "part"){
+            if (!this.partMenu) this.partMenu = new PartMenuView({model:this.model});
             this.partMenu.render();
         } else if (tabName == "script"){
             this.scriptMenu.render();
diff --git a/js/menus/PartMenuView.js b/js/menus/PartMenuView.js
index dec91a4e..6a6d7b55 100644
--- a/js/menus/PartMenuView.js
+++ b/js/menus/PartMenuView.js
@@ -7,57 +7,20 @@ PartMenuView = Backbone.View.extend({
     el: "#menuContent",
 
     events: {
-        "click .partType":                                  "_changePartType",
-        "click .materialType":                              "_changeMaterialType"
     },
 
-    initialize: function(options){
-
-        this.lattice = options.lattice;
+    initialize: function(){
 
         _.bindAll(this, "render");
-        _.bindAll(this, "_onKeyup");
-        //bind events
-        this.listenTo(this.lattice, "change", this.render);
-        $(document).bind('keyup', {state:false}, this._onKeyup);
-
-    },
-
-    _onKeyup: function(e){
-        if (this.model.get("currentTab") != "part") return;
-
-        if ($("input").is(":focus") && e.keyCode == 13) {//enter key
-            $(e.target).blur();
-            this.render();
-            return;
-        }
 
-        if ($(".cellSeparation").is(":focus")) this._updateNumber(e, "cellSeparation");
-    },
-
-    _updateNumber: function(e, property){
-        e.preventDefault();
-        var newVal = parseFloat($(e.target).val());
-        if (isNaN(newVal)) return;
-        var object = this.lattice.get(property);
-        object[$(e.target).data("type")] = newVal;
-        this.lattice.trigger("change:"+property);
-    },
-
-    _changePartType: function(e){
-        e.preventDefault();
-        this.lattice.set("partType", $(e.target).data("type"));
-    },
-
-     _changeMaterialType: function(e){
-        e.preventDefault();
-        this.lattice.set("materialType", $(e.target).data("type"));
+        //bind events
+        this.listenTo(globals.lattice, "change", this.render);
     },
 
     render: function(){
         if (this.model.changedAttributes()["currentNav"]) return;
         if (this.model.get("currentTab") != "part") return;
-        this.$el.html(this.template(_.extend(this.model.toJSON(), this.lattice.toJSON())));
+        this.$el.html(this.template(_.extend(globals.lattice.toJSON(), globals.plist)));
     },
 
     template: _.template('\
@@ -66,13 +29,13 @@ PartMenuView = Backbone.View.extend({
                 <button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= allPartTypes[cellType][connectionType][partType] %><span class="caret"></span></button>\
                 <ul role="menu" class="dropdown-menu">\
                     <% _.each(_.keys(allPartTypes[cellType][connectionType]), function(key){ %>\
-                        <li><a class="partType" data-type="<%= key %>" href="#"><%= allPartTypes[cellType][connectionType][key] %></a></li>\
+                        <li><a class="lattice dropdownSelector" data-property="partType" data-value="<%= key %>" href="#"><%= allPartTypes[cellType][connectionType][key] %></a></li>\
                     <% }); %>\
                 </ul>\
             </div><br/><br/>\
-        Cell Separation <% if (connectionType != "freeformFace"){ %>(xy, z): &nbsp;&nbsp;<input data-type="xy" value="<%= cellSeparation.xy %>" placeholder="XY" class="form-control numberInput cellSeparation" type="text">\
-        &nbsp;<input data-type="z" value="<%= cellSeparation.z %>" placeholder="Z" class="form-control numberInput cellSeparation" type="text">\
-        <% } else { %>( radial ): &nbsp;&nbsp;<input data-type="xy" value="<%= cellSeparation.xy %>" placeholder="XY" class="form-control numberInput cellSeparation" type="text"><% } %>\
+        Cell Separation <% if (connectionType != "freeformFace"){ %>(xy, z): &nbsp;&nbsp;<input data-property="cellSeparation" data-key="xy" value="<%= cellSeparation.xy %>" placeholder="XY" class="form-control floatInput lattice" type="text">\
+        &nbsp;<input data-property="cellSeparation" data-key="z" value="<%= cellSeparation.z %>" placeholder="Z" class="form-control floatInput lattice" type="text">\
+        <% } else { %>( radial ): &nbsp;&nbsp;<input data-property="cellSeparation" data-key="xy" value="<%= cellSeparation.xy %>" placeholder="XY" class="form-control floatInput lattice" type="text"><% } %>\
         <br/><br/>\
         <% if (allMaterialTypes[cellType][connectionType]){ %> \
         Material Type: &nbsp;&nbsp;<div class="btn-group">\
-- 
GitLab