';
+}
+
+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;
@@ -93,70 +383,276 @@ 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
+
+The following items are just forwarded to L:
+
+=over 2
+
+=item * C
+
+=item * C
+
+=item * C
+
+=back
+
+=head2 HIGH-LEVEL FUNCTIONS
+
+The following functions are just forwarded to L:
+
+=over 2
+
+=item * C
+
+=item * C
+
+=item * C
+
+=item * C
+
+=item * C
+
+=back
+
+Available high-level functions implemented in this module:
+
=over 4
-=item C
+=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
+
+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 date input field, with an attached javascript that will open a
+calendar on click.
+
+=item C
+
+Creates a HTML 'Escript type="text/javascript" src="..."E'
+tag for each file name parameter passed. Each file name will be
+postfixed with '.js' if it isn't already and prefixed with 'js/' if it
+doesn't contain a slash.
+
+=item C
+
+Creates a HTML 'Elink rel="text/stylesheet" href="..."E' tag
+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
+
+Will create a tabbed area. The tabs should be created with the helper function
+C. Example:
+
+ [% L.tabbed([
+ L.tab(LxERP.t8('Basic Data'), 'part/_main_tab.html'),
+ L.tab(LxERP.t8('Custom Variables'), 'part/_cvar_tab.html', if => SELF.display_cvar_tab),
+ ]) %]
+
+=item C
+
+Creates a generic input tag or textarea tag, depending on content size. The
+amount of desired rows must be either given with the C parameter or can
+be computed from the value and the C paramter, Accepted parameters
+include C for rendering a minimum of rows if a textarea is displayed.
+
+You can force input by setting rows to 1, and you can force textarea by setting
+rows to anything >1.
-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
+Creates a JavaScript snippet calling the jQuery function
+C on the select control with the ID C<$id>. The
+select itself is not created. C<%params> can contain the following
+entries:
-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.
+=over 2
-=item C
+=item C
-Creates a string suitable for a HTML 'select' tag consisting of one
-'EoptionE' tag for each element in C<\@collection>. The value
-to use and the title to display are extracted from the elements in
-C<\@collection>. Each element can be one of four things:
+The label of the list of available options. Defaults to the
+translation of 'Available'.
-=over 12
+=item C
-=item 1. An array reference with at least two elements. The first element is
-the value, the second element is its title.
+The label of the list of selected options. Defaults to the
+translation of 'Selected'.
-=item 2. A scalar. The scalar is both the value and the title.
+=back
+
+=item C
+
+Makes the children of the DOM element C<$selector> (a jQuery selector)
+sortable with the I library. The children can be
+dragged & dropped around. After dropping an element an URL can be
+postet to with the element IDs of the sorted children.
+
+If this is used then the JavaScript file C must be
+included manually as well as it isn't loaded via C<$::form-gt;header>.
+
+C<%params> can contain the following entries:
+
+=over 2
+
+=item C
+
+The URL to POST an AJAX request to after a dragged element has been
+dropped. The AJAX request's return value is ignored by default. If given then
+C<$params{with}> must be given as well.
+
+=item C
+
+If trueish then the AJAX request's return is accepted.
+
+=item C
+
+A string that is interpreted as the prefix of the children's ID. Upon
+POSTing the result each child whose ID starts with C<$params{with}> is
+considered. The prefix and the following "_" is removed from the
+ID. The remaining parts of the IDs of those children are posted as a
+single array parameter. The array parameter's name is either
+C<$params{as}> or, missing that, C<$params{with}>.
+
+=item C
+
+Sets the POST parameter name for AJAX request after dropping an
+element (see C<$params{with}>).
+
+=item C
+
+An optional jQuery selector specifying which part of the child element
+is dragable. If the parameter is not given then it defaults to
+C<.dragdrop> matching DOM elements with the class C. If the
+parameter is set and empty then the whole child element is dragable,
+and clicks through to underlying elements like inputs or links might
+not work.
+
+=item C
+
+If trueish then the children will not be recolored. The default is to
+recolor the children by setting the class C on odd and
+C on even entries.
+
+=item C
+
+An optional JavaScript string that is evaluated before sending the
+POST request. The result must be a string that is appended to the URL.
+
+=back
+
+Example:
+
+
+
+