X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/f2b76d67f773954dcfa59ff7c3ebb6f6607e2e43..56f7991d4910ae12c7d16aab025a2ab242ca5eeb:/SL/Template/Plugin/L.pm diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index 6d6b59f2d..bac6f7f12 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 { @@ -344,75 +358,33 @@ sub stylesheet_tag { return $code; } +my $date_tag_id_idx = 0; sub date_tag { my ($self, $name, $value, @slurp) = @_; + my %params = _hashify(@slurp); - my $name_e = _H($name); - my $seq = _tag_id(); - my $datefmt = apply { - s/d+/\%d/gi; - s/m+/\%m/gi; - s/y+/\%Y/gi; - } $::myconfig{"dateformat"}; - - my $cal_align = delete $params{cal_align} || 'BR'; - my $onchange = delete $params{onchange}; - my $str_value = blessed $value ? $value->to_lxoffice : $value; - - $self->input_tag($name, $str_value, - id => $name_e, + my $id = $self->name_to_id($name) . _tag_id(); + my @onchange = $params{onchange} ? (onChange => delete $params{onchange}) : (); + my @class = $params{no_cal} || $params{readonly} ? () : (class => 'datepicker'); + + return $self->input_tag( + $name, blessed($value) ? $value->to_lxoffice : $value, + id => $id, size => 11, - title => _H($::myconfig{dateformat}), - onBlur => 'check_right_date_format(this)', - ($onchange ? ( - onChange => $onchange, - ) : ()), + onblur => "check_right_date_format(this);", %params, - ) . ((!$params{no_cal} && !$params{readonly}) ? - $self->html_tag('img', undef, - src => 'image/calendar.png', - alt => $::locale->text('Calendar'), - id => "trigger$seq", - title => _H($::myconfig{dateformat}), - %params, - ) . - $self->javascript( - "Calendar.setup({ inputField: '$name_e', ifFormat: '$datefmt', align: '$cal_align', button: 'trigger$seq' });" - ) : ''); + @class, @onchange, + ); } 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 @@ -475,27 +447,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 { @@ -656,7 +616,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'; @@ -670,6 +630,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__ @@ -830,13 +811,10 @@ If C<%attributes> contains a key C then the value is taken as a JQuery selector and clicking this checkbox will also toggle all checkboxes matching the selector. -=item C $align_code, %attributes> +=item C Creates a date input field, with an attached javascript that will open a -calendar on click. The javascript ist by default anchoered at the bottom right -sight. This can be overridden with C, see Calendar documentation for -the details, usually you'll want a two letter abbreviation of the alignment. -Right + Bottom becomes C. +calendar on click. =item C @@ -862,14 +840,6 @@ for each file name parameter passed. Each file name will be postfixed with '.css' if it isn't already and prefixed with 'css/' if it doesn't contain a slash. -=item C $align_code, %attributes> - -Creates a date input field, with an attached javascript that will open a -calendar on click. The javascript ist by default anchoered at the bottom right -sight. This can be overridden with C, see Calendar documentation for -the details, usually you'll want a two letter abbreviation of the alignment. -Right + Bottom becomes C. - =item C Will create a tabbed area. The tabs should be created with the helper function @@ -880,9 +850,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 @@ -1011,6 +978,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