mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Migrating AssetAdmin fields to File/Folder/Image->getCMSFields()
This commit is contained in:
parent
0caf1991cf
commit
d9538d3085
@ -255,6 +255,28 @@ class File extends DataObject {
|
||||
return $this->canEdit($member);
|
||||
}
|
||||
|
||||
function getCMSFields() {
|
||||
$urlLink = "<div class='field readonly'>";
|
||||
$urlLink .= "<label class='left'>"._t('AssetTableField.URL','URL')."</label>";
|
||||
$urlLink .= "<span class='readonly'><a href='{$this->Link()}'>{$this->RelativeLink()}</a></span>";
|
||||
$urlLink .= "</div>";
|
||||
|
||||
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.
|
||||
* This can be useful when grouping files by type,
|
||||
|
@ -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
|
||||
<iframe name="AssetAdmin_upload" src="admin/assets/uploadiframe/{$this->ID}" id="AssetAdmin_upload" border="0" style="border-style none !important; width: 97%; min-height: 300px; height: 100%; height: expression(document.body.clientHeight) !important;">
|
||||
</iframe>
|
||||
HTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the children of this folder that are also folders.
|
||||
*/
|
||||
|
@ -73,6 +73,31 @@ class Image extends File {
|
||||
parent::defineMethods();
|
||||
}
|
||||
|
||||
function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$urlLink = "<div class='field readonly'>";
|
||||
$urlLink .= "<label class='left'>"._t('AssetTableField.URL','URL')."</label>";
|
||||
$urlLink .= "<span class='readonly'><a href='{$this->Link()}'>{$this->RelativeLink()}</a></span>";
|
||||
$urlLink .= "</div>";
|
||||
|
||||
$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",
|
||||
"<img id='thumbnailImage' src='{$thumbnail}?r=" . rand(1,100000) . "' alt='{$this->Name}' />"
|
||||
)
|
||||
);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* An image exists if it has a filename.
|
||||
* Does not do any filesystem checks.
|
||||
|
Loading…
Reference in New Issue
Block a user