From df683666b29196050b099e90b2fd882cf5eedf70 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 10 Sep 2013 10:31:11 +0200 Subject: [PATCH] Bug 7180: Adapt neworderempty code (js function moved). The js function fetchSortDropbox has been deleted in previous patch. The new function is getAuthValueDropbox. Test plan: - link some av to some funds - open an existing order and verify value are correctly filled in the sort1 and sort2 values - create a new order and verify behavior is the same as before Note: This patch generates 2 ajax queries (max) if the budget is linked to 2 av categories for sort1 and sort2. This could be improved using a template plugin for values display on load. Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall --- acqui/neworderempty.pl | 35 ++---------- .../prog/en/modules/acqui/neworderempty.tt | 59 ++++++++------------ 2 files changed, 28 insertions(+), 66 deletions(-) diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index 93794ea..0742a17 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -263,6 +263,8 @@ foreach my $r (@{$budgets}) { push @{$budget_loop}, { b_id => $r->{budget_id}, b_txt => $r->{budget_name}, + b_sort1_authcat => $r->{'sort1_authcat'}, + b_sort2_authcat => $r->{'sort2_authcat'}, b_active => $r->{budget_period_active}, b_sel => ( $r->{budget_id} == $budget_id ) ? 1 : 0, }; @@ -277,37 +279,8 @@ if ($close) { } -my $CGIsort1; -if ($budget) { # its a mod .. - if ( defined $budget->{'sort1_authcat'} ) { # with custom Asort* planning values - $CGIsort1 = GetAuthvalueDropbox( $budget->{'sort1_authcat'}, $data->{'sort1'} ); - } -} elsif(@{$budgets}){ - $CGIsort1 = GetAuthvalueDropbox( @$budgets[0]->{'sort1_authcat'}, '' ); -} - -# if CGIsort is successfully fetched, the use it -# else - failback to plain input-field -if ($CGIsort1) { - $template->param( CGIsort1 => $CGIsort1 ); -} else { - $template->param( sort1 => $data->{'sort1'} ); -} - -my $CGIsort2; -if ($budget) { - if ( defined $budget->{'sort2_authcat'} ) { - $CGIsort2 = GetAuthvalueDropbox( $budget->{'sort2_authcat'}, $data->{'sort2'} ); - } -} elsif(@{$budgets}) { - $CGIsort2 = GetAuthvalueDropbox( @$budgets[0]->{sort2_authcat}, '' ); -} - -if ($CGIsort2) { - $template->param( CGIsort2 => $CGIsort2 ); -} else { - $template->param( sort2 => $data->{'sort2'} ); -} +$template->param( sort1 => $data->{'sort1'} ); +$template->param( sort2 => $data->{'sort2'} ); if (C4::Context->preference('AcqCreateItem') eq 'ordering' && !$ordernumber) { # Check if ACQ framework exists diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt index e1d9ad5..7fa24c0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -142,6 +142,24 @@ $(document).ready(function() $('#budget_id .b_inactive').remove(); } }); + + $("#budget_id").change(function(){ + var destination_sort1 = $(this).parents('fieldset.rows').find('input[name="sort1"]'); + var sort1_authcat = $(this).find("option:selected").attr('data-sort1-authcat'); + var sort1 = $(destination_sort1).val() || ""; + if ( destination_sort1.length < 1 ) { + destination_sort1 = $(this).parents('fieldset.rows').find('select[name="sort1"]'); + } + var destination_sort2 = $(this).parents('fieldset.rows').find('input[name="sort2"]'); + var sort2_authcat = $(this).find("option:selected").attr('data-sort2-authcat'); + var sort2 = $(destination_sort2).val() || ""; + if ( destination_sort2.length < 1 ) { + destination_sort2 = $(this).parents('fieldset.rows').find('select[name="sort2"]'); + } + getAuthValueDropbox( 'sort1', sort1_authcat, destination_sort1, sort1 ); + getAuthValueDropbox( 'sort2', sort2_authcat, destination_sort2, sort2 ); + }); + $("#budget_id").change(); }); //]]> @@ -415,14 +433,14 @@ $(document).ready(function() [% Budget_name %] [% ELSE %] - [% FOREACH budget_loo IN budget_loop %] [% IF ( budget_loo.b_sel ) %] - + [% ELSE %] - [% IF ( budget_loo.b_active ) %] - [% ELSE %] + [% IF ( budget_loo.b_active ) %] + [% ELSE %] [% END %] [% END %] [% END %] @@ -545,39 +563,10 @@ $(document).ready(function()
  • The 2 following fields are available for your own usage. They can be useful for statistical purposes
    - - [% IF CGIsort1 %] - - [% ELSE %] - - [% END %] - -
  • +
  • - - [% IF CGIsort2 %] - - [% ELSE %] - - [% END %] - +
  • -- 1.7.10.4