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 ? '
'+getModDetails(details)+'
' : ''; - var randDetails = details ? getPortalRandDetails(details) : ''; + var miscDetails = details ? getPortalMiscDetails(guid,details) : ''; var resoDetails = details ? getResonatorDetails(details) : ''; //TODO? other status details... @@ -132,7 +135,7 @@ window.renderPortalDetails = function(guid) { ), modDetails, - randDetails, + miscDetails, resoDetails, statusDetails, '
' + linkDetails.join('') + '
' @@ -144,7 +147,7 @@ window.renderPortalDetails = function(guid) { -window.getRandPortalDetails = function(d) { +window.getPortalMiscDetails = function(guid,d) { var randDetails; @@ -160,7 +163,7 @@ window.getRandPortalDetails = function(d) { var linksText = [linkExpl('links'), linkExpl(' ↳ ' + links.incoming+'  •  '+links.outgoing+' ↴')]; var player = d.captured && d.captured.capturingPlayerId - ? '' + getPlayerName(d.captured.capturingPlayerId) + '' + ? '' + d.captured.capturingPlayerId + '' : null; var playerText = player ? ['owner', player] : null; diff --git a/code/portal_detail_display_tools.js b/code/portal_detail_display_tools.js index e3c67998..f9f02abf 100644 --- a/code/portal_detail_display_tools.js +++ b/code/portal_detail_display_tools.js @@ -102,7 +102,7 @@ window.getModDetails = function(d) { modTooltip = modName + '\n'; if (mod.installingUser) { - modTooltip += 'Installed by: '+ getPlayerName(mod.installingUser) + '\n'; + modTooltip += 'Installed by: '+ mod.installingUser + '\n'; } if (mod.stats) { @@ -176,7 +176,7 @@ window.getResonatorDetails = function(d) { var l = parseInt(reso.level); var v = parseInt(reso.energyTotal); - var nick = window.getPlayerName(reso.ownerGuid); + var nick = reso.ownerGuid; var dist = reso.distanceToPortal; // if array order and slot order drift apart, at least the octant // naming will still be correct.