mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 09:05:53 +00:00
APICHANGE: removed SWFUpload. Refactored Content Editors uploader to use standard uploader. (from r97489)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@102718 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
2e1b39dfc4
commit
32bdc74381
@ -59,10 +59,6 @@ class AssetAdmin extends LeftAndMain {
|
||||
if(!file_exists(ASSETS_PATH)) Filesystem::makeFolder(ASSETS_PATH);
|
||||
|
||||
Requirements::javascript(CMS_DIR . "/javascript/AssetAdmin.js");
|
||||
Requirements::javascript(CMS_DIR . "/javascript/CMSMain_upload.js");
|
||||
Requirements::javascript(CMS_DIR . "/javascript/Upload.js");
|
||||
Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/swfupload/swfupload/swfupload.js");
|
||||
|
||||
Requirements::css(CMS_DIR . "/css/AssetAdmin.css");
|
||||
|
||||
Requirements::customScript(<<<JS
|
||||
@ -104,8 +100,6 @@ JS
|
||||
* Return the form object shown in the uploadiframe.
|
||||
*/
|
||||
function UploadForm() {
|
||||
// disabled flash upload javascript (CMSMain_upload()) below,
|
||||
// see r54952 (originally committed in r42014)
|
||||
$form = new Form($this,'UploadForm', new FieldSet(
|
||||
new HiddenField("ID", "", $this->currentPageID()),
|
||||
new HiddenField("FolderID", "", $this->currentPageID()),
|
||||
|
@ -287,9 +287,6 @@ class LeftAndMain extends Controller {
|
||||
'sapphire/thirdparty/scriptaculous/controls.js',
|
||||
'cms/javascript/LeftAndMain.js',
|
||||
'sapphire/javascript/tree/tree.js',
|
||||
'sapphire/thirdparty/swfupload/swfupload/swfupload.js',
|
||||
'cms/javascript/Upload.js',
|
||||
'cms/javascript/TinyMCEImageEnhancement.js',
|
||||
'sapphire/javascript/TreeSelectorField.js',
|
||||
'cms/javascript/ThumbnailStripField.js',
|
||||
)
|
||||
|
@ -1,20 +0,0 @@
|
||||
.contentPanel .group {
|
||||
display: inline;
|
||||
margin-left: 2px;
|
||||
}
|
||||
.contentPanel .middleColumn {
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
.contentPanel .link {
|
||||
text-decoration: none;
|
||||
margin-left: 2px;
|
||||
}
|
||||
|
||||
|
||||
.contentPanel .tree_holder {
|
||||
display: inline;
|
||||
}
|
||||
.contentPanel #NewFolderName {
|
||||
width: 120px;
|
||||
margin-top: 0;
|
||||
}
|
@ -539,3 +539,29 @@
|
||||
#ui-datepicker-div {
|
||||
z-index: 1002;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload Image (Image Toolbar)
|
||||
*/
|
||||
#Form_EditorToolbarImageForm .file,
|
||||
#Form_EditorToolbarImageForm #UploadFormResponse {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.showUploadField {
|
||||
font-size: 11px;
|
||||
padding: 1px 3px;
|
||||
}
|
||||
.showUploadField a {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#UploadFormResponse {
|
||||
padding: 6px 0;
|
||||
font-size: 12px;
|
||||
}
|
||||
#UploadFormResponse.loading
|
||||
.loading#UploadFormResponse {
|
||||
background: url(../../cms/images/network-save.gif) no-repeat left center;
|
||||
padding-left: 20px;
|
||||
}
|
@ -1,166 +0,0 @@
|
||||
/**
|
||||
* This class is used for upload in asset part.
|
||||
* If one of methods is not commented look for comment in Upload.js
|
||||
|
||||
*/
|
||||
CMSMain_upload = Class.create();
|
||||
CMSMain_upload.prototype = {
|
||||
initialize: function() {
|
||||
|
||||
// If those 2 checks pass, we can provide upload capabilities to the user
|
||||
this.iframe = window.top.document.getElementById('AssetAdmin_upload');
|
||||
this.onLoad();
|
||||
},
|
||||
|
||||
onLoad: function() {
|
||||
this.upload = new Upload({
|
||||
fileUploadLimit : '6',
|
||||
securityID : $('SecurityID').value,
|
||||
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)
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Builds UI, called only when Upload object will be able to create flash uploader.
|
||||
*/
|
||||
|
||||
extendForm: function() {
|
||||
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');
|
||||
inputFileParent = inputFile.parentNode;
|
||||
inputFileParent.removeChild(inputFile);
|
||||
inputFile = this.iframe.contentDocument.createElement('input');
|
||||
inputFile.type = 'text';
|
||||
inputFile.id = 'Form_UploadForm_Files-0';
|
||||
inputFileParent.appendChild(inputFile);
|
||||
inputButton = this.iframe.contentDocument.getElementById('Form_UploadForm_Files-1');
|
||||
if(inputButton != null) inputButton.parentNode.removeChild(inputButton);
|
||||
inputButton = this.iframe.contentDocument.createElement('input');
|
||||
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);
|
||||
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();
|
||||
},
|
||||
|
||||
uploadFileQueuedCallback: function(file,queueLength) {
|
||||
this.upload.setFolderID(this.iframe.contentDocument.getElementById('Form_UploadForm_ID').value);
|
||||
this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = false;
|
||||
var fileContainer = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList');
|
||||
if(fileContainer == null) {
|
||||
fileContainer = this.iframe.contentDocument.createElement('div');
|
||||
fileContainer.id = 'Form_UploadForm_FilesList';
|
||||
this.iframe.contentDocument.getElementById('Form_UploadForm').appendChild(fileContainer);
|
||||
}
|
||||
|
||||
var fileToUpload = this.iframe.contentDocument.createElement('div');
|
||||
fileToUpload.id = 'Form_UploadForm_FilesList_' + file.id;
|
||||
fileToUpload.style.marginBottom = '3px';
|
||||
fileContainer.appendChild(fileToUpload);
|
||||
|
||||
var fileName = this.iframe.contentDocument.createElement('div');
|
||||
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);
|
||||
|
||||
var fileProgress = this.iframe.contentDocument.createElement('div');
|
||||
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;
|
||||
fileProgress.style.top = parseInt(fileProgress.style.top) + 6 + 'px';
|
||||
fileProgress.style.height = Element.getDimensions(fileName).height + 1 + 'px';
|
||||
fileToUpload.appendChild(fileProgress);
|
||||
|
||||
var fileDelete = this.iframe.contentDocument.createElement('input');
|
||||
fileDelete.id = file.id;
|
||||
fileDelete.type = 'button';
|
||||
fileDelete.value = 'Delete';
|
||||
Element.addClassName(fileDelete,'delete');
|
||||
fileToUpload.appendChild(fileDelete);
|
||||
Event.observe(fileDelete,'click',this.uploadFileCancelCallback.bind(this));
|
||||
},
|
||||
|
||||
uploadProgressCallback: function(file,bytesLoaded) {
|
||||
fileName = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Name_' + file.id);
|
||||
fileName.style.border = 'solid 1px black';
|
||||
fileProgress = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Progress_' + file.id);
|
||||
fileProgress.style.opacity = 0.3;fileProgress.style.filter = 'alpha(opacity=30)';
|
||||
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) {
|
||||
this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_Progress_' + file.id).finished = true;
|
||||
},
|
||||
|
||||
uploadFileCancelCallback: function(event) {
|
||||
element = Event.element(event);
|
||||
fileId = element.id;
|
||||
fileContainer = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList');
|
||||
elementToDelete = this.iframe.contentDocument.getElementById('Form_UploadForm_FilesList_' + fileId);
|
||||
elementToDelete.parentNode.removeChild(elementToDelete);
|
||||
filesToUpload = fileContainer.childNodes.length;
|
||||
if(filesToUpload > 0) {
|
||||
this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = false;
|
||||
} else {
|
||||
this.iframe.contentDocument.getElementById('Form_UploadForm_action_upload').disabled = true;
|
||||
}
|
||||
$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() {
|
||||
eval(this.upload.getUploadMessage().replace(/Uploaded 1 files/g,'Uploaded ' + this.upload.getFilesUploaded() + ' files'));
|
||||
}
|
||||
}
|
||||
window.top.document.CMSMain_upload = CMSMain_upload;
|
@ -1,225 +0,0 @@
|
||||
/**
|
||||
* This class is used for upload in TinyMCE editor.
|
||||
* If one of methods is not commented look for comment in Upload.js.
|
||||
*/
|
||||
TinyMCEImageEnhancement = Class.create();
|
||||
TinyMCEImageEnhancement.prototype = {
|
||||
initialize: function() {
|
||||
this.filesUploaded = 0;
|
||||
this.processInProgress = false;
|
||||
|
||||
Event.observe($('AddFolder'),'click',this.onAddFolder.bind(this));
|
||||
Event.observe($('FolderOk'),'click',this.onFolderOk.bind(this));
|
||||
Event.observe($('FolderCancel'),'click',this.onFolderCancel.bind(this));
|
||||
|
||||
this.onLoad();
|
||||
},
|
||||
|
||||
onLoad: function() {
|
||||
this.upload = new Upload({
|
||||
fileUploadLimit : '6',
|
||||
button_image_url : 'cms/images/swf-upload-button-small.jpg',
|
||||
button_width : 59,
|
||||
button_height: 18,
|
||||
fileQueued: this.uploadFileQueuedCallback.bind(this),
|
||||
fileComplete: this.uploadFileCompleteCallback.bind(this),
|
||||
queueComplete: this.uploadQueueCompleteCallback.bind(this)
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Method creates HTML element, only reason for this method is DRY.
|
||||
*/
|
||||
addElement: function(tag, className, parent, properties) {
|
||||
var e = document.createElement(tag);
|
||||
Element.addClassName(e,className);
|
||||
parent.appendChild(e);
|
||||
Object.extend(e,properties);
|
||||
return e;
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when user clicks "add folder" anchor.
|
||||
*/
|
||||
|
||||
onAddFolder: function(event) {
|
||||
Event.stop(event);
|
||||
Element.hide('AddFolder');
|
||||
Element.show('NewFolderName','FolderOk','FolderCancel');
|
||||
this.applyIE6Hack();
|
||||
},
|
||||
|
||||
/**
|
||||
* The user clicks the "ok" anchor link, the click event calls up
|
||||
* this function which creates a new AJAX request to add a new folder
|
||||
* using the addfolder function in AssetAdmin.php (admin/assets/addfolder).
|
||||
*/
|
||||
onFolderOk: function(event) {
|
||||
Event.stop(event);
|
||||
var folderName = $('NewFolderName').value;
|
||||
var options = {
|
||||
method: 'post',
|
||||
postBody: 'ParentID=' + this.getParentID() + '&ajax=1&returnID=1&Name=' + folderName + ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : ''),
|
||||
onSuccess: this.onFolderGetSuccess.bind(this),
|
||||
onFailure: function(transport) {
|
||||
errorMessage('Error: Folder not added', transport);
|
||||
}
|
||||
};
|
||||
|
||||
new Ajax.Request('admin/assets/addfolder', options);
|
||||
},
|
||||
|
||||
/**
|
||||
* If the "addFolderOk" function does a successful AJAX post, call this
|
||||
* function. Take the folder ID that was created in "addFolderOk"
|
||||
* via ajax and send data to modify that folder record.
|
||||
*/
|
||||
onFolderGetSuccess: function(transport) {
|
||||
var folderID = transport.responseText;
|
||||
|
||||
var date = new Date();
|
||||
var year = date.getFullYear();
|
||||
var month = date.getMonth() < 10 ? '0' + date.getMonth() : date.getMonth();
|
||||
var day = date.getDay() < 10 ? '0' + date.getDay() : date.getDay();
|
||||
var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
|
||||
var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
|
||||
var seconds = date.getSeconds() < 10 == 1 ? '0' + date.getSeconds() : date.getSeconds();
|
||||
var currentDate = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
|
||||
|
||||
var folderName = $('NewFolderName').value;
|
||||
|
||||
this.folderID = folderID;
|
||||
|
||||
statusMessage('Creating new folder');
|
||||
$('TreeDropdownField_Form_EditorToolbarImageForm_FolderID').itemTree = null;
|
||||
$('TreeDropdownField_Form_EditorToolbarImageForm_FolderID').setValue(this.folderID);
|
||||
$('NewFolderName').value = '';
|
||||
Element.show('AddFolder');
|
||||
Element.hide('NewFolderName','FolderOk','FolderCancel');
|
||||
this.removeIE6Hack();
|
||||
},
|
||||
|
||||
/**
|
||||
* If user doesn't want to add folder return to default UI.
|
||||
*/
|
||||
|
||||
onFolderCancel: function(event) {
|
||||
$('NewFolderName').value = '';
|
||||
Element.show('AddFolder');
|
||||
Element.hide('NewFolderName','FolderOk','FolderCancel');
|
||||
this.removeIE6Hack();
|
||||
Event.stop(event);
|
||||
return false;
|
||||
},
|
||||
|
||||
uploadFileQueuedCallback: function(file,queueLength) {
|
||||
if(this.getParentID() == "root") {
|
||||
statusMessage("Please choose folder","bad");
|
||||
}
|
||||
else {
|
||||
this.processInProgress = true;
|
||||
this.upload.swfu.addPostParam('FolderID', this.getParentID());
|
||||
this.upload.swfu.addFileParam(file.id,'ID',this.folderID);
|
||||
this.upload.swfu.addFileParam(file.id,'Files',file.name);
|
||||
$('UploadFiles').innerHTML = "Uploading Files...("+ this.filesUploaded +")";
|
||||
this.upload.swfu.startUpload(file.id);
|
||||
}
|
||||
},
|
||||
|
||||
uploadFileCompleteCallback: function(file,serverData) {
|
||||
this.filesUploaded++;
|
||||
$('UploadFiles').innerHTML = 'Uploading Files..... ('+ this.filesUploaded +")";
|
||||
},
|
||||
|
||||
uploadQueueCompleteCallback: function(serverData) {
|
||||
this.filesUploaded = this.upload.getFilesUploaded();
|
||||
$('UploadFiles').innerHTML = "";
|
||||
statusMessage('Uploaded Files Successfully','good');
|
||||
|
||||
$('FolderImages').ajaxGetFiles(this.getParentID(), null);
|
||||
},
|
||||
|
||||
/**
|
||||
* Iterates over all uploaded images and add them to TinyMCE editor
|
||||
*
|
||||
* @param transport object
|
||||
*/
|
||||
insertImages: function(transport) {
|
||||
//HACK FOR STRANGE ERROR OCCURING UNDER SAFARI
|
||||
if(transport.responseText == '') {
|
||||
$('Image').ajaxGetFiles(this.getParentID(), null, this.insertImages.bind(this));
|
||||
return;
|
||||
}
|
||||
//END OF HACK
|
||||
|
||||
$('Image').reapplyBehaviour();
|
||||
|
||||
this.addToTinyMCE = this.addToTinyMCE.bind(this);
|
||||
this.processInProgress = false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds particular image to TinyMCE. Most of code has been copied from tiny_mce_improvements.js / ImageThumbnail.onclick
|
||||
* Sorry for not following DRY, I didn't want to break smth in tiny_mce_improvements.
|
||||
*
|
||||
* @param target object
|
||||
*/
|
||||
|
||||
addToTinyMCE: function(target) {
|
||||
var formObj = $('Form_EditorToolbarImageForm');
|
||||
var altText = formObj.elements.AltText.value;
|
||||
var cssClass = formObj.elements.CSSClass.value;
|
||||
var baseURL = document.getElementsByTagName('base')[0].href;
|
||||
var relativeHref = target.href.substr(baseURL.length)
|
||||
if(!tinyMCE.selectedInstance) tinyMCE.selectedInstance = Toolbar.instance().editor;
|
||||
if(tinyMCE.selectedInstance.contentWindow.focus) tinyMCE.selectedInstance.contentWindow.focus();
|
||||
// Extract dest width and dest height from the class name
|
||||
var destWidth = null;
|
||||
var destHeight = null;
|
||||
try {
|
||||
var imgTag = target.getElementsByTagName('img')[0];
|
||||
destWidth = imgTag.className.match(/destwidth=([0-9.\-]+)([, ]|$)/) ? RegExp.$1 : null;
|
||||
destHeight = imgTag.className.match(/destheight=([0-9.\-]+)([, ]|$)/) ? RegExp.$1 : null;
|
||||
} catch(er) {
|
||||
}
|
||||
TinyMCE_AdvancedTheme._insertImage(relativeHref, altText, 0, '', '', destWidth, destHeight, '', '', cssClass);
|
||||
},
|
||||
|
||||
/**
|
||||
* Under IE6 when we click on "add folder" anchor, rest of anchors loose their correct position
|
||||
*
|
||||
*/
|
||||
|
||||
applyIE6Hack: function() {
|
||||
if(/msie/i.test(navigator.userAgent)) {
|
||||
elements = [$('FolderOk'),$('FolderCancel'),$('UploadFiles')];
|
||||
$A(elements).each(function(element) {
|
||||
element.style.position = "relative";
|
||||
element.style.top = "-3px";
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
removeIE6Hack: function() {
|
||||
if(/msie/i.test(navigator.userAgent)) {
|
||||
elements = [$('FolderOk'),$('FolderCancel'),$('UploadFiles')];
|
||||
$A(elements).each(function(element) {
|
||||
element.style.position = "";
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns id of upload folder.
|
||||
*
|
||||
*/
|
||||
|
||||
getParentID: function() {
|
||||
return $('Form_EditorToolbarImageForm_FolderID').value == '' ? 'root' : $('Form_EditorToolbarImageForm_FolderID').value;
|
||||
}
|
||||
}
|
||||
var tinyMCEImageEnhancement;
|
||||
|
||||
jQuery(function() {
|
||||
tinyMCEImageEnhancement = new TinyMCEImageEnhancement();
|
||||
});
|
@ -1,284 +0,0 @@
|
||||
/*
|
||||
This class is wrapper for SWFUpload class.
|
||||
If you want use SWFUpload, please use this class becuase it will take care of configuration
|
||||
error handling and other things.
|
||||
|
||||
*/
|
||||
|
||||
var Upload = Class.create();
|
||||
Upload.prototype = {
|
||||
|
||||
/**
|
||||
* Sets configuration data provided from user if smth is missing sets default value.
|
||||
*
|
||||
* @param params object contains all configuration data for upload.
|
||||
*/
|
||||
initialize: function(params) {
|
||||
|
||||
this.filesUploaded = 0;
|
||||
this.filesToUpload = 0;
|
||||
this.folderID = 'root';
|
||||
this.uploadInProgress = false;
|
||||
this.uploadMessage = '';
|
||||
this.queueComplete = this.uploadQueueCompleteCallback.bind(this);
|
||||
this.fileComplete = this.uploadFileCompleteCallback.bind(this);
|
||||
this.fileQueued = this.uploadFileQueuedCallback;
|
||||
|
||||
if(typeof params.fileSizeLimit != 'undefined') this.setFileSizeLimit = params.fileSizeLimit; else this.fileSizeLimit = '30720';
|
||||
if(typeof params.fileTypes != 'undefined') this.fileTypes = params.fileTypes; else this.fileTypes = '*.*';
|
||||
if(typeof params.fileTypesDescription != 'undefined') this.fileTypesDescription = params.fileTypesDescription; else this.fileTypesDescription = 'All Files';
|
||||
if(typeof params.fileUploadLimit != 'undefined') this.fileUploadLimit = params.fileUploadLimit; else this.fileUploadLimit = '6';
|
||||
if(typeof params.beginUploadOnQueue != 'undefined') this.beginUploadOnQueue = params.beginUploadOnQueue; else this.beginUploadOnQueue = true;
|
||||
if(typeof params.fileQueued != 'undefined') this.fileQueued = params.fileQueued;
|
||||
|
||||
if(typeof params.fileProgress != 'undefined') this.fileProgress = params.fileProgress; else this.fileProgress = Prototype.emptyFunction;
|
||||
if(typeof params.fileCancelled != 'undefined') this.fileCancelled = params.fileCancelled;
|
||||
if(typeof params.fileComplete != 'undefined') this.fileComplete = params.fileComplete;
|
||||
if(typeof params.queueComplete != 'undefined') this.queueComplete = params.queueComplete;
|
||||
if(typeof params.buildUI != 'undefined') this.customBuildUI = params.buildUI;
|
||||
if(typeof params.securityID != 'undefined') this.securityID = params.securityID;
|
||||
if(typeof params.button_image_url != 'undefined') this.buttonImageURL = params.button_image_url;
|
||||
if(typeof params.button_width != 'undefined') this.buttonWidth = params.button_width;
|
||||
if(typeof params.button_height != 'undefined') this.buttonHeight = params.button_height;
|
||||
|
||||
try {
|
||||
this.onLoad();
|
||||
} catch (ex) {
|
||||
// suppress the exception in case swfupload.js is loaded in a context that has no
|
||||
// placeholder elements
|
||||
if ( ex.indexOf('Could not find the placeholder element')==-1 )
|
||||
throw ex;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates SWFUpload object for uploading files.
|
||||
*
|
||||
*/
|
||||
onLoad: function() {
|
||||
|
||||
path = this.getBasePath();
|
||||
sessId = this.getSessionId();//Because flash doesn't send proper cookies, we need to set session id in URL.
|
||||
this.swfu = new SWFUpload({
|
||||
upload_url: path + 'admin/assets/UploadForm?action_doUpload=1&PHPSESSID=' + sessId, // Relative to the SWF file
|
||||
file_post_name: 'Files',
|
||||
file_size_limit : this.fileSizeLimit,
|
||||
file_types : this.fileTypes,
|
||||
file_types_description : this.fileTypesDescription,
|
||||
file_upload_limit : this.fileUploadLimit,
|
||||
begin_upload_on_queue : this.beginUploadOnQueue,
|
||||
use_server_data_event : true,
|
||||
validate_files: false,
|
||||
button_placeholder_id: "SWFUploadButton",
|
||||
file_queued_handler : this.fileQueued,
|
||||
upload_success_handler : this.queueComplete,
|
||||
file_dialog_complete_handler : this.fileCompleted,
|
||||
upload_progress_handler: this.uploadFileProgressCallback.bind(this),
|
||||
error_handler : this.uploadErrorCallback.bind(this),
|
||||
file_validation_handler : Prototype.emptyFunction,
|
||||
file_cancelled_handler: Prototype.emptyFunction,
|
||||
button_image_url : this.buttonImageURL,
|
||||
button_window_mode : "transparent",
|
||||
button_width : this.buttonWidth,
|
||||
button_height : this.buttonHeight,
|
||||
flash_url : 'sapphire/thirdparty/swfupload/swfupload/swfupload.swf',
|
||||
swfupload_loaded_handler: this.buildUI.bind(this),
|
||||
debug: false,
|
||||
preserve_relative_urls: true
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieves base path from URL.
|
||||
* TODO: Use base tag.
|
||||
*/
|
||||
|
||||
getBasePath: function() {
|
||||
var path = 'http://' + window.location.host + window.location.pathname;
|
||||
|
||||
if(path.match(/^(.*\/)admin/i)) return RegExp.$1;
|
||||
else return path;
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieves sessionId from cookie.
|
||||
*
|
||||
*/
|
||||
|
||||
getSessionId: function() {
|
||||
var start = document.cookie.indexOf('PHPSESSID')+10;
|
||||
var end = document.cookie.indexOf(';',start);
|
||||
if(end == -1) end = document.cookie.length;
|
||||
return document.cookie.substring(start,end);
|
||||
},
|
||||
|
||||
/**
|
||||
* Calls method defined by user, method should create user interface.
|
||||
*
|
||||
*/
|
||||
|
||||
buildUI: function() {
|
||||
return;
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when new file is added to the queue
|
||||
*
|
||||
* @param file object
|
||||
* @param queueLength int
|
||||
*/
|
||||
|
||||
uploadFileQueuedCallback: function(file,queueLength) {
|
||||
this.filesToUpload++;
|
||||
// this.swfu.fileQueued(file, queueLength);
|
||||
this.addFileParam(file);
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when uploading of particular file has finished
|
||||
*
|
||||
* @param file object
|
||||
* @param servedData string
|
||||
*/
|
||||
uploadFileCompleteCallback: function(file,serverData) {
|
||||
this.filesUploaded++;
|
||||
if(serverData) {
|
||||
var toEval = serverData.substr(serverData.indexOf('<script'));
|
||||
toEval = toEval.replace('<script type="text/javascript">','');
|
||||
toEval = toEval.replace('</script>','');
|
||||
this.uploadMessage = toEval;
|
||||
}
|
||||
|
||||
this.fileComplete(file, serverData);
|
||||
|
||||
// Run the next file in the queue, if there is one
|
||||
if(this.swfu.getStats().files_queued > 0) this.startUpload();
|
||||
// Otherwise indicate that the queue is finished
|
||||
else {
|
||||
this.queueComplete();
|
||||
this.uploadInProgress = false;
|
||||
this.filesUploaded = 0;
|
||||
this.filesToUpload = 0;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Called during uploading file.
|
||||
*
|
||||
* @param file object
|
||||
* @param bytes_complete int
|
||||
*/
|
||||
|
||||
uploadFileProgressCallback: function(file, bytes_complete) {
|
||||
this.uploadInProgress = true;
|
||||
this.fileProgress(file, bytes_complete);
|
||||
},
|
||||
|
||||
uploadQueueCompleteCallback: function(event) {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Called on error.
|
||||
* @param error_code int
|
||||
* @param file object
|
||||
* @param message string
|
||||
*/
|
||||
|
||||
uploadErrorCallback: function(error_code, file, message) {
|
||||
this.swfu.cancelQueue();
|
||||
switch(error_code) {
|
||||
case SWFUpload.ERROR_CODE_HTTP_ERROR:
|
||||
alert('You have encountered an error. File hasn\'t been uploaded. Please hit the "Refresh" button in your web browser. Error Code: HTTP Error, File name: ' + file.name + ', Message: ' + msg);
|
||||
break;
|
||||
case SWFUpload.ERROR_CODE_IO_ERROR:
|
||||
alert('You have encountered an error. File hasn\'t been uploaded. Please hit the "Refresh" button in your web browser. Error Code: IO Error, File name: ' + file.name + ', Message: ' + msg);
|
||||
break;
|
||||
case SWFUpload.ERROR_CODE_SECURITY_ERROR:
|
||||
alert('You have encountered an error. File hasn\'t been uploaded. Please hit the "Refresh" button in your web browser. Error Code: Security Error, File name: ' + file.name + ', Message: ' + msg);
|
||||
break;
|
||||
case SWFUpload.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT:
|
||||
alert('Files cannot be bigger than ' + this.fileSizeLimit/1024 + ' MB.');
|
||||
break;
|
||||
case SWFUpload.ERROR_CODE_ZERO_BYTE_FILE:
|
||||
alert('Files cannot be empty');
|
||||
break;
|
||||
case SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED:
|
||||
alert('You can only have six files in queue');
|
||||
break;
|
||||
case SWFUpload.ERROR_CODE_UPLOAD_FAILED:
|
||||
alert('You have encountered an error. File hasn\'t has been uploaded. Please hit the "Refresh" button in your web browser');
|
||||
break;
|
||||
case SWFUpload.ERROR_CODE_SPECIFIED_FILE_NOT_FOUND:
|
||||
alert('You have encountered an error. File hasn\'t has been uploaded. Please hit the "Refresh" button in your web browser');
|
||||
break;
|
||||
default:
|
||||
alert('You have encountered an error. File hasn\'t has been uploaded. Please hit the "Refresh" button in your web browser');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Because we are on top of standard upload we need to add some POST vars that
|
||||
* normally are being sent as part of form.
|
||||
*
|
||||
* @param file object
|
||||
*/
|
||||
|
||||
addFileParam: function(file) {
|
||||
this.swfu.addFileParam(file.id,'ID',this.folderID);
|
||||
this.swfu.addFileParam(file.id,'action_doUpload','1');
|
||||
this.swfu.addFileParam(file.id,'Files',file.name);
|
||||
this.swfu.addFileParam(file.id,'MAX_FILE_SIZE','31457280');
|
||||
},
|
||||
|
||||
/**
|
||||
* Starts file explorer.
|
||||
*
|
||||
*/
|
||||
|
||||
browse: function() {
|
||||
this.swfu.selectFiles();
|
||||
},
|
||||
|
||||
/**
|
||||
* Starts upload
|
||||
*
|
||||
*/
|
||||
|
||||
startUpload: function() {
|
||||
this.swfu.startUpload();
|
||||
},
|
||||
|
||||
/**
|
||||
* Cancels uploading of file.
|
||||
*/
|
||||
|
||||
cancelUpload: function(fileId) {
|
||||
this.filesToUpload--;
|
||||
this.swfu.cancelUpload(fileId);
|
||||
},
|
||||
|
||||
/*
|
||||
* Getters and setters.
|
||||
*/
|
||||
setFolderID: function(id) {
|
||||
this.folderID = id;
|
||||
},
|
||||
|
||||
getFilesUploaded: function() {
|
||||
return this.filesUploaded;
|
||||
},
|
||||
|
||||
getFilesToUpload: function() {
|
||||
return this.filesToUpload;
|
||||
},
|
||||
|
||||
getUploadMessage: function() {
|
||||
return this.uploadMessage;
|
||||
},
|
||||
|
||||
isUploadInProgress: function() {
|
||||
return this.uploadInProgress;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user