From d9538d30853c3c1161420e468a84b0e5cd02edbc Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 9 Jan 2012 17:14:40 +0100 Subject: [PATCH] ENHANCEMENT Migrating AssetAdmin fields to File/Folder/Image->getCMSFields() --- filesystem/File.php | 22 ++++++++++++++++++++++ filesystem/Folder.php | 36 +++++++++--------------------------- model/Image.php | 25 +++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 27 deletions(-) diff --git a/filesystem/File.php b/filesystem/File.php index 33d83c2dd..9db62de2e 100644 --- a/filesystem/File.php +++ b/filesystem/File.php @@ -254,6 +254,28 @@ class File extends DataObject { return $this->canEdit($member); } + + function getCMSFields() { + $urlLink = "
"; + $urlLink .= ""; + $urlLink .= "{$this->RelativeLink()}"; + $urlLink .= "
"; + + return new FieldList( + new TabSet('Root', + new Tab('Main', + new TextField("Title", _t('AssetTableField.TITLE','Title')), + new TextField("Name", _t('AssetTableField.FILENAME','Filename')), + new LiteralField("AbsoluteURL", $urlLink), + new ReadonlyField("FileType", _t('AssetTableField.TYPE','Type')), + new ReadonlyField("Size", _t('AssetTableField.SIZE','Size'), $this->getSize()), + new DropdownField("OwnerID", _t('AssetTableField.OWNER','Owner'), Member::mapInCMSGroups()), + new DateField_Disabled("Created", _t('AssetTableField.CREATED','First uploaded')), + new DateField_Disabled("LastEdited", _t('AssetTableField.LASTEDIT','Last changed')) + ) + ) + ); + } /** * Returns a category based on the file extension. diff --git a/filesystem/Folder.php b/filesystem/Folder.php index 1bc585d90..fecb3fe8e 100644 --- a/filesystem/Folder.php +++ b/filesystem/Folder.php @@ -404,6 +404,9 @@ class Folder extends File { $config->addComponent(new GridFieldSortableHeader()); $config->addComponent(new GridFieldPaginator(2)); $config->addComponent(new GridFieldAction_Delete()); + $config->addComponent(new GridFieldAction_Edit()); + $config->addComponent($gridFieldForm = new GridFieldItemEditView()); + $gridFieldForm->setTemplate('CMSGridFieldItemEditView'); $files = DataList::create('File')->filter('ParentID', $this->ID)->exclude('ClassName', 'Folder'); $gridField = new GridField('File','Files', $files, $config); $gridField->setDisplayFields(array( @@ -416,30 +419,19 @@ class Folder extends File { $titleField = ($this->ID && $this->ID != "root") ? new TextField("Title", _t('Folder.TITLE')) : new HiddenField("Title"); $fields = new FieldList( - new HiddenField("Name"), - new TabSet("Root", - new Tab("Files", _t('Folder.FILESTAB', "Files"), + new TabSet('Root', + new Tab('Main', $titleField, $gridField, + new HiddenField("ID"), + new HiddenField("Name"), new HiddenField("DestFolderID") - ), - new Tab("Details", _t('Folder.DETAILSTAB', "Details"), - new ReadonlyField("URL", _t('Folder.URL', 'URL')), - new ReadonlyField("ClassName", _t('Folder.TYPE','Type')), - new ReadonlyField("Created", _t('Folder.CREATED','First Uploaded')), - new ReadonlyField("LastEdited", _t('Folder.LASTEDITED','Last Updated')) - ), - new Tab("Upload", _t('Folder.UPLOADTAB', "Upload"), - new LiteralField("UploadIframe", - $this->getUploadIframe() - ) ) - ), - new HiddenField("ID") + ) ); if(!$this->canEdit()) { - $fields->removeFieldFromTab("Root", "Upload"); + $fields->removeByName("Upload"); } $this->extend('updateCMSFields', $fields); @@ -447,16 +439,6 @@ class Folder extends File { return $fields; } - /** - * Display the upload form. Returns an iframe tag that will show admin/assets/uploadiframe. - */ - function getUploadIframe() { - return << - -HTML; - } - /** * Get the children of this folder that are also folders. */ diff --git a/model/Image.php b/model/Image.php index ee82b3043..7986da6c5 100644 --- a/model/Image.php +++ b/model/Image.php @@ -73,6 +73,31 @@ class Image extends File { parent::defineMethods(); } + function getCMSFields() { + $fields = parent::getCMSFields(); + + $urlLink = "
"; + $urlLink .= ""; + $urlLink .= "{$this->RelativeLink()}"; + $urlLink .= "
"; + + $big = $this->URL; + $formattedImage = $this->getFormattedImage('AssetLibraryPreview'); + $thumbnail = $formattedImage ? $formattedImage->URL : ''; + + // Hmm this required the translated string to be appended to BottomRoot to add this to the Main tab + $fields->addFieldToTab('Root.Main', + new ReadonlyField("Dimensions", _t('AssetTableField.DIM','Dimensions')) + ); + $fields->addFieldToTab('Root.Main', + new LiteralField("ImageFull", + "{$this->Name}" + ) + ); + + return $fields; + } + /** * An image exists if it has a filename. * Does not do any filesystem checks.