mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
API CHANGE Removed SideReport javascript class, replaced with concrete implementation in CMSMain.js
ENHANCEMENT Using full form for 'site reports' panel in CMSMain->ReportForm(). Removed CMSMain->ReportSelector() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92727 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
1760759992
commit
2796a37a02
@ -56,7 +56,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
||||
'getshowdeletedsubtree',
|
||||
'getfilteredsubtree',
|
||||
'batchactions',
|
||||
'SearchTreeForm'
|
||||
'SearchTreeForm',
|
||||
'ReportForm'
|
||||
);
|
||||
|
||||
public function init() {
|
||||
@ -605,28 +606,46 @@ JS;
|
||||
|
||||
/*
|
||||
* Return a dropdown for selecting reports
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
function ReportSelector() {
|
||||
function ReportForm() {
|
||||
$reports = ClassInfo::subclassesFor("SideReport");
|
||||
|
||||
// $options[""] = _t('CMSMain.CHOOSEREPORT',"(Choose a report)");
|
||||
foreach($reports as $report) {
|
||||
if($report != 'SideReport' && singleton($report)->canView()) {
|
||||
$options[singleton($report)->group()][singleton($report)->sort()][$report] = singleton($report)->title();
|
||||
}
|
||||
}
|
||||
|
||||
$finalOptions = array();
|
||||
foreach($options as $group => $weights) {
|
||||
ksort($weights);
|
||||
foreach($weights as $weight => $reports) {
|
||||
foreach($reports as $class => $report) {
|
||||
$finalOptions[$group][$class] = $report;
|
||||
}
|
||||
}
|
||||
}
|
||||
$id = $this->request->requestVar('ID');
|
||||
$reportClass = $this->request->requestVar('ReportClass');
|
||||
$report = ClassInfo::exists($reportClass) ? new $reportClass() : false;
|
||||
$reportHtml = ($report) ? $report->getHTML() : false;
|
||||
|
||||
return new GroupedDropdownField("ReportSelector", _t('CMSMain.REPORT', 'Report'),$finalOptions);
|
||||
$form = new Form(
|
||||
$this,
|
||||
'ReportForm',
|
||||
new FieldSet(
|
||||
new DropdownField(
|
||||
"ReportClass",
|
||||
_t('CMSMain.REPORT', 'Report'),
|
||||
$options,
|
||||
$reportClass,
|
||||
null,
|
||||
_t('CMSMain.CHOOSEREPORT',"(Choose a report)")
|
||||
),
|
||||
new LiteralField('ReportHtml', $reportHtml),
|
||||
new HiddenField('ID', false, $id),
|
||||
new HiddenField('Locale', false, $this->Locale)
|
||||
),
|
||||
new FieldSet(
|
||||
new FormAction('sidereport', _t('CMSMain_left.ss.GO','Go'))
|
||||
)
|
||||
);
|
||||
$form->unsetValidator();
|
||||
|
||||
return $form;
|
||||
}
|
||||
function ReportFormParameters() {
|
||||
$reports = ClassInfo::subclassesFor("SideReport");
|
||||
@ -651,13 +670,15 @@ JS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content for a side report
|
||||
* Get the content for a side report.
|
||||
*
|
||||
* @param Array $data
|
||||
* @param Form $form
|
||||
* @return String
|
||||
*/
|
||||
function sidereport() {
|
||||
$reportClass = $this->urlParams['ID'];
|
||||
$report = ClassInfo::exists($reportClass) ? new $reportClass() : false;
|
||||
$report->setParams($this->request->requestVars());
|
||||
return $report ? $report->getHTML() : false;
|
||||
function sidereport($data, $form) {
|
||||
$form = $this->ReportForm();
|
||||
return (Director::is_ajax()) ? $form->forTemplate() : $form;
|
||||
}
|
||||
/**
|
||||
* Get the versions of the current page
|
||||
|
@ -232,7 +232,6 @@ class LeftAndMain extends Controller {
|
||||
Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.EditForm.js');
|
||||
|
||||
Requirements::javascript(CMS_DIR . '/javascript/SideTabs.js');
|
||||
Requirements::javascript(CMS_DIR . '/javascript/SideReports.js');
|
||||
|
||||
Requirements::themedCSS('typography');
|
||||
|
||||
|
@ -1,3 +1,19 @@
|
||||
(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);
|
||||
}
|
||||
};
|
||||
});
|
||||
}(jQuery));
|
||||
|
||||
if(typeof SiteTreeHandlers == 'undefined') SiteTreeHandlers = {};
|
||||
SiteTreeHandlers.parentChanged_url = 'admin/ajaxupdateparent';
|
||||
SiteTreeHandlers.orderChanged_url = 'admin/ajaxupdatesort';
|
||||
|
@ -475,4 +475,70 @@ var ss_MainLayout;
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* @class Simple form with a page type dropdown
|
||||
* which creates a new page through #Form_EditForm and adds a new tree node.
|
||||
* @name ss.Form_AddPageOptionsForm
|
||||
* @requires ss.i18n
|
||||
* @requires ss.reports_holder
|
||||
*/
|
||||
$('#Form_ReportForm').concrete(function($) {
|
||||
return/** @lends ss.reports_holder */{
|
||||
onmatch: function() {
|
||||
var self = this;
|
||||
|
||||
this.bind('submit', function(e) {
|
||||
return self._submit(e);
|
||||
});
|
||||
|
||||
// integrate with sitetree selection changes
|
||||
jQuery('#sitetree').bind('selectionchanged', function(e, data) {
|
||||
self.find(':input[name=ID]').val(data.node.getIdx());
|
||||
self.trigger('submit');
|
||||
});
|
||||
|
||||
// move submit button to the top
|
||||
this.find('#ReportClass').after(this.find('.Actions'));
|
||||
|
||||
// links in results
|
||||
this.find('ul a').bind('click', function(e) {
|
||||
var $link = $(this);
|
||||
$link.addClass('loading');
|
||||
jQuery('#Form_EditForm').concrete('ss').loadForm(
|
||||
$(this).attr('href'),
|
||||
function(e) {
|
||||
$link.removeClass('loading');
|
||||
}
|
||||
);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
|
||||
_submit: function(e) {
|
||||
var self = this;
|
||||
|
||||
// dont process if no report is selected
|
||||
var reportClass = this.find(':input[name=ReportClass]').val();
|
||||
if(!reportClass) return false;
|
||||
|
||||
var button = this.find(':submit:first');
|
||||
button.addClass('loading');
|
||||
|
||||
jQuery.ajax({
|
||||
url: this.attr('action'),
|
||||
data: this.serializeArray(),
|
||||
dataType: 'html',
|
||||
success: function(data, status) {
|
||||
// replace current form
|
||||
self.replaceWith(data);
|
||||
},
|
||||
complete: function(xmlhttp, status) {
|
||||
button.removeClass('loading');
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
});
|
||||
})(jQuery);
|
@ -1,108 +0,0 @@
|
||||
SideReports = Class.extend('SidePanel');
|
||||
SideReports.prototype = {
|
||||
initialize: function() {
|
||||
this.selector = $('ReportSelector');
|
||||
if(this.selector) this.selector.holder = this;
|
||||
this.SidePanel.initialize();
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
if(this.SidePanel) this.SidePanel.destroy();
|
||||
this.SidePanel = null;
|
||||
if(this.selector) this.selector.holder = null;
|
||||
this.selector = null;
|
||||
},
|
||||
|
||||
onshow: function() {
|
||||
if(this.selector.value) this.showreport();
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve a report via ajax
|
||||
*/
|
||||
showreport: function() {
|
||||
if(this.selector.value) {
|
||||
this.body.innerHTML = '<p>loading...</p>';
|
||||
this.ajaxGetPanel(this.afterPanelLoaded);
|
||||
} else {
|
||||
this.body.innerHTML = "<p>choose a report in the dropdown.</p>";
|
||||
}
|
||||
},
|
||||
afterPanelLoaded : function() {
|
||||
SideReportRecord.applyTo('#' + this.id + ' a');
|
||||
},
|
||||
ajaxURL: function() {
|
||||
var url = 'admin/sidereport/' + this.selector.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 = '<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.prototype = {
|
||||
destroy: function() {
|
||||
this.onclick = null;
|
||||
this.holder = null;
|
||||
},
|
||||
onclick: function() {
|
||||
$('reports_holder').showreport();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SideReportRecord = Class.create();
|
||||
SideReportRecord.prototype = {
|
||||
destroy: function() {
|
||||
this.onclick = null;
|
||||
},
|
||||
|
||||
onclick : function(event) {
|
||||
Event.stop(event);
|
||||
$('sitetree').loadingNode = $('sitetree').getTreeNodeByIdx( this.getID() );
|
||||
$('Form_EditForm').getPageFromServer(this.getID());
|
||||
},
|
||||
getID : function() {
|
||||
if(this.href.match(/\/([^\/]+)$/)) return parseInt(RegExp.$1);
|
||||
}
|
||||
}
|
||||
|
||||
SideReportGo.applyTo('#report_select_go');
|
||||
SideReportRecord.applyTo('#reports_holder a');
|
||||
SideReports.applyTo('#reports_holder');
|
||||
|
||||
Behaviour.register({
|
||||
'#ReportSelector' : {
|
||||
onchange : function() {
|
||||
$('reports_holder').reportSelected();
|
||||
}
|
||||
}
|
||||
});
|
@ -44,8 +44,6 @@
|
||||
<a href="#"><% _t('SITEREPORTS','Site Reports') %></a>
|
||||
</h3>
|
||||
<div class="listpane" id="reports_holder">
|
||||
<p id="ReportSelector_holder">$ReportSelector <input class="action" type="submit" id="report_select_go" value="<% _t('GO','Go') %>" /></p>
|
||||
<div class="unitBody">
|
||||
</div>
|
||||
$ReportForm
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user