From 405ce461c9b97485ad480fbeabd0790fb18dbfd0 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Mon, 25 May 2015 13:00:03 -0700 Subject: [PATCH] numberInput --- css/main.css | 2 +- js/menus/LatticeMenuView.js | 7 ++----- js/menus/MenuWrapperView.js | 41 +++++++++++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/css/main.css b/css/main.css index a164f553..921499c1 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 348dc486..793f3b56 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 80a210e0..ebf0eca5 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(){ -- GitLab