diff --git a/_config.php b/_config.php index 24634c9a..d12d80b7 100644 --- a/_config.php +++ b/_config.php @@ -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"); \ No newline at end of file diff --git a/code/controllers/AssetAdmin.php b/code/controllers/AssetAdmin.php index 84b9868a..7b7350a4 100644 --- a/code/controllers/AssetAdmin.php +++ b/code/controllers/AssetAdmin.php @@ -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( - '%s', - 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,18 +248,46 @@ 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 )); - + $treeField = new LiteralField('Tree', ''); // Tree view $fields->addFieldsToTab('Root.TreeView', array( diff --git a/code/controllers/CMSFileAddController.php b/code/controllers/CMSFileAddController.php deleted file mode 100644 index c3fb382e..00000000 --- a/code/controllers/CMSFileAddController.php +++ /dev/null @@ -1,142 +0,0 @@ -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( - '%s', - 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; - } - -} diff --git a/javascript/AssetAdmin.js b/javascript/AssetAdmin.js index 16bb8deb..01462e76 100644 --- a/javascript/AssetAdmin.js +++ b/javascript/AssetAdmin.js @@ -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)); diff --git a/templates/Includes/AssetAdmin_Content.ss b/templates/Includes/AssetAdmin_Content.ss index db5f1e51..e084c15b 100644 --- a/templates/Includes/AssetAdmin_Content.ss +++ b/templates/Includes/AssetAdmin_Content.ss @@ -1,4 +1,4 @@ -
+
<% with $EditForm %>
diff --git a/tests/behat/features/insert-an-image.feature b/tests/behat/features/insert-an-image.feature index 4fecacf7..cbad817a 100644 --- a/tests/behat/features/insert-an-image.feature +++ b/tests/behat/features/insert-an-image.feature @@ -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 diff --git a/tests/behat/features/manage-files.feature b/tests/behat/features/manage-files.feature index 214e4ddf..20a8abb6 100644 --- a/tests/behat/features/manage-files.feature +++ b/tests/behat/features/manage-files.feature @@ -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