// mercury3 download panel - dataone data package display // creates panel with dynamic (xhr) data retrieval. // registerButton function is used to map a button which will // activate the panel display to the resource map(s) (packageId parameter) // or just science metadata (pid parameter) M3.downloadPanel = M3.downloadPanel || { searchUrlBase : 'send/solrPass?wt=json&rows=1000', packageFields : '&fl=id,formatId,formatType,size,dataUrl', sortOrder : '&sort=formatType%20desc,formatId%20asc,size%20desc', packageButtonSelector : '.dataPackageButton', downloadPanelIdSelector : '#d1-download-panel', downloadPanelContentSelector : '#d1-download-panel-content', downloadPanelMsgSelector : '#d1-download-panel-message', metadataTypeString : 'METADATA', resourceMapTypeString : 'RESOURCE', buttonRegister : {}, registerButton : function(buttonId, packageId, pid) { if (this.buttonRegister[buttonId] == null) { this.buttonRegister[buttonId] = {}; this.buttonRegister[buttonId].packages = []; } if (packageId != null) { this.buttonRegister[buttonId].packages.push(packageId); } this.buttonRegister[buttonId].pid = pid; }, handleClick : function(event) { event.preventDefault(); var packageCount = M3.downloadPanel.buttonRegister[event.target.id].packages.length; var pid = M3.downloadPanel.buttonRegister[event.target.id].pid; $(M3.downloadPanel.downloadPanelContentSelector).html(''); $(M3.downloadPanel.downloadPanelIdSelector).dialog({width:900, height:250, position: { my: "center", at: "center", of: window }}); if (packageCount === 0) { $(M3.downloadPanel.downloadPanelMsgSelector).html('loading '+ pid + '....'); M3.downloadPanel.requestSciMeta(pid); } else { $(M3.downloadPanel.downloadPanelMsgSelector).html('loading package for '+ pid + '....'); M3.downloadPanel.requestDataPackage(M3.downloadPanel.buttonRegister[event.target.id].packages); } }, requestDataPackage : function(pidArray) { for (var i = 0; i < pidArray.length; i++) { var pid = pidArray[i]; var escapedPid = M3.escapeSolr(pid); escapedPid = encodeURIComponent(escapedPid); var packageQuery = '&q=resourceMap:' + escapedPid + ' OR id:' + escapedPid; var url = M3.downloadPanel.searchUrlBase + packageQuery + M3.downloadPanel.packageFields + M3.downloadPanel.sortOrder; $.get(url, M3.downloadPanel.displayResults); } }, requestSciMeta : function(pid) { var escapedPid = M3.escapeSolr(pid); escapedPid = encodeURIComponent(escapedPid); var idQuery = '&q=id:' + escapedPid; var url = M3.downloadPanel.searchUrlBase + idQuery + M3.downloadPanel.packageFields + M3.downloadPanel.sortOrder; $.get(url, M3.downloadPanel.displayResults); }, isScienceMetadata : function(docResult) { return docResult.formatType === M3.downloadPanel.metadataTypeString; }, isResourceMap : function(docResult) { return docResult.formatType === M3.downloadPanel.resourceMapTypeString; }, displayResults : function(data, status, jqXHR) { if (status === 'success') { var results = $.parseJSON(data); var count = results.response.numFound; var docs = results.response.docs; var tableContent = ''; var metadata = []; for (var i = 0; i < docs.length; i++) { var result = docs[i]; var isSciMetadata = M3.downloadPanel.isScienceMetadata(result); if (isSciMetadata === true) { metadata.push(result); } else { tableContent += M3.downloadPanel.addRowToTable(result); } } for (var j = 0; j < metadata.length; j++) { var result = metadata[j]; tableContent += M3.downloadPanel.addRowToTable(result); } tableContent += '
IdentifierTypeSizeDownload
' $(M3.downloadPanel.downloadPanelContentSelector).append(tableContent); $(M3.downloadPanel.downloadPanelMsgSelector).html(''); } else { $(M3.downloadPanel.downloadPanelMsgSelector).html('Could not load data!'); } }, addRowToTable : function(docResult) { var isResourceMap = M3.downloadPanel.isResourceMap(docResult); var row = ''; if (isResourceMap === false) { row += ""; } else { row += ""; } row += docResult.id; row += ''; if (isResourceMap === false) { row += ""; } else { row += ""; } row += docResult.formatId; row += ''; row += ""; row += M3.formatBytesForDisplay(docResult.size); row += ''; row += ""; var formatString = docResult.formatType; if (formatString === 'RESOURCE') { formatString = 'Package'; } row += "

"+formatString+"

"; row += '
'; row += ''; return row; }, initialize : function() { $(this.packageButtonSelector).click(M3.downloadPanel.handleClick); } };