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
This commit is contained in:
Sam Minnee 2009-10-15 22:43:58 +00:00
parent ce7497c38a
commit 2294857460
4 changed files with 104 additions and 11 deletions

View File

@ -676,12 +676,35 @@ JS;
} }
return new DropdownField("ReportSelector", _t('CMSMain.REPORT', 'Report'),$options); 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 .= "<div id=\"SideReportForm_$class\" style=\"display:none\">$html</div>\n\n";
}
return new LiteralField("ReportFormParameters", '<div id="SideReportForms" style="display:none">'.$pageHtml.'</div>');
}
/** /**
* Get the content for a side report * Get the content for a side report
*/ */
function sidereport() { function sidereport() {
$reportClass = $this->urlParams['ID']; $reportClass = $this->urlParams['ID'];
$report = ClassInfo::exists($reportClass) ? new $reportClass() : false; $report = ClassInfo::exists($reportClass) ? new $reportClass() : false;
$report->setParams($this->request->requestVars());
return $report ? $report->getHTML() : false; return $report ? $report->getHTML() : false;
} }
/** /**
@ -995,6 +1018,25 @@ JS;
return $form; 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 .= "<div id=\"BatchActionParameters_$class\" style=\"display:none\">$html</div>\n\n";
}
return new LiteralField("BatchActionParameters", '<div id="BatchActionParameters" style="display:none">'.$pageHtml.'</div>');
}
/** /**
* Returns a list of batch actions * Returns a list of batch actions
*/ */

View File

@ -6,6 +6,8 @@
* @subpackage content * @subpackage content
*/ */
abstract class SideReport extends Object { abstract class SideReport extends Object {
protected $params = array();
abstract function records(); abstract function records();
abstract function fieldsToShow(); abstract function fieldsToShow();
abstract function title(); abstract function title();
@ -65,6 +67,15 @@ abstract class SideReport extends Object {
} }
return $result; 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() { function title() {
return _t('SideReport.EMPTYPAGES',"Empty pages"); return _t('SideReport.EMPTYPAGES',"Empty pages");
} }
function records() { function records($params = null) {
return DataObject::get("SiteTree", "\"Content\" = '' OR \"Content\" IS NULL OR \"Content\" LIKE '<p></p>' OR \"Content\" LIKE '<p>&nbsp;</p>'", '"Title"'); return DataObject::get("SiteTree", "\"Content\" = '' OR \"Content\" IS NULL OR \"Content\" LIKE '<p></p>' OR \"Content\" LIKE '<p>&nbsp;</p>'", '"Title"');
} }
function fieldsToShow() { function fieldsToShow() {
@ -95,7 +106,7 @@ class SideReport_RecentlyEdited extends SideReport {
function title() { function title() {
return _t('SideReport.LAST2WEEKS',"Pages edited in the last 2 weeks"); 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')); $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"); 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() { function title() {
return _t('SideReport.BROKENLINKS',"Pages with broken links"); return _t('SideReport.BROKENLINKS',"Pages with broken links");
} }
function records() { function records($params = null) {
return DataObject::get("SiteTree", "HasBrokenLink = 1"); return DataObject::get("SiteTree", "HasBrokenLink = 1");
} }
function fieldsToShow() { function fieldsToShow() {
@ -129,7 +140,7 @@ class SideReport_ToDo extends SideReport {
function title() { function title() {
return _t('SideReport.TODO',"To do"); 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"); return DataObject::get("SiteTree", "\"SiteTree\".\"ToDo\" IS NOT NULL AND \"SiteTree\".\"ToDo\" <> ''", "\"SiteTree\".\"LastEdited\" DESC");
} }
function fieldsToShow() { function fieldsToShow() {

View File

@ -33,10 +33,38 @@ SideReports.prototype = {
}, },
ajaxURL: function() { ajaxURL: function() {
var url = 'admin/sidereport/' + this.selector.value; 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; 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 = '<form id="SideReportForm">'+
$('SideReportForm_'+this.selector.value).innerHTML
+'</form>';
$('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(); SideReportGo = Class.create();
@ -69,4 +97,12 @@ SideReportRecord.prototype = {
SideReportGo.applyTo('#report_select_go'); SideReportGo.applyTo('#report_select_go');
SideReportRecord.applyTo('#reports_holder a'); SideReportRecord.applyTo('#reports_holder a');
SideReports.applyTo('#reports_holder'); SideReports.applyTo('#reports_holder');
Behaviour.register({
'#ReportSelector' : {
onchange : function() {
$('reports_holder').reportSelected();
},
}
});

View File

@ -64,7 +64,8 @@
</div> </div>
</div> </div>
</form> </form>
$BatchActionParameters
<div id="batchactionsforms" style="display: none"> <div id="batchactionsforms" style="display: none">
<form class="actionparams" style="border:0" id="batchactions_options" action=""> <form class="actionparams" style="border:0" id="batchactions_options" action="">
<p><% _t('SELECTPAGESACTIONS','Select the pages that you want to change &amp; then click an action:') %></p> <p><% _t('SELECTPAGESACTIONS','Select the pages that you want to change &amp; then click an action:') %></p>
@ -151,9 +152,12 @@
<img id="reports_toggle_open" src="sapphire/images/toggle-open.gif" alt="-" style="display:none;" title="<% _t('CLOSEBOX') %>" /> <img id="reports_toggle_open" src="sapphire/images/toggle-open.gif" alt="-" style="display:none;" title="<% _t('CLOSEBOX') %>" />
<% _t('SITEREPORTS','Site Reports') %> <% _t('SITEREPORTS','Site Reports') %>
</h2> </h2>
$ReportFormParameters
<div class="listpane" id="reports_holder" style="display:none"> <div class="listpane" id="reports_holder" style="display:none">
<p id="ReportSelector_holder">$ReportSelector <input class="action" type="submit" id="report_select_go" value="<% _t('GO','Go') %>" /></p> <p id="ReportSelector_holder">
<div class="unitBody"> $ReportSelector
</div> <input class="action" type="submit" id="report_select_go" onclick="$('reports_holder').showreport();" value="<% _t('GO','Go') %>" />
</p>
<div class="unitBody"></div>
</div> </div>
</div> </div>