mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge pull request #1566 from jonom/fix-direct-edit
FIX Direct edit file by URL
This commit is contained in:
commit
95bb134e64
@ -12,7 +12,7 @@ addons:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- CORE_RELEASE=3
|
- CORE_RELEASE=3.4
|
||||||
- "ARTIFACTS_AWS_REGION=us-east-1"
|
- "ARTIFACTS_AWS_REGION=us-east-1"
|
||||||
- "ARTIFACTS_S3_BUCKET=silverstripe-travis-artifacts"
|
- "ARTIFACTS_S3_BUCKET=silverstripe-travis-artifacts"
|
||||||
- secure: "7V20Qk3bIG2AlTJaA5D/uzB8vUVvRwQp+xjRYUxlahtj9FcuqEV3HIyjwwJe0T6Z1bnRYuu28ZnCT2CfP9BBZ3FE7AwSZbPase9c0/at2qDJNqkvIdC1xZ1H6Fcy2LSwNB9wLQPe613ItVdanitEuwE41iowxBPslxUUTnwx7eY="
|
- secure: "7V20Qk3bIG2AlTJaA5D/uzB8vUVvRwQp+xjRYUxlahtj9FcuqEV3HIyjwwJe0T6Z1bnRYuu28ZnCT2CfP9BBZ3FE7AwSZbPase9c0/at2qDJNqkvIdC1xZ1H6Fcy2LSwNB9wLQPe613ItVdanitEuwE41iowxBPslxUUTnwx7eY="
|
||||||
|
@ -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() {
|
public function currentPageID() {
|
||||||
if(is_numeric($this->getRequest()->requestVar('ID'))) {
|
$id = 0;
|
||||||
return $this->getRequest()->requestVar('ID');
|
$request = $this->getRequest();
|
||||||
} elseif (is_numeric($this->urlParams['ID'])) {
|
if(is_numeric($request->requestVar('ID'))) {
|
||||||
return $this->urlParams['ID'];
|
$id = $request->requestVar('ID');
|
||||||
} elseif(Session::get("{$this->class}.currentPage")) {
|
} elseif (is_numeric($request->param('ID'))) {
|
||||||
return Session::get("{$this->class}.currentPage");
|
$id = $request->param('ID');
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
public function getEditForm($id = null, $fields = null) {
|
||||||
|
|
||||||
$form = parent::getEditForm($id, $fields);
|
$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();
|
$fields = $form->Fields();
|
||||||
$title = ($folder && $folder->isInDB()) ? $folder->Title : _t('AssetAdmin.FILES', 'Files');
|
$title = ($folder && $folder->isInDB()) ? $folder->Title : _t('AssetAdmin.FILES', 'Files');
|
||||||
$fields->push(new HiddenField('ID', false, $folder ? $folder->ID : null));
|
$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->canDelete()) return Security::permissionFailure();
|
||||||
if(!$record || !$record->ID) throw new SS_HTTPResponse_Exception("Bad record ID #" . (int)$data['ID'], 404);
|
if(!$record || !$record->ID) throw new SS_HTTPResponse_Exception("Bad record ID #" . (int)$data['ID'], 404);
|
||||||
$parentID = $record->ParentID;
|
$parentID = $record->ParentID;
|
||||||
|
$this->setCurrentPageID($parentID);
|
||||||
$record->delete();
|
$record->delete();
|
||||||
$this->setCurrentPageID(null);
|
|
||||||
|
|
||||||
$this->getResponse()->addHeader('X-Status', rawurlencode(_t('LeftAndMain.DELETED', 'Deleted.')));
|
$this->getResponse()->addHeader('X-Status', rawurlencode(_t('LeftAndMain.DELETED', 'Deleted.')));
|
||||||
$this->getResponse()->addHeader('X-Pjax', 'Content');
|
$this->getResponse()->addHeader('X-Pjax', 'Content');
|
||||||
@ -518,12 +529,13 @@ JS
|
|||||||
*/
|
*/
|
||||||
public function currentPage() {
|
public function currentPage() {
|
||||||
$id = $this->currentPageID();
|
$id = $this->currentPageID();
|
||||||
if($id && is_numeric($id) && $id > 0) {
|
if ($id > 0) {
|
||||||
$folder = DataObject::get_by_id('Folder', $id);
|
$folder = Folder::get()->byID($id);
|
||||||
if($folder && $folder->isInDB()) {
|
if ($folder && $folder->isInDB()) {
|
||||||
return $folder;
|
return $folder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Fallback to root
|
||||||
$this->setCurrentPageID(null);
|
$this->setCurrentPageID(null);
|
||||||
return new Folder();
|
return new Folder();
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ class CMSFileAddController extends LeftAndMain {
|
|||||||
private static $required_permission_codes = 'CMS_ACCESS_AssetAdmin';
|
private static $required_permission_codes = 'CMS_ACCESS_AssetAdmin';
|
||||||
private static $menu_title = 'Files';
|
private static $menu_title = 'Files';
|
||||||
private static $tree_class = 'Folder';
|
private static $tree_class = 'Folder';
|
||||||
|
|
||||||
// public function upload($request) {
|
// public function upload($request) {
|
||||||
// $formHtml = $this->renderWith(array('AssetAdmin_UploadContent'));
|
// $formHtml = $this->renderWith(array('AssetAdmin_UploadContent'));
|
||||||
// if($request->isAjax()) {
|
// 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)
|
* Return fake-ID "root" if no ID is found (needed to upload files into the root-folder)
|
||||||
*/
|
*/
|
||||||
public function currentPageID() {
|
public function currentPageID() {
|
||||||
if(is_numeric($this->getRequest()->requestVar('ID'))) {
|
$request = $this->getRequest();
|
||||||
return $this->getRequest()->requestVar('ID');
|
if (is_numeric($request->requestVar('ID'))) {
|
||||||
} elseif (is_numeric($this->urlParams['ID'])) {
|
return $request->requestVar('ID');
|
||||||
return $this->urlParams['ID'];
|
} elseif (is_numeric($request->param('ID'))) {
|
||||||
} elseif(Session::get("{$this->class}.currentPage")) {
|
return $request->param('ID');
|
||||||
return Session::get("{$this->class}.currentPage");
|
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -57,10 +56,6 @@ class CMSFileAddController extends LeftAndMain {
|
|||||||
Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js');
|
Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js');
|
||||||
Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css');
|
Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css');
|
||||||
|
|
||||||
if($currentPageID = $this->currentPageID()){
|
|
||||||
Session::set("{$this->class}.currentPage", $currentPageID);
|
|
||||||
}
|
|
||||||
|
|
||||||
$folder = $this->currentPage();
|
$folder = $this->currentPage();
|
||||||
|
|
||||||
$uploadField = UploadField::create('AssetUploadField', '');
|
$uploadField = UploadField::create('AssetUploadField', '');
|
||||||
@ -87,7 +82,7 @@ class CMSFileAddController extends LeftAndMain {
|
|||||||
$this,
|
$this,
|
||||||
'EditForm',
|
'EditForm',
|
||||||
new FieldList(
|
new FieldList(
|
||||||
$uploadField,
|
$uploadField,
|
||||||
new HiddenField('ID')
|
new HiddenField('ID')
|
||||||
),
|
),
|
||||||
new FieldList()
|
new FieldList()
|
||||||
@ -135,7 +130,7 @@ class CMSFileAddController extends LeftAndMain {
|
|||||||
'Title' => _t('AssetAdmin.Upload', 'Upload'),
|
'Title' => _t('AssetAdmin.Upload', 'Upload'),
|
||||||
'Link' => $this->Link()
|
'Link' => $this->Link()
|
||||||
)));
|
)));
|
||||||
|
|
||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user