Koha/labels/label-edit-batch.pl
Liz Rea fa99f75bdc Bug 14667: UI/UX improvements for the Label creator
Note: It would be good to adopt these same changes in the Patron Card creator for consistency and push
      them in conjunction with these changes. -Chris_n

Reasoning

Librarians will be doing label things in the following frequencies, from most frequent to least frequent:
1. Creating new label batches - every day/every few days
2. Managing existing label batches - every day/every few days
3. Managing existing label layouts - as needed, infrequent
5. Managing existing label templates - as needed, infrequent
6. Creating new label layouts - as needed, infrequent
7. Creating new label templates - as needed, infrequent
8. Managing existing printer profiles - possibly once only!
9. Creating new printer profiles - possibly once only!

This change to the label creator aims to make the most frequently used items easily accessible at the top of the main area,
reduces clutter on the page, and makes the label creator fall in line with UI paradigms found elsewhere in Koha.

To test:

Open the label creator: More -> Tools -> Label creator
Note that the toolbar has changed. It should be consistent across all of the label creator (it is an include).

+ New menu:

Label batch
1. make sure it looks ok - toolbar buttons are consistent at the top of the main block.
2. add items both by barcode, and by search (note this patch does not touch the pop up window. Another day.)
3. note that the usual buttons have moved below the textarea, and now have icons.
4. delete and export single items using the buttons corresponding to each item
5. select multiple and use the buttons above the table to remove and export selected items
6. export a full batch
7. deduplicate a batch
There should be no regressions in functionality.

Layout
1. This menu item should take you directly to the "Edit layout" screen.
2. no functional changes here.
3. note toolbar at top is consistent

Label template
1. this menu item should take you directly to the "Edit label template" page.
2. no functional changes here.
3. note toolbar at top is consistent.

Printer profile
1. this menu item should take you directly to the "Edit printer profile" page.
2. no functional changes here.
3. note toolbar at top is consistent.

+ Manage menu:

Label batches
1. This menu item should take you directly to the "currently available batches" page.
2. select a batch to edit using the buttons
3. select a batch to delete using the buttons - it should ask for confirm.
4. select several batches using the tickboxes, and select Export selected. Batches should be exported as normal.
5. note toolbar at top is consistent.

Layouts
1. This menu item should take you directly to the "currently available layouts" page.
2. select a layout to edit using the buttons
3. select a layout to delete using the buttons
4. note toolbar at top is consistent.

Label templates
1. This menu item should take you directly to the "currently available templates" page.
2. select a template to edit using the buttons
3. select a template to delete using the buttons
4. note toolbar at top is consistent.

Printer profiles
1. This menu item should take you directly to the "currently available profiles" page.
2. select a profile to edit using the buttons
3. select a profile to delete using the buttons
4. note toolbar at top is consistent

+ General
* note that sidebar now only has "labels home" instead of the full "manage" list. It seemed redundant with the toolbar tidied up.

Please note that I am happy to take suggestions/amendments to these changes.

Signed-off-by: Chris Nighswonger <cnighswonger@foundations.edu>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2015-10-06 11:22:55 -03:00

145 lines
5.6 KiB
Perl
Executable file

#!/usr/bin/perl
#
# Copyright 2006 Katipo Communications.
# Parts Copyright 2009 Foundations Bible College.
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use strict;
use warnings;
use vars qw($debug);
use CGI qw ( -utf8 );
use C4::Auth qw(get_template_and_user);
use C4::Output qw(output_html_with_http_headers);
use C4::Items qw(GetItem GetItemnumberFromBarcode);
use C4::Creators;
use C4::Labels;
my $cgi = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "labels/label-edit-batch.tt",
query => $cgi,
type => "intranet",
authnotrequired => 0,
flagsrequired => { catalogue => 1 },
debug => 1,
}
);
my $err = 0;
my $errstr = undef;
my $duplicate_count = undef;
my $duplicate_message = undef;
my $db_rows = {};
my $batch = undef;
my $display_columns = [ {_label_number => {label => 'Label Number', link_field => 0}},
{_summary => {label => 'Summary', link_field => 0}},
{_item_type => {label => 'Item Type', link_field => 0}},
{_barcode => {label => 'Barcode', link_field => 0}},
{_delete => {label => ' ', link_field => 0}},
{select => {label => 'Select', value => '_label_id'}},
];
my $op = $cgi->param('op') || 'edit';
my @label_ids;
my @item_numbers;
my $number_list;
my $number_type = $cgi->param('number_type') || "barcode";
my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0;
@label_ids = $cgi->param('label_id') if $cgi->param('label_id');
@item_numbers = $cgi->param('item_number') if $cgi->param('item_number');
$number_list = $cgi->param('number_list') if $cgi->param('number_list');
my $branch_code = C4::Context->userenv->{'branch'};
if ($op eq 'remove') {
$batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
foreach my $label_id (@label_ids) {
$err = $batch->remove_item($label_id);
}
$errstr = "item(s) not removed from batch $batch_id." if $err;
# Something like this would be nice to avoid problems with the browser's 'refresh' button, but it needs an error handling mechanism...
# print $cgi->redirect("label-edit-batch.pl?op=edit&batch_id=$batch_id");
# exit;
}
elsif ($op eq 'delete') {
$err = C4::Labels::Batch::delete(batch_id => $batch_id, branch_code => $branch_code);
$errstr = "batch $batch_id was not deleted." if $err;
}
elsif ($op eq 'add') {
if ($number_list) {
my @numbers_list = split /\n/, $number_list; # Entries are effectively passed in as a <cr> separated list
foreach my $number (@numbers_list) {
$number =~ s/\r$//; # strip any naughty return chars
if( $number_type eq "itemnumber" && GetItem($number) ) {
push @item_numbers, $number;
}
elsif ($number_type eq "barcode" ) { # we must test in case an invalid barcode is passed in; we effectively disgard them atm
if( my $item_number = GetItemnumberFromBarcode($number) ){
push @item_numbers, $item_number;
}
}
}
}
if ($batch_id != 0) {$batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);}
if ($batch_id == 0 || $batch == -2) {$batch = C4::Labels::Batch->new(branch_code => $branch_code);}
if ($branch_code){
foreach my $item_number (@item_numbers) {
$err = $batch->add_item($item_number);
}
$batch_id = $batch->get_attr('batch_id') if $batch_id == 0; #update batch_id if we added to a new batch
$errstr = "item(s) not added to batch $batch_id." if $err;
}
else {
$err = 1;
$errstr = "items(s) not added, the error was: Branch is not set, you please set your branch before adding items to a batch";
}
}
elsif ($op eq 'new') {
$batch = C4::Labels::Batch->new(branch_code => $branch_code);
$batch_id = $batch->get_attr('batch_id');
}
elsif ($op eq 'de_duplicate') {
$batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
$duplicate_count = $batch->remove_duplicates();
$duplicate_message = 1 if $duplicate_count != -1;
$errstr = "batch $batch_id not fully de-duplicated." if $duplicate_count == -1;
}
else { # edit
$batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
}
my $items = $batch->get_attr('items');
$db_rows = get_label_summary(items => $items, batch_id => $batch_id);
my $table = html_table($display_columns, $db_rows);
$template->param(
err => $err,
errstr => $errstr,
) if ($err ne 0);
$template->param(
op => $op,
batch_id => $batch_id,
table_loop => $table,
duplicate_message => $duplicate_message,
duplicate_count => $duplicate_count,
);
output_html_with_http_headers $cgi, $cookie, $template->output;