6855 |
25 Oct 22 |
nicklas |
var DownloadZip = function() |
6854 |
24 Oct 22 |
nicklas |
2 |
{ |
6854 |
24 Oct 22 |
nicklas |
var zip = {}; |
6854 |
24 Oct 22 |
nicklas |
4 |
|
6854 |
24 Oct 22 |
nicklas |
// Page initialization |
6854 |
24 Oct 22 |
nicklas |
zip.initPage = function() |
6854 |
24 Oct 22 |
nicklas |
7 |
{ |
6855 |
25 Oct 22 |
nicklas |
var pageId = Doc.getPageId(); |
6855 |
25 Oct 22 |
nicklas |
if (pageId == 'password-dialog') |
6855 |
25 Oct 22 |
nicklas |
10 |
{ |
6856 |
25 Oct 22 |
nicklas |
Buttons.addClickHandler('generate', zip.generatePassword); |
6855 |
25 Oct 22 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
6855 |
25 Oct 22 |
nicklas |
Buttons.addClickHandler('btnDownload', zip.makeZip); |
6855 |
25 Oct 22 |
nicklas |
14 |
} |
6854 |
24 Oct 22 |
nicklas |
15 |
} |
6855 |
25 Oct 22 |
nicklas |
16 |
|
6855 |
25 Oct 22 |
nicklas |
zip.initElement = function(element, autoInit) |
6855 |
25 Oct 22 |
nicklas |
18 |
{ |
6855 |
25 Oct 22 |
nicklas |
if (autoInit == 'download-as-zip') |
6855 |
25 Oct 22 |
nicklas |
20 |
{ |
6855 |
25 Oct 22 |
nicklas |
Events.addEventHandler(element, 'click', zip.openPasswordDialog); |
6855 |
25 Oct 22 |
nicklas |
22 |
} |
6855 |
25 Oct 22 |
nicklas |
23 |
} |
6854 |
24 Oct 22 |
nicklas |
24 |
|
6855 |
25 Oct 22 |
nicklas |
zip.openPasswordDialog = function(event) |
6855 |
25 Oct 22 |
nicklas |
26 |
{ |
6855 |
25 Oct 22 |
nicklas |
var fileId = Data.int(event.currentTarget, 'file-id'); |
6855 |
25 Oct 22 |
nicklas |
var homeUrl = Data.get(event.currentTarget, 'home'); |
6855 |
25 Oct 22 |
nicklas |
29 |
|
6855 |
25 Oct 22 |
nicklas |
var url = homeUrl+'/download-as-zip.jsp?ID=' + App.getSessionId(); |
6855 |
25 Oct 22 |
nicklas |
url += '&fileId='+fileId; |
6855 |
25 Oct 22 |
nicklas |
Dialogs.openPopup(url, 'DownloadAsZip'+fileId, 450, 300); |
6855 |
25 Oct 22 |
nicklas |
33 |
} |
6855 |
25 Oct 22 |
nicklas |
34 |
|
6856 |
25 Oct 22 |
nicklas |
35 |
|
6856 |
25 Oct 22 |
nicklas |
zip.generatePassword = function() |
6856 |
25 Oct 22 |
nicklas |
37 |
{ |
6856 |
25 Oct 22 |
nicklas |
var C = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz123456789%!#=*-.abcdefghijkmnpqrstuvwxyz'; |
6856 |
25 Oct 22 |
nicklas |
var pwd = ''; |
6856 |
25 Oct 22 |
nicklas |
for (var i = 0; i < 12; i++) |
6856 |
25 Oct 22 |
nicklas |
41 |
{ |
6856 |
25 Oct 22 |
nicklas |
var p = Math.floor(Math.random()*C.length); |
6856 |
25 Oct 22 |
nicklas |
pwd += C.substring(p, p+1); |
6856 |
25 Oct 22 |
nicklas |
44 |
} |
6856 |
25 Oct 22 |
nicklas |
var frm = document.forms['options']; |
6856 |
25 Oct 22 |
nicklas |
frm.password.value = pwd; |
6856 |
25 Oct 22 |
nicklas |
47 |
} |
6856 |
25 Oct 22 |
nicklas |
48 |
|
6854 |
24 Oct 22 |
nicklas |
zip.makeZip = function() |
6854 |
24 Oct 22 |
nicklas |
50 |
{ |
6854 |
24 Oct 22 |
nicklas |
var frm = document.forms['options']; |
6855 |
25 Oct 22 |
nicklas |
var url = 'Session.servlet?ID='+App.getSessionId(); |
6854 |
24 Oct 22 |
nicklas |
url += '&cmd=DownloadFileAsZip'; |
6854 |
24 Oct 22 |
nicklas |
url += '&fileId='+Data.get('page-data', 'file-id'); |
6854 |
24 Oct 22 |
nicklas |
url += '&password='+encodeURIComponent(frm.password.value); |
6856 |
25 Oct 22 |
nicklas |
url += '&remember='+(frm.rememberPassword.checked?1:0); |
6854 |
24 Oct 22 |
nicklas |
window.opener.location.href = url; |
6854 |
24 Oct 22 |
nicklas |
App.closeWindow(); |
6854 |
24 Oct 22 |
nicklas |
59 |
} |
6854 |
24 Oct 22 |
nicklas |
60 |
|
6854 |
24 Oct 22 |
nicklas |
return zip; |
6854 |
24 Oct 22 |
nicklas |
62 |
}(); |
6854 |
24 Oct 22 |
nicklas |
63 |
|
6855 |
25 Oct 22 |
nicklas |
Doc.onLoad(DownloadZip.initPage); |
6855 |
25 Oct 22 |
nicklas |
Doc.addElementInitializer(DownloadZip.initElement); |