From d09b2ecb52f719951b0efb6b7a66c9817ef54baf Mon Sep 17 00:00:00 2001 From: Fridolyn SOMERS Date: Mon, 13 Aug 2012 13:55:11 +0200 Subject: [PATCH] Bug 8629: update of statistics fields on fund selection in order creation/edition Signed-off-by: Marc Veron Followed test plan in comment #1 Behaves as described in the test plan. Useful feature! Signed-off-by: Paul Poulain --- acqui/addorderiso2709.pl | 6 --- acqui/fetch_sort_dropbox.pl | 54 ++++++++++++------- acqui/neworderempty.pl | 4 -- koha-tmpl/intranet-tmpl/prog/en/js/acq.js | 10 +++- .../prog/en/modules/acqui/addorderiso2709.tt | 28 +++++----- .../prog/en/modules/acqui/neworderempty.tt | 7 +-- 6 files changed, 61 insertions(+), 48 deletions(-) diff --git a/acqui/addorderiso2709.pl b/acqui/addorderiso2709.pl index 002fbf519a..b1b49106bb 100755 --- a/acqui/addorderiso2709.pl +++ b/acqui/addorderiso2709.pl @@ -298,10 +298,7 @@ if ($budget) { # its a mod .. } } elsif ( scalar(@$budgets) ) { $CGIsort1 = GetAuthvalueDropbox( @$budgets[0]->{'sort1_authcat'}, '' ); -} else { - $CGIsort1 = GetAuthvalueDropbox( '', '' ); } - # if CGIsort is successfully fetched, the use it # else - failback to plain input-field if ($CGIsort1) { @@ -317,10 +314,7 @@ if ($budget) { } } elsif ( scalar(@$budgets) ) { $CGIsort2 = GetAuthvalueDropbox( @$budgets[0]->{sort2_authcat}, '' ); -} else { - $CGIsort2 = GetAuthvalueDropbox( '', '' ); } - if ($CGIsort2) { $template->param( CGIsort2 => $CGIsort2 ); } else { diff --git a/acqui/fetch_sort_dropbox.pl b/acqui/fetch_sort_dropbox.pl index 2dfeb81f2a..ce47fb7926 100755 --- a/acqui/fetch_sort_dropbox.pl +++ b/acqui/fetch_sort_dropbox.pl @@ -54,40 +54,54 @@ Sort number. 1 or 2 for the moment. my $input = new CGI; my $budget_id = $input->param('budget_id'); -my $sort_id = $input->param('sort'); +my $sort_nb = $input->param('sort'); +die "sort parameter can only be 1 or 2" unless ($sort_nb == 1 || $sort_nb == 2); my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "acqui/ajax.tmpl", query => $input, type => "intranet", authnotrequired => 0, - flagsrequired => {editcatalogue => 'edit_catalogue'}, + flagsrequired => {acquisition => 'order_manage'}, debug => 0, } ); -my $budget = GetBudget($budget_id); -my $dropbox_values = GetAuthvalueDropbox( $budget->{'sort'.$sort_id.'_authcat'}, '' ); +my $ret_html; +my $name = 'sort'.$sort_nb; +my $authcat_field = 'sort'.$sort_nb.'_authcat'; -my @authorised_values; -my %authorised_lib; +my $budget = GetBudget($budget_id); -foreach ( @$dropbox_values) { - push @authorised_values, $_->{value}; - $authorised_lib{$_->{value}} = $_->{label}; -} +if ( $budget && $budget->{$authcat_field} ) { + # with custom Asort* planning values + my $dropbox_values = GetAuthvalueDropbox( $budget->{$authcat_field}, '' ); -my $budget_authvalue_dropbox = CGI::scrolling_list( - -values => \@authorised_values, - -labels => \%authorised_lib, - -default => $authorised_values[0], -); + my @authorised_values; + my %authorised_lib; + my $default_value; + foreach ( @$dropbox_values) { + push @authorised_values, $_->{value}; + $authorised_lib{$_->{value}} = $_->{label}; + $default_value = $_->{value} if $_->{'default'}; + } -# strip off select tags -$budget_authvalue_dropbox =~ s/^\//; -$budget_authvalue_dropbox =~ s/\<\/select\>$//; -chomp $budget_authvalue_dropbox; + $ret_html = CGI::scrolling_list( + -values => \@authorised_values, + -labels => \%authorised_lib, + -default => $default_value, + -override => 1, + -size => 1, + -multiple => 0, + -name => $name, + -id => $name, + ); + +} else { + # free input + $ret_html = ''; +} -$template->param( return => $budget_authvalue_dropbox ); +$template->param( 'return' => $ret_html ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index a461a1bbba..4a3eb49ce6 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -281,8 +281,6 @@ if ($budget) { # its a mod .. } } elsif(@{$budgets}){ $CGIsort1 = GetAuthvalueDropbox( @$budgets[0]->{'sort1_authcat'}, '' ); -}else{ - $CGIsort1 = GetAuthvalueDropbox( '', '' ); } # if CGIsort is successfully fetched, the use it @@ -300,8 +298,6 @@ if ($budget) { } } elsif(@{$budgets}) { $CGIsort2 = GetAuthvalueDropbox( @$budgets[0]->{sort2_authcat}, '' ); -}else{ - $CGIsort2 = GetAuthvalueDropbox( '', '' ); } if ($CGIsort2) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js index 2efeba0e92..028dae437d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/acq.js @@ -744,7 +744,7 @@ function fetchSortDropbox(f) { for (i=1;i<=2;i++) { - var sort_dropbox = document.getElementById('sort'+i); + var sort_zone = document.getElementById('sort'+i+'_zone'); var url = '../acqui/fetch_sort_dropbox.pl?sort='+i+'&budget_id='+budgetId; var xmlhttp = null; @@ -764,7 +764,13 @@ for (i=1;i<=2;i++) { } }; // rc = eval ( xmlhttp.responseText ); - sort_dropbox.innerHTML = xmlhttp.responseText; + var retRootType = xmlhttp.responseXML.firstChild.nodeName; + var existingInputs = sort_zone.getElementsByTagName('input'); + if (existingInputs.length > 0 && retRootType == 'input') { + // when sort is already an input, do not override to preseve value + return; + } + sort_zone.innerHTML = xmlhttp.responseText; } } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt index 7a7e72a574..71ae462622 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt @@ -188,7 +188,7 @@
  • The 2 following fields are available for your own usage. They can be useful for statistical purposes
    - + [% IF CGIsort1 %] [% END %] +
  • - - [% IF CGIsort2 %] - + [% FOREACH sort_opt IN CGIsort2 %] + [% IF sort_opt.default %] + + [% ELSE %] + + [% END %] [% END %] + + [% ELSE %] + [% END %] - - [% ELSE %] - - [% END %] +
  • 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 566318fa9b..0195dd8928 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -508,7 +508,7 @@ $(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 %] [% END %] +
  • -- 2.39.5