Bug 9457: [ENH] Ordering branches should be case independent (2)

This patch replace use of CGI::scroll_list() to show list of branches.

In two files, marc21_linking_section.pl and unimarc_field_4XX.pl,
the scrolling list is created but not used in the template file,
so the code is removed.

Also minor renaming/normalizing of variables.

To test:
1) Install with some branches, records and patrons

2.1) Select a record, click 'Place hold', select user,
     there is a library pull-down next to 'Pickup at:',
     list is ordered case sensitive
2.2) Go to Reports > Average loan time,
     next to Library is a pull-down,
     list without order
2.3) Go to Reports > Catalog by item type,
     next to 'Select a library' is a pull-down,
     list is ordered case sensitive
2.4) This is tricky, go to Reports home,
     change last part of URL 'reports-home.pl' with
     'manager.pl?report_name=issues_by_borrower_category'
     (can't find a direct link), next to 'Select a library'
     is a library pull-down,
     list without order
2.5) Edit/Add a patron, on section 'Library management'
     there is a library pull-down, case sensitive
2.6) OPAC, as logged user, make a suggestion or hold,
     there is library pull-down, correct order

3) Apply the patch

4.1) Repeat 2.1), correctly ordered list
4.2) Repeat 2.2), correctly ordered list
4.3) Repeat 2.3), correctly ordered list
4.4) Repeat 2.4), correctly ordered list
4.5) This is a bit more work
     There are 3 possible situations to test:
     A) No branches, must show a message that are no
        libraries defined
     B) New patron, must show a correctly ordered
        list of branches, current branch selected
     C) Edit patron, must show a correctly ordered
        list of branches, patron branch selected
4.6) Small changes on variable names, so retest 2.6)

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
This commit is contained in:
Bernardo Gonzalez Kriegel 2013-01-23 11:44:41 -03:00 committed by Jared Camins-Esakov
parent 8abc43db63
commit 2d9f5fc69e
16 changed files with 144 additions and 214 deletions

View File

