mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
BUGFIX: re-applied commit 1192d5b671
in order to get ReportAdmin to work with entwine Tree, not _left _right javascript.
This commit is contained in:
parent
a3da342b06
commit
a3bd51e388
@ -23,42 +23,40 @@ class ReportAdmin extends LeftAndMain {
|
|||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
parent::init();
|
parent::init();
|
||||||
|
|
||||||
Requirements::javascript(CMS_DIR . '/javascript/ReportAdmin_left.js');
|
|
||||||
Requirements::javascript(CMS_DIR . '/javascript/ReportAdmin_right.js');
|
|
||||||
|
|
||||||
Requirements::css(CMS_DIR . '/css/ReportAdmin.css');
|
Requirements::css(CMS_DIR . '/css/ReportAdmin.css');
|
||||||
|
|
||||||
// Set custom options for TinyMCE specific to ReportAdmin
|
// Set custom options for TinyMCE specific to ReportAdmin
|
||||||
HtmlEditorConfig::get('cms')->setOption('ContentCSS', project() . '/css/editor.css');
|
HtmlEditorConfig::get('cms')->setOption('ContentCSS', project() . '/css/editor.css');
|
||||||
HtmlEditorConfig::get('cms')->setOption('Lang', i18n::get_tinymce_lang());
|
HtmlEditorConfig::get('cms')->setOption('Lang', i18n::get_tinymce_lang());
|
||||||
|
|
||||||
// Always block the HtmlEditorField.js otherwise it will be sent with an ajax request
|
// Always block the HtmlEditorField.js otherwise it will be sent with an ajax request
|
||||||
Requirements::block(SAPPHIRE_DIR . '/javascript/HtmlEditorField.js');
|
Requirements::block(SAPPHIRE_DIR . '/javascript/HtmlEditorField.js');
|
||||||
|
Requirements::javascript(CMS_DIR . '/javascript/ReportAdmin.Tree.js');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does the parent permission checks, but also
|
* Does the parent permission checks, but also
|
||||||
* makes sure that instantiatable subclasses of
|
* makes sure that instantiatable subclasses of
|
||||||
* {@link Report} exist. By default, the CMS doesn't
|
* {@link Report} exist. By default, the CMS doesn't
|
||||||
* include any Reports, so there's no point in showing
|
* include any Reports, so there's no point in showing
|
||||||
*
|
*
|
||||||
* @param Member $member
|
* @param Member $member
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function canView($member = null) {
|
function canView($member = null) {
|
||||||
if(!$member && $member !== FALSE) $member = Member::currentUser();
|
if(!$member && $member !== FALSE) $member = Member::currentUser();
|
||||||
|
|
||||||
if(!parent::canView($member)) return false;
|
if(!parent::canView($member)) return false;
|
||||||
|
|
||||||
$hasViewableSubclasses = false;
|
$hasViewableSubclasses = false;
|
||||||
foreach($this->Reports() as $report) {
|
foreach($this->Reports() as $report) {
|
||||||
if($report->canView($member)) return true;
|
if($report->canView($member)) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a DataObjectSet of SS_Report subclasses
|
* Return a DataObjectSet of SS_Report subclasses
|
||||||
* that are available for use.
|
* that are available for use.
|
||||||
@ -72,61 +70,59 @@ class ReportAdmin extends LeftAndMain {
|
|||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Show a report based on the URL query string.
|
|
||||||
*
|
|
||||||
* @param SS_HTTPRequest $request The HTTP request object
|
|
||||||
*/
|
|
||||||
public function show($request) {
|
|
||||||
$params = $request->allParams();
|
|
||||||
|
|
||||||
return $this->showWithEditForm($params, $this->reportEditFormFor($params['ID']));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @TODO What does this do?
|
* Get EditForm for the class specified in request or in session variable
|
||||||
*
|
|
||||||
* @param unknown_type $params
|
|
||||||
* @param unknown_type $editForm
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
protected function showWithEditForm($params, $editForm) {
|
|
||||||
if(isset($params['ID'])) Session::set('currentReport', $params['ID']);
|
|
||||||
if(isset($params['OtherID'])) Session::set('currentOtherID', $params['OtherID']);
|
|
||||||
|
|
||||||
if(Director::is_ajax()) {
|
|
||||||
SSViewer::setOption('rewriteHashlinks', false);
|
|
||||||
|
|
||||||
$result = $this->customise(array(
|
|
||||||
'EditForm' => $editForm
|
|
||||||
))->renderWith($this->getTemplatesWithSuffix('_right'));
|
|
||||||
|
|
||||||
return $this->getLastFormIn($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For the current report that the user is viewing,
|
|
||||||
* return a Form instance with the fields for that
|
|
||||||
* report.
|
|
||||||
*
|
*
|
||||||
* @return Form
|
* @return Form
|
||||||
*/
|
*/
|
||||||
public function EditForm() {
|
public function EditForm($request = null) {
|
||||||
// Return the report if the ID is sent by request, or we're specifically asking for the edit form
|
$className = Session::get('currentPage');
|
||||||
$id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : ($this->getRequest()->latestParam('Action') == 'EditForm') ? Session::get('currentReport') : null;
|
$requestId = $request ? $request->requestVar('ID') : null;
|
||||||
|
|
||||||
if($id) {
|
if ( $requestId )
|
||||||
foreach($this->Reports() as $report) {
|
return $this->getEditForm($requestId);
|
||||||
if($id == $report->ID()) return $this->reportEditFormFor($id);
|
|
||||||
}
|
// $className can be null
|
||||||
}
|
return $this->getEditForm($className);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a Form instance with fields for the
|
||||||
|
* particular report currently viewed.
|
||||||
|
*
|
||||||
|
* @param string $className Class of the report to fetch
|
||||||
|
* @return Form
|
||||||
|
*/
|
||||||
|
public function getEditForm($className = null) {
|
||||||
|
if (!$className) {
|
||||||
|
return $form = $this->EmptyForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!class_exists($className)) {
|
||||||
|
die("$className does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
Session::set('currentPage', $className);
|
||||||
|
|
||||||
|
$obj = new $className();
|
||||||
|
if(!$obj->canView()) return Security::permissionFailure($this);
|
||||||
|
|
||||||
|
$fields = $obj->getCMSFields();
|
||||||
|
|
||||||
|
$idField = new HiddenField('ID');
|
||||||
|
$idField->setValue($className);
|
||||||
|
$fields->push($idField);
|
||||||
|
|
||||||
|
$actions = new FieldSet();
|
||||||
|
|
||||||
|
$form = new Form($this, 'EditForm', $fields, $actions);
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current report
|
* Get the current report
|
||||||
*
|
*
|
||||||
@ -134,7 +130,7 @@ class ReportAdmin extends LeftAndMain {
|
|||||||
*/
|
*/
|
||||||
public function CurrentReport() {
|
public function CurrentReport() {
|
||||||
$id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : ($this->getRequest()->latestParam('Action') == 'EditForm') ? Session::get('currentReport') : null;
|
$id = isset($_REQUEST['ID']) ? $_REQUEST['ID'] : ($this->getRequest()->latestParam('Action') == 'EditForm') ? Session::get('currentReport') : null;
|
||||||
|
|
||||||
if($id) {
|
if($id) {
|
||||||
foreach($this->Reports() as $report) {
|
foreach($this->Reports() as $report) {
|
||||||
if($id == $report->ID()) return $report;
|
if($id == $report->ID()) return $report;
|
||||||
@ -142,56 +138,12 @@ class ReportAdmin extends LeftAndMain {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a Form instance with fields for the
|
|
||||||
* particular report currently viewed.
|
|
||||||
*
|
|
||||||
* @TODO Dealing with multiple data types for the
|
|
||||||
* $id parameter is confusing. Ideally, it should
|
|
||||||
* deal with only one.
|
|
||||||
*
|
|
||||||
* @param id|string $id The ID of the report, or class name
|
|
||||||
* @return Form
|
|
||||||
*/
|
|
||||||
public function reportEditFormFor($id) {
|
|
||||||
$page = false;
|
|
||||||
$fields = new FieldSet();
|
|
||||||
$actions = new FieldSet();
|
|
||||||
|
|
||||||
$reports = SS_Report::get_reports('ReportAdmin');
|
|
||||||
$obj = $reports[$id];
|
|
||||||
|
|
||||||
if($obj) $fields = $obj->getCMSFields();
|
|
||||||
if($obj) $actions = $obj->getCMSActions();
|
|
||||||
|
|
||||||
$idField = new HiddenField('ID');
|
|
||||||
$idField->setValue($id);
|
|
||||||
$fields->push($idField);
|
|
||||||
|
|
||||||
$form = new Form($this, 'EditForm', $fields, $actions);
|
|
||||||
|
|
||||||
$form->loadDataFrom($_REQUEST);
|
|
||||||
|
|
||||||
// Include search criteria in the form action so that pagination works
|
|
||||||
$filteredCriteria = array_merge($_GET, $_POST);
|
|
||||||
foreach(array('ID','url','ajax','ctf','update','action_updatereport','SecurityID') as $notAParam) {
|
|
||||||
unset($filteredCriteria[$notAParam]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$formLink = $this->Link() . '/EditForm';
|
|
||||||
if($filteredCriteria) $formLink .= '?' . http_build_query($filteredCriteria);
|
|
||||||
$form->setFormAction($formLink);
|
|
||||||
$form->setTemplate('ReportAdminForm');
|
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if we have reports and need
|
* Determine if we have reports and need
|
||||||
* to display the "Reports" main menu item
|
* to display the "Reports" main menu item
|
||||||
* in the CMS.
|
* in the CMS.
|
||||||
*
|
*
|
||||||
* The test for an existance of a report
|
* The test for an existance of a report
|
||||||
* is done by checking for a subclass of
|
* is done by checking for a subclass of
|
||||||
* "SS_Report" that exists.
|
* "SS_Report" that exists.
|
||||||
|
Loading…
Reference in New Issue
Block a user