';
}
-sub date_tag {
- my ($self, $name, $value, @slurp) = @_;
- my %params = _hashify(@slurp);
- my $name_e = _H($name);
- my $seq = _tag_id();
+sub sortable_table_header {
+ my ($self, $by, %params) = _hashify(2, @_);
+
+ my $controller = $self->{CONTEXT}->stash->get('SELF');
+ my $models = $params{models} || $self->{CONTEXT}->stash->get('MODELS');
+ my $sort_spec = $models->get_sort_spec;
+ my $by_spec = $sort_spec->{$by};
+ my %current_sort_params = $models->get_current_sort_params;
+ my ($image, $new_dir) = ('', $current_sort_params{dir});
+ my $title = delete($params{title}) || $::locale->text($by_spec->{title});
+
+ if ($current_sort_params{sort_by} eq $by) {
+ my $current_dir = $current_sort_params{sort_dir} ? 'up' : 'down';
+ $image = '';
+ $new_dir = 1 - ($current_sort_params{sort_dir} || 0);
+ }
- $params{cal_align} ||= 'BR';
+ $params{ $models->sorted->form_params->[0] } = $by;
+ $params{ $models->sorted->form_params->[1] } = ($new_dir ? '1' : '0');
- $self->input_tag($name, $value,
- id => $name_e,
- size => 11,
- title => _H($::myconfig{dateformat}),
- onBlur => 'check_right_date_format(this)',
- %params,
- ) . ((!$params{no_cal}) ?
- $self->html_tag('img', undef,
- src => 'image/calendar.png',
- id => "trigger$seq",
- title => _H($::myconfig{dateformat}),
- %params,
- ) .
- $self->javascript(
- "Calendar.setup({ inputField: '$name_e', ifFormat: '$::myconfig{jsc_dateformat}', align: '$params{cal_align}', button: 'trigger$seq' });"
- ) : '');
+ return '' . _H($title) . $image . '';
+}
-sub javascript_tag {
- my $self = shift;
- my $code = '';
+sub paginate_controls {
+ my ($self, %params) = _hashify(1, @_);
- foreach my $file (@_) {
- $file .= '.js' unless $file =~ m/\.js$/;
- $file = "js/${file}" unless $file =~ m|/|;
+ my $controller = $self->{CONTEXT}->stash->get('SELF');
+ my $models = $params{models} || $self->{CONTEXT}->stash->get('MODELS');
+ my $pager = $models->paginated;
+# my $paginate_spec = $controller->get_paginate_spec;
- $code .= qq||;
- }
+ my %paginate_params = $models->get_paginate_args;
- return $code;
+ my %template_params = (
+ pages => \%paginate_params,
+ url_maker => sub {
+ my %url_params = _hashify(0, @_);
+ $url_params{ $pager->form_params->[0] } = delete $url_params{page};
+ $url_params{ $pager->form_params->[1] } = delete $url_params{per_page} if exists $url_params{per_page};
+
+ return $models->get_callback(%url_params);
+ },
+ %params,
+ );
+
+ return SL::Presenter->get->render('common/paginate', %template_params);
}
1;
@@ -241,64 +413,69 @@ Usage from a template:
[% USE L %]
- [% L.select_tag('direction', [ [ 'left', 'To the left' ], [ 'right', 'To the right' ] ]) %]
+ [% L.select_tag('direction', [ [ 'left', 'To the left' ], [ 'right', 'To the right', 1 ] ]) %]
+
+ [% L.select_tag('direction', [ { direction => 'left', display => 'To the left' },
+ { direction => 'right', display => 'To the right' } ],
+ value_key => 'direction', title_key => 'display', default => 'right')) %]
- [% L.select_tag('direction', L.options_for_select([ { direction => 'left', display => 'To the left' },
- { direction => 'right', display => 'To the right' } ],
- value => 'direction', title => 'display', default => 'right')) %]
+ [% L.select_tag('direction', [ { direction => 'left', display => 'To the left' },
+ { direction => 'right', display => 'To the right', selected => 1 } ],
+ value_key => 'direction', title_key => 'display')) %]
=head1 DESCRIPTION
A module modeled a bit after Rails' ActionView helpers. Several small
functions that create HTML tags from various kinds of data sources.
+The C attribute is usually calculated automatically. This can be
+overridden by either specifying an C attribute or by setting
+C to trueish.
+
=head1 FUNCTIONS
=head2 LOW-LEVEL FUNCTIONS
-=over 4
+The following items are just forwarded to L:
-=item C
+=over 2
-Converts a name to a HTML id by replacing various characters.
+=item * C
-=item C
+=item * C
-Creates a string from all elements in C<%items> suitable for usage as
-HTML tag attributes. Keys and values are HTML escaped even though keys
-must not contain non-ASCII characters for browsers to accept them.
+=item * C
-=item C
+=back
-Creates an opening and closing HTML tag for C<$tag_name> and puts
-C<$content_string> between the two. If C<$content_string> is undefined
-or empty then only a Etag/E tag will be created. Attributes
-are key/value pairs added to the opening tag.
+=head2 HIGH-LEVEL FUNCTIONS
-C<$content_string> is not HTML escaped.
+The following functions are just forwarded to L:
-=back
+=over 2
-=head2 HIGH-LEVEL FUNCTIONS
+=item * C
-=over 4
+=item * C
-=item C
+=item * C
-Creates a HTML 'select' tag named C<$name> with the contents
-C<$options_string> and with arbitrary HTML attributes from
-C<%attributes>. The tag's C defaults to C.
+=item * C
-The C<$options_string> is usually created by the
-L function. If C<$options_string> is an array
-reference then it will be passed to L
-automatically.
+=item * C
-=item C
+=back
-Creates a HTML 'input type=text' tag named C<$name> with the value
-C<$value> and with arbitrary HTML attributes from C<%attributes>. The
-tag's C defaults to C.
+Available high-level functions implemented in this module:
+
+=over 4
+
+=item C
+
+Creates a HTML 'select' tag with the two entries C and C by
+calling L. C<$value> determines
+which entry is selected. The C<%attributes> are passed through to
+L.
=item C
@@ -306,23 +483,10 @@ Creates a HTML 'textarea' tag named C<$name> with the content
C<$value> and with arbitrary HTML attributes from C<%attributes>. The
tag's C defaults to C.
-=item C
-
-Creates a HTML 'input type=checkbox' tag named C<$name> with arbitrary
-HTML attributes from C<%attributes>. The tag's C defaults to
-C. The tag's C defaults to C<1>.
-
-If C<%attributes> contains a key C