First check in of map of science visualization
This commit is contained in:
parent
c365f9a39a
commit
e6ea91b8be
232 changed files with 1853 additions and 0 deletions
50
productMods/js/visualization/mapofscience/DownloadManager.js
Normal file
50
productMods/js/visualization/mapofscience/DownloadManager.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
/**
|
||||
* Manage async download contents and make sure don't have the same
|
||||
* download request in the same time. Provide ability to abort download.
|
||||
*/
|
||||
|
||||
var DownloadManager = Class.extend({
|
||||
init: function() {
|
||||
this.downloadList = {};
|
||||
},
|
||||
download: function(url, success) {
|
||||
if (!this.hasKey(url)) {
|
||||
this.downloadList[url] = { success: success, // TODO Try removing this property
|
||||
jqxhr: this.startDownload(url, success, this.downloadList)};
|
||||
}
|
||||
},
|
||||
downloadAndWait: function(url, success) {
|
||||
if (!this.hasKey(url)) {
|
||||
$.ajax({
|
||||
url: url,
|
||||
async: false,
|
||||
dataType: 'json',
|
||||
success: function(countData) { success(countData); }
|
||||
});
|
||||
}
|
||||
},
|
||||
startDownload: function(url, success, downloadList) {
|
||||
return $.getJSON(url, // TODO Not always "latest" //TODO Test on server with big file that consume 3 seconds download time. Then Keep on and off the checkbox while downloading, to verify if the duplicate happens
|
||||
function(countData) {
|
||||
if (success) {
|
||||
success(countData);
|
||||
}
|
||||
delete(downloadList[url]);
|
||||
}
|
||||
);
|
||||
},
|
||||
hasKey: function(url) {
|
||||
return (this.downloadList[url]);
|
||||
},
|
||||
abort: function(url) {
|
||||
var options = this.downloadList[url];
|
||||
if (options) {
|
||||
options.jqxhr.abort();
|
||||
delete(this.downloadList[url]);
|
||||
}
|
||||
},
|
||||
isDone: function(url) {
|
||||
return !this.hasKey(url);
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue