finish up exception handling for importing taxes and reporting messages back to the user

This commit is contained in:
Colin Kuskie 2008-06-17 23:28:28 +00:00
parent a67775b17d
commit 2049c28ce3

View file

@ -496,21 +496,40 @@ sub www_importTax {
unless $admin->canManage; unless $admin->canManage;
my $storage = WebGUI::Storage->create($session); my $storage = WebGUI::Storage->create($session);
my $taxFile = $storage->addFileFromFormPost('importFile', 1); my $taxFile = $storage->addFileFromFormPost('importFile', 1);
$self->importTaxData($storage->getPath($taxFile)) if $taxFile; eval {
return $self->www_manage; $self->importTaxData($storage->getPath($taxFile)) if $taxFile;
};
my ($exception, $status_message);
if ($exception = Exception::Class->caught('WebGUI::Error::InvalidFile')) {
$status_message = sprintf 'A problem was found with your file: %s',
$exception->error;
if ($exception->brokenLine) {
$status_message .= sprintf ' on line %d', $exception->brokenLine;
}
}
elsif ($exception = Exception::Class->caught()) {
$status_message = sprintf 'A problem happened during the import: %s', $exception->error;
}
return $self->www_manage($status_message);
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 www_manage ( ) =head2 www_manage ( $status_message )
User interface to manage taxes. Provides a list of current taxes, and forms for adding User interface to manage taxes. Provides a list of current taxes, and forms for adding
new tax info, exporting and importing sets of taxes, and deleting individual tax data. new tax info, exporting and importing sets of taxes, and deleting individual tax data.
=head3 $status_message
A message to display to the user. This is usually a problem that was found during
import.
=cut =cut
sub www_manage { sub www_manage {
my $self = shift; my $self = shift;
my $status_message = shift;
my $session = $self->session; my $session = $self->session;
my $admin = WebGUI::Shop::Admin->new($session); my $admin = WebGUI::Shop::Admin->new($session);
return $session->privilege->insufficient return $session->privilege->insufficient
@ -565,8 +584,16 @@ sub www_manage {
$addForm->submit( $addForm->submit(
value => $i18n->get('add a tax'), value => $i18n->get('add a tax'),
); );
my $output =sprintf <<EODIV, $i18n->get(364, 'WebGUI'), $addForm->print, $exportForm, $importForm; my $output;
<div class=" yui-skin-sam"> if ($status_message) {
$output = <<EOSM;
<div class="error">
$status_message
</div>
EOSM
}
$output .=sprintf <<EODIV, $i18n->get(364, 'WebGUI'), $addForm->print, $exportForm, $importForm;
<div class="yui-skin-sam">
<div id="search"><form id="keywordSearchForm"><input type="text" name="keywords" id="keywordsField" /><input type="submit" value="%s" /></form></div> <div id="search"><form id="keywordSearchForm"><input type="text" name="keywords" id="keywordsField" /><input type="submit" value="%s" /></form></div>
<div id="paging"></div> <div id="paging"></div>
<div id="dt"></div> <div id="dt"></div>