2007-09-16 04:36:42 +02:00
|
|
|
/**
|
|
|
|
* If one of methods is not commented look for comment in Upload.js
|
|
|
|
*/
|
2007-09-16 04:36:16 +02:00
|
|
|
CMSMain_upload = Class.create();
|
|
|
|
CMSMain_upload.prototype = {
|
2007-09-16 04:34:08 +02:00
|
|
|
initialize: function() {
|
2007-09-16 04:36:16 +02:00
|
|
|
this.iframe = window.top.document.getElementById('AssetAdmin_upload');
|
|
|
|
this.onLoad();
|
2007-09-16 04:34:08 +02:00
|
|
|
},
|
2007-09-16 04:36:16 +02:00
|
|
|
|
2007-09-16 04:34:08 +02:00
|
|
|
onLoad: function() {
|
2007-09-16 04:36:16 +02:00
|
|
|
this.upload = new Upload({
|
|
|
|
fileUploadLimit : '6',
|
|
|
|
beginUploadOnQueue : false,
|
|
|
|
fileQueued : this.uploadFileQueuedCallback.bind(this),
|
|
|
|
fileProgress : this.uploadProgressCallback.bind(this),
|
|
|
|
fileCancelled : this.uploadFileCancelCallback.bind(this),
|
|
|
|
fileComplete : this.uploadFileCompleteCallback.bind(this),
|
|
|
|
queueComplete : this.uploadQueueCompleteCallback.bind(this),
|
|
|
|
buildUI : this.extendForm.bind(this)
|
2007-09-16 04:34:08 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2007-09-16 04:36:42 +02:00
|
|
|
/**
|
|
|
|
* Builds UI, called only when Upload object will be able to create flash uploader.
|
|
|
|
*/
|
|
|
|
|
2007-09-16 04:34:08 +02:00
|
|
|
extendForm: function() {
|
2007-09-16 04:36:16 +02:00
|
|
|
if(this.iframe.contentDocument == undefined) this.iframe.contentDocument = document.frames[0].document;//IE HACK
|
|
|
|
element = this.iframe.contentDocument.getElementById('Form_UploadForm');
|
|
|
|
inputFile = this.iframe.contentDocument.getElementById('Form_UploadForm_Files-0');
|
2007-09-16 04:34:08 +02:00
|
|
|
inputFileParent = inputFile.parentNode;
|
|
|
|
inputFileParent.removeChild(inputFile);
|
2007-09-16 04:36:16 +02:00
|
|
|
inputFile = this.iframe.contentDocument.createElement('input');
|
2007-09-16 04:34:08 +02:00
|
|
|
inputFile.type = 'text';
|
|
|
|
inputFile.id = 'Form_UploadForm_Files-0';
|
|
|
|
inputFileParent.appendChild(inputFile);
|
2007-09-16 04:36:16 +02:00
|
|
|
inputButton = this.iframe.contentDocument.getElementById('Form_UploadForm_Files-1');
|
2007-09-16 04:34:08 +02:00
|
|
|
if(inputButton != null) inputButton.parentNode.removeChild(inputButton);
|
2007-09-16 04:36:16 +02:00
|
|
|
inputButton = this.iframe.contentDocument.createElement('input');
|
2007-09-16 04:34:08 +02:00
|
|
|
inputButton.type = 'button';
|
|
|
|
inputButton.id = 'Form_UploadForm_Files-1';
|
|
|
|
inputButton.value = ' Browse...';
|
|
|
|
inputButton.style.width = '66px';
|
|
|
|
inputButton.style.height = '19px';
|
|
|
|
inputButton.style.position = 'relative';
|
|
|
|
inputButton.style.top = '1px';
|
|
|
|
inputButton.style.fontFamily = 'Arial';
|
|
|
|
inputButton.style.fontSize = '1.06em';
|
|
|
|
inputFileParent.appendChild(inputButton);
|
2007-09-16 04:36:16 +02:00
|
|
|
Event.observe(inputButton,'click',this.onBrowseClick.bind(this));
|
|
|
|
Event.observe(this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload'),'click',this.onUploadClick.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
onBrowseClick: function(event) {
|
|
|
|
this.upload.browse();
|
|
|
|
},
|
|
|
|
|
|
|
|
onUploadClick: function(event) {
|
|
|
|
Event.stop(event);
|
|
|
|
this.upload.startUpload();
|
2007-09-16 04:34:08 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
uploadFileQueuedCallback: function(file,queueLength) {
|
2007-09-16 17:21:41 +02:00
|
|
|
this.upload.setFolderID(this.iframe.contentDocument.getElementById('Form_UploadForm_ID').value);
|
2007-09-16 04:36:16 +02:00
|
|
|
this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = false;
|
|
|
|
var fileContainer = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList');
|
2007-09-16 04:34:08 +02:00
|
|
|
if(fileContainer == null) {
|
2007-09-16 04:36:16 +02:00
|
|
|
fileContainer = this.iframe.contentDocument.createElement('div');
|
2007-09-16 04:34:08 +02:00
|
|
|
fileContainer.id = 'Form_UploadForm_FilesList';
|
2007-09-16 04:36:16 +02:00
|
|
|
this.iframe.contentDocument.getElementById('Form_UploadForm').appendChild(fileContainer);
|
2007-09-16 04:34:08 +02:00
|
|
|
}
|
|
|
|
|
2007-09-16 04:36:16 +02:00
|
|
|
var fileToUpload = this.iframe.contentDocument.createElement('div');
|
2007-09-16 04:34:08 +02:00
|
|
|
fileToUpload.id = 'Form_UploadForm_FilesList_' + file.id;
|
|
|
|
fileToUpload.style.marginBottom = '3px';
|
|
|
|
fileContainer.appendChild(fileToUpload);
|
|
|
|
|
2007-09-16 04:36:16 +02:00
|
|
|
var fileName = this.iframe.contentDocument.createElement('div');
|
2007-09-16 04:34:08 +02:00
|
|
|
fileName.id = 'Form_UploadForm_FilesList_Name_' + file.id;
|
|
|
|
fileName.style.position = 'relative';
|
|
|
|
fileName.style.top = '-4px';
|
|
|
|
fileName.style.display = 'inline';
|
|
|
|
fileName.style.padding = '2px';
|
|
|
|
fileName.innerHTML = file.name;
|
|
|
|
fileName.style.height = Element.getDimensions(fileName).height + 1 + 'px';//IE hack
|
|
|
|
fileToUpload.appendChild(fileName);
|
|
|
|
|
2007-09-16 04:36:16 +02:00
|
|
|
var fileProgress = this.iframe.contentDocument.createElement('div');
|
2007-09-16 04:34:08 +02:00
|
|
|
fileProgress.id = 'Form_UploadForm_FilesList_Progress_' + file.id;
|
|
|
|
Position.clone(fileName,fileProgress);
|
|
|
|
fileProgress.style.backgroundColor = 'black';
|
|
|
|
fileProgress.style.display = 'inline';
|
|
|
|
fileProgress.style.position = 'absolute';
|
|
|
|
fileProgress.style.left = '5px';
|
|
|
|
fileProgress.style.width = '0px';
|
|
|
|
fileProgress.finished = false;
|
|
|
|
switch(BrowserDetect.browser) {
|
|
|
|
case 'Explorer':
|
|
|
|
fileProgress.style.top = parseInt(fileProgress.style.top) + 6 + 'px';
|
|
|
|
break;
|
|
|
|
case 'Safari':
|
|
|
|
fileProgress.style.top = parseInt(fileProgress.style.top) + 4 + 'px';
|
|
|
|
break;
|
|
|
|
case 'Firefox':
|
|
|
|
fileProgress.style.top = parseInt(fileProgress.style.top) + 8 + 'px';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fileProgress.style.height = Element.getDimensions(fileName).height + 1 + 'px';
|
|
|
|
fileToUpload.appendChild(fileProgress);
|
|
|
|
|
2007-09-16 04:36:16 +02:00
|
|
|
var fileDelete = this.iframe.contentDocument.createElement('input');
|
2007-09-16 04:34:08 +02:00
|
|
|
fileDelete.id = file.id;
|
|
|
|
fileDelete.type = 'button';
|
|
|
|
fileDelete.value = 'Delete';
|
|
|
|
Element.addClassName(fileDelete,'delete');
|
|
|
|
fileToUpload.appendChild(fileDelete);
|
2007-09-16 04:36:16 +02:00
|
|
|
Event.observe(fileDelete,'click',this.uploadFileCancelCallback.bind(this));
|
2007-09-16 04:34:08 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
uploadProgressCallback: function(file,bytesLoaded) {
|
2007-09-16 04:36:16 +02:00
|
|
|
fileName = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Name_' + file.id);
|
2007-09-16 04:34:08 +02:00
|
|
|
fileName.style.border = 'solid 1px black';
|
2007-09-16 04:36:16 +02:00
|
|
|
fileProgress = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Progress_' + file.id);
|
|
|
|
fileProgress.style.opacity = 0.3;fileProgress.style.filter = 'alpha(opacity=30)';
|
2007-09-16 04:34:08 +02:00
|
|
|
if(!fileProgress.cloned) {
|
|
|
|
Position.clone(fileName,fileProgress);
|
|
|
|
fileProgress.style.width = '0px';
|
|
|
|
fileProgress.cloned = true;
|
|
|
|
}
|
|
|
|
fileProgress.style.width = (bytesLoaded / file.size) * Element.getDimensions(fileName).width - 1 + 'px';
|
|
|
|
},
|
|
|
|
|
|
|
|
uploadFileCompleteCallback: function(file,serverData) {
|
2007-09-16 04:36:16 +02:00
|
|
|
this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Progress_' + file.id).finished = true;
|
2007-09-16 04:34:08 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
uploadFileCancelCallback: function(event) {
|
|
|
|
element = Event.element(event);
|
|
|
|
fileId = element.id;
|
2007-09-16 04:36:16 +02:00
|
|
|
fileContainer = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList');
|
|
|
|
elementToDelete = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_' + fileId);
|
2007-09-16 04:34:08 +02:00
|
|
|
elementToDelete.parentNode.removeChild(elementToDelete);
|
|
|
|
filesToUpload = fileContainer.childNodes.length;
|
|
|
|
if(filesToUpload > 0) {
|
2007-09-16 04:36:16 +02:00
|
|
|
this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = false;
|
2007-09-16 04:34:08 +02:00
|
|
|
} else {
|
2007-09-16 04:36:16 +02:00
|
|
|
this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = true;
|
2007-09-16 04:34:08 +02:00
|
|
|
}
|
|
|
|
$A(fileContainer.childNodes).each(
|
|
|
|
function(item) {
|
|
|
|
$A(item.childNodes).each(
|
|
|
|
function(item) {
|
|
|
|
if(item.id.indexOf('Name') != -1) {
|
|
|
|
fileName = item;
|
|
|
|
}
|
|
|
|
if(item.id.indexOf('Progress') != -1) {
|
|
|
|
fileProgress = item;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Position.clone(fileName,fileProgress);
|
|
|
|
if(fileProgress.finished == false) fileProgress.style.width = '0px';
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
uploadQueueCompleteCallback: function() {
|
2007-09-16 04:36:16 +02:00
|
|
|
eval(this.upload.getUploadMessage().replace('1',this.upload.getFilesUploaded()));
|
2007-09-16 04:34:08 +02:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 04:36:16 +02:00
|
|
|
window.top.document.CMSMain_upload = CMSMain_upload;
|