From 4715c4ed71a3d23af475672c153d46653a4ec68c Mon Sep 17 00:00:00 2001 From: jonsowman Date: Tue, 10 Aug 2010 21:52:05 +0000 Subject: [PATCH] Fixed wrongly numbering index, and made the dialog draggable --- predict/index.php | 1 + predict/js/pred.js | 38 +++++++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/predict/index.php b/predict/index.php index 06197ec..efc811a 100644 --- a/predict/index.php +++ b/predict/index.php @@ -139,6 +139,7 @@ var hlTimeout = 5000; // high latency
+ Saved Locations
?
diff --git a/predict/js/pred.js b/predict/js/pred.js index ed01ae6..27e61e0 100644 --- a/predict/js/pred.js +++ b/predict/js/pred.js @@ -27,6 +27,7 @@ $(document).ready(function() { // make launch card draggable $("#input_form").draggable({containment: '#map_canvas', handle: 'img.handle', snap: '#map_canvas'}); $("#scenario_info").draggable({containment: '#map_canvas', handle: 'img.handle', snap: '#map_canvas'}); + $("#location_save_local").draggable({containment: '#map_canvas', handle: 'img.handle', snap: '#map_canvas'}); $("#run_pred_btn").button(); $("#req_sub_btn").button(); @@ -622,11 +623,16 @@ function setupEventHandlers() { if ( $.Jookie.Get(cookie_name, "idx") > 5 ) { throwError("Too many saved locations"); } else { - idx++; - $.Jookie.Set(cookie_name, idx+"_lat", req_lat); - $.Jookie.Set(cookie_name, idx+"_lon", req_lon); - $.Jookie.Set(cookie_name, idx+"_alt", req_alt); - $.Jookie.Set(cookie_name, idx+"_name", req_name); + // Find the next free index we can use + var i=1; + while ( $.Jookie.Get(cookie_name, i+"_name") && i<=5 ) { + i++; + } + // We will use this idx for the next location + $.Jookie.Set(cookie_name, i+"_lat", req_lat); + $.Jookie.Set(cookie_name, i+"_lon", req_lon); + $.Jookie.Set(cookie_name, i+"_alt", req_alt); + $.Jookie.Set(cookie_name, i+"_name", req_name); // Increase the index $.Jookie.Set(cookie_name, "idx", idx); @@ -652,8 +658,9 @@ function setupEventHandlers() { $("#site").change(function() { if ( $("#site").val() == "Other" ) { appendDebug("User requested locally saved launch sites"); - constructCookieLocationsTable("cusf_predictor"); - $("#location_save_local").fadeIn(); + if ( constructCookieLocationsTable("cusf_predictor") ) { + $("#location_save_local").fadeIn(); + } } else { plotClick(); } @@ -717,24 +724,28 @@ function constructCookieLocationsTable(cookie_name) { $.Jookie.Initialise(cookie_name, 99999999); if ( !$.Jookie.Get(cookie_name, "idx") || $.Jookie.Get(cookie_name, "idx") == 0 ) { throwError("Tried to write from an empty cookie"); + return false; } else { idx = $.Jookie.Get(cookie_name, "idx"); - t += "IndexNameUseDelete"; - for (i=1; i<=idx; i++) { + t += "NameUseDelete"; + var i=1; + var j=0; + while ( j"+$.Jookie.Get(cookie_name, i+"_name")+""; + t += ""+$.Jookie.Get(cookie_name, i+"_name")+""; t += "Use"; t += ""; t += "Delete"; t += ""; t += ""; - } else { - i--; + j++; } + i++; } t += ""; $("#locations_table").html(t); + return true; } } @@ -759,8 +770,9 @@ function deleteCookieLocation(cookie_name, idx) { $.Jookie.Unset(cookie_name, idx+"_name"); // Decrease quantity in cookie by one var qty = $.Jookie.Get(cookie_name, "idx"); - qty--; + qty -= 1; $.Jookie.Set(cookie_name, "idx", qty); + $("#location_save_local").fadeOut(); } function POSIXtoHM(timestamp, format) {