X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/f866d16b4e837443b71ffaf3b78c1127ac57717e..36b5dead243946c4447e9a854ebd67e613853f88:/SL/Template/Plugin/L.pm diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index 8523db9e0..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; @@ -582,6 +591,56 @@ sub truncate { 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__ @@ -864,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