From b4eebe78fa813b2da75415775f2a8acb9137f5c8 Mon Sep 17 00:00:00 2001 From: amandaghassaei <amandaghassaei@gmail.com> Date: Mon, 16 Mar 2015 22:11:24 -0400 Subject: [PATCH] merge edit and preview ui --- js/menus/AnimationMenuView.js | 54 +++++++++++++++++++++++++---------- js/menus/LatticeMenuView.js | 3 +- js/menus/MenuWrapperView.js | 2 +- js/menus/SendMenuView.js | 31 ++------------------ js/models/AppState.js | 14 +++++---- 5 files changed, 53 insertions(+), 51 deletions(-) diff --git a/js/menus/AnimationMenuView.js b/js/menus/AnimationMenuView.js index 2e59860a..bc556eb0 100644 --- a/js/menus/AnimationMenuView.js +++ b/js/menus/AnimationMenuView.js @@ -8,41 +8,65 @@ AnimationMenuView = Backbone.View.extend({ el: "#menuContent", events: { - "click #playStockSim": "_playStockSim", - "click #pauseStockSim": "_pauseStockSim" + "click #playStockSim": "_playStockSim", + "click #pauseStockSim": "_pauseStockSim", + "click #saveSendMenu": "_save", + "click #overrideEdits": "_postProcess" }, - initialize: function(options){ + initialize: function(){ - this.appState = options.appState; + _.bindAll(this, "render", "_codeEdit"); //bind events - this.listenTo(this.model, "change:currentScene", this.render); + this.listenTo(this.model, "change:stockSimulationPlaying", this.render); + this.listenTo(dmaGlobals.assembler, "change", this.render); + $(document).bind('keyup', {state:false}, this._codeEdit); }, - _playStockSim: function(e){ + _save: function(e){ e.preventDefault(); - dmaGlobals.appState.set("stockSimulationPlaying", true); + dmaGlobals.assembler.save(); }, - _pauseStockSim: function(e){ + _postProcess: function(e){ + e.preventDefault(); + dmaGlobals.assembler.postProcess(); + }, + + _codeEdit: function(e){ + var textarea = $("#gcodeEditor"); + if (!textarea.is(":focus")) return; e.preventDefault(); - dmaGlobals.appState.set("stockSimulationPlaying", false); + dmaGlobals.assembler.makeProgramEdits(textarea.val()); }, - _changeScene: function(e){ + _playStockSim: function(e){ + e.preventDefault(); + this.model.set("stockSimulationPlaying", true); + }, + + _pauseStockSim: function(e){ e.preventDefault(); - this.model.set("currentScene", $(e.target).data("type")); + this.model.set("stockSimulationPlaying", false); }, render: function(){ - if (this.appState.get("currentTab") != "animate") return; - this.$el.html(this.template(this.model.toJSON())); + if (this.model.get("currentTab") != "animate") return; + if (dmaGlobals.assembler.get("needsPostProcessing")) dmaGlobals.assembler.postProcess(); + this.$el.html(this.template(_.extend(this.model.toJSON(), dmaGlobals.assembler.toJSON()))); }, template: _.template('\ - <a href="#" id="playStockSim" class=" btn btn-block btn-lg btn-default">Play</a><br/>\ - <a href="#" id="pauseStockSim" class=" btn btn-block btn-lg btn-default">Pause</a><br/>\ + <% if (stockSimulationPlaying){ %>\ + <a href="#" id="pauseStockSim" class=" btn btn-block btn-lg btn-warning">Pause</a><br/>\ + <% } else { %>\ + <a href="#" id="playStockSim" class=" btn btn-block btn-lg btn-success">Play</a><br/>\ + <% } %>\ + <a href="#" id="saveSendMenu" class=" btn btn-block btn-lg btn-default">Save</a><br/>\ + Assembly Time: <br/><br/>\ + <textarea id="gcodeEditor"><%= dataOut %></textarea><br/><br/>\ + <a href="#" id="overrideEdits" class=" btn btn-block btn-lg btn-default">Undo Changes</a><br/>\ ') }); diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index 885d2673..16ca4aeb 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -24,8 +24,7 @@ LatticeMenuView = Backbone.View.extend({ this.lattice = options.lattice; - _.bindAll(this, "render"); - _.bindAll(this, "_onKeyup"); + _.bindAll(this, "render", "_onKeyup"); //bind events this.listenTo(this.lattice, "change", this.render); $(document).bind('keyup', {state:false}, this._onKeyup); diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index ee51d2be..2f2cd7fa 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -27,7 +27,7 @@ MenuWrapper = Backbone.View.extend({ this.materialMenu = new MaterialMenuView({model:this.model}); this.optimizeMenu = new OptimizationMenuView({model:this.model}); this.assemblerMenu = new AssemblerMenuView({model:this.model, assembler: dmaGlobals.assembler}); - this.animationMenu = new AnimationMenuView({model:lattice.get("basePlane"), appState:this.model}); + this.animationMenu = new AnimationMenuView({model:this.model}); this.camMenu = new CamMenuView({model:this.model, lattice:lattice, assembler:dmaGlobals.assembler}); this.sendMenu = new SendMenuView({model:this.model}); diff --git a/js/menus/SendMenuView.js b/js/menus/SendMenuView.js index a92e62d8..f92a2943 100644 --- a/js/menus/SendMenuView.js +++ b/js/menus/SendMenuView.js @@ -7,46 +7,21 @@ SendMenuView = Backbone.View.extend({ el: "#menuContent", events: { - "click #saveSendMenu": "_save", - "click #overrideEdits": "_postProcess" }, initialize: function(){ //bind events - this.listenTo(dmaGlobals.assembler, "change", this.render); - $(document).bind('keyup', {state:false}, this._codeEdit); _.bindAll(this, "render"); }, - _save: function(e){ - e.preventDefault(); - dmaGlobals.assembler.save(); - }, - - _postProcess: function(e){ - e.preventDefault(); - dmaGlobals.assembler.postProcess(); - }, - - _codeEdit: function(e){ - var textarea = $("#gcodeEditor"); - if (!textarea.is(":focus")) return; - e.preventDefault(); - dmaGlobals.assembler.makeProgramEdits(textarea.val()); - }, - render: function(){ if (this.model.get("currentTab") != "send") return; - if (dmaGlobals.assembler.get("needsPostProcessing")) dmaGlobals.assembler.postProcess(); - this.$el.html(this.template(dmaGlobals.assembler.toJSON())); + this.$el.html(this.template(this.model.toJSON())); }, - template: _.template('\ - <a href="#" id="saveSendMenu" class=" btn btn-block btn-lg btn-default">Save</a><br/>\ - <textarea id="gcodeEditor"><%= dataOut %></textarea><br/><br/>\ - <a href="#" id="overrideEdits" class=" btn btn-block btn-lg btn-default">Undo Changes</a><br/>\ - ') + + template: _.template('') }); \ No newline at end of file diff --git a/js/models/AppState.js b/js/models/AppState.js index a4e48611..e79f3967 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -38,7 +38,7 @@ AppState = Backbone.Model.extend({ assembler:"Assembler", cam: "Process", animate:"Preview", - send: "Edit" + send: "Send" } }, @@ -162,7 +162,7 @@ AppState = Backbone.Model.extend({ $(document).bind('keyup', {state:false}, this._handleKeyStroke); $(document).bind('mousewheel', {}, this._handleScroll); - this.listenTo(this, "change:currentTab", this._storeTab); + this.listenTo(this, "change:currentTab", this._tabChanged); this.listenTo(this, "change:currentNav", this._updateCurrentTabForNav); this.listenTo(this, "change:currentTab", this._updateCellMode); @@ -188,9 +188,13 @@ AppState = Backbone.Model.extend({ /////////////////////////////////////////////////////////////////////////////// - _storeTab: function(){ - var currentNav = this.get("currentNav"); + _tabChanged: function(){ var currentTab = this.get("currentTab"); + if (currentTab != "animate") this.set("stockSimulationPlaying", false); + this._storeTab(this.get("currentNav"), currentTab); + }, + + _storeTab: function(currentNav, currentTab){ if (currentNav == "navDesign") this.set("lastDesignTab", currentTab); else if (currentNav == "navSim") this.set("lastSimulationTab", currentTab); else if (currentNav == "navAssemble") this.set("lastAssembleTab", currentTab); @@ -259,7 +263,7 @@ AppState = Backbone.Model.extend({ if (e.shiftKey){ $("#saveAsModel").modal("show"); } else { - dmaGlobals.lattice.saveJSON(); + dmaGlobals.appState.saveJSON(); } } break; -- GitLab