Merge pull request #1566 from jonom/fix-direct-edit

FIX Direct edit file by URL
This commit is contained in:
Daniel Hensby 2016-08-01 00:58:29 +01:00 committed by GitHub
commit 95bb134e64
3 changed files with 35 additions and 28 deletions

View File

@ -12,7 +12,7 @@ addons:
env:
global:
- CORE_RELEASE=3
- CORE_RELEASE=3.4
- "ARTIFACTS_AWS_REGION=us-east-1"
- "ARTIFACTS_S3_BUCKET=silverstripe-travis-artifacts"
- secure: "7V20Qk3bIG2AlTJaA5D/uzB8vUVvRwQp+xjRYUxlahtj9FcuqEV3HIyjwwJe0T6Z1bnRYuu28ZnCT2CfP9BBZ3FE7AwSZbPase9c0/at2qDJNqkvIdC1xZ1H6Fcy2LSwNB9wLQPe613ItVdanitEuwE41iowxBPslxUUTnwx7eY="

View File

@ -47,18 +47,28 @@ class AssetAdmin extends LeftAndMain implements PermissionProvider{
);
/**
* Return fake-ID "root" if no ID is found (needed to upload files into the root-folder)
* Return fake-ID 0 (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;
$id = 0;
$request = $this->getRequest();
if(is_numeric($request->requestVar('ID'))) {
$id = $request->requestVar('ID');
} elseif (is_numeric($request->param('ID'))) {
$id = $request->param('ID');
}
// Detect current folder in gridfield item edit view
if ($id && $id > 0) {
if (!Folder::get()->filter('ID', $id)->exists()) {
$file = File::get()->byID($id);
$id = ($file) ? $file->ParentID : 0;
}
}
$id = (int)$id;
$this->setCurrentPageID($id);
return $id;
}
/**
@ -153,8 +163,9 @@ JS
}
public function getEditForm($id = null, $fields = null) {
$form = parent::getEditForm($id, $fields);
$folder = ($id && is_numeric($id)) ? DataObject::get_by_id('Folder', $id, false) : $this->currentPage();
$folder = $this->currentPage();
$fields = $form->Fields();
$title = ($folder && $folder->isInDB()) ? $folder->Title : _t('AssetAdmin.FILES', 'Files');
$fields->push(new HiddenField('ID', false, $folder ? $folder->ID : null));
@ -338,8 +349,8 @@ JS
if($record && !$record->canDelete()) return Security::permissionFailure();
if(!$record || !$record->ID) throw new SS_HTTPResponse_Exception("Bad record ID #" . (int)$data['ID'], 404);
$parentID = $record->ParentID;
$this->setCurrentPageID($parentID);
$record->delete();
$this->setCurrentPageID(null);
$this->getResponse()->addHeader('X-Status', rawurlencode(_t('LeftAndMain.DELETED', 'Deleted.')));
$this->getResponse()->addHeader('X-Pjax', 'Content');
@ -518,12 +529,13 @@ JS
*/
public function currentPage() {
$id = $this->currentPageID();
if($id && is_numeric($id) && $id > 0) {
$folder = DataObject::get_by_id('Folder', $id);
if($folder && $folder->isInDB()) {
if ($id > 0) {
$folder = Folder::get()->byID($id);
if ($folder && $folder->isInDB()) {
return $folder;
}
}
// Fallback to root
$this->setCurrentPageID(null);
return new Folder();
}

View File

@ -6,7 +6,7 @@ class CMSFileAddController extends LeftAndMain {
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()) {
@ -36,12 +36,11 @@ class CMSFileAddController extends LeftAndMain {
* 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");
$request = $this->getRequest();
if (is_numeric($request->requestVar('ID'))) {
return $request->requestVar('ID');
} elseif (is_numeric($request->param('ID'))) {
return $request->param('ID');
} else {
return 0;
}
@ -57,10 +56,6 @@ class CMSFileAddController extends LeftAndMain {
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', '');
@ -87,7 +82,7 @@ class CMSFileAddController extends LeftAndMain {
$this,
'EditForm',
new FieldList(
$uploadField,
$uploadField,
new HiddenField('ID')
),
new FieldList()
@ -135,7 +130,7 @@ class CMSFileAddController extends LeftAndMain {
'Title' => _t('AssetAdmin.Upload', 'Upload'),
'Link' => $this->Link()
)));
return $items;
}