';
}
-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 ($self, $by, %params) = _hashify(2, @_);
my $controller = $self->{CONTEXT}->stash->get('SELF');
- my $sort_spec = $controller->get_sort_spec;
+ 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 = $controller->get_current_sort_params;
+ 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{by} eq $by) {
- my $current_dir = $current_sort_params{dir} ? 'up' : 'down';
+ 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{dir} || 0);
+ $new_dir = 1 - ($current_sort_params{sort_dir} || 0);
}
- $params{ $sort_spec->{FORM_PARAMS}->[0] } = $by;
- $params{ $sort_spec->{FORM_PARAMS}->[1] } = ($new_dir ? '1' : '0');
+ $params{ $models->sorted->form_params->[0] } = $by;
+ $params{ $models->sorted->form_params->[1] } = ($new_dir ? '1' : '0');
- return '' . _H($title) . $image . '';
+ return '' . _H($title) . $image . '';
}
sub paginate_controls {
- my ($self) = @_;
+ my ($self, %params) = _hashify(1, @_);
my $controller = $self->{CONTEXT}->stash->get('SELF');
- my $paginate_spec = $controller->get_paginate_spec;
- my %paginate_params = $controller->get_current_paginate_params;
+ 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(@_);
- $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};
+ 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 $controller->get_callback(%url_params);
+ return $models->get_callback(%url_params);
},
+ %params,
);
return SL::Presenter->get->render('common/paginate', %template_params);
@@ -680,86 +424,47 @@ Usage from a template:
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.
+The following items are just forwarded to L:
-=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.
+=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
-
-=item C
+The following functions are just forwarded to L:
-Creates a HTML 'select' tag named C<$name> with the contents of one
-'EoptionE' tag for each element in C<\@collection> and with arbitrary
-HTML attributes from C<%attributes>. 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:
+=over 2
-=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 third element is optional and and should contain a boolean.
-If it is true, than the element will be used as default.
+=item * C
-=item 2. A scalar. The scalar is both the value and the title.
+=item * C
-=item 3. A hash reference. In this case C<%attributes> must contain
-I, I and may contain I keys that name the keys in the element to use
-for the value, title and default respectively.
+=item * C
-=item 4. A blessed reference. In this case C<%attributes> must contain
-I, I and may contain I keys that name functions called on the blessed
-reference whose return values are used as the value, title and default
-respectively.
+=item * C
=back
-For cases 3 and 4 C<$attributes{value_key}> defaults to C,
-C<$attributes{title_key}> defaults to C<$attributes{value_key}>
-and C<$attributes{default_key}> defaults to C.
-
-In addition to pure keys/method you can also provide coderefs as I
-and/or I and/or I. If present, these take precedence over keys or methods,
-and are called with the element as first argument. It must return the value, title or default.
-
-Lastly a joint coderef I may be provided, which in turn takes
-precedence over the C and C subs. It will only be called once for each
-element and must return a list of value and title.
+Available high-level functions implemented in this module:
-If the option C is set then an empty element (value
-C) will be used as the first element. The title to display for
-this element can be set with the option C and defaults to
-an empty string.
-
-The option C can be either a scalar or an array reference
-containing the values of the options which should be set to be
-selected.
-
-The tag's C defaults to C.
+=over 4
=item C
@@ -768,49 +473,12 @@ calling L. C<$value> determines
which entry is selected. The C<%attributes> are passed through to
L.
-=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
-
-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.
-
-=item C
-
-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.
-
-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 '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