@@ -54,13 +54,17 @@ function addToSandwich(type, item){
54
54
// add the new subgoal to the sidebar
55
55
if ( ! foundIt ) {
56
56
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 ) {
60
64
drawSubgoal ( item . id ) ;
61
- sideSubgoalExpandy ( item . id , 0 ) ;
62
- } ) ;
63
- }
65
+ }
66
+ sideSubgoalExpandy ( item . id , 0 ) ;
67
+ } ) ;
64
68
}
65
69
else if ( ! type . localeCompare ( "idealAction" ) && item . name ) {
66
70
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() {
300
304
301
305
//Happens after refresh
302
306
//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?
303
310
function reloadSandwich ( ) {
304
311
console . log ( "Reloading sandwich menu..." ) ;
305
312
var sidebarHTML = localStorage . getItem ( 'sidebarHTML' ) ;
@@ -314,9 +321,14 @@ function reloadSandwich () {
314
321
if ( currId . length == 1 ) {
315
322
//It's a subgoal
316
323
//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 ) {
318
328
drawSubgoal ( currId ) ;
319
- } ) ;
329
+ }
330
+ sideSubgoalExpandy ( currId , 0 ) ;
331
+ } ) ;
320
332
//todo: add collapse onclick function here.
321
333
}
322
334
0 commit comments