mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +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() {
|
||||
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');
|
||||
|
||||
// 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
|
||||
Requirements::block(SAPPHIRE_DIR . '/javascript/HtmlEditorField.js');
|
||||
Requirements::javascript(CMS_DIR . '/javascript/ReportAdmin.Tree.js');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,97 +110,63 @@ class ReportAdmin extends LeftAndMain {
|
||||
$processedReports[] = new $subClass();
|
||||
}
|
||||
}
|
||||
|
||||
$reports = new DataObjectSet($processedReports);
|
||||
|
||||
return $reports;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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?
|
||||
*
|
||||
* @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.
|
||||
* Get EditForm for the class specified in request or in session variable
|
||||
*
|
||||
* @param HTTPRequest
|
||||
* @return Form
|
||||
*/
|
||||
public function EditForm() {
|
||||
$ids = array();
|
||||
$id = $this->currentPageID();
|
||||
$subClasses = $this->getReportClassNames();
|
||||
public function EditForm($request = null) {
|
||||
$className = Session::get('currentPage');
|
||||
$requestId = $request ? $request->requestVar('ID') : null;
|
||||
|
||||
if($subClasses) {
|
||||
foreach($subClasses as $subClass) {
|
||||
$obj = new $subClass();
|
||||
$ids[] = $obj->ID();
|
||||
}
|
||||
}
|
||||
if ( $requestId )
|
||||
return $this->getEditForm($requestId);
|
||||
|
||||
if($id && in_array($id, $ids)) return $this->reportEditFormFor($id);
|
||||
else return false;
|
||||
// $className can be null
|
||||
return $this->getEditForm($className);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param string $className Class of the report to fetch
|
||||
* @return Form
|
||||
*/
|
||||
public function reportEditFormFor($id) {
|
||||
$page = false;
|
||||
$fields = new FieldSet();
|
||||
$actions = new FieldSet();
|
||||
|
||||
if(is_numeric($id)) $page = DataObject::get_by_id('SiteTree', $id);
|
||||
$reportClass = is_object($page) ? 'SS_Report_' . $page->ClassName : $id;
|
||||
|
||||
$obj = new $reportClass();
|
||||
if($obj) $fields = $obj->getCMSFields();
|
||||
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($id);
|
||||
$idField->setValue($className);
|
||||
$fields->push($idField);
|
||||
|
||||
|
||||
$actions = new FieldSet();
|
||||
|
||||
$form = new Form($this, 'EditForm', $fields, $actions);
|
||||
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if we have reports and need
|
||||
* to display the "Reports" main menu item
|
||||
|
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 %>
|
||||
<ul id="sitetree" class="tree unformatted">
|
||||
<li id="$ID" class="Root">
|
||||
<ul id="sitetree" class="tree unformatted">
|
||||
<li id="record-$ID" class="Root">
|
||||
<a><% _t('REPORTS','Reports') %></a>
|
||||
<ul>
|
||||
<% control Reports %>
|
||||
<li id="$ID">
|
||||
<li id="record-$ID">
|
||||
<a href="admin/reports/show/$ID" title="$TreeDescription">$TreeTitle</a>
|
||||
</li>
|
||||
<% end_control %>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
<% end_if %>
|
@ -4,10 +4,15 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<h2><% _t('REPORTS','Reports') %></h2>
|
||||
|
||||
<div id="treepanes">
|
||||
<div id="sitetree_holder">
|
||||
<% include ReportAdmin_SiteTree %>
|
||||
</div>
|
||||
<h3>
|
||||
<a href="#"><% _t('REPORTS','Reports') %></a>
|
||||
</h3>
|
||||
<div id="sitetree_holder">
|
||||
<div id="sitetree_and_tools">
|
||||
<div id="sitetree_ul">
|
||||
<% include ReportAdmin_SiteTree %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user