Bug 3706 Label templates/layouts do not save properly

Two issues here:

1. No radio box was selected by default in the format section of the layout editor. This actually needs some additional attention to allow the user
to establish a default method of entering the format string. As noted in comments in the code, this would probably be best implimented by adding yet
another syspref. However, I don't have time atm.

2. On saving a new template, if no profile was assigned to the new template, the script threw an error and died.

Both issues are addressed in this patch.

Signed-off-by: Galen Charlton <gmcharlt@gmail.com>
This commit is contained in:
Chris Nighswonger 2009-10-12 11:50:59 -04:00 committed by Galen Charlton
parent 3433edd1c4
commit 3bab38c3fc
4 changed files with 19 additions and 14 deletions

View file

@ -96,11 +96,11 @@
<!-- /TMPL_LOOP -->
</div>
</li>
<!-- TMPL_IF NAME="layout_string" -->
<!-- TMPL_UNLESS NAME="layout_string" -->
<li class="radio"><input type="radio" id="layout_choice_list" name="layout_choice" value="layout_string" checked="checked" /> <label for="layout_choice_list">List Fields</label></li>
<!-- TMPL_ELSE -->
<li class="radio"><input type="radio" id="layout_choice_list" name="layout_choice" value="layout_string" /> <label for="layout_choice_list">List Fields</label></li>
<!-- /TMPL_IF -->
<!-- /TMPL_UNLESS -->
<li> <fieldset id="layout_string" class="brief">
<label for="format_string">Data Fields</label>
<input type="text" name="format_string" id="format_string" size="80" value="<!-- TMPL_VAR ESCAPE='HTML' NAME="format_string" -->" />

View file

@ -44,6 +44,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
my $op = $cgi->param('op') || $ARGV[0] || '';
my $layout_id = $cgi->param('layout_id') || $cgi->param('element_id') || $ARGV[1] || '';
my $layout_choice = $cgi->param('layout_choice') || '';
my $layout = '';
sub _set_selected {
@ -108,7 +109,7 @@ if ($op eq 'edit') {
}
elsif ($op eq 'save') {
my $format_string = '';
if ($cgi->param('layout_choice') eq 'layout_table') { # translate the field table into a format_string
if ($layout_choice eq 'layout_table') { # translate the field table into a format_string
my @layout_table = ();
foreach my $cgi_param ($cgi->param()) {
if (($cgi_param =~ m/^(.*)_tbl$/) && ($cgi->param($cgi_param))) {
@ -165,5 +166,6 @@ $template->param(
font_size => $layout->get_attr('font_size'),
callnum_split => $layout->get_attr('callnum_split'),
format_string => $layout->get_attr('format_string'),
layout_string => 1, # FIXME: This should not be hard-coded; It should perhaps be yet another syspref... CN
);
output_html_with_http_headers $cgi, $cookie, $template->output;

View file

@ -41,6 +41,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
);
my $op = $cgi->param('op');
warn "operation = $op\n";
my $template_id = $cgi->param('template_id') || $cgi->param('element_id');
my $label_template = undef;
my $profile_list = undef;
@ -85,9 +86,11 @@ elsif ($op eq 'save') {
else { # if no label_id, this is a new layout so insert it
$label_template = C4::Labels::Template->new(@params);
my $template_id = $label_template->save();
my $profile = C4::Labels::Profile->retrieve(profile_id => $cgi->param('profile_id'));
$profile->set_attr(template_id => $template_id) if $template_id != $profile->get_attr('template_id');
$profile->save();
if ($cgi->param('profile_id')) {
my $profile = C4::Labels::Profile->retrieve(profile_id => $cgi->param('profile_id'));
$profile->set_attr(template_id => $template_id) if $template_id != $profile->get_attr('template_id');
$profile->save();
}
}
print $cgi->redirect("label-manage.pl?label_element=template");
exit;