diff --git a/css/main.css b/css/main.css index a164f5534c73e03c78dec135c994012db69bacc0..921499c1a2d9f939dbc8a0cab326d3b663a0eaf6 100644 --- a/css/main.css +++ b/css/main.css @@ -183,7 +183,7 @@ hr { margin: 20px 0; } -input.numberInput{ +input.intInput, number.floatInput{ width:22%; display: inline; padding: 8px 10px; diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index 348dc486c96a11e5dfe30408caf95d580d26b778..793f3b56aabfec24f0aa25298e066ae2b515c6be 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -32,10 +32,7 @@ LatticeMenuView = Backbone.View.extend({ }, _updateGikLength: function(e){ - e.preventDefault(); - var newVal = parseInt($(e.target).val()); - if (isNaN(newVal)) return; - globals.lattice.set("gikLength", newVal); + }, _clearCells: function(e){ @@ -104,7 +101,7 @@ LatticeMenuView = Backbone.View.extend({ <br/><br/>\ <% } %>\ <% if (connectionType == "gik") { %>\ - GIK Length: <input id="gikLength" value="<%= gikLength %>" placeholder="GIK length" class="form-control numberInput" type="text"><br/>\ + GIK Length: <input data-property="gikLength" value="<%= gikLength %>" placeholder="GIK length" class="form-control intInput lattice" type="text"><br/>\ <br/>\ <% } %>\ <% if (allMaterialTypes[cellType][connectionType]){ %> \ diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index 80a210e04c0b0541bd3d23f26621d6d34c97853a..ebf0eca585d160c0f8be6c6c7702509021ccf1d2 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -9,7 +9,7 @@ MenuWrapper = Backbone.View.extend({ events: { "click .menuWrapperTab>a": "_tabWasSelected", - "click .dropdownSelector": "_makeDropdownSelection" + "click .dropdownSelector": "_makeDropdownSelection", }, initialize: function(){ @@ -46,7 +46,7 @@ MenuWrapper = Backbone.View.extend({ if ($("input").is(":focus") && e.keyCode == 13) {//enter key $(e.target).blur(); -// this.render(); + this._renderTab(); return; } @@ -55,11 +55,39 @@ MenuWrapper = Backbone.View.extend({ }, _updateFloat: function(e){ - + e.preventDefault(); + var $target = $(e.target); + var newVal = parseFloat($target.val()); + if (isNaN(newVal)) { + console.warn("value is not float"); + return; + } + this._setNumber($target, newVal); }, _updateInt: function(e){ + e.preventDefault(); + var $target = $(e.target); + var newVal = parseInt($target.val()); + if (isNaN(newVal)) { + console.warn("value is NaN"); + return; + } + this._setNumber($target, newVal); + }, + _setNumber: function($target, newVal){ + var property = $target.data("property"); + if (!property) { + console.warn("no property associated with number input"); + return; + } + var key = $target.data("key"); + if (key){ + if ($target.hasClass("lattice")) globals.lattice.get(property)[key] = newVal; + return; + } + if ($target.hasClass("lattice")) globals.lattice.set(property, newVal); }, _makeDropdownSelection: function(e){ @@ -89,6 +117,12 @@ MenuWrapper = Backbone.View.extend({ } }); + this._renderTab(tabName); + }, + + _renderTab: function(tabName){ + if (!tabName) tabName = this.model.get("currentTab"); + if (tabName == "lattice"){ if (!this.latticeMenu) this.latticeMenu = new LatticeMenuView({model:this.model}); this.latticeMenu.render(); @@ -118,7 +152,6 @@ MenuWrapper = Backbone.View.extend({ console.warn("no tab initialized!"); $("#menuContent").html('Coming Soon.');//clear out content from menu } - }, render: function(){