CRM-12887 intial restructure into js file
[civicrm-core.git] / templates / CRM / Contribute / Page / DashBoard.js
1 // http://civicrm.org/licensing
2 cj(document).ready( function( ) {
3 getChart( );
4 cj('#chart_view').click(function( ) {
5 if ( cj('#chart_view').hasClass('ui-state-default') ) {
6 cj('#chart_view').removeClass('ui-state-default').addClass('ui-state-active ui-tabs-selected');
7 cj('#table_view').removeClass('ui-state-active ui-tabs-selected').addClass('ui-state-default');
8 getChart( );
9 cj('#tableData').children().html('');
10 }
11 });
12 cj('#table_view').click(function( ) {
13 if ( cj('#table_view').hasClass('ui-state-default') ) {
14 cj('#table_view').removeClass('ui-state-default').addClass('ui-state-active ui-tabs-selected');
15 cj('#chart_view').removeClass('ui-state-active ui-tabs-selected').addClass('ui-state-default');
16 buildTabularView();
17 cj('#chartData').children().html('');
18 }
19 });
20 });
21
22 function getChart( ) {
23 var year = cj('#select_year').val( );
24 var charttype = cj('#chart_type').val( );
25 var date = new Date()
26 var currentYear = date.getFullYear( );
27 if ( !charttype ) charttype = 'bvg';
28 if ( !year ) year = currentYear;
29
30 var chartUrl = CRM.url("civicrm/ajax/chart", {snippet : 4});
31 chartUrl += "&year=" + year + "&type=" + charttype;
32 cj.ajax({
33 url : chartUrl,
34 success : function(html){
35 cj( "#chartData" ).html( html );
36 }
37 });
38
39 }
40
41 function buildTabularView( ) {
42 var tableUrl = CRM.url("civicrm/contribute/ajax/tableview", {showtable:1, snippet:4});
43 cj.ajax({
44 url : tableUrl,
45 success : function(html){
46 cj( "#tableData" ).html( html );
47 }
48 });
49 }