]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Template/Plugin/L.pm
Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
[mfinanz.git] / SL / Template / Plugin / L.pm
index 0b4967d3484f77c125cba4547d7e5811829d7d6b..8523db9e0b9382402e23c4d4ebbb9a5141169f36 100644 (file)
@@ -252,6 +252,14 @@ sub options_for_select {
   return $code;
 }
 
+sub yes_no_tag {
+  my ($self, $name, $value) = splice @_, 0, 3;
+  my %attributes            = _hashify(@_);
+
+  my $options               = $self->options_for_select([ [ 1, $::locale->text('Yes') ], [ 0, $::locale->text('No') ] ], default => $value ? 1 : 0);
+  return $self->select_tag($name, $options, %attributes);
+}
+
 sub javascript {
   my ($self, $data) = @_;
   return $self->html_tag('script', $data, type => 'text/javascript');
@@ -352,7 +360,7 @@ sub vendor_selector {
                                               default      => $actual_vendor_id,
                                               title_sub    => sub { $_[0]->vendornumber . " : " . $_[0]->name },
                                               'with_empty' => 1);
-  
+
   return $self->select_tag($name, $options_str, %params);
 }
 
@@ -367,7 +375,7 @@ sub part_selector {
                                               default      => $actual_part_id,
                                               title_sub    => sub { $_[0]->partnumber . " : " . $_[0]->description },
                                               'with_empty' => 1);
-  
+
   return $self->select_tag($name, $options_str, %params);
 }
 
@@ -562,6 +570,18 @@ sub dump {
   return '<pre>' . Data::Dumper::Dumper(@_) . '</pre>';
 }
 
+sub truncate {
+  my ($self, $text, @slurp) = @_;
+  my %params                = _hashify(@slurp);
+
+  $params{at}             ||= 50;
+  $params{at}               =  3 if 3 > $params{at};
+  $params{at}              -= 3;
+
+  return $text if length($text) < $params{at};
+  return substr($text, 0, $params{at}) . '...';
+}
+
 1;
 
 __END__
@@ -629,6 +649,13 @@ L</options_for_select> function. If C<$options_string> is an array
 reference then it will be passed to L</options_for_select>
 automatically.
 
+=item C<yes_no_tag $name, $value, %attributes>
+
+Creates a HTML 'select' tag with the two entries C<yes> and C<no> by
+calling L<select_tag> and L<options_for_select>. C<$value> determines
+which entry is selected. The C<%attributes> are passed through to
+L<select_tag>.
+
 =item C<input_tag $name, $value, %attributes>
 
 Creates a HTML 'input type=text' tag named C<$name> with the value
@@ -903,6 +930,16 @@ the resulting tab will get ignored by C<tabbed>:
 
   L.tab('Awesome tab wih much info', '_much_info.html', if => SELF.wants_all)
 
+=item C<truncate $text, %params>
+
+Returns the C<$text> truncated after a certain number of
+characters.
+
+The number of characters to truncate at is determined by the parameter
+C<at> which defaults to 50. If the text is longer than C<$params{at}>
+then it will be truncated and postfixed with '...'. Otherwise it will
+be returned unmodified.
+
 =back
 
 =head1 MODULE AUTHORS