diff --git a/code/controllers/AssetAdmin.php b/code/controllers/AssetAdmin.php index 70bc50c7..e85a2f15 100644 --- a/code/controllers/AssetAdmin.php +++ b/code/controllers/AssetAdmin.php @@ -6,7 +6,7 @@ * @package cms * @subpackage assets */ -class AssetAdmin extends LeftAndMain { +class AssetAdmin extends LeftAndMain implements PermissionProvider{ static $url_segment = 'assets'; @@ -30,7 +30,7 @@ class AssetAdmin extends LeftAndMain { 'removefile', 'savefile', 'deleteUnusedThumbnails' => 'ADMIN', - 'SyncForm', + 'doSync', 'filter', ); @@ -122,8 +122,8 @@ JS new GridFieldSortableHeader(), new GridFieldDefaultColumns(), new GridFieldPaginator(15), - new GridFieldAction_Edit(), - new GridFieldAction_Delete(), + new GridFieldDeleteAction(), + new GridFieldEditAction(), new GridFieldPopupForms() ); $gridField = new GridField('File','Files', $this->getList(), $gridFieldConfig); @@ -160,7 +160,12 @@ JS $addFolderBtn = new LiteralField( 'AddFolderButton', sprintf( - '%s', + '%s', + Controller::join_links($this->Link('AddForm'), '?' . http_build_query(array( + 'action_doAdd' => 1, + 'ParentID' => $folder->ID, + 'SecurityID' => $form->getSecurityToken()->getValue() + ))), Controller::join_links($this->Link('addfolder'), '?ParentID=' . $folder->ID), _t('Folder.AddFolderButton', 'Add folder') ) @@ -168,6 +173,20 @@ JS } else { $addFolderBtn = ''; } + + if($folder->canEdit()) { + $syncButton = new LiteralField( + 'SyncButton', + sprintf( + '%s', + _t('AssetAdmin.FILESYSTEMSYNCTITLE', 'Update the CMS database entries of files on the filesystem. Useful when new files have been uploaded outside of the CMS, e.g. through FTP.'), + $this->Link('doSync'), + _t('FILESYSTEMSYNC','Sync files') + ) + ); + } else { + $syncButton = null; + } // Move existing fields to a "details" tab, unless they've already been tabbed out through extensions. // Required to keep Folder->getCMSFields() simple and reuseable, @@ -177,8 +196,11 @@ JS $tabList = new Tab('ListView', _t('AssetAdmin.ListView', 'List View')), $tabTree = new Tab('TreeView', _t('AssetAdmin.TreeView', 'Tree View')) ); + $tabList->addExtraClass("content-listview"); + $tabTree->addExtraClass("content-treeview"); if($fields->Count() && $folder->exists()) { $tabs->push($tabDetails = new Tab('DetailsView', _t('AssetAdmin.DetailsView', 'Details'))); + $tabDetails->addExtraClass("content-galleryview"); foreach($fields as $field) { $fields->removeByName($field->Name()); $tabDetails->push($field); @@ -186,13 +208,14 @@ JS } $fields->push($tabs); } - + // List view $fields->addFieldsToTab('Root.ListView', array( $actionsComposite = Object::create('CompositeField', Object::create('CompositeField', $uploadBtn, - $addFolderBtn + $addFolderBtn, + $syncButton //TODO: add this into a batch actions menu as in https://github.com/silverstripe/silverstripe-design/raw/master/Design/ss3-ui_files-manager-list-view.jpg )->addExtraClass('cms-actions-row') )->addExtraClass('cms-content-toolbar field'), $gridField @@ -217,10 +240,9 @@ JS )); $fields->setForm($form); - $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // TODO Can't merge $FormAttributes in template at the moment - $form->addExtraClass('center ss-tabset ' . $this->BaseCSSClasses()); + $form->addExtraClass('cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses()); $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); $this->extend('updateEditForm', $form); @@ -318,9 +340,9 @@ JS $fields->dataFieldByName('ParentID')->setValue($this->request->getVar('ParentID')); $form->setFields($fields); - $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); - $form->addExtraClass('center ' . $this->BaseCSSClasses()); + // TODO Can't merge $FormAttributes in template at the moment + $form->addExtraClass('cms-add-form cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses()); return $form; } @@ -341,20 +363,23 @@ JS singleton($class)->hasExtension('Hierarchy') && isset($data['ParentID']) && is_numeric($data['ParentID']) + && $data['ParentID'] ) { $parentRecord = DataObject::get_by_id($class, $data['ParentID']); if( $parentRecord->hasMethod('canAddChildren') && !$parentRecord->canAddChildren() ) return Security::permissionFailure($this); + } else { + $parentRecord = null; } $parent = (isset($data['ParentID']) && is_numeric($data['ParentID'])) ? (int)$data['ParentID'] : 0; $name = (isset($data['Name'])) ? basename($data['Name']) : _t('AssetAdmin.NEWFOLDER',"NewFolder"); - if(!isset($parentRecord) || !$parentRecord->ID) $parent = 0; + if(!$parentRecord || !$parentRecord->ID) $parent = 0; // Get the folder to be created - if(isset($parentRecord->ID)) $filename = $parentRecord->FullPath . $name; + if($parentRecord && $parentRecord->ID) $filename = $parentRecord->FullPath . $name; else $filename = ASSETS_PATH . '/' . $name; // Actually create @@ -380,14 +405,10 @@ JS mkdir($record->FullPath); chmod($record->FullPath, Filesystem::$file_create_mask); - if($this->isAjax()) { - $link = Controller::join_links($this->Link('show'), $record->ID); - $this->getResponse()->addHeader('X-ControllerURL', $link); - $form = $this->getEditForm($record->ID); - return $form->forTemplate(); - } else { - return $this->redirect(Controller::join_links($this->Link('show'), $record->ID)); - } + $parentID = $parentRecord ? $parentRecord->ID : 'root'; + $link = Controller::join_links($this->Link('show'), $parentID); + $this->getResponse()->addHeader('X-ControllerURL', $link); + return $this->redirect($link); } /** @@ -419,28 +440,15 @@ JS //------------------------------------------------------------------------------------------// // Data saving handlers + /** - * @return Form + * Can be queried with an ajax request to trigger the filesystem sync. It returns a FormResponse status message + * to display in the CMS */ - public function SyncForm() { - $form = new Form( - $this, - 'SyncForm', - new FieldList( - ), - new FieldList( - FormAction::create('doSync', _t('FILESYSTEMSYNC','Look for new files')) - ->describe(_t('AssetAdmin_left.ss.FILESYSTEMSYNC_DESC', 'SilverStripe maintains its own database of the files & images stored in your assets/ folder. Click this button to update that database, if files are added to the assets/ folder from outside SilverStripe, for example, if you have uploaded files via FTP.')) - ->setUseButtonTag(true) - ) - ); - $form->setFormMethod('GET'); - - return $form; - } - - public function doSync($data, $form) { - return Filesystem::sync(); + public function doSync() { + $message = Filesystem::sync(); + FormResponse::status_message($message, 'good'); + echo FormResponse::respond(); } /** @@ -541,8 +549,14 @@ JS 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($this->Link('show'), 'root'); + // The root element should explicitly point to the root node. + // Used in CMSFileAddController subclass as well, so specifically link to AssetAdmin + $items[0]->Link = Controller::join_links(singleton('AssetAdmin')->Link('show'), 'root'); + + // HACK Force linkage to AssetAdmin, even when current controller is CMSFileAddController + foreach($items as $item) { + if($item->Link) $item->Link = str_replace('assets/add/show/', 'assets/show/', $item->Link); + } // If a search is in progress, don't show the path if($this->request->requestVar('q')) { @@ -553,8 +567,29 @@ JS ))); } + // If we're adding a folder, note that in breadcrumbs as well + if($this->request->param('Action') == 'addfolder') { + $items->push(new ArrayData(array( + 'Title' => _t('Folder.AddFolderButton', 'Add folder'), + 'Link' => false + ))); + } + + // TODO Remove once ViewableData->First()/Last() is fixed + foreach($items as $i => $item) $item->iteratorProperties($i, $items->Count()); + return $items; } + + function providePermissions() { + $title = _t("AssetAdmin.MENUTITLE", LeftAndMain::menu_title_for_class($this->class)); + return array( + "CMS_ACCESS_AssetAdmin" => array( + 'name' => sprintf(_t('CMSMain.ACCESS', "Access to '%s' section"), $title), + 'category' => _t('Permission.CMS_ACCESS_CATEGORY', 'CMS Access') + ) + ); + } } /** diff --git a/code/controllers/CMSFileAddController.php b/code/controllers/CMSFileAddController.php index 5487aa6f..aa1a84cd 100644 --- a/code/controllers/CMSFileAddController.php +++ b/code/controllers/CMSFileAddController.php @@ -2,8 +2,8 @@ class CMSFileAddController extends AssetAdmin { static $url_segment = 'assets/add'; - static $url_priority = 60; + static $required_permission_codes = 'CMS_ACCESS_AssetAdmin'; // public function upload($request) { // $formHtml = $this->renderWith(array('AssetAdmin_UploadContent')); @@ -16,6 +16,11 @@ class CMSFileAddController extends AssetAdmin { // } // } + public function Content() { + // Disable AssetAdmin layout including the search panel + return $this->renderWith('LeftAndMain_Content'); + } + /** * @return Form * @todo what template is used here? AssetAdmin_UploadContent.ss doesn't seem to be used anymore @@ -45,7 +50,8 @@ class CMSFileAddController extends AssetAdmin { new FieldList() ); $form->addExtraClass('center cms-edit-form ' . $this->BaseCSSClasses()); - $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); + // Don't use AssetAdmin_EditForm, as it assumes a different panel structure + $form->setTemplate('LeftAndMain_EditForm'); $form->Fields()->push( new LiteralField( 'BackLink', @@ -61,6 +67,9 @@ class CMSFileAddController extends AssetAdmin { return $form; } + /** + * Disable AssetAdmin search panel + */ function Tools() { return false; } diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php index 1384c32c..992bcd8d 100644 --- a/code/controllers/CMSMain.php +++ b/code/controllers/CMSMain.php @@ -38,7 +38,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr 'publishall', 'publishitems', 'PublishItemsForm', - 'RootForm', 'sidereport', 'SideReportsForm', 'submit', @@ -525,40 +524,12 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $this->extend('updateEditForm', $form); return $form; - } if ($id == 0 || $id == 'root') { - return $this->RootForm(); } else if($id) { return new Form($this, "EditForm", new FieldList( new LabelField('PageDoesntExistLabel',_t('CMSMain.PAGENOTEXISTS',"This page doesn't exist"))), new FieldList() ); } } - - /** - * @return Form - */ - function RootForm() { - $siteConfig = SiteConfig::current_site_config(); - $fields = $siteConfig->getCMSFields(); - - $actions = $siteConfig->getCMSActions(); - $form = new Form($this, 'RootForm', $fields, $actions); - $form->addExtraClass('root-form'); - $form->addExtraClass('cms-edit-form'); - // TODO Can't merge $FormAttributes in template at the moment - $form->addExtraClass('cms-content center ss-tabset'); - if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); - $form->setHTMLID('Form_EditForm'); - $form->loadDataFrom($siteConfig); - $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); - - // Use