BUGFIX: fixed doUpload ajax submission to correctly handle files submitted via the content editor submission.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@91480 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Will Rossiter 2009-11-12 22:06:37 +00:00
parent 87e7599ff0
commit cd1a08d6a6
3 changed files with 37 additions and 25 deletions

View File

@ -165,15 +165,29 @@ JS
* It will save the uploaded files to /assets/ and create new File objects as required. * It will save the uploaded files to /assets/ and create new File objects as required.
*/ */
function doUpload($data, $form) { function doUpload($data, $form) {
$processedFiles = array();
if(!isset($data['Files'])) return Director::set_status_code("404");
if(is_array($data['Files'])) {
foreach($data['Files'] as $param => $files) { foreach($data['Files'] as $param => $files) {
if(!is_array($files)) $files = array($files); if(!is_array($files)) $files = array($files);
foreach($files as $key => $value) { foreach($files as $key => $value) {
$processedFiles[$key][$param] = $value; $processedFiles[$key][$param] = $value;
} }
} }
}
else {
$proccessedFiles[] = $data['Files'];
}
if($data['ID'] && $data['ID'] != 'root') $folder = DataObject::get_by_id("Folder", $data['ID']); // get the folder to upload to.
else $folder = singleton('Folder'); if(isset($data['FolderID']) && $data['FolderID'] != "root") {
$folder = DataObject::get_by_id('Folder', $data['FolderID']);
}
else {
$folder = DataObject::get_one('Folder');
}
$newFiles = array(); $newFiles = array();
$fileSizeWarnings = ''; $fileSizeWarnings = '';

View File

@ -18,7 +18,7 @@ TinyMCEImageEnhancement.prototype = {
onLoad: function() { onLoad: function() {
this.upload = new Upload({ this.upload = new Upload({
fileUploadLimit : '6', fileUploadLimit : '6',
button_image_url : '../cms/images/swf-upload-button-small.jpg', button_image_url : 'cms/images/swf-upload-button-small.jpg',
button_width : 59, button_width : 59,
button_height: 18, button_height: 18,
fileQueued: this.uploadFileQueuedCallback.bind(this), fileQueued: this.uploadFileQueuedCallback.bind(this),
@ -118,11 +118,9 @@ TinyMCEImageEnhancement.prototype = {
} }
else { else {
this.processInProgress = true; this.processInProgress = true;
this.upload.setFolderID(this.getParentID()); this.upload.swfu.addPostParam('FolderID', this.getParentID());
this.upload.addFileParam(file.id,'ID',this.folderID); this.upload.swfu.addFileParam(file.id,'ID',this.folderID);
this.upload.addFileParam(file.id,'action_doUpload','1'); this.upload.swfu.addFileParam(file.id,'Files',file.name);
this.upload.addFileParam(file.id,'Files',file.name);
this.upload.addFileParam(file.id,'MAX_FILE_SIZE','31457280');
$('UploadFiles').innerHTML = "Uploading Files...("+ this.filesUploaded +")"; $('UploadFiles').innerHTML = "Uploading Files...("+ this.filesUploaded +")";
this.upload.swfu.startUpload(file.id); this.upload.swfu.startUpload(file.id);
} }
@ -133,13 +131,12 @@ TinyMCEImageEnhancement.prototype = {
$('UploadFiles').innerHTML = 'Uploading Files..... ('+ this.filesUploaded +")"; $('UploadFiles').innerHTML = 'Uploading Files..... ('+ this.filesUploaded +")";
}, },
uploadQueueCompleteCallback: function() { uploadQueueCompleteCallback: function(serverData) {
this.filesUploaded = this.upload.getFilesUploaded(); this.filesUploaded = this.upload.getFilesUploaded();
$('UploadFiles').innerHTML = "upload"; $('UploadFiles').innerHTML = "";
statusMessage('Uploaded ' + this.upload.getFilesUploaded() + ' files','good'); statusMessage('Uploaded Files Successfully','good');
if(this.getParentID() != 'root') {
$('Image').ajaxGetFiles(this.getParentID(), null, this.insertImages.bind(this)); $('FolderImages').ajaxGetFiles(this.getParentID(), null);
}
}, },
/** /**
@ -158,7 +155,6 @@ TinyMCEImageEnhancement.prototype = {
$('Image').reapplyBehaviour(); $('Image').reapplyBehaviour();
this.addToTinyMCE = this.addToTinyMCE.bind(this); this.addToTinyMCE = this.addToTinyMCE.bind(this);
this.processInProgress = false; this.processInProgress = false;
}, },

View File

@ -53,7 +53,7 @@ Upload.prototype = {
path = this.getBasePath(); path = this.getBasePath();
sessId = this.getSessionId();//Because flash doesn't send proper cookies, we need to set session id in URL. sessId = this.getSessionId();//Because flash doesn't send proper cookies, we need to set session id in URL.
this.swfu = new SWFUpload({ this.swfu = new SWFUpload({
upload_url: path + 'admin/assets/UploadForm?SecurityID=' + this.securityID + '&PHPSESSID=' + sessId, // Relative to the SWF file upload_url: path + 'admin/assets/UploadForm?action_doUpload=1&PHPSESSID=' + sessId, // Relative to the SWF file
file_post_name: 'Files', file_post_name: 'Files',
file_size_limit : this.fileSizeLimit, file_size_limit : this.fileSizeLimit,
file_types : this.fileTypes, file_types : this.fileTypes,
@ -71,11 +71,13 @@ Upload.prototype = {
file_validation_handler : Prototype.emptyFunction, file_validation_handler : Prototype.emptyFunction,
file_cancelled_handler: Prototype.emptyFunction, file_cancelled_handler: Prototype.emptyFunction,
button_image_url : this.buttonImageURL, button_image_url : this.buttonImageURL,
button_window_mode : "transparent",
button_width : this.buttonWidth, button_width : this.buttonWidth,
button_height : this.buttonHeight, button_height : this.buttonHeight,
flash_url : 'jsparty/SWFUpload/swfupload.swf', // Relative to this file flash_url : 'jsparty/SWFUpload/swfupload.swf', // Relative to this file
swfupload_loaded_handler: this.buildUI.bind(this), swfupload_loaded_handler: this.buildUI.bind(this),
debug: false debug: false,
preserve_relative_urls: true
}); });
}, },