Permalink
Browse files

BUGFIX Fixed AssetAdmin->doUpload() javascript callbacks

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92815 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent f12db27 commit 97ece94acf9032fb19683797c3d14b7bd87f3d6f @chillu chillu committed Nov 21, 2009
Showing with 13 additions and 22 deletions.
  1. +13 −22 code/AssetAdmin.php
View
@@ -122,7 +122,7 @@ function uploadiframe() {
Requirements::javascript(SAPPHIRE_DIR . "/javascript/prototype_improvements.js");
//Requirements::javascript(CMS_DIR . "/javascript/LeftAndMain.js");
Requirements::javascript(CMS_DIR . "/thirdparty/multifile/multifile.js");
- Requirements::css(THIRDPARTY_DIR . "/multifile/multifile.css");
+ Requirements::css(CMS_DIR . "/thirdparty/multifile/multifile.css");
Requirements::css(CMS_DIR . "/css/typography.css");
Requirements::css(CMS_DIR . "/css/layout.css");
Requirements::css(CMS_DIR . "/css/cms_left.css");
@@ -196,15 +196,13 @@ function doUpload($data, $form) {
$newFiles = array();
$fileSizeWarnings = '';
- $uploadErrors = '';
- $jsErrors = '';
+ $errorsArr = '';
$status = '';
$statusMessage = '';
foreach($processedFiles as $tmpFile) {
if($tmpFile['error'] == UPLOAD_ERR_NO_TMP_DIR) {
- $status = 'bad';
- $statusMessage = _t('AssetAdmin.NOTEMP', 'There is no temporary folder for uploads. Please set upload_tmp_dir in php.ini.');
+ $errorsArr[] = _t('AssetAdmin.NOTEMP', 'There is no temporary folder for uploads. Please set upload_tmp_dir in php.ini.');
break;
}
@@ -221,27 +219,27 @@ function doUpload($data, $form) {
$valid = true;
} else {
$upload = new Upload();
- $upload->setAllowedExtensions(self::$allowed_extensions);
+ $upload->setAllowedExtensions(array('gif'));
$upload->setAllowedMaxFileSize(self::$allowed_max_file_size);
$valid = $upload->validate($tmpFile);
if(!$valid) {
- $errors = $upload->getErrors();
- if($errors) foreach($errors as $error) {
- $jsErrors .= "alert('" . Convert::raw2js($error) . "');";
- }
+ $errorsArr = $upload->getErrors();
}
}
// move file to given folder
if($valid) $newFiles[] = $folder->addUploadToFolder($tmpFile);
}
}
-
+
if($newFiles) {
$numFiles = sizeof($newFiles);
$statusMessage = sprintf(_t('AssetAdmin.UPLOADEDX',"Uploaded %s files"),$numFiles) ;
$status = "good";
- } else if($status != 'bad') {
+ } else if($errorsArr) {
+ $statusMessage = implode('\n', $errorsArr);
+ $status = 'bad';
+ } else {
$statusMessage = _t('AssetAdmin.NOTHINGTOUPLOAD','There was nothing to upload');
$status = "";
}
@@ -256,19 +254,12 @@ function doUpload($data, $form) {
$fileNames[] = $fileObj->Name;
}
- $sFileIDs = implode(',', $fileIDs);
- $sFileNames = implode(',', $fileNames);
-
+ // TODO Replace with clientside logic which doesn't have assumptions in the response
echo <<<HTML
<script type="text/javascript">
- /* IDs: $sFileIDs */
- /* Names: $sFileNames */
-
- var form = parent.document.getElementById('Form_EditForm');
- form.getPageFromServer(form.elements.ID.value);
+ var url = parent.document.getElementById('sitetree').getTreeNodeByIdx( "{$folder->ID}" ).getElementsByTagName('a')[0].href;
+ parent.jQuery('#Form_EditForm').concrete('ss').loadForm(url);
parent.statusMessage("{$statusMessage}","{$status}");
- $jsErrors
- parent.document.getElementById('sitetree').getTreeNodeByIdx( "{$folder->ID}" ).getElementsByTagName('a')[0].className += ' contents';
</script>
HTML;
}

0 comments on commit 97ece94

Please sign in to comment.