Skip to content
Snippets Groups Projects
Commit f18dc6d4 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

script menu

parent ae26f99d
Branches
No related tags found
No related merge requests found
...@@ -22,7 +22,6 @@ MenuWrapper = Backbone.View.extend({ ...@@ -22,7 +22,6 @@ MenuWrapper = Backbone.View.extend({
//init all tab view controllers //init all tab view controllers
this.sketchMenu = new SketchMenuView({model:lattice, appState:this.model}); 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.scriptMenu = new ScriptMenuView({model:this.model});
this.physicsMenu = new PhysicsMenuView({model:this.model}); this.physicsMenu = new PhysicsMenuView({model:this.model});
this.materialMenu = new MaterialMenuView({model:this.model}); this.materialMenu = new MaterialMenuView({model:this.model});
...@@ -43,13 +42,11 @@ MenuWrapper = Backbone.View.extend({ ...@@ -43,13 +42,11 @@ MenuWrapper = Backbone.View.extend({
_onKeyUp: function(e){ _onKeyUp: function(e){
if ($("input").is(":focus") && e.keyCode == 13) {//enter key if ($("input").is(":focus") && e.keyCode == 13) {//enter key
$(e.target).blur(); $(e.target).blur();
this._renderTab(); this._renderTab();
return; return;
} }
if ($(".floatInput").is(":focus")) this._updateFloat(e); if ($(".floatInput").is(":focus")) this._updateFloat(e);
if ($(".intInput").is(":focus")) this._updateInt(e); if ($(".intInput").is(":focus")) this._updateInt(e);
}, },
...@@ -85,6 +82,7 @@ MenuWrapper = Backbone.View.extend({ ...@@ -85,6 +82,7 @@ MenuWrapper = Backbone.View.extend({
var key = $target.data("key"); var key = $target.data("key");
if (key){ if (key){
if ($target.hasClass("lattice")) globals.lattice.get(property)[key] = newVal; if ($target.hasClass("lattice")) globals.lattice.get(property)[key] = newVal;
globals.lattice.trigger("change:"+property);
return; return;
} }
if ($target.hasClass("lattice")) globals.lattice.set(property, newVal); if ($target.hasClass("lattice")) globals.lattice.set(property, newVal);
...@@ -137,6 +135,7 @@ MenuWrapper = Backbone.View.extend({ ...@@ -137,6 +135,7 @@ MenuWrapper = Backbone.View.extend({
} else if (tabName == "sketch"){ } else if (tabName == "sketch"){
this.sketchMenu.render(); this.sketchMenu.render();
} else if (tabName == "part"){ } else if (tabName == "part"){
if (!this.partMenu) this.partMenu = new PartMenuView({model:this.model});
this.partMenu.render(); this.partMenu.render();
} else if (tabName == "script"){ } else if (tabName == "script"){
this.scriptMenu.render(); this.scriptMenu.render();
......
...@@ -7,57 +7,20 @@ PartMenuView = Backbone.View.extend({ ...@@ -7,57 +7,20 @@ PartMenuView = Backbone.View.extend({
el: "#menuContent", el: "#menuContent",
events: { events: {
"click .partType": "_changePartType",
"click .materialType": "_changeMaterialType"
}, },
initialize: function(options){ initialize: function(){
this.lattice = options.lattice;
_.bindAll(this, "render"); _.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"); //bind events
}, this.listenTo(globals.lattice, "change", this.render);
_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"));
}, },
render: function(){ render: function(){
if (this.model.changedAttributes()["currentNav"]) return; if (this.model.changedAttributes()["currentNav"]) return;
if (this.model.get("currentTab") != "part") 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('\ template: _.template('\
...@@ -66,13 +29,13 @@ PartMenuView = Backbone.View.extend({ ...@@ -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>\ <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">\ <ul role="menu" class="dropdown-menu">\
<% _.each(_.keys(allPartTypes[cellType][connectionType]), function(key){ %>\ <% _.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>\ </ul>\
</div><br/><br/>\ </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">\ 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-type="z" value="<%= cellSeparation.z %>" placeholder="Z" class="form-control numberInput cellSeparation" 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-type="xy" value="<%= cellSeparation.xy %>" placeholder="XY" class="form-control numberInput cellSeparation" 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/>\ <br/><br/>\
<% if (allMaterialTypes[cellType][connectionType]){ %> \ <% if (allMaterialTypes[cellType][connectionType]){ %> \
Material Type: &nbsp;&nbsp;<div class="btn-group">\ Material Type: &nbsp;&nbsp;<div class="btn-group">\
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment