diff --git a/code/ReportAdmin.php b/code/ReportAdmin.php index 6d15820e..0bbdb825 100755 --- a/code/ReportAdmin.php +++ b/code/ReportAdmin.php @@ -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 diff --git a/javascript/ReportAdmin.Tree.js b/javascript/ReportAdmin.Tree.js new file mode 100755 index 00000000..ab9adf33 --- /dev/null +++ b/javascript/ReportAdmin.Tree.js @@ -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); + } + }; + }); +}); \ No newline at end of file diff --git a/javascript/ReportAdmin_left.js b/javascript/ReportAdmin_left.js deleted file mode 100755 index e82833b2..00000000 --- a/javascript/ReportAdmin_left.js +++ /dev/null @@ -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(); - } -}); \ No newline at end of file diff --git a/javascript/ReportAdmin_right.js b/javascript/ReportAdmin_right.js deleted file mode 100755 index d065708b..00000000 --- a/javascript/ReportAdmin_right.js +++ /dev/null @@ -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 - <% end_if %> \ No newline at end of file diff --git a/templates/Includes/ReportAdmin_left.ss b/templates/Includes/ReportAdmin_left.ss index 5134bbd4..3473b555 100755 --- a/templates/Includes/ReportAdmin_left.ss +++ b/templates/Includes/ReportAdmin_left.ss @@ -4,10 +4,15 @@ } -

<% _t('REPORTS','Reports') %>

-
-
- <% include ReportAdmin_SiteTree %> -
+

+ <% _t('REPORTS','Reports') %> +

+
+
+
+ <% include ReportAdmin_SiteTree %> +
+
+