mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT GridField-based file listing
This commit is contained in:
parent
4f49c452ac
commit
f2717f0788
@ -416,14 +416,31 @@ class Folder extends File {
|
|||||||
$config->addComponent(new GridFieldAction_Edit());
|
$config->addComponent(new GridFieldAction_Edit());
|
||||||
$config->addComponent($gridFieldForm = new GridFieldPopupForms(Controller::curr(), 'EditForm'));
|
$config->addComponent($gridFieldForm = new GridFieldPopupForms(Controller::curr(), 'EditForm'));
|
||||||
$gridFieldForm->setTemplate('CMSGridFieldPopupForms');
|
$gridFieldForm->setTemplate('CMSGridFieldPopupForms');
|
||||||
$files = DataList::create('File')->filter('ParentID', $this->ID)->exclude('ClassName', 'Folder');
|
|
||||||
|
if($this->ID) {
|
||||||
|
// When a specific folder is selected, show only children files,
|
||||||
|
// and include children folders to allow navigating into them.
|
||||||
|
$files = DataList::create('File')
|
||||||
|
->filter('ParentID', $this->ID)
|
||||||
|
->sort('(CASE WHEN "ClassName" = \'Folder\' THEN 0 ELSE 1 END)');
|
||||||
|
} else {
|
||||||
|
// On the root folder, show all files but exclude folders - newest first.
|
||||||
|
$files = DataList::create('File')
|
||||||
|
->exclude('ClassName', 'Folder')
|
||||||
|
->sort('Created', 'Desc');
|
||||||
|
}
|
||||||
|
|
||||||
$gridField = new GridField('File','Files', $files, $config);
|
$gridField = new GridField('File','Files', $files, $config);
|
||||||
$gridField->setDisplayFields(array(
|
$gridField->setDisplayFields(array(
|
||||||
'StripThumbnail' => '',
|
'StripThumbnail' => '',
|
||||||
'Parent.FileName' => 'Folder',
|
// 'Parent.FileName' => 'Folder',
|
||||||
'Title'=>'Title',
|
'Title'=>'Title',
|
||||||
|
'Date'=>'Created',
|
||||||
'Size'=>'Size',
|
'Size'=>'Size',
|
||||||
));
|
));
|
||||||
|
$gridField->setFieldFormatting(array(
|
||||||
|
'Date' => 'Nice'
|
||||||
|
));
|
||||||
|
|
||||||
$titleField = ($this->ID && $this->ID != "root") ? new TextField("Title", _t('Folder.TITLE')) : new HiddenField("Title");
|
$titleField = ($this->ID && $this->ID != "root") ? new TextField("Title", _t('Folder.TITLE')) : new HiddenField("Title");
|
||||||
|
|
||||||
@ -432,23 +449,33 @@ class Folder extends File {
|
|||||||
new TabSet('Root',
|
new TabSet('Root',
|
||||||
new Tab('listview', _t('AssetAdmin.ListView', 'List View'),
|
new Tab('listview', _t('AssetAdmin.ListView', 'List View'),
|
||||||
$titleField,
|
$titleField,
|
||||||
|
new LiteralField(
|
||||||
|
'UploadButton',
|
||||||
|
sprintf(
|
||||||
|
'<div class="cms-content-constructive-actions">' .
|
||||||
|
'<a class="ss-ui-button ss-ui-action-constructive cms-panel-link" data-target-panel=".cms-content" href="%s">%s</a>' .
|
||||||
|
'</div>',
|
||||||
|
Controller::join_links(singleton('CMSFileAddController')->Link(), '?ID=' . $this->ID),
|
||||||
|
_t('Folder.UploadFilesButton', 'Upload')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
new LiteralField(
|
||||||
|
'AddFolderButton',
|
||||||
|
sprintf(
|
||||||
|
'<div class="cms-content-constructive-actions">' .
|
||||||
|
'<a class="ss-ui-button ss-ui-action-constructive cms-page-add-button" href="%s">%s</a>' .
|
||||||
|
'</div>',
|
||||||
|
singleton('CMSFileAddController')->Link(),
|
||||||
|
_t('Folder.AddFolderButton', 'Add folder')
|
||||||
|
)
|
||||||
|
),
|
||||||
$gridField,
|
$gridField,
|
||||||
new HiddenField("ID"),
|
new HiddenField("ID"),
|
||||||
new HiddenField("DestFolderID")
|
new HiddenField("DestFolderID")
|
||||||
),
|
|
||||||
new Tab('galleryview', _t('AssetAdmin.GalleryView', 'Gallery View'),
|
|
||||||
new LiteralField("", "<em>Not implemented yet</em>")
|
|
||||||
),
|
|
||||||
new Tab('treeview', _t('AssetAdmin.TreeView', 'Tree View'),
|
|
||||||
new LiteralField("", "<em>Not implemented yet</em>")
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!$this->canEdit()) {
|
|
||||||
$fields->removeByName("Upload");
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->extend('updateCMSFields', $fields);
|
$this->extend('updateCMSFields', $fields);
|
||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
<h3 class="ss-uploadfield-choosefiles"><% _t('AssetUploadField.CHOOSEFILES', 'Choose files') %></h3>
|
|
||||||
<div class="ss-uploadfield-item ss-uploadfield-addfile">
|
<div class="ss-uploadfield-item ss-uploadfield-addfile">
|
||||||
<div class="ss-uploadfield-item-info">
|
<div class="ss-uploadfield-item-info">
|
||||||
<label class="ss-uploadfield-fromcomputer ss-ui-button ui-corner-all" title="<% _t('AssetUploadField.FROMCOMPUTERINFO', 'Upload from your computer') %>" for="$id">
|
<label class="ss-uploadfield-fromcomputer ss-ui-button ui-corner-all" title="<% _t('AssetUploadField.FROMCOMPUTERINFO', 'Upload from your computer') %>" for="$id">
|
||||||
|
Loading…
Reference in New Issue
Block a user