Bugzilla – Attachment 31853 Details for
Bug 12987
Update table footer with the visible rows
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12987: Update table footer with the visible rows
Bug-12987-Update-table-footer-with-the-visible-row.patch (text/plain), 12.55 KB, created by
Jonathan Druart
on 2014-09-24 15:11:52 UTC
(
hide
)
Description:
Bug 12987: Update table footer with the visible rows
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2014-09-24 15:11:52 UTC
Size:
12.55 KB
patch
obsolete
>From ac3a2c095ec2df04113ec6d36583629745d34c16 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Wed, 24 Sep 2014 17:07:18 +0200 >Subject: [PATCH] Bug 12987: Update table footer with the visible rows > >This patch is the preparation step for others. > >On acqui/acqui-home.pl and admin/aqbudgets.pl, it will be possible to >see the totals in the footer updated with the filtered rows. > >Test plan: >This cannot be tested alone, you have to apply it with others (see the >"Blocked" bug reports). >--- > .../prog/en/includes/format_price.inc | 27 +++++++++++ > koha-tmpl/intranet-tmpl/prog/en/js/datatables.js | 32 +++++++++++++ > .../prog/en/modules/acqui/acqui-home.tt | 53 ++++++++++++++++------ > .../prog/en/modules/admin/aqbudgets.tt | 31 ++++++++----- > 4 files changed, 118 insertions(+), 25 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/format_price.inc > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/format_price.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/format_price.inc >new file mode 100644 >index 0000000..b0e5a8d >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/format_price.inc >@@ -0,0 +1,27 @@ >+[% USE Koha %] >+<script type="text/javascript"> >+ [%# This should use the Format template plugin, but not pushed yet %] >+ [% IF Koha.Preference("CurrencyFormat") == 'FR' %] >+ var default_value = { >+ thousands_sep: ' ', >+ decimal_point: ',', >+ decimal_digits: 2 >+ }; >+ [% ELSE %] >+ var default_value = { >+ thousands_sep: ',', >+ decimal_point: '.', >+ decimal_digits: 2 >+ }; >+ [% END %] >+ Number.prototype.format_price = function( value, params ) { >+ params = params == undefined ? {} : params; >+ var thousands_sep = params.thousands_sep == undefined ? default_value.thousands_sep : params.thousands_sep, >+ decimal_point = params.decimal_point == undefined ? default_value.decimal_point : params.decimal_point, >+ //symbol = params.symbol == undefined ? '$' : params.symbol, // Not implemented yet >+ decimal_digits = params.decimal_digits == undefined ? default_value.decimal_digits : params.decimal_digits; >+ >+ var re = '\\d(?=(\\d{' + 3 + '})+' + '\\D' + ')', value = this.toFixed(decimal_digits); >+ return value.replace('.', decimal_point).replace(new RegExp(re, 'g'), '$&' + thousands_sep); >+ } >+</script> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js >index 49ccb74..838f27e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js >+++ b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js >@@ -607,3 +607,35 @@ function parse_callnumber ( html ) { > return ""; > } > } >+ >+// see http://www.datatables.net/examples/advanced_init/footer_callback.html >+function footer_column_sum( api, column_numbers ) { >+ // Remove the formatting to get integer data for summation >+ var intVal = function ( i ) { >+ if ( typeof i === 'number' ) { >+ if ( isNaN(i) ) return 0; >+ return i; >+ } else if ( typeof i === 'string' ) { >+ var value = i.replace(/[a-zA-Z ,.]/g, '')*1; >+ if ( isNaN(value) ) return 0; >+ return value; >+ } >+ return 0; >+ }; >+ >+ >+ for ( var indice = 0 ; indice < column_numbers.length ; indice++ ) { >+ var column_number = column_numbers[indice]; >+ >+ var total = 0; >+ var cells = api.column( column_number, { page: 'current' } ).nodes().to$().find("span.total_amount"); >+ $(cells).each(function(){ >+ total += intVal( $(this).html() ); >+ }); >+ total /= 100; // Hard-coded decimal precision >+ >+ // Update footer >+ $( api.column( column_number ).footer() ).html(total.format_price()); >+ }; >+} >+ >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt >index 6c3b3eb..08b6f89 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt >@@ -13,11 +13,6 @@ dt_overwrite_html_sorting_localeCompare(); > > $(document).ready(function() { > >- var inactive = $(".b_inactive,.bu_active"); >- var active = $(".bu_inactive"); >- inactive.hide(); >- active.show(); >- > var oTable = $("#accounts").dataTable($.extend(true, {}, dataTablesDefaults, { > "fnDrawCallback": function ( oSettings ) { > if ( oSettings.aiDisplay.length == 0 ) >@@ -45,6 +40,10 @@ $(document).ready(function() { > } > } > }, >+ "footerCallback": function ( row, data, start, end, display ) { >+ var api = this.api(), data; >+ footer_column_sum( api, [ 6, 7, 8, 9 ] ); >+ }, > "aoColumnDefs": [ > { "bVisible": false, "aTargets": [ 0, 1 ] }, > { "bSortable": false, "aTargets": ["_all"] } >@@ -168,10 +167,10 @@ $(document).ready(function() { > <th></th> > <th></th> > <th colspan="4">Total</th> >- <th class="data"><span class="bu_active">[% total %]</span><span class="bu_inactive" >[% total_active %]</span></th> >- <th class="data"><span class="bu_active">[% totordered %]</span><span class="bu_inactive" >[% totordered_active %]</span></th> >- <th class="data"><span class="bu_active">[% totspent %]</span><span class="bu_inactive" >[% totspent_active %]</span></th> >- <th class="data"><span class="bu_active">[% totavail %]</span><span class="bu_inactive" >[% totavail_active %]</span></th> >+ <th class="data"></th> >+ <th class="data"></th> >+ <th class="data"></th> >+ <th class="data"></th> > </tr> > </tfoot> > <tbody> >@@ -199,10 +198,38 @@ $(document).ready(function() { > [% END %] > </td> > <td>[% loop_budge.budget_branchname %]</td> >- <td class="data"><span title="[% loop_budge.budget_amount %]">[% loop_budge.formatted_budget_amount %]</span></td> >- <td class="data"><span title="[% loop_budge.budget_ordered %]"><a href="ordered.pl?fund=[% loop_budge.budget_id %]&fund_code=[% loop_budge.budget_code %]">[% loop_budge.formatted_budget_ordered %]</a></span></td> >- <td class="data"><span title="[% loop_budge.budget_spent %]"><a href="spent.pl?fund=[% loop_budge.budget_id %]&fund_code=[% loop_budge.budget_code %]">[% loop_budge.formatted_budget_spent %]</span></a></td> >- <td class="data"><span title="[% loop_budge.budget_avail %]">[% loop_budge.formatted_budget_avail %]</td> >+ <td class="data"> >+ [% IF loop_budge.budget_parent_id %] >+ [% loop_budge.formatted_budget_amount %] >+ [% ELSE %] >+ <span class="total_amount">[% loop_budge.formatted_budget_amount %]</span> >+ [% END %] >+ </td> >+ <td class="data"> >+ <a href="ordered.pl?fund=[% loop_budge.budget_id %]&fund_code=[% loop_budge.budget_code %]"> >+ [% IF loop_budge.budget_parent_id %] >+ [% loop_budge.formatted_budget_ordered %] >+ [% ELSE %] >+ <span class="total_amount">[% loop_budge.formatted_budget_ordered %]</span> >+ [% END %] >+ </a> >+ </td> >+ <td class="data"> >+ <a href="spent.pl?fund=[% loop_budge.budget_id %]&fund_code=[% loop_budge.budget_code %]"> >+ [% IF loop_budge.budget_parent_id %] >+ [% loop_budge.formatted_budget_spent %] >+ [% ELSE %] >+ <span class="total_amount">[% loop_budge.formatted_budget_spent %]</span> >+ [% END %] >+ </a> >+ </td> >+ <td class="data"> >+ [% IF loop_budge.budget_parent_id %] >+ [% loop_budge.formatted_budget_avail %] >+ [% ELSE %] >+ <span class="total_amount">[% loop_budge.formatted_budget_avail %]</span> >+ [% END %] >+ </td> > </tr> > [% END %] > </tbody> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt >index b0c4344..50566a0 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt >@@ -152,6 +152,8 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") > //<![CDATA[ > // > $(document).ready(function() { >+ >+ > var oTable = $("#budgeth").dataTable($.extend(true, {}, dataTablesDefaults, { > "fnDrawCallback": function ( oSettings ) { > if ( oSettings.aiDisplay.length == 0 ) >@@ -179,6 +181,10 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") > } > } > }, >+ "footerCallback": function ( row, data, start, end, display ) { >+ var api = this.api(), data; >+ footer_column_sum( api, [ 4, 6, 8, 10 ], 2 ); >+ }, > "aoColumnDefs": [ > { "bVisible": false, "aTargets": [ 0, 1 ] }, > { "bSortable": false, "aTargets": ["_all"] } >@@ -213,6 +219,7 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") > }); > $("#hide_inactive").click(); > [% END %] >+ oTable.fnAddFilters("filter", 750); > > $("#filterbutton").click(function() { > $("#fundfilters").slideToggle(0); >@@ -295,13 +302,13 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") > <th></th> > <th></th> > <th colspan="2" style="text-align: left;" nowrap="nowrap">Period allocated [% IF ( budget_period_total ) %][% budget_period_total %][% END %] </th> >- <th nowrap="nowrap" class="data"> [% period_alloc_total %]</th> >+ <th class="data"></th> > <th></th> >- <th class="data">[% ordered_total %]</th> >+ <th class="data"></td> > <th></th> >- <th class="data">[% spent_total %]</th> >+ <th class="data"></th> > <th></th> >- <th class="data">[% available_total %]</th> >+ <th class="data"></th> > <th></th> > </tr> > </tfoot> >@@ -320,35 +327,35 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") > [% IF budget.budget_parent_id %] > <span class="child_fund_amount">[% budget.budget_amount %]</span> > [% ELSE %] >- [% budget.budget_amount %] >+ <span class="total_amount">[% budget.budget_amount %]</span> > [% END %] > </td> > <td class="data"> > [% IF budget.budget_parent_id %] > <span class="child_fund_amount">[% budget.budget_ordered %]</span> > [% ELSE %] >- [% budget.budget_ordered %] >+ <span class="total_amount">[% budget.budget_ordered %]</span> > [% END %] > </td> > <td class="data"> > [% IF budget.budget_parent_id %] > <span class="child_fund_amount">[% budget.total_ordered %]</span> > [% ELSE %] >- [% budget.total_ordered %] >+ <span class="total_amount">[% budget.total_ordered %]</span> > [% END %] > </td> > <td class="data"> > [% IF budget.budget_parent_id %] > <span class="child_fund_amount">[% budget.budget_spent %]</span> > [% ELSE %] >- [% budget.budget_spent %] >+ <span class="total_amount">[% budget.budget_spent %]</span> > [% END %] > </td> > <td class="data"> > [% IF budget.budget_parent_id %] > <span class="child_fund_amount">[% budget.total_spent %]</span> > [% ELSE %] >- [% budget.total_spent %] >+ <span class="total_amount">[% budget.total_spent %]</span> > [% END %] > </td> > >@@ -364,11 +371,11 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") > [% END %] > [% ELSE %] > [% IF (value > 0) %] >- <span style="color: green;"> >+ <span class="total_amount" style="color: green;"> > [% ELSIF (value < 0) %] >- <span style="color: red;"> >+ <span class="total_amount" style="color: red;"> > [% ELSE %] >- <span> >+ <span class="totalamount"> > [% END %] > [% END %] > [% text %] >-- >2.1.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 12987
:
31853
|
31854
|
31976
|
32019
|
32094
|
32095
|
32812
|
32813
|
32814
|
32815