@@ -54,13 +54,17 @@ function addToSandwich(type, item){
5454 // add the new subgoal to the sidebar
5555 if ( ! foundIt ) {
5656 sidebarBody ( ) . find ( "#subgoalList" ) . append ( sideSubgoal ) ;
57- }
58-
59- sidebarBody ( ) . find ( "#sideSubgoal" + item . id ) . unbind ( "click" ) . click ( function ( ) {
57+ }
58+
59+ }
60+ sidebarBody ( ) . find ( "#sideSubgoal" + item . id ) . unbind ( "click" ) . click ( function ( ) {
61+ subArr = getSubgoalArrayFromLocal ( ) ; // in case something changes before the button is clicked
62+ // do not enter drawSubgoal with a different id until the current subgoal is saved
63+ if ( statusIsTrue ( "gotSubgoalQuestions" ) || item . id == subArr . length ) {
6064 drawSubgoal ( item . id ) ;
61- sideSubgoalExpandy ( item . id , 0 ) ;
62- } ) ;
63- }
65+ }
66+ sideSubgoalExpandy ( item . id , 0 ) ;
67+ } ) ;
6468 }
6569 else if ( ! type . localeCompare ( "idealAction" ) && item . name ) {
6670 var sideAction = '<div superCoolAttr="' + item . subgoalId + '-' + item . actionId + '" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;text-indent:25px;color:blue;text-decoration:underline;margin:5px;" id="sideAction' + item . subgoalId + '-' + item . actionId + '">Action ' + item . actionId + ': ' + item . name + '</div>' ;
@@ -300,6 +304,9 @@ $( window ).unload(function() {
300304
301305//Happens after refresh
302306//confused about when this happens exactly
307+
308+ // TODO: Refactoring. This function contains code that exists elsewhere (see addToSandwich). Is it wise to have
309+ // buttons within an each() loop?
303310function reloadSandwich ( ) {
304311 console . log ( "Reloading sandwich menu..." ) ;
305312 var sidebarHTML = localStorage . getItem ( 'sidebarHTML' ) ;
@@ -314,9 +321,14 @@ function reloadSandwich () {
314321 if ( currId . length == 1 ) {
315322 //It's a subgoal
316323 //console.log("subgoal");
317- sidebarBody ( ) . find ( "#sideSubgoal" + currId ) . unbind ( "click" ) . click ( function ( ) {
324+ sidebarBody ( ) . find ( "#sideSubgoal" + currId ) . unbind ( "click" ) . click ( function ( ) {
325+ var subArr = getSubgoalArrayFromLocal ( ) ; // in case something changes before the button is clicked
326+ // do not enter drawSubgoal with a different id until the current subgoal is saved
327+ if ( statusIsTrue ( "gotSubgoalQuestions" ) || currId == subArr . length ) {
318328 drawSubgoal ( currId ) ;
319- } ) ;
329+ }
330+ sideSubgoalExpandy ( currId , 0 ) ;
331+ } ) ;
320332 //todo: add collapse onclick function here.
321333 }
322334
0 commit comments