X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/257c66781231ccace0a43539779c2cb17324e7b1..5f49de40a2c8c6eca92bb3fd88c1ee0126264bd1:/SL/Template/Plugin/L.pm diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index f7ffc11b2..8523db9e0 100644 --- a/SL/Template/Plugin/L.pm +++ b/SL/Template/Plugin/L.pm @@ -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'); @@ -342,6 +350,36 @@ autocomplete_customer('#$name_e\_name'); JS } +# simple version with select_tag +sub vendor_selector { + my ($self, $name, $value, %params) = @_; + + my $actual_vendor_id = (defined $::form->{"$name"})? ((ref $::form->{"$name"}) ? $::form->{"$name"}->id : $::form->{"$name"}) : + (ref $value && $value->can('id')) ? $value->id : ''; + my $options_str = $self->options_for_select(SL::DB::Manager::Vendor->get_all(), + default => $actual_vendor_id, + title_sub => sub { $_[0]->vendornumber . " : " . $_[0]->name }, + 'with_empty' => 1); + + return $self->select_tag($name, $options_str, %params); +} + + +# simple version with select_tag +sub part_selector { + my ($self, $name, $value, %params) = @_; + + my $actual_part_id = (defined $::form->{"$name"})? ((ref $::form->{"$name"})? $::form->{"$name"}->id : $::form->{"$name"}) : + (ref $value && $value->can('id')) ? $value->id : ''; + my $options_str = $self->options_for_select(SL::DB::Manager::Part->get_all(), + default => $actual_part_id, + title_sub => sub { $_[0]->partnumber . " : " . $_[0]->description }, + 'with_empty' => 1); + + return $self->select_tag($name, $options_str, %params); +} + + sub javascript_tag { my $self = shift; my $code = ''; @@ -532,6 +570,18 @@ sub dump { return '
' . Data::Dumper::Dumper(@_) . '
'; } +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__ @@ -599,6 +649,13 @@ L function. If C<$options_string> is an array reference then it will be passed to L automatically. +=item C + +Creates a HTML 'select' tag with the two entries C and C by +calling L and L. C<$value> determines +which entry is selected. The C<%attributes> are passed through to +L. + =item C Creates a HTML 'input type=text' tag named C<$name> with the value @@ -873,6 +930,16 @@ the resulting tab will get ignored by C: L.tab('Awesome tab wih much info', '_much_info.html', if => SELF.wants_all) +=item C + +Returns the C<$text> truncated after a certain number of +characters. + +The number of characters to truncate at is determined by the parameter +C 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