From 4265dd23b868fe994313abe26277100e6f96a7d7 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 24 Jun 2013 11:33:24 +1200 Subject: [PATCH] CRM-12887 intial restructure into js file --- CRM/Contribute/Page/DashBoard.php | 1 + templates/CRM/Contribute/Page/DashBoard.js | 49 +++++++++++++++++ templates/CRM/Contribute/Page/DashBoard.tpl | 58 +-------------------- 3 files changed, 51 insertions(+), 57 deletions(-) create mode 100644 templates/CRM/Contribute/Page/DashBoard.js diff --git a/CRM/Contribute/Page/DashBoard.php b/CRM/Contribute/Page/DashBoard.php index ce1c640d6c..1b5fcc0256 100644 --- a/CRM/Contribute/Page/DashBoard.php +++ b/CRM/Contribute/Page/DashBoard.php @@ -121,6 +121,7 @@ class CRM_Contribute_Page_DashBoard extends CRM_Core_Page { $chartForm->setEmbedded(TRUE); $chartForm->process(); $chartForm->run(); + CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Contribute/Page/DashBoard.js'); return parent::run(); } diff --git a/templates/CRM/Contribute/Page/DashBoard.js b/templates/CRM/Contribute/Page/DashBoard.js new file mode 100644 index 0000000000..af9a7eeb19 --- /dev/null +++ b/templates/CRM/Contribute/Page/DashBoard.js @@ -0,0 +1,49 @@ +// http://civicrm.org/licensing +cj(document).ready( function( ) { + getChart( ); + cj('#chart_view').click(function( ) { + if ( cj('#chart_view').hasClass('ui-state-default') ) { + cj('#chart_view').removeClass('ui-state-default').addClass('ui-state-active ui-tabs-selected'); + cj('#table_view').removeClass('ui-state-active ui-tabs-selected').addClass('ui-state-default'); + getChart( ); + cj('#tableData').children().html(''); + } + }); + cj('#table_view').click(function( ) { + if ( cj('#table_view').hasClass('ui-state-default') ) { + cj('#table_view').removeClass('ui-state-default').addClass('ui-state-active ui-tabs-selected'); + cj('#chart_view').removeClass('ui-state-active ui-tabs-selected').addClass('ui-state-default'); + buildTabularView(); + cj('#chartData').children().html(''); + } + }); +}); + +function getChart( ) { + var year = cj('#select_year').val( ); + var charttype = cj('#chart_type').val( ); + var date = new Date() + var currentYear = date.getFullYear( ); + if ( !charttype ) charttype = 'bvg'; + if ( !year ) year = currentYear; + + var chartUrl = CRM.url("civicrm/ajax/chart", {snippet : 4}); + chartUrl += "&year=" + year + "&type=" + charttype; + cj.ajax({ + url : chartUrl, + success : function(html){ + cj( "#chartData" ).html( html ); + } + }); + +} + +function buildTabularView( ) { + var tableUrl = CRM.url("civicrm/contribute/ajax/tableview", {showtable:1, snippet:4}); + cj.ajax({ + url : tableUrl, + success : function(html){ + cj( "#tableData" ).html( html ); + } + }); +} \ No newline at end of file diff --git a/templates/CRM/Contribute/Page/DashBoard.tpl b/templates/CRM/Contribute/Page/DashBoard.tpl index bdc202cbcb..93f46d754a 100644 --- a/templates/CRM/Contribute/Page/DashBoard.tpl +++ b/templates/CRM/Contribute/Page/DashBoard.tpl @@ -88,61 +88,5 @@
{include file="CRM/Contribute/Form/Selector.tpl" context="dashboard"}
-{/if}{literal} - -{/literal} - +{/if} {/if} \ No newline at end of file -- 2.25.1