';
}
+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{ $models->sorted->form_params->[0] } = $by;
+ $params{ $models->sorted->form_params->[1] } = ($new_dir ? '1' : '0');
+
+ return '' . _H($title) . $image . '';
+}
+
+sub paginate_controls {
+ my ($self, %params) = _hashify(1, @_);
+
+ 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;
+
+ my %paginate_params = $models->get_paginate_args;
+
+ 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;
__END__
@@ -428,81 +409,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', 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' } ],
+ value_key => 'direction', title_key => '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
-
-=item C
-
-Converts a name to a HTML id by replacing various characters.
-
-=item C
+The following items are just forwarded to L:
-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.
+=over 2
-=item C
+=item * C
-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.
+=item * C
-C<$content_string> is not HTML escaped.
+=item * C
=back
=head2 HIGH-LEVEL FUNCTIONS
-=over 4
+The following functions are just forwarded to L:
-=item C
+=over 2
-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
+=item * C
-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.
+=item * C
-=item C
+=item * C
-Creates a HTML 'input type=hidden' tag named C<$name> with the value
-C<$value> and with arbitrary HTML attributes from C<%attributes>. The
-tag's C defaults to C.
+=back
-=item C
+Available high-level functions implemented in this module:
-Creates a HTML 'input type=submit class=submit' tag named C<$name> with the
-value C<$value> and with arbitrary HTML attributes from C<%attributes>. The
-tag's C defaults to C.
+=over 4
-If C<$attributes{confirm}> is set then a JavaScript popup dialog will
-be added via the C handler asking the question given with
-C<$attributes{confirm}>. If request is only submitted if the user
-clicks the dialog's ok/yes button.
+=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
@@ -510,23 +479,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