diff --git a/code/CMSMain.php b/code/CMSMain.php index dacdd7d5a8..803f560f3e 100755 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -56,7 +56,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr 'getshowdeletedsubtree', 'getfilteredsubtree', 'batchactions', - 'SearchTreeForm' + 'SearchTreeForm', + 'ReportForm' ); public function init() { @@ -605,28 +606,46 @@ public function delete($data, $form) { /* * 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; + + $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 new GroupedDropdownField("ReportSelector", _t('CMSMain.REPORT', 'Report'),$finalOptions); + return $form; } function ReportFormParameters() { $reports = ClassInfo::subclassesFor("SideReport"); @@ -651,13 +670,15 @@ function ReportFormParameters() { } /** - * 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 diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index 3938316dcd..de7c06bf20 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -232,7 +232,6 @@ function init() { 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'); diff --git a/javascript/CMSMain.Tree.js b/javascript/CMSMain.Tree.js index 824b7cb68f..bce89f0cc0 100644 --- a/javascript/CMSMain.Tree.js +++ b/javascript/CMSMain.Tree.js @@ -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'; diff --git a/javascript/CMSMain.js b/javascript/CMSMain.js index badd633db5..769d7b3f17 100644 --- a/javascript/CMSMain.js +++ b/javascript/CMSMain.js @@ -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); \ No newline at end of file diff --git a/javascript/SideReports.js b/javascript/SideReports.js deleted file mode 100755 index fc01c0bcd0..0000000000 --- a/javascript/SideReports.js +++ /dev/null @@ -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 = '

loading...

'; - this.ajaxGetPanel(this.afterPanelLoaded); - } else { - this.body.innerHTML = "

choose a report in the dropdown.

"; - } - }, - 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 = '
'+ - $('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(); -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(); - } - } -}); \ No newline at end of file diff --git a/templates/Includes/CMSMain_left.ss b/templates/Includes/CMSMain_left.ss index ad567299e2..9f39414fda 100755 --- a/templates/Includes/CMSMain_left.ss +++ b/templates/Includes/CMSMain_left.ss @@ -44,8 +44,6 @@ <% _t('SITEREPORTS','Site Reports') %>
-

$ReportSelector

-
-
+ $ReportForm