@ -356,25 +356,7 @@ sub plugin {
);
$sth->finish;
my @branchloop;
my @select_branch;
my %select_branches;
my $branches = GetBranches;
push @select_branch, "";
$select_branches{''} = "";
foreach my $thisbranch ( keys %$branches ) {
push @select_branch, $branches->{$thisbranch}->{'branchcode'};
$select_branches{ $branches->{$thisbranch}->{'branchcode'} } =
$branches->{$thisbranch}->{'branchname'};
}
my $CGIbranch = CGI::scrolling_list(
-name => 'value',
-values => \@select_branch,
-labels => \%select_branches,
-size => 1,
-multiple => 0
);
$sth->finish;
# To show list of branches please use GetBranchesLoop() and modify template
my $req = $dbh->prepare(
"select distinctrow left(publishercode,45) from biblioitems order by publishercode"
@ -404,7 +386,6 @@ sub plugin {
$template->param( #classlist => $classlist,
CGIitemtype => $CGIitemtype,
CGIbranch => $CGIbranch,
CGIPublisher => $CGIpublisher,
itypeloop => \@itemtypes,
index => $query->param('index'),

View File

@ -511,25 +511,7 @@ sub plugin {
);
$sth->finish;
my @branchloop;
my @select_branch;
my %select_branches;
my $branches = GetBranches;
push @select_branch, "";
$select_branches{''} = "";
foreach my $thisbranch ( keys %$branches ) {
push @select_branch, $branches->{$thisbranch}->{'branchcode'};
$select_branches{ $branches->{$thisbranch}->{'branchcode'} } =
$branches->{$thisbranch}->{'branchname'};
}
my $CGIbranch = CGI::scrolling_list(
-name => 'value',
-values => \@select_branch,
-labels => \%select_branches,
-size => 1,
-multiple => 0
);
$sth->finish;
# To show list of branches please use GetBranchesLoop() and modify template
my $req =
$dbh->prepare(
@ -560,7 +542,6 @@ sub plugin {
$template->param( #classlist => $classlist,
CGIitemtype => $CGIitemtype,
CGIbranch => $CGIbranch,
CGIPublisher => $CGIpublisher,
itypeloop => \@itemtypes,
index => $query->param('index'),

View File

@ -988,14 +988,25 @@
[% END %]
[% UNLESS nobranchcode %]
<li>
[% IF ( mandatorybranchcode ) %]
[%- IF ( mandatorybranchcode ) -%]
<label for="branchcode" class="required">
[% ELSE %]
[%- ELSE -%]
<label for="branchcode">
[% END %]
Library: </label>
[% CGIbranch %]
[% IF ( mandatorybranchcode ) %]<span class="required">Required</span>[% END %]
[%- END -%]
Library:</label>
<select name="branchcode" size="1" id="branchcode">
<option value=""></option>
[%- FOREACH branchloo IN branchloop %]
[% IF ( branchloo.selected ) -%]
<option value="[% branchloo.branchcode %]" selected="selected">[% branchloo.branchname %]</option>
[%- ELSE -%]
<option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option>
[%- END -%]
[%- END %]
</select>
[% IF ( mandatorybranchcode ) -%]
<span class="required">Required</span>
[%- END %]
</li>
[% END %]
<li>

View File

@ -164,7 +164,13 @@
<td>Library</td>
<td><input type="radio" name="Line" value="branchcode" /></td>
<td><input type="radio" name="Column" value="branchcode" /></td>
<td>[% CGIBranch %]</td>
<td><select name="Filter" size="1" id="branch">
<option value=""></option>
[%- FOREACH branchloo IN branchloop %]
<option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
[%- END %]
</select>
</td>
</tr>
<!-- Modified according to statistics table
<tr>

View File

@ -51,19 +51,35 @@
</table>
[% END %]
[% ELSE %]
<form method="post" action="/cgi-bin/koha/reports/manager.pl">
<fieldset class="rows">
<legend>Checkouts by patron category</legend>
<ol><li><label for="borrowercategory">Select a borrower category</label><select name="value" id="borrowercategory"><option value="" > Any Category code</option>
[% FOREACH loopcategorie IN loopcategories %]
<option value="[% loopcategorie.value %]" >[% loopcategorie.description %] </option>
[% END %]
</select></li>
<li><label for="branch">Select a library:</label> [% CGIbranch %]</li></ol></fieldset>
<fieldset class="action"><input type="submit" value="Submit" />
<input type="hidden" name="report_name" value="[% report_name %]" />
<input type="hidden" name="do_it" value="1" /></fieldset>
</form>
<form method="post" action="/cgi-bin/koha/reports/manager.pl">
<fieldset class="rows">
<legend>Checkouts by patron category</legend>
<ol>
<li>
<label for="borrowercategory">Select a borrower category</label>
<select name="value" id="borrowercategory">
<option value="">Any Category code</option>
[%- FOREACH loopcategorie IN loopcategories %]
<option value="[% loopcategorie.value %]" >[% loopcategorie.description %]</option>
[%- END %]
</select>
</li>
<li>
<label for="branch">Select a library:</label>
<select name="value" size="1" id="branch">
<option value=""></option>
[%- FOREACH branchloo IN branchloop %]
<option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option>
[%- END %]
</select>
</li>
</ol>
</fieldset>
<fieldset class="action"><input type="submit" value="Submit" />
<input type="hidden" name="report_name" value="[% report_name %]" />
<input type="hidden" name="do_it" value="1" />
</fieldset>
</form>
[% END %]
</div>

View File

@ -57,14 +57,31 @@ $(document).ready(function(){
</table>
[% END %]
[% ELSE %]
<h3>View a count of items held at your library grouped by item type</h3>
<form method="post" action="/cgi-bin/koha/reports/manager.pl?report_name=itemtypes">
<fieldset class="rows"><ol><li><label for="value">Select a library</label> [% CGIbranch %]
<span class="tip">Select none to see all libraries</span></li></ol></fieldset>
<fieldset class="action"><input type="submit" value="Submit" />
<input type="hidden" name="report_name" value="[% report_name %]" />
<input type="hidden" name="do_it" value="1" /></fieldset>
</form>
<h3>View a count of items held at your library grouped by item type</h3>
<form method="post" action="/cgi-bin/koha/reports/manager.pl?report_name=itemtypes">
<fieldset class="rows">
<ol>
<li>
<label for="value">Select a library</label>
<select name="value" size="1" id="value">
<option value=""></option>
[%- FOREACH branchloo IN branchloop %]
[% IF ( branchloo.selected ) -%]
<option value="[% branchloo.branchcode %]" selected="selected">[% branchloo.branchname %]</option>
[%- ELSE -%]
<option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option>
[%- END -%]
[%- END %]
</select>
<span class="tip">Select none to see all libraries</span>
</li>
</ol>
</fieldset>
<fieldset class="action"><input type="submit" value="Submit" />
<input type="hidden" name="report_name" value="[% report_name %]" />
<input type="hidden" name="do_it" value="1" />
</fieldset>
</form>
[% END %]
</div>

View File

@ -286,7 +286,15 @@ function checkMultiHold() {
</li>
<li>
<label for="pickup">Pickup at:</label>
[% CGIbranch %]
<select name="pickup" size="1" id="pickup">
[%- FOREACH branchloo IN branchloop %]
[% IF ( branchloo.selected ) -%]
<option value="[% branchloo.branchcode %]" selected="selected">[% branchloo.branchname %]</option>
[%- ELSE -%]
<option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option>
[%- END -%]
[%- END %]
</select>
</li>
[% IF ( reserve_in_future ) %]
@ -620,9 +628,9 @@ function checkMultiHold() {
<select name="pickup">
[% FOREACH branchloo IN reserveloo.branchloop %]
[% IF ( branchloo.selected ) %]
<option value="[% branchloo.value %]" selected="selected">
<option value="[% branchloo.branchcode %]" selected="selected">
[% ELSE %]
<option value="[% branchloo.value %]">
<option value="[% branchloo.branchcode %]">
[% END %]
[% branchloo.branchname %]
</option>

View File

@ -390,21 +390,21 @@
<td class="branch">
[% UNLESS ( bibitemloo.holdable ) %]
<select name="branch" id="branch_[% bibitemloo.biblionumber %]" disabled="disabled">
[% FOREACH branchChoicesLoo IN bibitemloo.branchChoicesLoop %]
[% IF ( branchChoicesLoo.selected ) %]
<option value="[% branchChoicesLoo.value %]" selected="selected">[% branchChoicesLoo.branchname %]</option>
[% FOREACH branchloo IN bibitemloo.branchloop %]
[% IF ( branchloo.selected ) %]
<option value="[% branchloo.branchcode %]" selected="selected">[% branchloo.branchname %]</option>
[% ELSE %]
<option value="[% branchChoicesLoo.value %]">[% branchChoicesLoo.branchname %]</option>
<option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option>
[% END %]
[% END %]
</select>
[% ELSE %]
<select name="branch" id="branch_[% bibitemloo.biblionumber %]">
[% FOREACH branchChoicesLoo IN bibitemloo.branchChoicesLoop %]
[% IF ( branchChoicesLoo.selected ) %]
<option value="[% branchChoicesLoo.value %]" selected="selected">[% branchChoicesLoo.branchname %]</option>
[% FOREACH branchloo IN bibitemloo.branchloop %]
[% IF ( branchloo.selected ) %]
<option value="[% branchloo.branchcode %]" selected="selected">[% branchloo.branchname %]</option>
[% ELSE %]
<option value="[% branchChoicesLoo.value %]">[% branchChoicesLoo.branchname %]</option>
<option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option>
[% END %]
[% END %]
</select>

View File

@ -116,14 +116,14 @@ $.tablesorter.addParser({
[% IF ( itemtypeloo.selected ) %]<option value="[% itemtypeloo.itemtype %]" selected="selected"> [% ELSE %]<option value="[% itemtypeloo.itemtype %]"> [% END %] [% itemtypeloo.description %]</option>
[% END %]
</select> </li>
[% IF ( branch_loop ) %]
[% IF ( branchloop ) %]
<li><label for="branch">Library:</label>
<select name="branch" id="branch">
[% FOREACH branch_loo IN branch_loop %]
[% IF ( branch_loo.selected ) %]
<option value="[% branch_loo.value %]" selected="selected">[% branch_loo.branchname %]</option>
[% FOREACH branchloo IN branchloop %]
[% IF ( branchloo.selected ) %]
<option value="[% branchloo.branchcode %]" selected="selected">[% branchloo.branchname %]</option>
[% ELSE %]
<option value="[% branch_loo.value %]">[% branch_loo.branchname %]</option>
<option value="[% branchloo.branchcode %]">[% branchloo.branchname %]</option>
[% END %]
[% END %]
</select>

View File

@ -568,43 +568,18 @@ foreach (keys(%flags)) {
push @flagdata,\%row;
}
#get Branches
my @branches;
my @select_branch;
my %select_branches;
# get Branch Loop
# in modify mod: userbranch value for GetBranchesLoop() comes from borrowers table
# in add mod: userbranch value come from branches table (ip correspondence)
my $onlymine=(C4::Context->preference('IndependantBranches') &&
C4::Context->userenv &&
C4::Context->userenv->{flags} % 2 !=1 &&
C4::Context->userenv->{branch}?1:0);
my $branches=GetBranches($onlymine);
my $default;
my $CGIbranch;
for my $branch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
push @select_branch,$branch;
$select_branches{$branch} = $branches->{$branch}->{'branchname'};
$default = C4::Context->userenv->{'branch'} if (C4::Context->userenv && C4::Context->userenv->{'branch'});
}
if(scalar(@select_branch) > 0){
# --------------------------------------------------------------------------------------------------------
#in modify mod :default value from $CGIbranch comes from borrowers table
#in add mod: default value come from branches table (ip correspendence)
my $userbranch = C4::Context->userenv->{'branch'};
if (defined ($data{'branchcode'}) and ( $op eq 'modify' || ( $op eq 'add' && $category_type eq 'C' ) )) {
$default = $data{'branchcode'};
}
$CGIbranch = CGI::scrolling_list(-id => 'branchcode',
-name => 'branchcode',
-values => \@select_branch,
-labels => \%select_branches,
-size => 1,
-override => 1,
-multiple =>0,
-default => $default,
);
$userbranch = $data{'branchcode'};
}
if(!$CGIbranch){
my $branchloop = GetBranchesLoop( $userbranch );
if( !$branchloop ){
$no_add = 1;
$template->param(no_branches => 1);
}
@ -709,7 +684,7 @@ $template->param(
check_member => $check_member,#to know if the borrower already exist(=>1) or not (=>0)
"op$op" => 1);
$template->param(CGIbranch=>$CGIbranch) if ($CGIbranch);
$template->param( branchloop => $branchloop ) if ( $branchloop );
$template->param(
nodouble => $nodouble,
borrowernumber => $borrowernumber, #register number

View File

@ -108,8 +108,7 @@ my $branch = $query->param('branch') || $borr->{'branchcode'} || C4::Context->us
$template->param( branch => $branch );
# make branch selection options...
my $CGIbranchloop = GetBranchesLoop($branch);
$template->param( CGIbranch => $CGIbranchloop );
my $branchloop = GetBranchesLoop($branch);
# Is the person allowed to choose their branch
my $OPACChooseBranch = (C4::Context->preference("OPACAllowUserToChooseBranch")) ? 1 : 0;
@ -358,7 +357,7 @@ foreach my $biblioNum (@biblionumbers) {
my $record = GetMarcBiblio($biblioNum);
# Init the bib item with the choices for branch pickup
my %biblioLoopIter = ( branchChoicesLoop => $CGIbranchloop );
my %biblioLoopIter = ( branchloop => $branchloop );
# Get relevant biblio data.
my $biblioData = $biblioDataHash{$biblioNum};

View File

@ -131,8 +131,8 @@ if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) {
my $branch = $input->param('branch') || $borr->{'branchcode'} || C4::Context->userenv->{branch} || '' ;
# make branch selection options...
my $CGIbranchloop = GetBranchesLoop($branch);
$template->param( branch_loop => $CGIbranchloop );
my $branchloop = GetBranchesLoop($branch);
$template->param( branchloop => $branchloop );
}
$template->param(

View File

@ -160,21 +160,6 @@ if ($do_it) {
$hassort1 =1 if ($value);
push @select, $value;
}
my $branches=GetBranches();
my @select_branch;
my %select_branches;
push @select_branch,"";
$select_branches{""} = "";
foreach my $branch (keys %$branches) {
push @select_branch, $branch;
$select_branches{$branch} = $branches->{$branch}->{'branchname'};
}
my $CGIBranch=CGI::scrolling_list( -name => 'Filter',
-id => 'branch',
-values => \@select_branch,
-labels => \%select_branches,
-size => 1,
-multiple => 0 );
my $CGISort1=CGI::scrolling_list( -name => 'Filter',
-id => 'sort1',
@ -209,14 +194,14 @@ if ($do_it) {
my $CGIsepChoice=GetDelimiterChoices;
$template->param(
CGIBorCat => $CGIBorCat,
CGIItemType => $CGIItemTypes,
CGIBranch => $CGIBranch,
hassort1=> $hassort1,
hassort2=> $hassort2,
HlghtSort2 => $hglghtsort2,
CGISort1 => $CGISort1,
CGISort2 => $CGISort2,
CGIBorCat => $CGIBorCat,
CGIItemType => $CGIItemTypes,
branchloop => GetBranchesLoop(),
hassort1 => $hassort1,
hassort2 => $hassort2,
HlghtSort2 => $hglghtsort2,
CGISort1 => $CGISort1,
CGISort2 => $CGISort2,
CGIextChoice => $CGIextChoice,
CGIsepChoice => $CGIsepChoice
);

View File

@ -62,36 +62,22 @@ the hashes are then translated to hash / arrays to be returned to manager.pl & s
=cut
sub set_parameters {
my ($template) = @_;
my $dbh = C4::Context->dbh;
my $branches=GetBranches();
my @branches;
my @select_branch;
my %select_branches;
push @select_branch,"";
$select_branches{""} = "";
foreach my $branch (keys %$branches) {
push @select_branch, $branch;
$select_branches{$branch} = $branches->{$branch}->{'branchname'};
}
my $CGIbranch=CGI::scrolling_list( -name => 'value',
-id => 'branch',
-values => \@select_branch,
-labels => \%select_branches,
-size => 1,
-multiple => 0 );
$template->param(CGIbranch => $CGIbranch);
my ($template) = @_;
$template->param( branchloop => GetBranchesLoop() );
my ($codes,$labels)=GetborCatFromCatType(undef,undef);
my @borcatloop;
foreach my $thisborcat (sort keys %$labels) {
push @borcatloop, {value => $thisborcat,
description => $labels->{$thisborcat},
};
}
$template->param(loopcategories => \@borcatloop);
return $template;
my ($codes,$labels)=GetborCatFromCatType(undef,undef);
my @borcatloop;
foreach my $thisborcat (sort keys %$labels) {
push @borcatloop, {
value => $thisborcat,
description => $labels->{$thisborcat},
};
}
$template->param(loopcategories => \@borcatloop);
return $template;
}
sub calculate {
my ($parameters) = @_;
my @results =();

View File

@ -32,29 +32,11 @@ use C4::Branch; # GetBranches
sub set_parameters {
my ($template) = @_;
my $dbh = C4::Context->dbh;
my $branches=GetBranches();
my @branches;
my $default;
my @select_branch;
my %select_branches;
push @select_branch,"";
$select_branches{""} = "";
for my $branch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
push @select_branch, $branch;
$select_branches{$branch} = $branches->{$branch}->{'branchname'};
$default = C4::Context->userenv->{'branch'} if (C4::Context->userenv && C4::Context->userenv->{'branch'});
}
my $CGIbranch=CGI::scrolling_list( -name => 'value',
-id => 'value',
-values => \@select_branch,
-labels => \%select_branches,
-size => 1,
-multiple => 0,
-default => $default, );
$template->param(CGIbranch => $CGIbranch);
my $userbranch = C4::Context->userenv->{'branch'};
$template->param( branchloop => GetBranchesLoop($userbranch) );
return $template;
}
sub calculate {
my ($parameters) = @_;
my @results =();

View File

@ -65,23 +65,7 @@ my $showallitems = $input->param('showallitems');
my $branches = GetBranches();
my $itemtypes = GetItemTypes();
my $default = C4::Context->userenv->{branch};
my @values;
my %label_of;
foreach my $branchcode ( sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches ) {
push @values, $branchcode;
$label_of{$branchcode} = $branches->{$branchcode}->{branchname};
}
my $CGIbranch = CGI::scrolling_list(
-name => 'pickup',
-id => 'pickup',
-values => \@values,
-default => $default,
-labels => \%label_of,
-size => 1,
-multiple => 0,
);
my $userbranch = C4::Context->userenv->{branch};
# Select borrowers infos
my $findborrower = $input->param('findborrower');
@ -590,8 +574,7 @@ foreach my $biblionumber (@biblionumbers) {
my $time = time();
$template->param(
CGIbranch => $CGIbranch,
branchloop => GetBranchesLoop($userbranch),
time => $time,
fixedRank => $fixedRank,
);