[11/40] Work on layout editor interface.

This commit is contained in:
Chris Nighswonger 2009-07-24 23:03:05 -04:00
parent b44db285a6
commit 4554222629
4 changed files with 31 additions and 36 deletions

View file

@ -96,7 +96,7 @@ C4::Labels::Layout -A class for creating and manipulating layout objects in Koha
sub new {
my $invocant = shift;
if (_check_params(@_) eq 1) {
return 1;
return -1;
}
my $type = ref($invocant) || $invocant;
my $self = {
@ -134,7 +134,7 @@ sub retrieve {
$sth->execute($opts{'layout_id'});
if ($sth->err) {
syslog("LOG_ERR", "Database returned the following error: %s", $sth->errstr);
return 1;
return -1;
}
my $self = $sth->fetchrow_hashref;
bless ($self, $type);
@ -169,14 +169,14 @@ sub delete {
}
if ($query_param eq '') { # If there is no layout id then we cannot delete it
syslog("LOG_ERR", "%s : Cannot delete layout as the layout id is invalid or non-existant.", $call_type);
return 1;
return -1;
}
my $query = "DELETE FROM labels_layouts WHERE layout_id = ?";
my $sth = C4::Context->dbh->prepare($query);
$sth->execute($query_param);
if ($sth->err) {
syslog("LOG_ERR", "%s : Database returned the following error: %s", $call_type, $sth->errstr);
return 1;
return -1;
}
return 0;
}
@ -277,7 +277,7 @@ sub get_attr {
sub set_attr {
my $self = shift;
if (_check_params(@_) eq 1) {
return 1;
return -1;
}
my %attrs = @_;
foreach my $attrib (keys(%attrs)) {

View file

@ -24,18 +24,12 @@ use Data::Dumper;
use C4::Context;
use C4::Debug;
use C4::Labels::Lib 1.000000 qw(get_unit_values);
BEGIN {
use version; our $VERSION = qv('1.0.0_1');
}
my $unit_values = {
POINT => 1,
INCH => 72,
MM => 2.83464567,
CM => 28.3464567,
};
sub _check_params {
my $given_params = {};
my $exit_code = 0;
@ -47,7 +41,7 @@ sub _check_params {
'offset_vert',
'creep_horz',
'creep_vert',
'unit',
'units',
);
if (scalar(@_) >1) {
$given_params = {@_};
@ -69,10 +63,11 @@ sub _check_params {
sub _conv_points {
my $self = shift;
$self->{offset_horz} = $self->{offset_horz} * $unit_values->{$self->{unit}};
$self->{offset_vert} = $self->{offset_vert} * $unit_values->{$self->{unit}};
$self->{creep_horz} = $self->{creep_horz} * $unit_values->{$self->{unit}};
$self->{creep_vert} = $self->{creep_vert} * $unit_values->{$self->{unit}};
my @unit_value = grep {$_->{'type'} eq $self->{units}} get_unit_values();
$self->{offset_horz} = $self->{offset_horz} * $unit_value[0]->{'value'};
$self->{offset_vert} = $self->{offset_vert} * $unit_value[0]->{'value'};
$self->{creep_horz} = $self->{creep_horz} * $unit_value[0]->{'value'};
$self->{creep_vert} = $self->{creep_vert} * $unit_value[0]->{'value'};
return $self;
}
@ -109,7 +104,7 @@ sub new {
offset_vert => 0,
creep_horz => 0,
creep_vert => 0,
unit => 'POINT',
units => 'POINT',
@_,
};
bless ($self, $type);
@ -135,7 +130,7 @@ sub retrieve {
my $invocant = shift;
my %opts = @_;
my $type = ref($invocant) || $invocant;
my $query = "SELECT * FROM printers_profile WHERE prof_id = ?";
my $query = "SELECT * FROM printers_profile WHERE profile_id = ?";
my $sth = C4::Context->dbh->prepare($query);
$sth->execute($opts{profile_id});
if ($sth->err) {
@ -148,34 +143,34 @@ sub retrieve {
return $self;
}
=head2 C4::Labels::Profile->delete(prof_id => profile_id) | $profile->delete()
=head2 C4::Labels::Profile->delete(profile_id => profile_id) | $profile->delete()
Invoking the delete method attempts to delete the profile from the database. The method returns 0 upon success
and 1 upon failure. Errors are logged to the syslog.
examples:
my $exitstat = $profile->delete(); # to delete the record behind the $profile object
my $exitstat = C4::Labels::Profile->delete(prof_id => 1); # to delete profile record 1
my $exitstat = C4::Labels::Profile->delete(profile_id => 1); # to delete profile record 1
=cut
sub delete {
my $self = shift;
if (!$self->{'prof_id'}) { # If there is no profile prof_id then we cannot delete it
if (!$self->{'profile_id'}) { # If there is no profile profile_id then we cannot delete it
syslog("LOG_ERR", "Cannot delete profile as it has not been saved.");
return 1;
}
my $query = "DELETE FROM printers_profile WHERE prof_id = ?";
my $query = "DELETE FROM printers_profile WHERE profile_id = ?";
my $sth = C4::Context->dbh->prepare($query);
$sth->execute($self->{'prof_id'});
$sth->execute($self->{'profile_id'});
return 0;
}
=head2 $profile->save()
Invoking the I<save> method attempts to insert the profile into the database if the profile is new and
update the existing profile record if the profile exists. The method returns the new record prof_id upon
success and -1 upon failure (This avoids conflicting with a record prof_id of 1). Errors are logged to the syslog.
update the existing profile record if the profile exists. The method returns the new record profile_id upon
success and -1 upon failure (This avoids conflicting with a record profile_id of 1). Errors are logged to the syslog.
example:
my $exitstat = $profile->save(); # to save the record behind the $profile object
@ -184,17 +179,17 @@ sub delete {
sub save {
my $self = shift;
if ($self->{'prof_id'}) { # if we have an prof_id, the record exists and needs UPDATE
if ($self->{'profile_id'}) { # if we have an profile_id, the record exists and needs UPDATE
my @params;
my $query = "UPDATE printers_profile SET ";
foreach my $key (keys %{$self}) {
next if $key eq 'prof_id';
next if $key eq 'profile_id';
push (@params, $self->{$key});
$query .= "$key=?, ";
}
$query = substr($query, 0, (length($query)-2));
push (@params, $self->{'prof_id'});
$query .= " WHERE prof_id=?;";
push (@params, $self->{'profile_id'});
$query .= " WHERE profile_id=?;";
warn "DEBUG: Updating: $query\n" if $debug;
my $sth = C4::Context->dbh->prepare($query);
$sth->execute(@params);
@ -202,7 +197,7 @@ sub save {
syslog("LOG_ERR", "C4::Labels::Profile : Database returned the following error: %s", $sth->errstr);
return -1;
}
return $self->{'prof_id'};
return $self->{'profile_id'};
}
else { # otherwise create a new record
my @params;
@ -225,7 +220,7 @@ sub save {
syslog("LOG_ERR", "C4::Labels::Profile : Database returned the following error: %s", $sth->errstr);
return -1;
}
my $sth1 = C4::Context->dbh->prepare("SELECT MAX(prof_id) FROM printers_profile;");
my $sth1 = C4::Context->dbh->prepare("SELECT MAX(profile_id) FROM printers_profile;");
$sth1->execute();
my $tmpl_id = $sth1->fetchrow_array;
return $tmpl_id;

View file

@ -32,7 +32,7 @@
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<!-- TMPL_INCLUDE NAME="tools-labels-toolbar.inc" -->
<!-- TMPL_INCLUDE NAME="labels-new-toolbar.inc" -->
<form name="input" action="/cgi-bin/koha/labels/label-edit-layout.pl" method="get">
<fieldset class="rows">
<legend><!-- TMPL_IF NAME="layout_id" -->Edit<!-- TMPL_ELSE -->Create<!-- /TMPL_IF --> Label Layout</legend>

View file

@ -48,7 +48,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
my $op = $cgi->param('op') || $ARGV[0] || '';
my $layout_id = $cgi->param('layout_id') || $ARGV[1] || '';
my $layout_id = $cgi->param('layout_id') || $cgi->param('element_id') || $ARGV[1] || '';
my $layout = '';
sub _set_selected {
@ -89,7 +89,7 @@ sub _select_format_string { # generate field table based on format_string
$col_index++;
$field_index++;
if ((($col_index > 0) && !($col_index % $cols)) || ($field_index == $field_count)) { # wrap to new row
if ($field_index == $field_count) { # in this case fill out row with empty fields
if (($field_index == $field_count) && ($row_index > 0)) { # in this case fill out row with empty fields
while ($col_index < $cols) {
$$fields[$col_index] = {field_empty => 1, field_name => '', field_label => '', order => [{num => '', selected => 0}]};
$col_index++;
@ -145,7 +145,7 @@ elsif ($op eq 'save') {
$layout = C4::Labels::Layout->new(@params);
$layout->save();
}
print $cgi->redirect("label-layout.pl");
print $cgi->redirect("label-manage.pl?label_element=layout");
exit;
}
else { # if we get here, this is a new layout