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}${tag}>"; } +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