From: Coleman Watts Date: Tue, 25 Jun 2013 01:39:58 +0000 (-0700) Subject: CRM-12887 simplify markup and js X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=870891652a88f2b0a2084195d60217c0677deac5;p=civicrm-core.git CRM-12887 simplify markup and js ---------------------------------------- * CRM-12887: Js tidy-up on Contribution dashboard http://issues.civicrm.org/jira/browse/CRM-12887 --- diff --git a/templates/CRM/Contribute/Page/DashBoard.js b/templates/CRM/Contribute/Page/DashBoard.js index 2564089198..120c700c69 100644 --- a/templates/CRM/Contribute/Page/DashBoard.js +++ b/templates/CRM/Contribute/Page/DashBoard.js @@ -4,36 +4,28 @@ cj(function ($) { 'use strict'; - function getChart() { - var chartUrl = CRM.url("civicrm/ajax/chart", { - 'snippet': 4, - 'year': $('#select_year').val() || new Date().getFullYear(), - 'type': $('#chart_type').val() || 'bvg' - }); - $("#chartData").load(chartUrl, function() { - $("select", "#chartData").change(getChart); - }); - } - - function buildTabularView() { - var tableUrl = CRM.url("civicrm/contribute/ajax/tableview", {showtable: 1, snippet: 4}); - $("#tableData").load(tableUrl); - } - - $('#chart_view').click(function() { - if ($('#chart_view').hasClass('ui-state-default')) { - $('#chart_view').removeClass('ui-state-default').addClass('ui-state-active ui-tabs-selected'); - $('#table_view').removeClass('ui-state-active ui-tabs-selected').addClass('ui-state-default'); - getChart(); - $('#tableData').children().html(''); + var load = { + chart_view: function() { + var chartUrl = CRM.url("civicrm/ajax/chart", { + 'snippet': 4, + 'year': $('#select_year').val() || new Date().getFullYear(), + 'type': $('#chart_type').val() || 'bvg' + }); + $("#chartData").load(chartUrl, function() { + $("select", "#chartData").change(load.chart_view); + }); + }, + table_view: function() { + var tableUrl = CRM.url("civicrm/contribute/ajax/tableview", {showtable: 1, snippet: 4}); + $("#chartData").load(tableUrl); } - }); - $('#table_view').click(function() { - if ($('#table_view').hasClass('ui-state-default')) { - $('#table_view').removeClass('ui-state-default').addClass('ui-state-active ui-tabs-selected'); - $('#chart_view').removeClass('ui-state-active ui-tabs-selected').addClass('ui-state-default'); - buildTabularView(); - $('#chartData').children().html(''); + }; + + $('#chart_view, #table_view').click(function() { + if ($(this).hasClass('ui-state-default')) { + $('.ui-tabs-selected', '#mainTabContainer').removeClass('ui-state-active ui-tabs-selected').addClass('ui-state-default'); + $(this).removeClass('ui-state-default').addClass('ui-state-active ui-tabs-selected'); + load[this.id](); } }); @@ -42,7 +34,7 @@ cj(function ($) { $('#table_view').click(); } else { - getChart(); + load.chart_view(); } }); diff --git a/templates/CRM/Contribute/Page/DashBoard.tpl b/templates/CRM/Contribute/Page/DashBoard.tpl index 93f46d754a..ff9eb4cef1 100644 --- a/templates/CRM/Contribute/Page/DashBoard.tpl +++ b/templates/CRM/Contribute/Page/DashBoard.tpl @@ -80,7 +80,7 @@ {/if}
-
+
{if $pager->_totalItems}