From: Coleman Watts Date: Mon, 24 Jun 2013 22:31:48 +0000 (-0700) Subject: CRM-12887 fix click handlers and respect hash X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4cbc3ca2930d666669cd83dd5c549a07cdb7a73e;p=civicrm-core.git CRM-12887 fix click handlers and respect hash ---------------------------------------- * CRM-12887: Js tidy-up on Contribution dashboard http://issues.civicrm.org/jira/browse/CRM-12887 --- diff --git a/CRM/Contribute/Form/ContributionCharts.php b/CRM/Contribute/Form/ContributionCharts.php index b2610aba36..4c4f6ab0ff 100644 --- a/CRM/Contribute/Form/ContributionCharts.php +++ b/CRM/Contribute/Form/ContributionCharts.php @@ -71,10 +71,10 @@ class CRM_Contribute_Form_ContributionCharts extends CRM_Core_Form { public function buildQuickForm() { //p3 = Three dimensional pie chart. //bvg = Vertical bar chart - $this->addElement('select', 'chart_type', ts('Chart Style'), array('bvg' => ts('Bar'), + $this->addElement('select', 'chart_type', ts('Chart Style'), array( + 'bvg' => ts('Bar'), 'p3' => ts('Pie'), - ), - array('onchange' => "getChart();") + ) ); $defaultValues['chart_type'] = $this->_chartType; $this->setDefaults($defaultValues); @@ -92,9 +92,7 @@ class CRM_Contribute_Form_ContributionCharts extends CRM_Core_Form { } } - $this->addElement('select', 'select_year', ts('Select Year (for monthly breakdown)'), - $years, array('onchange' => "getChart();") - ); + $this->addElement('select', 'select_year', ts('Select Year (for monthly breakdown)'), $years); $this->setDefaults(array( 'select_year' => ($this->_year) ? $this->_year : $currentYear, )); diff --git a/templates/CRM/Contribute/Page/DashBoard.js b/templates/CRM/Contribute/Page/DashBoard.js index 2ebb3c5b3c..e1a37f3314 100644 --- a/templates/CRM/Contribute/Page/DashBoard.js +++ b/templates/CRM/Contribute/Page/DashBoard.js @@ -18,19 +18,20 @@ cj(function ($) { year = currentYear; } chartUrl = CRM.url("civicrm/ajax/chart", { - 'snippet' : 4, - 'year' : year, - 'type' : charttype + 'snippet': 4, + 'year': year, + 'type': charttype + }); + $("#chartData").load(chartUrl, function() { + $("select", "#chartData").change(getChart); }); - $(chartData).load(chartUrl); } function buildTabularView() { var tableUrl = CRM.url("civicrm/contribute/ajax/tableview", {showtable: 1, snippet: 4}); - $(tableData).load(tableUrl); + $("#tableData").load(tableUrl); } - getChart(); $('#chart_view').click(function() { if ($('#chart_view').hasClass('ui-state-default')) { $('#chart_view').removeClass('ui-state-default').addClass('ui-state-active ui-tabs-selected'); @@ -47,5 +48,13 @@ cj(function ($) { $('#chartData').children().html(''); } }); + + // Initialize chart or table based on url hash + if (window.location.hash === '#table_layout') { + $('#table_view').click(); + } + else { + getChart(); + } });