Skip to content

Commit baeb0c9

Browse files
authored
Merge pull request #46 from diananova/save-subgoal
Ensures previously saved subgoals are not overwritten when the user clicks on them before saving the current subgoal. Calling drawSubgoal with a different id is restricted to after the current subgoal has been saved.
2 parents 7833e5c + b8188fb commit baeb0c9

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

scripts/prewalkthrough.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ function makeEditable () {
8181
* scenario -> scenarioName
8282
*/
8383

84+
// TODO: Refactoring. This function might benefit from being broken up into smaller functions, and/or adding a way
85+
// to periodically update variables like length of subgoalArray.
8486
function handlePreWalkthroughInfo () {
8587

8688
//var sidebarHead = $("#mySidebar").contents().find("head");

scripts/saveState.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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?
303310
function 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

scripts/walkthrough.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ function preDrawAction(subgoalId){
136136
* Description: This function handles displaying information for a given subgoal including displaying previously saved
137137
* information and saving newly entered information
138138
* Params: subgoalNum - id of the subgoal to make (may or may not be the current subgoal)
139+
*
140+
* TODO: This function needs refactoring. A number of problems are arising because of state changes
141+
* that happen in the middle of execution.
139142
*/
140143
function drawSubgoal(subgoalId){
141144
var id = "#GenderMagFrame";

0 commit comments

Comments
 (0)