From 2796a37a028b7be704613c7c984c76d6fd6c2696 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 21 Nov 2009 03:15:55 +0000 Subject: [PATCH] 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 --- code/CMSMain.php | 59 +++++++++++----- code/LeftAndMain.php | 1 - javascript/CMSMain.Tree.js | 16 +++++ javascript/CMSMain.js | 66 ++++++++++++++++++ javascript/SideReports.js | 108 ----------------------------- templates/Includes/CMSMain_left.ss | 4 +- 6 files changed, 123 insertions(+), 131 deletions(-) delete mode 100755 javascript/SideReports.js diff --git a/code/CMSMain.php b/code/CMSMain.php index dacdd7d5..803f560f 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 @@ 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 diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index 3938316d..de7c06bf 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -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'); diff --git a/javascript/CMSMain.Tree.js b/javascript/CMSMain.Tree.js index 824b7cb6..bce89f0c 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 badd633d..769d7b3f 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 fc01c0bc..00000000 --- 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 ad567299..9f39414f 100755 --- a/templates/Includes/CMSMain_left.ss +++ b/templates/Includes/CMSMain_left.ss @@ -44,8 +44,6 @@ <% _t('SITEREPORTS','Site Reports') %>
-

$ReportSelector

-
-
+ $ReportForm