From 8eb13d51280186cfd341f94afd48e431cd7f9b94 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 19 Feb 2008 00:49:33 +0000 Subject: [PATCH] Moved folder admin form to Folder::getCMSFields() to let you more easily manipulate the form with a decorator git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@49797 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- filesystem/Folder.php | 92 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 87 insertions(+), 5 deletions(-) diff --git a/filesystem/Folder.php b/filesystem/Folder.php index 575cc7c6d..b6f4bdfd6 100755 --- a/filesystem/Folder.php +++ b/filesystem/Folder.php @@ -95,13 +95,16 @@ class Folder extends File { // Get index of database content - $dbChildren = DataObject::get("File", "ParentID = $parentID"); - if(isset($dbChildren)) { + // We don't use DataObject so that things like subsites doesn't muck with this. + $dbChildren = DB::query("SELECT * FROM File WHERE ParentID = $parentID"); + $hasDbChild = array(); + if($dbChildren) { foreach($dbChildren as $dbChild) { - $hasDbChild[$dbChild->Name] = $dbChild; + $className = $dbChild['ClassName']; + $hasDbChild[$dbChild['Name']] = new $className($dbChild); } - $unwantedDbChildren = $hasDbChild; } + $unwantedDbChildren = $hasDbChild; // Iterate through the actual children, correcting the database as necessary @@ -335,7 +338,86 @@ class Folder extends File { function cmsCleanup_parentChanged(){ } - + + /** + * Return the FieldSet used to edit this folder in the CMS. + * You can modify this fieldset by subclassing folder, or by creating a {@link DataObjectDecorator} + * and implemeting updateCMSFields(FieldSet $fields) on that decorator. + */ + function getCMSFields() { + $nameField = ($this->ID > 0) ? new TextField("Name") : new HiddenField("Name"); + + $fileList = new AssetTableField( + $this, + "Files", + "File", + array("Title" => _t('AssetAdmin.TITLE', "Title"), "LinkedURL" => _t('AssetAdmin.FILENAME', "Filename")), + "" + ); + $fileList->setFolder($this); + $fileList->setPopupCaption(_t('AssetAdmin.VIEWEDITASSET', "View/Edit Asset")); + + $nameField = ($this->ID && $this->ID != "root") ? new TextField("Name", "Folder Name") : new HiddenField("Name"); + if( $this->userCanEdit() ) { + $deleteButton = new InlineFormAction('deletemarked',_t('AssetAdmin.DELSELECTED','Delete selected files'), 'delete'); + $deleteButton->includeDefaultJS(false); + } else { + $deleteButton = new HiddenField('deletemarked'); + } + + $fields = new FieldSet( + new HiddenField("Title"), + new TabSet("Root", + new Tab(_t('AssetAdmin.FILESTAB', "Files"), + $nameField, + $fileList, + $deleteButton, + new HiddenField("FileIDs"), + new HiddenField("DestFolderID") + ), + new Tab(_t('AssetAdmin.DETAILSTAB', "Details"), + new ReadonlyField("URL", _t('AssetAdmin.URL', 'URL')), + new ReadonlyField("ClassName", _t('AssetAdmin.TYPE','Type')), + new ReadonlyField("Created", _t('AssetAdmin.CREATED','First Uploaded')), + new ReadonlyField("LastEdited", _t('AssetAdmin.LASTEDITED','Last Updated')) + ), + new Tab(_t('AssetAdmin.UPLOADTAB', "Upload"), + new LiteralField("UploadIframe", + $this->getUploadIframe() + ) + )/* This has been disabled for now because of it's mass memory consumption + , + new Tab(_t('AssetAdmin.UNUSEDFILESTAB', "Unused files"), + new LiteralField("UnusedAssets", + "

"._t('AssetAdmin.UNUSEDFILESTITLE', 'Unused files')."

" + ), + $this->getAssetList(), + new LiteralField("UnusedThumbnails", + "
+
+

"._t('AssetAdmin.UNUSEDTHUMBNAILSTITLE', 'Unused thumbnails')."

+ +
" + ) + )*/ + ), + new HiddenField("ID") + ); + + $this->extend('updateCMSFields', $fields); + + return $fields; + } + + /** + * Display the upload form. Returns an iframe tag that will show admin/assets/uploadiframe. + */ + function getUploadIframe() { + return << + +HTML; + } /** * Since this is a folder, we don't have any content as such. */