2406 |
07 May 14 |
nicklas |
var Remote = function() |
2406 |
07 May 14 |
nicklas |
2 |
{ |
2406 |
07 May 14 |
nicklas |
var remote = {}; |
2407 |
08 May 14 |
nicklas |
var files; |
2593 |
19 Aug 14 |
nicklas |
var debug = 0; |
2406 |
07 May 14 |
nicklas |
6 |
|
2406 |
07 May 14 |
nicklas |
remote.initPage = function() |
2406 |
07 May 14 |
nicklas |
8 |
{ |
2406 |
07 May 14 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
6824 |
30 Aug 22 |
nicklas |
//Buttons.addClickHandler('btnSaveToBase', remote.saveToBase); |
2406 |
07 May 14 |
nicklas |
11 |
|
2406 |
07 May 14 |
nicklas |
var url = '../OpenGrid.servlet?ID='+App.getSessionId(); |
2406 |
07 May 14 |
nicklas |
url += '&cmd=ListProjectFiles'; |
3837 |
12 Apr 16 |
nicklas |
url += '&clusterId='+Data.get('page-data', 'cluster-id', ''); |
2406 |
07 May 14 |
nicklas |
url += '&path='+encodeURIComponent(Data.get('page-data', 'path')); |
3605 |
16 Nov 15 |
nicklas |
url += '&archive='+encodeURIComponent(Data.get('page-data', 'archive', '')); |
3837 |
12 Apr 16 |
nicklas |
url += '&itemType='+Data.get('page-data', 'item-type', ''); |
3837 |
12 Apr 16 |
nicklas |
url += '&itemId='+Data.int('page-data', 'item-id'); |
3837 |
12 Apr 16 |
nicklas |
url += '&fileserver='+Data.int('page-data', 'fileserver-id', 0); |
2644 |
09 Sep 14 |
nicklas |
20 |
|
2644 |
09 Sep 14 |
nicklas |
Wizard.showLoadingAnimation('Loading files...'); |
2644 |
09 Sep 14 |
nicklas |
Wizard.asyncJsonRequest(url, remote.onFilesLoaded); |
2406 |
07 May 14 |
nicklas |
23 |
} |
2406 |
07 May 14 |
nicklas |
24 |
|
2644 |
09 Sep 14 |
nicklas |
remote.onFilesLoaded = function(response) |
2406 |
07 May 14 |
nicklas |
26 |
{ |
2644 |
09 Sep 14 |
nicklas |
files = response.files; |
2644 |
09 Sep 14 |
nicklas |
if (files.length == 0) |
2406 |
07 May 14 |
nicklas |
29 |
{ |
2644 |
09 Sep 14 |
nicklas |
Wizard.setFatalError('Could not find any files in folder ' + response.projectArchive + Data.get('page-data', 'path')); |
2406 |
07 May 14 |
nicklas |
return; |
2406 |
07 May 14 |
nicklas |
32 |
} |
2406 |
07 May 14 |
nicklas |
33 |
|
2406 |
07 May 14 |
nicklas |
var html = '<table id="file-list">'; |
2406 |
07 May 14 |
nicklas |
html += '<tr>'; |
2407 |
08 May 14 |
nicklas |
html += '<th></th>'; |
2406 |
07 May 14 |
nicklas |
html += '<th>Folder / file</th>'; |
2406 |
07 May 14 |
nicklas |
html += '<th class="file-size">Size</th>'; |
3839 |
13 Apr 16 |
nicklas |
html += '<th class="last-modified">Last modified</th>'; |
3839 |
13 Apr 16 |
nicklas |
html += '<th class="owner">Owner</th>'; |
2578 |
15 Aug 14 |
nicklas |
html += '<th>Download</th>'; |
2406 |
07 May 14 |
nicklas |
html += '</tr>'; |
2407 |
08 May 14 |
nicklas |
var currentFolder = '-'; |
2406 |
07 May 14 |
nicklas |
for (var fileNo = 0; fileNo < files.length; fileNo++) |
2406 |
07 May 14 |
nicklas |
45 |
{ |
2406 |
07 May 14 |
nicklas |
var file = files[fileNo]; |
2406 |
07 May 14 |
nicklas |
var path = file.path; |
2406 |
07 May 14 |
nicklas |
var i = path.lastIndexOf('/'); |
2406 |
07 May 14 |
nicklas |
49 |
|
2407 |
08 May 14 |
nicklas |
var folder = (i > 0) ? path.substring(0, i) : '.'; |
2407 |
08 May 14 |
nicklas |
var filename = path.substring(i+1); |
2407 |
08 May 14 |
nicklas |
file.folder = folder; |
2407 |
08 May 14 |
nicklas |
file.name = filename; |
7341 |
11 Sep 23 |
nicklas |
var lastDot = file.name.lastIndexOf('.'); |
7116 |
17 Apr 23 |
nicklas |
file.ext = lastDot >= 0 ? file.name.substr(lastDot+1) : null; |
2407 |
08 May 14 |
nicklas |
56 |
|
2407 |
08 May 14 |
nicklas |
if (folder != currentFolder) |
2406 |
07 May 14 |
nicklas |
58 |
{ |
2406 |
07 May 14 |
nicklas |
html += '<tr class="folder">'; |
2578 |
15 Aug 14 |
nicklas |
html += '<td><img src="../images/remote_folder.png"></td>'; |
3839 |
13 Apr 16 |
nicklas |
html += '<td colspan="5">'+Strings.encodeTags(folder)+'</td>'; |
2406 |
07 May 14 |
nicklas |
html += '</tr>'; |
2407 |
08 May 14 |
nicklas |
currentFolder = folder; |
2406 |
07 May 14 |
nicklas |
64 |
} |
2406 |
07 May 14 |
nicklas |
65 |
|
2406 |
07 May 14 |
nicklas |
html += '<tr class="file highlight">'; |
2578 |
15 Aug 14 |
nicklas |
html += '<td></td>'; |
2407 |
08 May 14 |
nicklas |
html += '<td class="file-name">'+Strings.encodeTags(file.name)+'</td>'; |
2406 |
07 May 14 |
nicklas |
html += '<td class="file-size">'+Numbers.formatBytes(file.size)+'</td>'; |
3839 |
13 Apr 16 |
nicklas |
html += '<td class="last-modified">'+Reggie.reformatDate(file.lastModified)+'</td>'; |
3839 |
13 Apr 16 |
nicklas |
html += '<td class="owner">'+Strings.encodeTags(file.owner)+'</td>'; |
2406 |
07 May 14 |
nicklas |
html += '<td>'; |
2407 |
08 May 14 |
nicklas |
html += '<span class="link download-file" data-file-no="'+fileNo+'" title="Download this file to your local computer"><img src="../images/download.png"></span>'; |
7118 |
18 Apr 23 |
nicklas |
if (file.ext == 'txt' || file.ext == 'out' || file.ext == 'vcf' || file.ext == 'tsv' || file.ext == 'csv' || file.ext == 'bed') |
7116 |
17 Apr 23 |
nicklas |
75 |
{ |
7116 |
17 Apr 23 |
nicklas |
html += '<span class="link view-tabular-file" data-file-no="'+fileNo+'" title="View this file as a data table"><img src="../images/report.png"></span>'; |
7116 |
17 Apr 23 |
nicklas |
77 |
} |
7312 |
29 Aug 23 |
nicklas |
else if (file.ext == 'png' || file.ext == 'pdf') |
7312 |
29 Aug 23 |
nicklas |
79 |
{ |
7312 |
29 Aug 23 |
nicklas |
html += '<span class="link view-file" data-file-no="'+fileNo+'" title="View this file in a popup window"><img src="../../../images/zoom.png"></span>'; |
7312 |
29 Aug 23 |
nicklas |
81 |
} |
2406 |
07 May 14 |
nicklas |
html += '</td>'; |
2406 |
07 May 14 |
nicklas |
html += '</tr>'; |
2406 |
07 May 14 |
nicklas |
84 |
} |
2406 |
07 May 14 |
nicklas |
html += '</table>'; |
2644 |
09 Sep 14 |
nicklas |
Doc.element('files').innerHTML = html; |
2406 |
07 May 14 |
nicklas |
87 |
|
2406 |
07 May 14 |
nicklas |
var downloadable = document.getElementsByClassName('download-file'); |
2407 |
08 May 14 |
nicklas |
for (var fileNo = 0; fileNo < downloadable.length; fileNo++) |
2406 |
07 May 14 |
nicklas |
90 |
{ |
2406 |
07 May 14 |
nicklas |
Events.addEventHandler(downloadable[fileNo], 'click', remote.downloadFile); |
2406 |
07 May 14 |
nicklas |
92 |
} |
7312 |
29 Aug 23 |
nicklas |
93 |
|
7312 |
29 Aug 23 |
nicklas |
var viewable = document.getElementsByClassName('view-file'); |
7312 |
29 Aug 23 |
nicklas |
for (var fileNo = 0; fileNo < viewable.length; fileNo++) |
7312 |
29 Aug 23 |
nicklas |
96 |
{ |
7312 |
29 Aug 23 |
nicklas |
Events.addEventHandler(viewable[fileNo], 'click', remote.viewFile); |
7312 |
29 Aug 23 |
nicklas |
98 |
} |
7116 |
17 Apr 23 |
nicklas |
99 |
|
7116 |
17 Apr 23 |
nicklas |
var tabular = document.getElementsByClassName('view-tabular-file'); |
7116 |
17 Apr 23 |
nicklas |
for (var fileNo = 0; fileNo < tabular.length; fileNo++) |
7116 |
17 Apr 23 |
nicklas |
102 |
{ |
7116 |
17 Apr 23 |
nicklas |
Events.addEventHandler(tabular[fileNo], 'click', remote.viewTabularFile); |
7116 |
17 Apr 23 |
nicklas |
104 |
} |
2406 |
07 May 14 |
nicklas |
105 |
} |
2406 |
07 May 14 |
nicklas |
106 |
|
2406 |
07 May 14 |
nicklas |
remote.downloadFile = function(event) |
2406 |
07 May 14 |
nicklas |
108 |
{ |
2407 |
08 May 14 |
nicklas |
var fileNo = Data.get(event.currentTarget, 'file-no'); |
2407 |
08 May 14 |
nicklas |
var file = files[fileNo]; |
2407 |
08 May 14 |
nicklas |
var path = Data.get('page-data', 'path')+'/'+file.path; |
3837 |
12 Apr 16 |
nicklas |
112 |
|
2406 |
07 May 14 |
nicklas |
var url = '../OpenGrid.servlet?ID='+App.getSessionId(); |
2406 |
07 May 14 |
nicklas |
url += '&cmd=DownloadProjectFile'; |
3837 |
12 Apr 16 |
nicklas |
url += '&clusterId='+encodeURIComponent(Data.get('page-data', 'cluster-id', '')); |
2406 |
07 May 14 |
nicklas |
url += '&path='+encodeURIComponent(path); |
3837 |
12 Apr 16 |
nicklas |
url += '&fileserver='+Data.int('page-data', 'fileserver-id', 0); |
3605 |
16 Nov 15 |
nicklas |
url += '&archive='+encodeURIComponent(file.archive || ''); |
2407 |
08 May 14 |
nicklas |
url += '&size='+file.size; |
2406 |
07 May 14 |
nicklas |
120 |
|
2406 |
07 May 14 |
nicklas |
location.href = url; |
2406 |
07 May 14 |
nicklas |
122 |
} |
2406 |
07 May 14 |
nicklas |
123 |
|
7312 |
29 Aug 23 |
nicklas |
remote.viewFile = function(event) |
7312 |
29 Aug 23 |
nicklas |
125 |
{ |
7312 |
29 Aug 23 |
nicklas |
var fileNo = Data.get(event.currentTarget, 'file-no'); |
7312 |
29 Aug 23 |
nicklas |
var file = files[fileNo]; |
7312 |
29 Aug 23 |
nicklas |
var path = Data.get('page-data', 'path')+'/'+file.path; |
7312 |
29 Aug 23 |
nicklas |
129 |
|
7312 |
29 Aug 23 |
nicklas |
var url = '../OpenGrid.servlet?ID='+App.getSessionId(); |
7312 |
29 Aug 23 |
nicklas |
url += '&cmd=ViewProjectFile'; |
7312 |
29 Aug 23 |
nicklas |
url += '&clusterId='+encodeURIComponent(Data.get('page-data', 'cluster-id', '')); |
7312 |
29 Aug 23 |
nicklas |
url += '&path='+encodeURIComponent(path); |
7312 |
29 Aug 23 |
nicklas |
url += '&fileserver='+Data.int('page-data', 'fileserver-id', 0); |
7312 |
29 Aug 23 |
nicklas |
url += '&archive='+encodeURIComponent(file.archive || ''); |
7312 |
29 Aug 23 |
nicklas |
url += '&size='+file.size; |
7312 |
29 Aug 23 |
nicklas |
137 |
|
7312 |
29 Aug 23 |
nicklas |
Dialogs.openPopup(url, 'ViewFile'+fileNo, 900, 600); |
7312 |
29 Aug 23 |
nicklas |
139 |
} |
7312 |
29 Aug 23 |
nicklas |
140 |
|
7312 |
29 Aug 23 |
nicklas |
141 |
|
7116 |
17 Apr 23 |
nicklas |
remote.viewTabularFile = function(event) |
7116 |
17 Apr 23 |
nicklas |
143 |
{ |
7116 |
17 Apr 23 |
nicklas |
var fileNo = Data.get(event.currentTarget, 'file-no'); |
7116 |
17 Apr 23 |
nicklas |
var file = files[fileNo]; |
7116 |
17 Apr 23 |
nicklas |
var path = Data.get('page-data', 'path')+'/'+file.path; |
7116 |
17 Apr 23 |
nicklas |
147 |
|
7116 |
17 Apr 23 |
nicklas |
var url = '../OpenGrid.servlet?ID='+App.getSessionId(); |
7116 |
17 Apr 23 |
nicklas |
url += '&cmd=ViewTabularFile'; |
7116 |
17 Apr 23 |
nicklas |
url += '&clusterId='+encodeURIComponent(Data.get('page-data', 'cluster-id', '')); |
7116 |
17 Apr 23 |
nicklas |
url += '&path='+encodeURIComponent(path); |
7116 |
17 Apr 23 |
nicklas |
url += '&fileserver='+Data.int('page-data', 'fileserver-id', 0); |
7116 |
17 Apr 23 |
nicklas |
url += '&archive='+encodeURIComponent(file.archive || ''); |
7116 |
17 Apr 23 |
nicklas |
url += '&size='+file.size; |
7116 |
17 Apr 23 |
nicklas |
155 |
|
7116 |
17 Apr 23 |
nicklas |
Dialogs.openPopup(url, 'ViewTabularFile'+fileNo, 1200, 800); |
7116 |
17 Apr 23 |
nicklas |
157 |
} |
7116 |
17 Apr 23 |
nicklas |
158 |
|
2406 |
07 May 14 |
nicklas |
return remote; |
2406 |
07 May 14 |
nicklas |
160 |
}(); |
2406 |
07 May 14 |
nicklas |
161 |
|
2406 |
07 May 14 |
nicklas |
Doc.onLoad(Remote.initPage); |