X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/67079598f8f98a12e12a8acddc3afbf12bb58c5d..36b5dead243946c4447e9a854ebd67e613853f88:/SL/Template/Plugin/L.pm diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index 0b4967d34..c3411305a 100644 --- a/SL/Template/Plugin/L.pm +++ b/SL/Template/Plugin/L.pm @@ -83,6 +83,15 @@ sub html_tag { return "<${tag}${attributes}>${content}"; } +sub img_tag { + my ($self, @slurp) = @_; + my %options = _hashify(@slurp); + + $options{alt} ||= ''; + + return $self->html_tag('img', undef, %options); +} + sub select_tag { my $self = shift; my $name = shift; @@ -252,6 +261,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 +369,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 +384,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 +579,68 @@ 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}) . '...'; +} + +sub sortable_table_header { + my ($self, $by, @slurp) = @_; + my %params = _hashify(@slurp); + + my $controller = $self->{CONTEXT}->stash->get('SELF'); + my $sort_spec = $controller->get_sort_spec; + my $by_spec = $sort_spec->{$by}; + my %current_sort_params = $controller->get_current_sort_params; + my ($image, $new_dir) = ('', $current_sort_params{dir}); + my $title = delete($params{title}) || $by_spec->{title}; + + if ($current_sort_params{by} eq $by) { + my $current_dir = $current_sort_params{dir} ? 'up' : 'down'; + $image = ''; + $new_dir = 1 - ($current_sort_params{dir} || 0); + } + + $params{ $sort_spec->{FORM_PARAMS}->[0] } = $by; + $params{ $sort_spec->{FORM_PARAMS}->[1] } = ($new_dir ? '1' : '0'); + + return '' . _H($title) . $image . ''; +} + +sub paginate_controls { + my ($self) = @_; + + my $controller = $self->{CONTEXT}->stash->get('SELF'); + my $paginate_spec = $controller->get_paginate_spec; + my %paginate_params = $controller->get_current_paginate_params; + + my %template_params = ( + pages => { + cur => $paginate_params{page}, + max => $paginate_params{num_pages}, + common => $paginate_params{common_pages}, + }, + url_maker => sub { + my %url_params = _hashify(@_); + $url_params{ $paginate_spec->{FORM_PARAMS}->[0] } = delete $url_params{page}; + $url_params{ $paginate_spec->{FORM_PARAMS}->[1] } = delete $url_params{per_page} if exists $url_params{per_page}; + + return $controller->get_callback(%url_params); + }, + ); + + my $output; + $controller->_template_obj->process('templates/webpages/common/paginate.html', \%template_params, \$output); + return $output; +} + 1; __END__ @@ -629,6 +708,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 @@ -837,6 +923,29 @@ containing the values C<[ 6, 2, 15 ]>. Dumps the Argument using L into a EpreE block. +=item C + +Create a link and image suitable for placement in a table +header. C<$by> must be an index set up by the controller with +L. + +The optional parameter C<$params{title}> can override the column title +displayed to the user. Otherwise the column title from the +controller's sort spec is used. + +The other parameters in C<%params> are passed unmodified to the +underlying call to L. + +See the documentation of L for an +overview and further usage instructions. + +=item C + +Create a set of links used to paginate a list view. + +See the documentation of L for an +overview and further usage instructions. + =back =head2 CONVERSION FUNCTIONS @@ -903,6 +1012,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