mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Reimplementation for reports (#49) - removing unneeded code and remaking the template to use standard SiteTree functionality.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92788 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
a9adcbefaa
commit
1192d5b671
@ -24,9 +24,6 @@ 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
|
||||||
@ -35,6 +32,7 @@ class ReportAdmin extends LeftAndMain {
|
|||||||
|
|
||||||
// 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');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,92 +110,58 @@ class ReportAdmin extends LeftAndMain {
|
|||||||
$processedReports[] = new $subClass();
|
$processedReports[] = new $subClass();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$reports = new DataObjectSet($processedReports);
|
$reports = new DataObjectSet($processedReports);
|
||||||
|
|
||||||
return $reports;
|
return $reports;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a report based on the URL query string.
|
* Get EditForm for the class specified in request or in session variable
|
||||||
*
|
|
||||||
* @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?
|
|
||||||
*
|
|
||||||
* @param unknown_type $params
|
|
||||||
* @param unknown_type $editForm
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
protected function showWithEditForm($params, $editForm) {
|
|
||||||
if(isset($params['ID'])) Session::set('currentPage', $params['ID']);
|
|
||||||
if(isset($params['OtherID'])) Session::set('currentOtherID', $params['OtherID']);
|
|
||||||
|
|
||||||
if(Director::is_ajax()) {
|
|
||||||
SSViewer::setOption('rewriteHashlinks', false);
|
|
||||||
|
|
||||||
return $form->formHtmlContent();
|
|
||||||
}
|
|
||||||
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For the current report that the user is viewing,
|
|
||||||
* return a Form instance with the fields for that
|
|
||||||
* report.
|
|
||||||
*
|
*
|
||||||
|
* @param HTTPRequest
|
||||||
* @return Form
|
* @return Form
|
||||||
*/
|
*/
|
||||||
public function EditForm() {
|
public function EditForm($request = null) {
|
||||||
$ids = array();
|
$className = Session::get('currentPage');
|
||||||
$id = $this->currentPageID();
|
$requestId = $request ? $request->requestVar('ID') : null;
|
||||||
$subClasses = $this->getReportClassNames();
|
|
||||||
|
|
||||||
if($subClasses) {
|
if ( $requestId )
|
||||||
foreach($subClasses as $subClass) {
|
return $this->getEditForm($requestId);
|
||||||
$obj = new $subClass();
|
|
||||||
$ids[] = $obj->ID();
|
// $className can be null
|
||||||
}
|
return $this->getEditForm($className);
|
||||||
}
|
|
||||||
|
|
||||||
if($id && in_array($id, $ids)) return $this->reportEditFormFor($id);
|
|
||||||
else return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a Form instance with fields for the
|
* Return a Form instance with fields for the
|
||||||
* particular report currently viewed.
|
* particular report currently viewed.
|
||||||
*
|
*
|
||||||
* @TODO Dealing with multiple data types for the
|
* @param string $className Class of the report to fetch
|
||||||
* $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
|
* @return Form
|
||||||
*/
|
*/
|
||||||
public function reportEditFormFor($id) {
|
public function getEditForm($className = null) {
|
||||||
$page = false;
|
if (!$className) {
|
||||||
$fields = new FieldSet();
|
return $form = $this->EmptyForm();
|
||||||
$actions = new FieldSet();
|
}
|
||||||
|
|
||||||
if(is_numeric($id)) $page = DataObject::get_by_id('SiteTree', $id);
|
if (!class_exists($className)) {
|
||||||
$reportClass = is_object($page) ? 'SS_Report_' . $page->ClassName : $id;
|
die("$className does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
$obj = new $reportClass();
|
Session::set('currentPage', $className);
|
||||||
if($obj) $fields = $obj->getCMSFields();
|
|
||||||
|
$obj = new $className();
|
||||||
|
if(!$obj->canView()) return Security::permissionFailure($this);
|
||||||
|
|
||||||
|
$fields = $obj->getCMSFields();
|
||||||
|
|
||||||
$idField = new HiddenField('ID');
|
$idField = new HiddenField('ID');
|
||||||
$idField->setValue($id);
|
$idField->setValue($className);
|
||||||
$fields->push($idField);
|
$fields->push($idField);
|
||||||
|
|
||||||
|
$actions = new FieldSet();
|
||||||
|
|
||||||
$form = new Form($this, 'EditForm', $fields, $actions);
|
$form = new Form($this, 'EditForm', $fields, $actions);
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
|
15
javascript/ReportAdmin.Tree.js
Executable file
15
javascript/ReportAdmin.Tree.js
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
jQuery(function($) {
|
||||||
|
/**
|
||||||
|
* @class Tree panel.
|
||||||
|
* @name ss.sitetree
|
||||||
|
*/
|
||||||
|
$('#sitetree').concrete('ss', function($){
|
||||||
|
return/** @lends ss.sitetree */{
|
||||||
|
onmatch: function() {
|
||||||
|
// make sure current ID of loaded form is actually selected in tree
|
||||||
|
var id = $('#Form_EditForm :input[name=ID]').val();
|
||||||
|
if (id) this[0].setCurrentByIdx(id);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
@ -1,56 +0,0 @@
|
|||||||
if(typeof SiteTreeHandlers == 'undefined') SiteTreeHandlers = {};
|
|
||||||
|
|
||||||
SiteTree.prototype = {
|
|
||||||
castAsTreeNode: function(li) {
|
|
||||||
behaveAs(li, SiteTreeNode, this.options);
|
|
||||||
},
|
|
||||||
|
|
||||||
getIdxOf : function(treeNode) {
|
|
||||||
if(treeNode && treeNode.id)
|
|
||||||
return treeNode.id;
|
|
||||||
},
|
|
||||||
|
|
||||||
getTreeNodeByIdx : function(idx) {
|
|
||||||
if(!idx) idx = "0";
|
|
||||||
return document.getElementById(idx);
|
|
||||||
},
|
|
||||||
|
|
||||||
initialise: function() {
|
|
||||||
this.observeMethod('SelectionChanged', this.changeCurrentTo);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
SiteTreeNode.prototype.onselect = function() {
|
|
||||||
$('sitetree').changeCurrentTo(this);
|
|
||||||
jQuery('#sitetree').trigger('selectionchanged');
|
|
||||||
if($('sitetree').notify('SelectionChanged', this)) {
|
|
||||||
this.getPageFromServer();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
SiteTreeNode.prototype.getPageFromServer = function() {
|
|
||||||
if(this.id)
|
|
||||||
$('Form_EditForm').getPageFromServer(this.id);
|
|
||||||
};
|
|
||||||
|
|
||||||
function reloadSiteTree() {
|
|
||||||
|
|
||||||
new Ajax.Request( 'admin/report/getsitetree', {
|
|
||||||
method: get,
|
|
||||||
onSuccess: function( response ) {
|
|
||||||
$('sitetree_holder').innerHTML = response.responseText;
|
|
||||||
},
|
|
||||||
onFailure: function( response ) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
jQuery(document).ready(function() {
|
|
||||||
if($('sitetree')) {
|
|
||||||
var selectedNode = $('sitetree').getElementsByTagName('li')[1];
|
|
||||||
selectedNode.onselect();
|
|
||||||
}
|
|
||||||
});
|
|
@ -1,112 +0,0 @@
|
|||||||
|
|
||||||
Behaviour.register({
|
|
||||||
'#Form_EditForm' : {
|
|
||||||
initialise : function() {
|
|
||||||
this.openTab = null;
|
|
||||||
this.prepareForm();
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Processing called whenever a page is loaded in the right - including the initial one
|
|
||||||
*/
|
|
||||||
prepareForm : function() {
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request a page from the server via Ajax
|
|
||||||
*/
|
|
||||||
getPageFromServer : function(id) {
|
|
||||||
if(id) {
|
|
||||||
this.receivingID = id;
|
|
||||||
|
|
||||||
// Treenode might not exist if that part of the tree is closed
|
|
||||||
var treeNode = $('sitetree').getTreeNodeByIdx(id);
|
|
||||||
|
|
||||||
if(treeNode) treeNode.addNodeClass('loading');
|
|
||||||
|
|
||||||
statusMessage("loading...");
|
|
||||||
|
|
||||||
var requestURL = 'admin/reports/show/' + id;
|
|
||||||
new Ajax.Request(requestURL, {
|
|
||||||
asynchronous : true,
|
|
||||||
method : 'post',
|
|
||||||
postBody : 'ajax=1',
|
|
||||||
onSuccess : this.successfullyReceivedPage.bind(this),
|
|
||||||
onFailure : function(response) {
|
|
||||||
errorMessage('error loading page',response);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
throw("getPageFromServer: Bad page ID: " + id);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
successfullyReceivedPage : function(response) {
|
|
||||||
this.loadNewPage(response.responseText);
|
|
||||||
|
|
||||||
// Treenode might not exist if that part of the tree is closed
|
|
||||||
var treeNode = $('sitetree').getTreeNodeByIdx(this.receivingID);
|
|
||||||
if(treeNode) {
|
|
||||||
$('sitetree').changeCurrentTo(treeNode);
|
|
||||||
treeNode.removeNodeClass('loading');
|
|
||||||
}
|
|
||||||
statusMessage('');
|
|
||||||
|
|
||||||
if( this.openTab ) {
|
|
||||||
openTab( this.openTab );
|
|
||||||
this.openTab = null;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
didntReceivePage : function(response) {
|
|
||||||
errorMessage('error loading page', response);
|
|
||||||
$('sitetree').getTreeNodeByIdx(this.elements.ID.value).removeNodeClass('loading');
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load a new page into the right-hand form
|
|
||||||
*/
|
|
||||||
loadNewPage : function(formContent) {
|
|
||||||
rightHTML = formContent;
|
|
||||||
rightHTML = rightHTML.replace(/href *= *"#/g, 'href="' + window.location.href.replace(/#.*$/,'') + '#');
|
|
||||||
|
|
||||||
// Note: TinyMCE coupling
|
|
||||||
jQuery('#Form_EditForm').concrete('ss').cleanup();
|
|
||||||
|
|
||||||
// Prepare iframes for removal, otherwise we get loading bugs
|
|
||||||
var i, allIframes = this.getElementsByTagName('iframe');
|
|
||||||
if(allIframes) for(i=0;i<allIframes.length;i++) {
|
|
||||||
allIframes[i].contentWindow.location.href = 'about:blank';
|
|
||||||
allIframes[i].parentNode.removeChild(allIframes[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.innerHTML = rightHTML;
|
|
||||||
|
|
||||||
allIframes = this.getElementsByTagName('iframe');
|
|
||||||
if(allIframes) for(i=0;i<allIframes.length;i++) {
|
|
||||||
try {
|
|
||||||
allIframes[i].contentWindow.location.href = allIframes[i].src;
|
|
||||||
} catch(er) {alert(er.message);}
|
|
||||||
}
|
|
||||||
|
|
||||||
_TAB_DIVS_ON_PAGE = [];
|
|
||||||
|
|
||||||
try {
|
|
||||||
var tabs = document.getElementsBySelector('#Form_EditForm ul.tabstrip');
|
|
||||||
} catch(er) {/* alert('a: '+ er.message + '\n' + er.line);*/ }
|
|
||||||
try {
|
|
||||||
for(var i=0;i<tabs.length;i++) if(tabs[i].tagName) initTabstrip(tabs[i]);
|
|
||||||
} catch(er) { /*alert('b: '+ er.message + '\n' + er.line); */}
|
|
||||||
|
|
||||||
// if(this.prepareForm) this.prepareForm();
|
|
||||||
Behaviour.apply($('Form_EditForm'));
|
|
||||||
if(this.prepareForm)
|
|
||||||
this.prepareForm();
|
|
||||||
|
|
||||||
this.resetElements();
|
|
||||||
|
|
||||||
window.ontabschanged();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
@ -1,14 +1,14 @@
|
|||||||
<% if Reports %>
|
<% if Reports %>
|
||||||
<ul id="sitetree" class="tree unformatted">
|
<ul id="sitetree" class="tree unformatted">
|
||||||
<li id="$ID" class="Root">
|
<li id="record-$ID" class="Root">
|
||||||
<a><% _t('REPORTS','Reports') %></a>
|
<a><% _t('REPORTS','Reports') %></a>
|
||||||
<ul>
|
<ul>
|
||||||
<% control Reports %>
|
<% control Reports %>
|
||||||
<li id="$ID">
|
<li id="record-$ID">
|
||||||
<a href="admin/reports/show/$ID" title="$TreeDescription">$TreeTitle</a>
|
<a href="admin/reports/show/$ID" title="$TreeDescription">$TreeTitle</a>
|
||||||
</li>
|
</li>
|
||||||
<% end_control %>
|
<% end_control %>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<% end_if %>
|
<% end_if %>
|
@ -4,10 +4,15 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<h2><% _t('REPORTS','Reports') %></h2>
|
|
||||||
|
|
||||||
<div id="treepanes">
|
<div id="treepanes">
|
||||||
<div id="sitetree_holder">
|
<h3>
|
||||||
<% include ReportAdmin_SiteTree %>
|
<a href="#"><% _t('REPORTS','Reports') %></a>
|
||||||
</div>
|
</h3>
|
||||||
|
<div id="sitetree_holder">
|
||||||
|
<div id="sitetree_and_tools">
|
||||||
|
<div id="sitetree_ul">
|
||||||
|
<% include ReportAdmin_SiteTree %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user