X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FTemplate%2FPlugin%2FL.pm;h=871e683bf19eda39e6cd76f131712d09c589bc73;hb=a3cf1d2381e1db5ab972e6f0c74ff157012b221a;hp=9cf5ebb8529931eefb297affe11ddcf284dca46e;hpb=51d0274dc6b40830d38bcc209bb9c402433c1b38;p=kivitendo-erp.git diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index 9cf5ebb85..871e683bf 100644 --- a/SL/Template/Plugin/L.pm +++ b/SL/Template/Plugin/L.pm @@ -6,6 +6,8 @@ use List::MoreUtils qw(apply); use List::Util qw(max); use Scalar::Util qw(blessed); +use SL::Presenter; + use strict; { # This will give you an id for identifying html tags and such. @@ -83,6 +85,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; @@ -102,6 +113,8 @@ sub select_tag { my $title_sub = delete($attributes{title_sub}); my $default_sub = delete($attributes{default_sub}); + my $with_empty = delete($attributes{with_empty}); + my $empty_title = delete($attributes{empty_title}); my %selected; @@ -119,8 +132,8 @@ sub select_tag { my @options; - if ( delete($attributes{with_empty}) ) { - push(@options, [undef, $attributes{empty_title} || '']); + if ( $with_empty ) { + push(@options, [undef, $empty_title || '']); } my $normalize_entry = sub { @@ -171,7 +184,7 @@ sub select_tag { my $title; if ( $value_title_sub ) { - ($value, $title) = $value_title_sub->($entry); + ($value, $title) = @{ $value_title_sub->($entry) }; } else { $value = $normalize_entry->('value', $entry, $value_sub, $value_key); @@ -270,7 +283,8 @@ sub input_tag { } sub hidden_tag { - return shift->input_tag(@_, type => 'hidden'); + my ($self, $name, $value, @slurp) = @_; + return $self->input_tag($name, $value, _hashify(@slurp), type => 'hidden'); } sub div_tag { @@ -301,7 +315,9 @@ sub submit_tag { my ($self, $name, $value, @slurp) = @_; my %attributes = _hashify(@slurp); - $attributes{onclick} = "if (confirm('" . delete($attributes{confirm}) . "')) return true; else return false;" if $attributes{confirm}; + if ( $attributes{confirm} ) { + $attributes{onclick} = 'return confirm("'. _J(delete($attributes{confirm})) .'");'; + } return $self->input_tag($name, $value, %attributes, type => 'submit', class => 'submit'); } @@ -383,34 +399,10 @@ sub customer_picker { my ($self, $name, $value, %params) = @_; my $name_e = _H($name); - $self->hidden_tag($name, (ref $value && $value->can('id')) ? $value->id : '') . - $self->input_tag("$name_e\_name", (ref $value && $value->can('name')) ? $value->name : '', %params) . - $self->javascript(<{layout}->add_javascripts('autocomplete_customer.js'); + + $self->hidden_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => 'customer_autocomplete') . + $self->input_tag("$name_e\_name", (ref $value && $value->can('name')) ? $value->name : '', %params); } # simple version with select_tag @@ -473,27 +465,15 @@ sub tabbed { next if $tab eq ''; - my $selected = $params{selected} == $i; - my $tab_id = "__tab_id_$i"; - push @header, $self->li_tag( - $self->link('', $tab->{name}, rel => $tab_id), - ($selected ? (class => 'selected') : ()) - ); - push @blocks, $self->div_tag($tab->{data}, - id => $tab_id, class => 'tabcontent'); + my $tab_id = "__tab_id_$i"; + push @header, $self->li_tag($self->link('#' . $tab_id, $tab->{name})); + push @blocks, $self->div_tag($tab->{data}, id => $tab_id); } return '' unless @header; - return $self->ul_tag( - join('', @header), id => $id, class => 'shadetabs' - ) . - $self->div_tag( - join('', @blocks), class => 'tabcontentstyle' - ) . - $self->javascript( - qq|var $id = new ddtabcontent("$id");$id.setpersist(true);| . - qq|$id.setselectedClassTarget("link");$id.init();| - ); + + my $ul = $self->ul_tag(join('', @header), id => $id); + return $self->div_tag(join('', $ul, @blocks), class => 'tabwidget'); } sub tab { @@ -654,7 +634,7 @@ sub sortable_table_header { 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}; + my $title = delete($params{title}) || $::locale->text($by_spec->{title}); if ($current_sort_params{by} eq $by) { my $current_dir = $current_sort_params{dir} ? 'up' : 'down'; @@ -668,6 +648,27 @@ sub sortable_table_header { 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 => \%paginate_params, + 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); + }, + ); + + return SL::Presenter->get->render('common/paginate', %template_params); +} + 1; __END__ @@ -878,9 +879,6 @@ C. Example: L.tab(LxERP.t8('Custom Variables'), 'part/_cvar_tab.html', if => SELF.display_cvar_tab), ]) %] -An optional attribute is C, which accepts the ordinal of a tab which -should be selected by default. - =item C Creates a generic input tag or textarea tag, depending on content size. The @@ -1009,6 +1007,13 @@ 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