From 0bf00ea34c2b269ab937bd13a6aebf5c5e7ec817 Mon Sep 17 00:00:00 2001 From: Zach Wise Date: Fri, 31 Aug 2012 17:25:48 -0500 Subject: [PATCH] Changed timeout function for loading Google Docs so that it tries several times to get json ref #219 --- source/js/VMM.Timeline.DataObj.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/source/js/VMM.Timeline.DataObj.js b/source/js/VMM.Timeline.DataObj.js index acf25ca..84800dd 100644 --- a/source/js/VMM.Timeline.DataObj.js +++ b/source/js/VMM.Timeline.DataObj.js @@ -166,24 +166,34 @@ if (typeof VMM.Timeline !== 'undefined' && typeof VMM.Timeline.DataObj == 'undef googlespreadsheet: { getData: function(raw) { - var key, url, timeout; + var getjsondata, key, url, timeout, tries = 0; key = VMM.Util.getUrlVars(raw)["key"]; url = "https://spreadsheets.google.com/feeds/list/" + key + "/od6/public/values?alt=json"; timeout = setTimeout(function() { trace("Google Docs timeout"); - VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Google Docs is not responding"); + if (tries < 3) { + VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Still waiting on Google Docs, trying again " + tries); + tries ++; + requestJsonData(); + } else { + VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Google Docs is not responding"); + } }, 6000); - VMM.getJSON(url, VMM.Timeline.DataObj.model.googlespreadsheet.buildData) - .error(function(jqXHR, textStatus, errorThrown) { - trace("Google Docs ERROR"); - trace("Google Docs ERROR: " + textStatus + " " + jqXHR.responseText); - }) - .success(function(d) { - clearTimeout(timeout); - }); + function requestJsonData() { + getjsondata = VMM.getJSON(url, VMM.Timeline.DataObj.model.googlespreadsheet.buildData) + .error(function(jqXHR, textStatus, errorThrown) { + trace("Google Docs ERROR"); + trace("Google Docs ERROR: " + textStatus + " " + jqXHR.responseText); + }) + .success(function(d) { + clearTimeout(timeout); + }); + } + + requestJsonData(); }, buildData: function(d) {