mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge pull request #1279 from open-sausages/pulls/move-addfile-ui
Moved upload files page to main files area
This commit is contained in:
commit
dc9286af6e
@ -21,6 +21,5 @@ CMSMenu::remove_menu_item('CMSPageSettingsController');
|
||||
CMSMenu::remove_menu_item('CMSPageHistoryController');
|
||||
CMSMenu::remove_menu_item('CMSPageReportsController');
|
||||
CMSMenu::remove_menu_item('CMSPageAddController');
|
||||
CMSMenu::remove_menu_item('CMSFileAddController');
|
||||
|
||||
CMSMenu::remove_menu_item("SiteConfigLeftAndMain");
|
@ -153,6 +153,9 @@ JS
|
||||
}
|
||||
|
||||
public function getEditForm($id = null, $fields = null) {
|
||||
Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js');
|
||||
Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css');
|
||||
|
||||
$form = parent::getEditForm($id, $fields);
|
||||
$folder = ($id && is_numeric($id)) ? DataObject::get_by_id('Folder', $id, false) : $this->currentPage();
|
||||
$fields = $form->Fields();
|
||||
@ -188,19 +191,6 @@ JS
|
||||
Controller::join_links($this->Link('show'), '%s')
|
||||
);
|
||||
|
||||
if($folder->canCreate()) {
|
||||
$uploadBtn = new LiteralField(
|
||||
'UploadButton',
|
||||
sprintf(
|
||||
'<a class="ss-ui-button font-icon-upload cms-panel-link" data-pjax-target="Content" data-icon="drive-upload" href="%s">%s</a>',
|
||||
Controller::join_links(singleton('CMSFileAddController')->Link(), '?ID=' . $folder->ID),
|
||||
_t('Folder.UploadFilesButton', 'Upload')
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$uploadBtn = null;
|
||||
}
|
||||
|
||||
if(!$folder->hasMethod('canAddChildren') || ($folder->hasMethod('canAddChildren') && $folder->canAddChildren())) {
|
||||
// TODO Will most likely be replaced by GridField logic
|
||||
$addFolderBtn = new LiteralField(
|
||||
@ -258,15 +248,43 @@ JS
|
||||
// we only add buttons if they're available. User might not have permission and therefore
|
||||
// the button shouldn't be available. Adding empty values into a ComposteField breaks template rendering.
|
||||
$actionButtonsComposite = CompositeField::create()->addExtraClass('cms-actions-row');
|
||||
if($uploadBtn) $actionButtonsComposite->push($uploadBtn);
|
||||
if($addFolderBtn) $actionButtonsComposite->push($addFolderBtn);
|
||||
if($syncButton) $actionButtonsComposite->push($syncButton);
|
||||
|
||||
// Add the upload field for new media
|
||||
if($currentPageID = $this->currentPageID()){
|
||||
Session::set("{$this->class}.currentPage", $currentPageID);
|
||||
}
|
||||
|
||||
$folder = $this->currentPage();
|
||||
|
||||
$uploadField = UploadField::create('AssetUploadField', '');
|
||||
$uploadField->setConfig('previewMaxWidth', 40);
|
||||
$uploadField->setConfig('previewMaxHeight', 30);
|
||||
$uploadField->setConfig('changeDetection', false);
|
||||
$uploadField->addExtraClass('ss-assetuploadfield');
|
||||
$uploadField->removeExtraClass('ss-uploadfield');
|
||||
$uploadField->setTemplate('AssetUploadField');
|
||||
|
||||
if($folder->exists() && $folder->getFilename()) {
|
||||
// The Upload class expects a folder relative *within* assets/
|
||||
$path = preg_replace('/^' . ASSETS_DIR . '\//', '', $folder->getFilename());
|
||||
$uploadField->setFolderName($path);
|
||||
} else {
|
||||
$uploadField->setFolderName('/'); // root of the assets
|
||||
}
|
||||
|
||||
$exts = $uploadField->getValidator()->getAllowedExtensions();
|
||||
asort($exts);
|
||||
$uploadField->Extensions = implode(', ', $exts);
|
||||
|
||||
// List view
|
||||
$fields->addFieldsToTab('Root.ListView', array(
|
||||
$actionsComposite = CompositeField::create(
|
||||
$actionButtonsComposite
|
||||
)->addExtraClass('cms-content-toolbar field'),
|
||||
$uploadField,
|
||||
new HiddenField('ID'),
|
||||
$gridField
|
||||
));
|
||||
|
||||
|
@ -1,142 +0,0 @@
|
||||
<?php
|
||||
class CMSFileAddController extends LeftAndMain {
|
||||
|
||||
private static $url_segment = 'assets/add';
|
||||
private static $url_priority = 60;
|
||||
private static $required_permission_codes = 'CMS_ACCESS_AssetAdmin';
|
||||
private static $menu_title = 'Files';
|
||||
private static $tree_class = 'Folder';
|
||||
|
||||
// public function upload($request) {
|
||||
// $formHtml = $this->renderWith(array('AssetAdmin_UploadContent'));
|
||||
// if($request->isAjax()) {
|
||||
// return $formHtml;
|
||||
// } else {
|
||||
// return $this->customise(array(
|
||||
// 'Content' => $formHtml
|
||||
// ))->renderWith(array('AssetAdmin', 'LeftAndMain'));
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Custom currentPage() method to handle opening the 'root' folder
|
||||
*/
|
||||
public function currentPage() {
|
||||
$id = $this->currentPageID();
|
||||
if($id && is_numeric($id) && $id > 0) {
|
||||
$folder = DataObject::get_by_id('Folder', $id);
|
||||
if($folder && $folder->exists()) {
|
||||
return $folder;
|
||||
}
|
||||
}
|
||||
return new Folder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return fake-ID "root" if no ID is found (needed to upload files into the root-folder)
|
||||
*/
|
||||
public function currentPageID() {
|
||||
if(is_numeric($this->getRequest()->requestVar('ID'))) {
|
||||
return $this->getRequest()->requestVar('ID');
|
||||
} elseif (is_numeric($this->urlParams['ID'])) {
|
||||
return $this->urlParams['ID'];
|
||||
} elseif(Session::get("{$this->class}.currentPage")) {
|
||||
return Session::get("{$this->class}.currentPage");
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $id Not used.
|
||||
* @param null $fields Not used.
|
||||
* @return Form
|
||||
* @todo what template is used here? AssetAdmin_UploadContent.ss doesn't seem to be used anymore
|
||||
*/
|
||||
public function getEditForm($id = null, $fields = null) {
|
||||
Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js');
|
||||
Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css');
|
||||
|
||||
if($currentPageID = $this->currentPageID()){
|
||||
Session::set("{$this->class}.currentPage", $currentPageID);
|
||||
}
|
||||
|
||||
$folder = $this->currentPage();
|
||||
|
||||
$uploadField = UploadField::create('AssetUploadField', '');
|
||||
$uploadField->setConfig('previewMaxWidth', 40);
|
||||
$uploadField->setConfig('previewMaxHeight', 30);
|
||||
$uploadField->setConfig('changeDetection', false);
|
||||
$uploadField->addExtraClass('ss-assetuploadfield');
|
||||
$uploadField->removeExtraClass('ss-uploadfield');
|
||||
$uploadField->setTemplate('AssetUploadField');
|
||||
|
||||
if($folder->exists() && $folder->getFilename()) {
|
||||
// The Upload class expects a folder relative *within* assets/
|
||||
$path = preg_replace('/^' . ASSETS_DIR . '\//', '', $folder->getFilename());
|
||||
$uploadField->setFolderName($path);
|
||||
} else {
|
||||
$uploadField->setFolderName('/'); // root of the assets
|
||||
}
|
||||
|
||||
$exts = $uploadField->getValidator()->getAllowedExtensions();
|
||||
asort($exts);
|
||||
$uploadField->Extensions = implode(', ', $exts);
|
||||
|
||||
$form = CMSForm::create(
|
||||
$this,
|
||||
'EditForm',
|
||||
new FieldList(
|
||||
$uploadField,
|
||||
new HiddenField('ID')
|
||||
),
|
||||
new FieldList()
|
||||
)->setHTMLID('Form_EditForm');
|
||||
$form->setResponseNegotiator($this->getResponseNegotiator());
|
||||
$form->addExtraClass('center cms-edit-form ' . $this->BaseCSSClasses());
|
||||
// Don't use AssetAdmin_EditForm, as it assumes a different panel structure
|
||||
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
|
||||
$form->Fields()->push(
|
||||
new LiteralField(
|
||||
'BackLink',
|
||||
sprintf(
|
||||
'<a href="%s" class="backlink ss-ui-button cms-panel-link" data-icon="back">%s</a>',
|
||||
Controller::join_links(singleton('AssetAdmin')->Link('show'), $folder ? $folder->ID : 0),
|
||||
_t('AssetAdmin.BackToFolder', 'Back to folder')
|
||||
)
|
||||
)
|
||||
);
|
||||
$form->loadDataFrom($folder);
|
||||
|
||||
$this->extend('updateEditForm', $form);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $unlinked
|
||||
* @return ArrayList
|
||||
*/
|
||||
public function Breadcrumbs($unlinked = false) {
|
||||
$items = parent::Breadcrumbs($unlinked);
|
||||
|
||||
// The root element should explicitly point to the root node.
|
||||
$items[0]->Link = Controller::join_links(singleton('AssetAdmin')->Link('show'), 0);
|
||||
|
||||
// Enforce linkage of hierarchy to AssetAdmin
|
||||
foreach($items as $item) {
|
||||
$baselink = $this->Link('show');
|
||||
if(strpos($item->Link, $baselink) !== false) {
|
||||
$item->Link = str_replace($baselink, singleton('AssetAdmin')->Link('show'), $item->Link);
|
||||
}
|
||||
}
|
||||
|
||||
$items->push(new ArrayData(array(
|
||||
'Title' => _t('AssetAdmin.Upload', 'Upload'),
|
||||
'Link' => $this->Link()
|
||||
)));
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
}
|
@ -122,5 +122,14 @@
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Reload the gridfield to show the user the file has been added
|
||||
*/
|
||||
$('.AssetAdmin.cms-edit-form .ss-uploadfield-item-progress').entwine({
|
||||
onunmatch: function () {
|
||||
$('.AssetAdmin.cms-edit-form .ss-gridfield').reload();
|
||||
}
|
||||
})
|
||||
});
|
||||
}(jQuery));
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div id="assetadmin-cms-content" class="cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content">
|
||||
<div id="assetadmin-cms-content" class="cms-content center cms-tabset ss-uploadfield-dropzone $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content">
|
||||
|
||||
<% with $EditForm %>
|
||||
<div class="cms-content-header north">
|
||||
|
@ -14,9 +14,8 @@ Feature: Insert an image into a page
|
||||
|
||||
Scenario: I can insert an image from a URL
|
||||
Given I press the "Insert Media" button
|
||||
Then I should see "Choose files to upload..."
|
||||
|
||||
When I press the "From the web" button
|
||||
When I click "add by URL" in the ".ss-uploadfield-item-info" element
|
||||
And I fill in "RemoteURL" with "http://www.silverstripe.org/themes/ssv3/img/ss_logo.png"
|
||||
And I press the "Add url" button
|
||||
Then I should see "ss_logo.png (www.silverstripe.org)" in the ".ss-assetuploadfield span.name" element
|
||||
@ -29,7 +28,6 @@ Feature: Insert an image into a page
|
||||
@assets
|
||||
Scenario: I can insert an image uploaded from my own computer
|
||||
Given I press the "Insert Media" button
|
||||
And I press the "From your computer" button
|
||||
And I attach the file "testfile.jpg" to "AssetUploadField" with HTML5
|
||||
# TODO Delay previous step until upload succeeded
|
||||
And I wait for 2 seconds
|
||||
@ -43,7 +41,6 @@ Feature: Insert an image into a page
|
||||
Scenario: I can upload an image from my own computer that matches the name of an existing file
|
||||
Given a "image" "assets/Uploads/file1.jpg"
|
||||
When I press the "Insert Media" button
|
||||
And I press the "From your computer" button
|
||||
And I attach the file "file1.jpg" to "AssetUploadField" with HTML5
|
||||
# TODO Delay previous step until upload succeeded
|
||||
And I wait for 2 seconds
|
||||
@ -57,7 +54,6 @@ Feature: Insert an image into a page
|
||||
|
||||
Scenario: I can insert an image from the CMS file store
|
||||
Given I press the "Insert Media" button
|
||||
And I press the "From the CMS" button
|
||||
And I fill in the "ParentID" dropdown with "folder1"
|
||||
And I click on "file1" in the "Files" table
|
||||
When I press the "Insert" button
|
||||
@ -67,7 +63,6 @@ Feature: Insert an image into a page
|
||||
|
||||
Scenario: I can edit properties of an image before inserting it
|
||||
Given I press the "Insert Media" button
|
||||
And I press the "From the CMS" button
|
||||
And I fill in the "ParentID" dropdown with "folder1"
|
||||
And I click on "file1" in the "Files" table
|
||||
And I press the "Edit" button
|
||||
|
@ -25,10 +25,8 @@ Feature: Manage files
|
||||
|
||||
Scenario: I can upload a file to a folder
|
||||
Given I click on "folder1" in the "Files" table
|
||||
And I press the "Upload" button
|
||||
And I attach the file "testfile.jpg" to "AssetUploadField" with HTML5
|
||||
And I wait for 5 seconds
|
||||
And I press the "Back to folder" button
|
||||
Then the "folder1" table should contain "testfile"
|
||||
|
||||
Scenario: I can edit a file
|
||||
@ -51,14 +49,13 @@ Feature: Manage files
|
||||
And I click on "file1" in the "folder1" table
|
||||
And I fill in "folder2" for the "Folder" dropdown
|
||||
And I press the "Save" button
|
||||
# /show/0 is to ensure that we are on top level folder
|
||||
And I go to "/admin/assets/show/0"
|
||||
And I click "Files" in the ".breadcrumbs-wrapper" element
|
||||
And I click on "folder2" in the "Files" table
|
||||
And the "folder2" table should contain "file1"
|
||||
|
||||
Scenario: I can see allowed extensions help
|
||||
When I go to "/admin/assets/add"
|
||||
And I follow "Show allowed extensions"
|
||||
When I go to "/admin/assets/"
|
||||
And I click "Show allowed extensions" in the ".ss-uploadfield-view-allowed-extensions" element
|
||||
Then I should see "png,"
|
||||
|
||||
Scenario: I can filter the files list view using name
|
||||
|
Loading…
Reference in New Issue
Block a user