diff --git a/code/boot.js b/code/boot.js index a771c4e4..50258b5f 100644 --- a/code/boot.js +++ b/code/boot.js @@ -540,6 +540,7 @@ function boot() { window.setupPlayerStat(); window.setupTooltips(); window.chat.setup(); + window.portalDetail.setup(); window.setupQRLoadLib(); window.setupLayerChooserSelectOne(); window.setupLayerChooserStatusRecorder(); diff --git a/code/map_data_cache.js b/code/data_cache.js similarity index 100% rename from code/map_data_cache.js rename to code/data_cache.js diff --git a/code/hooks.js b/code/hooks.js index b6a7ef6c..fb295655 100644 --- a/code/hooks.js +++ b/code/hooks.js @@ -48,7 +48,8 @@ // called after each map data request finished. Argument is // {success: boolean} indicated the request success or fail. // iitcLoaded: called after IITC and all plugins loaded - +// portalDetailLoaded: called when a request to load full portal detail +// completes. guid, success, details parameters window._hooks = {} window.VALID_HOOKS = [ @@ -58,7 +59,8 @@ window.VALID_HOOKS = [ 'portalDetailsUpdated', 'publicChatDataAvailable', 'factionChatDataAvailable', 'requestFinished', 'nicknameClicked', - 'geoSearch', 'iitcLoaded']; + 'geoSearch', 'iitcLoaded', + 'portalDetailLoaded']; window.runHooks = function(event, data) { if(VALID_HOOKS.indexOf(event) === -1) throw('Unknown event type: ' + event); diff --git a/code/portal_detail.js b/code/portal_detail.js new file mode 100644 index 00000000..f33da496 --- /dev/null +++ b/code/portal_detail.js @@ -0,0 +1,55 @@ +/// PORTAL DETAIL ////////////////////////////////////// +// code to retrieve the new potal detail data from the servers + + +// anonymous function wrapper for the code - any variables/functions not placed into 'window' will be private +(function(){ + +var cache; + + +window.portalDetail = function() {}; + +window.portalDetail.setup = function() { + cache = new DataCache(); + + cache.startExpireInterval(20); +} + +window.portalDetail.get = function(guid) { + return cache.get(guid); +} + +window.portalDetail.isFresh = function(guid) { + return cache.isFresh(guid); +} + + +var handleResponse = function(guid, data, success) { + + if (success) { + cache.store(guid,data); + + //FIXME..? better way of handling sidebar refreshing... + + if (guid == selectedPortal) { + renderPortalDetails(guid); + } + } + + window.runHooks ('portalDetailLoaded', {guid:guid, success:success, details:data}); +} + +window.portalDetail.request = function(guid) { + + window.postAjax('getPortalDetails', {guid:guid}, + function(data,textStatus,jqXHR) { handleResponse(guid, data, true); }, + function() { handleResponse(guid, undefined, false); } + ); +} + + + +})(); // anonumous wrapper function end + + diff --git a/code/portal_detail_display.js b/code/portal_detail_display.js index 4a14b343..ce67431e 100644 --- a/code/portal_detail_display.js +++ b/code/portal_detail_display.js @@ -3,11 +3,14 @@ // methods that highlight the portal in the map view. window.renderPortalDetails = function(guid) { - // TODO: start a request for the selected portal detailed data - // (do this even if not in window.portals?) - selectPortal(window.portals[guid] ? guid : null); + if (!portalDetail.isFresh(guid)) { + portalDetail.request(guid); + } + + // TODO? handle the case where we request data for a particular portal GUID, but it *isn't* in + // window.portals.... if(!window.portals[guid]) { urlPortal = guid; @@ -21,11 +24,11 @@ window.renderPortalDetails = function(guid) { var portal = window.portals[guid]; var data = portal.options.data; - var details = undefined; //TODO: get the details + var details = portalDetail.get(guid); var modDetails = details ? '