mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merged revisions 52392 via svnmerge from
http://svn.silverstripe.com/open/modules/cms/branches/2.2.2 ........ r52392 | sminnee | 2008-04-09 18:00:12 +1200 (Wed, 09 Apr 2008) | 1 line Upgraded SWFUpload to improve CMS uploads ........ git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@53499 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
ff10f2c9f7
commit
5aea02ee82
@ -132,7 +132,7 @@ class AssetAdmin extends LeftAndMain {
|
||||
*/
|
||||
function UploadForm() {
|
||||
|
||||
return new Form($this,'UploadForm', new FieldSet(
|
||||
$form = new Form($this,'UploadForm', new FieldSet(
|
||||
new HiddenField("ID", "", $this->currentPageID()),
|
||||
// needed because the button-action is triggered outside the iframe
|
||||
new HiddenField("action_doUpload", "", "1"),
|
||||
@ -151,6 +151,11 @@ class AssetAdmin extends LeftAndMain {
|
||||
")
|
||||
), new FieldSet(
|
||||
));
|
||||
|
||||
// Makes ajax easier
|
||||
$form->disableSecurityToken();
|
||||
|
||||
return $form;
|
||||
|
||||
}
|
||||
|
||||
@ -229,7 +234,7 @@ class AssetAdmin extends LeftAndMain {
|
||||
|
||||
$sFileIDs = implode(',', $fileIDs);
|
||||
$sFileNames = implode(',', $fileNames);
|
||||
|
||||
|
||||
echo <<<HTML
|
||||
<script type="text/javascript">
|
||||
/* IDs: $sFileIDs */
|
||||
|
@ -5,21 +5,24 @@
|
||||
*/
|
||||
CMSMain_upload = Class.create();
|
||||
CMSMain_upload.prototype = {
|
||||
initialize: function() {
|
||||
// Due to a bug in the flash plugin on Linux and Mac, we need at least version 9.0.64 to use SWFUpload
|
||||
if(navigator.appVersion.indexOf("Mac") != -1 || navigator.appVersion.indexOf("X11") != -1 || navigator.appVersion.indexOf("Linux") != -1) {
|
||||
pv = getFlashPlayerVersion();
|
||||
if(pv.major < 9 || (pv.major == 9 && pv.minor == 0 && pv.rev < 64)) {
|
||||
return;
|
||||
}
|
||||
initialize: function() {
|
||||
// We require flash 9
|
||||
pv = getFlashPlayerVersion();
|
||||
if(pv.major < 9) return;
|
||||
|
||||
// Due to a bug in the flash plugin on Linux and Mac, we need at least version 9.0.64 to use SWFUpload
|
||||
if(navigator.appVersion.indexOf("Mac") != -1 || navigator.appVersion.indexOf("X11") != -1 || navigator.appVersion.indexOf("Linux") != -1) {
|
||||
if(pv.major == 9 && pv.minor == 0 && pv.rev < 64) return;
|
||||
}
|
||||
|
||||
// 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',
|
||||
fileUploadLimit : '6',
|
||||
securityID : $('SecurityID').value,
|
||||
beginUploadOnQueue : false,
|
||||
fileQueued : this.uploadFileQueuedCallback.bind(this),
|
||||
@ -175,7 +178,7 @@ CMSMain_upload.prototype = {
|
||||
},
|
||||
|
||||
uploadQueueCompleteCallback: function() {
|
||||
eval(this.upload.getUploadMessage().replace('1',this.upload.getFilesUploaded()));
|
||||
eval(this.upload.getUploadMessage().replace(/Uploaded 1 files/g,'Uploaded ' + this.upload.getFilesUploaded() + ' files'));
|
||||
}
|
||||
}
|
||||
window.top.document.CMSMain_upload = CMSMain_upload;
|
||||
window.top.document.CMSMain_upload = CMSMain_upload;
|
||||
|
@ -29,7 +29,7 @@ Upload.prototype = {
|
||||
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.buildUI != 'undefined') this.customBuildUI = params.buildUI;
|
||||
if(typeof params.securityID != 'undefined') this.securityID = params.securityID;
|
||||
this.onLoad();
|
||||
},
|
||||
@ -42,7 +42,7 @@ Upload.prototype = {
|
||||
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_target_url: path + '/assets/index/root?executeForm=UploadForm&SecurityID=' + this.securityID + '&PHPSESSID=' + sessId, // Relative to the SWF file
|
||||
upload_url: path + 'admin/assets/index/root?executeForm=UploadForm&SecurityID=' + this.securityID + '&PHPSESSID=' + sessId, // Relative to the SWF file
|
||||
file_post_name: 'Files',
|
||||
file_size_limit : this.fileSizeLimit,
|
||||
file_types : this.fileTypes,
|
||||
@ -53,15 +53,14 @@ Upload.prototype = {
|
||||
validate_files: false,
|
||||
|
||||
file_queued_handler : this.uploadFileQueuedCallback.bind(this),
|
||||
file_complete_handler : this.uploadFileCompleteCallback.bind(this),
|
||||
file_progress_handler: this.uploadFileProgressCallback.bind(this),
|
||||
queue_complete_handler : this.uploadQueueCompleteCallback.bind(this),
|
||||
upload_success_handler : this.uploadFileCompleteCallback.bind(this),
|
||||
upload_progress_handler: this.uploadFileProgressCallback.bind(this),
|
||||
error_handler : this.uploadErrorCallback.bind(this),
|
||||
file_validation_handler : Prototype.emptyFunction,
|
||||
file_cancelled_handler: Prototype.emptyFunction,
|
||||
|
||||
flash_url : 'jsparty/SWFUpload/SWFUpload.swf', // Relative to this file
|
||||
ui_function: this.buildUI.bind(this),
|
||||
flash_url : 'jsparty/SWFUpload/swfupload_f9.swf', // Relative to this file
|
||||
swfupload_loaded_handler: this.buildUI.bind(this),
|
||||
debug: false
|
||||
});
|
||||
},
|
||||
@ -73,8 +72,9 @@ Upload.prototype = {
|
||||
|
||||
getBasePath: function() {
|
||||
var path = 'http://' + window.location.host + window.location.pathname;
|
||||
if(path[path.length-1] == '/') path = path.substring(0,path.length-1);
|
||||
return path;
|
||||
|
||||
if(path.match(/^(.*\/)admin/i)) return RegExp.$1;
|
||||
else return path;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -117,14 +117,26 @@ Upload.prototype = {
|
||||
* @param file object
|
||||
* @param servedData string
|
||||
*/
|
||||
|
||||
uploadFileCompleteCallback: function(file,serverData) {
|
||||
this.filesUploaded++;
|
||||
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);
|
||||
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;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@ -138,18 +150,7 @@ Upload.prototype = {
|
||||
this.uploadInProgress = true;
|
||||
this.fileProgress(file, bytes_complete);
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when whole queue has been uploaded or cancelled.
|
||||
*/
|
||||
|
||||
uploadQueueCompleteCallback: function() {
|
||||
this.queueComplete();
|
||||
this.uploadInProgress = false;
|
||||
this.filesUploaded = 0;
|
||||
this.filesToUpload = 0;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Called on error.
|
||||
* @param error_code int
|
||||
@ -209,7 +210,7 @@ Upload.prototype = {
|
||||
*/
|
||||
|
||||
browse: function() {
|
||||
this.swfu.browse();
|
||||
this.swfu.selectFiles();
|
||||
},
|
||||
|
||||
/**
|
||||
@ -252,4 +253,4 @@ Upload.prototype = {
|
||||
isUploadInProgress: function() {
|
||||
return this.uploadInProgress;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user