diff --git a/js/menus/MSetupMenuView.js b/js/menus/MSetupMenuView.js index 7b08c3babba5dd2662d5de6a05951bd98d4612b3..53df07001c168cbd1ac80093ae690ba1d40015d0 100644 --- a/js/menus/MSetupMenuView.js +++ b/js/menus/MSetupMenuView.js @@ -21,7 +21,7 @@ define(['jquery', 'underscore', 'menuParent', 'lattice', 'plist', 'text!mSetupMe }, _makeTemplateJSON: function(){ - return _.extend(this.model.toJSON(), plist. lattice.toJSON()); + return _.extend(this.model.toJSON(), plist, lattice.toJSON()); }, template: _.template(template) diff --git a/js/menus/MenuParentView.js b/js/menus/MenuParentView.js index 45ebe547f614b12481c24a0581a56bfc59440e5a..e801b3d46137507516a9eedf9cf81aea24d84c03 100644 --- a/js/menus/MenuParentView.js +++ b/js/menus/MenuParentView.js @@ -9,17 +9,29 @@ define(['jquery', 'underscore', 'backbone'], function($, _, Backbone){ el: "#menuContent", - initialize: function(){ + initialize: function(options){ _.bindAll(this, "render"); - if (this._initialize) this._initialize();//call subclass + if (this._initialize) this._initialize(options);//call subclass }, getPropertyOwner: function($target){ return null;//override in subclasses }, + deleteExitMenu: function(e, callback){ + callback(); + }, + + cancelExitMenu: function(e, callback){ + callback(); + }, + + saveExitMenu: function(e, callback){ + callback(); + }, + render: function(){ if (this.model.changedAttributes()["currentNav"]) return; if ($("input[type=text]").is(":focus")) return; diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index 0c6a8bffa6d0444452677cf75c3a35ade1aaa1d0..3c8efc8968cd7841c50ee18f7cd2c99a48eec441 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -22,13 +22,20 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice', 'appState', 'tex initialize: function(){ + this.currentNav = null; + this.currentTab = null; + _.bindAll(this, "render", "_updateCurrentTab", "_setVisibility", "_hide", "_show", "_onKeyUp"); $(document).bind('keyup', {}, this._onKeyUp); //bind events - this.listenTo(this.model, "change:currentNav", this.render); + this.listenTo(this.model, "change:currentNav", function(){ + if (this.currentNav == this.model.get("currentNav")) return; + this.render(); + }); this.listenTo(lattice, "change:cellType change:connectionType change:latticeType", this._populateAndShow); this.listenTo(this.model, "change:currentTab", function(){ + if (this.currentTab == this.model.get("currentTab")) return; if (!this.model.changedAttributes() || this.model.changedAttributes()["currentNav"]) return; this._updateCurrentTab(); }); @@ -226,6 +233,38 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice', 'appState', 'tex + _deleteExitMenu: function(e){ + e.preventDefault(); + var nextNav = this._getNextNav(); + this.menu.deleteExitMenu(e, function(){ + appState.set("currentNav", nextNav); + }); + }, + + _cancelExitMenu: function(e){ + e.preventDefault(); + var nextNav = this._getNextNav(); + this.menu.cancelExitMenu(e, function(){ + appState.set("currentNav", nextNav); + }); + }, + + _saveExitMenu: function(e){ + e.preventDefault(); + var nextNav = this._getNextNav(); + this.menu.saveExitMenu(e, function(){ + appState.set("currentNav", nextNav); + }); + }, + + _getNextNav: function(){ + var parentNav = plist.allMenus[this.model.get("currentNav")].parent; + if (parentNav === undefined) console.warn("no parent nav found, unable to exit menu"); + return parentNav || appState.get("currentNav"); + }, + + + _tabWasSelected: function(e){ e.preventDefault(); @@ -233,8 +272,25 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice', 'appState', 'tex this.model.set("currentTab", tabName); }, - _updateCurrentTab: function(){ + initTabWithObject: function(object, tab, nav){ + //bypass appstate event listening + this.model.set("currentTab", tab, {silent:true}); + if (nav === undefined || nav == this.model.get("currentNav")) this._updateCurrentTab(object); + else { + this.model.set("currentNav", nav, {silent:true}); + this.render(object); + } + this.model.trigger("change:currentTab change:currentNav"); + }, + + _updateCurrentTab: function(object){ var tabName = this.model.get("currentTab"); + this.currentTab = tabName;//todo + this._selectTab(tabName); + this._renderTab(tabName, object); + }, + + _selectTab: function(tabName){ _.each($(".menuWrapperTab"), function(tab){ var $tab = $(tab); if ($tab.data('name') == tabName){ @@ -243,7 +299,6 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice', 'appState', 'tex $tab.removeClass("active"); } }); - this._renderTab(tabName); }, _softRenderTab: function(){ @@ -251,29 +306,32 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice', 'appState', 'tex else console.warn("no menu found"); }, - _renderTab: function(tabName){ + _renderTab: function(tabName, object){ if (!tabName || !_.isString(tabName)) tabName = this.model.get("currentTab"); if (this.menu) this.menu.destroy(); var self = this; - require([tabName + "Menu"], function(MenuView){ - self.menu = new MenuView({model:self.model}); + require(["menus/" + tabName.charAt(0).toUpperCase() + tabName.slice(1) + "MenuView"], function(MenuView){ + var data = {model:self.model}; + if (object) data.myObject = object; + self.menu = new MenuView(data); self.menu.render(); }); }, - render: function(){ + render: function(object){ + this.currentNav = this.model.get("currentNav"); var self = this; this._hide(function(){ $("#menuContent").html("");//clear current menu - self._populateAndShow(); - self.model.trigger("change:currentTab");//this was updated silently before todo need this? + self._populateAndShow(object); + }, true); }, - _populateAndShow: function(){ + _populateAndShow: function(object){ $("#menuHeader").html(this.template(_.extend(this.model.toJSON(), lattice.toJSON(), plist))); - this._updateCurrentTab(); + this._updateCurrentTab(object); this._show(); }, diff --git a/js/plists/PList.js b/js/plists/PList.js index 845d2cff031790539cd37afa36842dba11adbc16..b55c459886d62da5ee045c1e3040c0015d586496 100644 --- a/js/plists/PList.js +++ b/js/plists/PList.js @@ -66,7 +66,7 @@ define(['three'], function(THREE){ navOptimize:{ name: "Optimize", tabs:{ - optimize:"Optimize" + optimization:"Optimize" } }, navAssemble:{ @@ -76,7 +76,7 @@ define(['three'], function(THREE){ assemblerSetup: "Setup", cam: "Globals", // editCamOutput: "Edit", - animate:"Preview" + animation:"Preview" } }, navDNAAssemble:{