From 229485746018978d94ed2ba2fb76d98aac03f1f5 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 15 Oct 2009 22:43:58 +0000 Subject: [PATCH] ENHANCMENT side reports can now have parameters (from r85329) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@89220 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/CMSMain.php | 42 ++++++++++++++++++++++++++++++ code/SideReport.php | 19 +++++++++++--- javascript/SideReports.js | 42 +++++++++++++++++++++++++++--- templates/Includes/CMSMain_left.ss | 12 ++++++--- 4 files changed, 104 insertions(+), 11 deletions(-) diff --git a/code/CMSMain.php b/code/CMSMain.php index 2aed6ea6..190f8c35 100755 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -676,12 +676,35 @@ JS; } return new DropdownField("ReportSelector", _t('CMSMain.REPORT', 'Report'),$options); } + function ReportFormParameters() { + $reports = ClassInfo::subclassesFor("SideReport"); + + $forms = array(); + foreach($reports as $report) { + if ($report != 'SideReport') { + if ($fieldset = singleton($report)->getParameterFields()) { + $formHtml = ''; + foreach($fieldset as $field) { + $formHtml .= $field->Field(); + } + $forms[$report] = $formHtml; + } + } + } + $pageHtml = ''; + foreach($forms as $class => $html) { + $pageHtml .= "
$html
\n\n"; + } + return new LiteralField("ReportFormParameters", ''); + } + /** * Get the content for a side report */ function sidereport() { $reportClass = $this->urlParams['ID']; $report = ClassInfo::exists($reportClass) ? new $reportClass() : false; + $report->setParams($this->request->requestVars()); return $report ? $report->getHTML() : false; } /** @@ -995,6 +1018,25 @@ JS; return $form; } + function BatchActionParameters() { + $batchActions = CMSBatchActionHandler::$batch_actions; + + $forms = array(); + foreach($batchActions as $batchAction) { + if ($fieldset = singleton($batchAction)->getParameterFields()) { + $formHtml = ''; + foreach($fieldset as $field) { + $formHtml .= $field->Field(); + } + $forms[$batchAction] = $formHtml; + } + } + $pageHtml = ''; + foreach($forms as $class => $html) { + $pageHtml .= "
$html
\n\n"; + } + return new LiteralField("BatchActionParameters", ''); + } /** * Returns a list of batch actions */ diff --git a/code/SideReport.php b/code/SideReport.php index 50f40dc8..9d7395f4 100755 --- a/code/SideReport.php +++ b/code/SideReport.php @@ -6,6 +6,8 @@ * @subpackage content */ abstract class SideReport extends Object { + protected $params = array(); + abstract function records(); abstract function fieldsToShow(); abstract function title(); @@ -65,6 +67,15 @@ abstract class SideReport extends Object { } return $result; } + + function setParams($params) { + $this->params = $params; + } + + // if your batchaction has parameters, return a fieldset here + function getParameterFields() { + return false; + } } /** @@ -76,7 +87,7 @@ class SideReport_EmptyPages extends SideReport { function title() { return _t('SideReport.EMPTYPAGES',"Empty pages"); } - function records() { + function records($params = null) { return DataObject::get("SiteTree", "\"Content\" = '' OR \"Content\" IS NULL OR \"Content\" LIKE '

' OR \"Content\" LIKE '

 

'", '"Title"'); } function fieldsToShow() { @@ -95,7 +106,7 @@ class SideReport_RecentlyEdited extends SideReport { function title() { return _t('SideReport.LAST2WEEKS',"Pages edited in the last 2 weeks"); } - function records() { + function records($params = null) { $threshold = strtotime('-14 days', SSDatetime::now()->Format('U')); return DataObject::get("SiteTree", "\"SiteTree\".\"LastEdited\" > '".date("Y-m-d H:i:s", $threshold)."'", "\"SiteTree\".\"LastEdited\" DESC"); } @@ -115,7 +126,7 @@ class SideReport_BrokenLinks extends SideReport { function title() { return _t('SideReport.BROKENLINKS',"Pages with broken links"); } - function records() { + function records($params = null) { return DataObject::get("SiteTree", "HasBrokenLink = 1"); } function fieldsToShow() { @@ -129,7 +140,7 @@ class SideReport_ToDo extends SideReport { function title() { return _t('SideReport.TODO',"To do"); } - function records() { + function records($params = null) { return DataObject::get("SiteTree", "\"SiteTree\".\"ToDo\" IS NOT NULL AND \"SiteTree\".\"ToDo\" <> ''", "\"SiteTree\".\"LastEdited\" DESC"); } function fieldsToShow() { diff --git a/javascript/SideReports.js b/javascript/SideReports.js index a16af4c6..83a7360f 100755 --- a/javascript/SideReports.js +++ b/javascript/SideReports.js @@ -33,10 +33,38 @@ SideReports.prototype = { }, ajaxURL: function() { var url = 'admin/sidereport/' + this.selector.value; - if($('LangSelector')) url += "?locale=" + $('LangSelector').value; + if ($('SideReportForm')) { + url += '?'+Form.serialize('SideReportForm'); + if($('LangSelector')) url += "&locale=" + $('LangSelector').value; + } else { + if($('LangSelector')) url += "?locale=" + $('LangSelector').value; + } return url; + }, + reportSelected: function() { + var value = this.selector.value; + if ($('SideReportForm')) { + $('SideReportForm').parentNode.removeChild($('SideReportForm')); + } + if ($('SideReportForm_'+this.selector.value)) { + // Copy form content... + var form = '
'+ + $('SideReportForm_'+this.selector.value).innerHTML + +'
'; + $('ReportSelector_holder').innerHTML += form; + } + + this.selector = $('ReportSelector'); + this.selector.value = value; + if(this.selector) this.selector.holder = this; + Behaviour.register({ + '#ReportSelector' : { + onchange : function() { + $('reports_holder').reportSelected(); + }, + } + }); } - } SideReportGo = Class.create(); @@ -69,4 +97,12 @@ SideReportRecord.prototype = { SideReportGo.applyTo('#report_select_go'); SideReportRecord.applyTo('#reports_holder a'); -SideReports.applyTo('#reports_holder'); \ No newline at end of file +SideReports.applyTo('#reports_holder'); + +Behaviour.register({ + '#ReportSelector' : { + onchange : function() { + $('reports_holder').reportSelected(); + }, + } +}); \ No newline at end of file diff --git a/templates/Includes/CMSMain_left.ss b/templates/Includes/CMSMain_left.ss index 56ec2da5..660686fb 100755 --- a/templates/Includes/CMSMain_left.ss +++ b/templates/Includes/CMSMain_left.ss @@ -64,7 +64,8 @@ - + + $BatchActionParameters