mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 09:05:53 +00:00
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:
parent
ce7497c38a
commit
2294857460
@ -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
|
||||||
*/
|
*/
|
||||||
|
@ -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> </p>'", '"Title"');
|
return DataObject::get("SiteTree", "\"Content\" = '' OR \"Content\" IS NULL OR \"Content\" LIKE '<p></p>' OR \"Content\" LIKE '<p> </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() {
|
||||||
|
@ -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();
|
||||||
@ -70,3 +98,11 @@ 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();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
@ -65,6 +65,7 @@
|
|||||||
</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 & then click an action:') %></p>
|
<p><% _t('SELECTPAGESACTIONS','Select the pages that you want to change & 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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user