Bug 8629: update of statistics fields on fund selection in order creation/edition

Signed-off-by: Marc Veron <veron@veron.ch>

Followed test plan in comment #1
Behaves as described in the test plan.
Useful feature!

Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
This commit is contained in:
Fridolyn SOMERS 2012-08-13 13:55:11 +02:00 committed by Paul Poulain
parent 8f1400c8cc
commit d09b2ecb52
6 changed files with 62 additions and 49 deletions

View File

@ -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 {

View File

@ -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 $ret_html;
my $name = 'sort'.$sort_nb;
my $authcat_field = 'sort'.$sort_nb.'_authcat';
my $budget = GetBudget($budget_id);
my $dropbox_values = GetAuthvalueDropbox( $budget->{'sort'.$sort_id.'_authcat'}, '' );
my @authorised_values;
my %authorised_lib;
if ( $budget && $budget->{$authcat_field} ) {
# with custom Asort* planning values
my $dropbox_values = GetAuthvalueDropbox( $budget->{$authcat_field}, '' );
foreach ( @$dropbox_values) {
push @authorised_values, $_->{value};
$authorised_lib{$_->{value}} = $_->{label};
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'};
}
$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 = '<input type="text" size="20" name="'.$name.'" id="'.$name.'" />';
}
my $budget_authvalue_dropbox = CGI::scrolling_list(
-values => \@authorised_values,
-labels => \%authorised_lib,
-default => $authorised_values[0],
);
# strip off select tags
$budget_authvalue_dropbox =~ s/^\<select.*?\"\>//;
$budget_authvalue_dropbox =~ s/\<\/select\>$//;
chomp $budget_authvalue_dropbox;
$template->param( return => $budget_authvalue_dropbox );
$template->param( 'return' => $ret_html );
output_html_with_http_headers $input, $cookie, $template->output;

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -188,7 +188,7 @@
</li>
<li><div class="hint">The 2 following fields are available for your own usage. They can be useful for statistical purposes</div>
<label for="sort1">Planning value1: </label>
<span id="sort1_zone">
[% IF CGIsort1 %]
<select id="sort1" size="1" name="sort1">
[% FOREACH sort_opt IN CGIsort1 %]
@ -202,23 +202,25 @@
[% ELSE %]
<input type="text" id="sort1" size="20" name="sort1" value="[% sort1 %]" />
[% END %]
</span>
</li>
<li>
<label for="sort2">Planning value2: </label>
[% IF CGIsort2 %]
<select id="sort2" size="1" name="sort1">
[% FOREACH sort_opt IN CGIsort2 %]
[% IF sort_opt.default %]
<option value="[% sort_opt.id %]" selected="selected">[% sort_opt.label %]</option>
[% ELSE %]
<option value="[% sort_opt.id %]">[% sort_opt.label %]</option>
<span id="sort2_zone">
[% IF CGIsort2 %]
<select id="sort2" size="1" name="sort1">
[% FOREACH sort_opt IN CGIsort2 %]
[% IF sort_opt.default %]
<option value="[% sort_opt.id %]" selected="selected">[% sort_opt.label %]</option>
[% ELSE %]
<option value="[% sort_opt.id %]">[% sort_opt.label %]</option>
[% END %]
[% END %]
</select>
[% ELSE %]
<input type="text" id="sort2" size="20" name="sort2" value="[% sort2 %]" />
[% END %]
</select>
[% ELSE %]
<input type="text" id="sort2" size="20" name="sort2" value="[% sort2 %]" />
[% END %]
</span>
</li>
<li>

View File

@ -508,7 +508,7 @@ $(document).ready(function()
</li>
<li><div class="hint">The 2 following fields are available for your own usage. They can be useful for statistical purposes</div>
<label for="sort1">Statistic 1: </label>
<span id="sort1_zone">
[% IF CGIsort1 %]
<select id="sort1" size="1" name="sort1">
[% FOREACH sort_opt IN CGIsort1 %]
@ -520,13 +520,13 @@ $(document).ready(function()
[% END %]
</select>
[% ELSE %]
<input type="text" id="sort1" size="20" name="sort1" value="[% sort1 %]" />
[% END %]
</span>
</li>
<li>
<label for="sort2">Statistic 2: </label>
<span id="sort2_zone">
[% IF CGIsort2 %]
<select id="sort2" size="1" name="sort2">
[% FOREACH sort_opt IN CGIsort2 %]
@ -540,6 +540,7 @@ $(document).ready(function()
[% ELSE %]
<input type="text" id="sort2" size="20" name="sort2" value="[% sort2 %]" />
[% END %]
</span>
</li>
</ol>
</fieldset>