From cd1a08d6a699ce2448c4c01936c02a9e431d9a68 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Thu, 12 Nov 2009 22:06:37 +0000 Subject: [PATCH] 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 --- code/AssetAdmin.php | 32 +++++++++++++++++++-------- javascript/TinyMCEImageEnhancement.js | 24 +++++++++----------- javascript/Upload.js | 6 +++-- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/code/AssetAdmin.php b/code/AssetAdmin.php index 32126393..c2c0dc0f 100755 --- a/code/AssetAdmin.php +++ b/code/AssetAdmin.php @@ -165,23 +165,37 @@ JS * It will save the uploaded files to /assets/ and create new File objects as required. */ function doUpload($data, $form) { - foreach($data['Files'] as $param => $files) { - if(!is_array($files)) $files = array($files); - foreach($files as $key => $value) { - $processedFiles[$key][$param] = $value; + $processedFiles = array(); + + if(!isset($data['Files'])) return Director::set_status_code("404"); + + if(is_array($data['Files'])) { + foreach($data['Files'] as $param => $files) { + if(!is_array($files)) $files = array($files); + foreach($files as $key => $value) { + $processedFiles[$key][$param] = $value; + } } } + else { + $proccessedFiles[] = $data['Files']; + } + + // get the folder to upload to. + if(isset($data['FolderID']) && $data['FolderID'] != "root") { + $folder = DataObject::get_by_id('Folder', $data['FolderID']); + } + else { + $folder = DataObject::get_one('Folder'); + } - if($data['ID'] && $data['ID'] != 'root') $folder = DataObject::get_by_id("Folder", $data['ID']); - else $folder = singleton('Folder'); - $newFiles = array(); $fileSizeWarnings = ''; $uploadErrors = ''; $jsErrors = ''; $status = ''; $statusMessage = ''; - + foreach($processedFiles as $tmpFile) { if($tmpFile['error'] == UPLOAD_ERR_NO_TMP_DIR) { $status = 'bad'; @@ -226,7 +240,7 @@ JS $statusMessage = _t('AssetAdmin.NOTHINGTOUPLOAD','There was nothing to upload'); $status = ""; } - + $fileIDs = array(); $fileNames = array(); foreach($newFiles as $newFile) { diff --git a/javascript/TinyMCEImageEnhancement.js b/javascript/TinyMCEImageEnhancement.js index 667e9cdd..d5a43cad 100644 --- a/javascript/TinyMCEImageEnhancement.js +++ b/javascript/TinyMCEImageEnhancement.js @@ -18,7 +18,7 @@ TinyMCEImageEnhancement.prototype = { onLoad: function() { this.upload = new Upload({ 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_height: 18, fileQueued: this.uploadFileQueuedCallback.bind(this), @@ -118,11 +118,9 @@ TinyMCEImageEnhancement.prototype = { } else { this.processInProgress = true; - this.upload.setFolderID(this.getParentID()); - this.upload.addFileParam(file.id,'ID',this.folderID); - this.upload.addFileParam(file.id,'action_doUpload','1'); - this.upload.addFileParam(file.id,'Files',file.name); - this.upload.addFileParam(file.id,'MAX_FILE_SIZE','31457280'); + 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); } @@ -133,13 +131,12 @@ TinyMCEImageEnhancement.prototype = { $('UploadFiles').innerHTML = 'Uploading Files..... ('+ this.filesUploaded +")"; }, - uploadQueueCompleteCallback: function() { + uploadQueueCompleteCallback: function(serverData) { this.filesUploaded = this.upload.getFilesUploaded(); - $('UploadFiles').innerHTML = "upload"; - statusMessage('Uploaded ' + this.upload.getFilesUploaded() + ' files','good'); - if(this.getParentID() != 'root') { - $('Image').ajaxGetFiles(this.getParentID(), null, this.insertImages.bind(this)); - } + $('UploadFiles').innerHTML = ""; + statusMessage('Uploaded Files Successfully','good'); + + $('FolderImages').ajaxGetFiles(this.getParentID(), null); }, /** @@ -158,8 +155,7 @@ TinyMCEImageEnhancement.prototype = { $('Image').reapplyBehaviour(); this.addToTinyMCE = this.addToTinyMCE.bind(this); - - this.processInProgress = false; + this.processInProgress = false; }, /** diff --git a/javascript/Upload.js b/javascript/Upload.js index 905c1ab7..88227c49 100644 --- a/javascript/Upload.js +++ b/javascript/Upload.js @@ -53,7 +53,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_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_size_limit : this.fileSizeLimit, file_types : this.fileTypes, @@ -71,11 +71,13 @@ Upload.prototype = { 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 : 'jsparty/SWFUpload/swfupload.swf', // Relative to this file swfupload_loaded_handler: this.buildUI.bind(this), - debug: false + debug: false, + preserve_relative_urls: true }); },