use Rose::Object::MakeMethods::Generic (
scalar => [ qw(controller model query with_objects filtered sorted paginated finalized final_params) ],
- 'scalar --get_set_init' => [ qw(handlers source additional_url_params) ],
+ 'scalar --get_set_init' => [ qw(handlers source list_action additional_url_params) ],
array => [ qw(plugins) ],
);
my @plugins;
for my $plugin (qw(filtered sorted paginated)) {
- next unless my $spec = delete $params{$plugin} // {};
+ next if exists($params{$plugin}) && !$params{$plugin};
+
+ my $spec = delete $params{$plugin} // {};
my $plugin_class = "SL::Controller::Helper::GetModels::" . ucfirst $plugin;
push @plugins, $self->$plugin($plugin_class->new(%$spec, get_models => $self));
}
);
};
- $self->registere_handlers('callback' => $callback);
+ $self->register_handlers('callback' => $callback);
+}
+
+sub get_callback_params {
+ my ($self, %override_params) = @_;
+
+ my %default_params = $self->_run_handlers('callback', action => $self->list_action);
}
sub get_callback {
my ($self, %override_params) = @_;
- my %default_params = $self->_run_handlers('callback', action => $self->controller->action_name);
+ my %default_params = $self->get_callback_params(%override_params);
return $self->controller->url_for(%default_params, %override_params);
}
$::form
}
+sub init_list_action {
+ $_[0]->controller->action_name
+}
+
sub init_additional_url_params { +{} }
1;
=head1 NAME
-SL::Controller::Helper::GetModels - Base class for a the GetModels system.
+SL::Controller::Helper::GetModels - Base class for the GetModels system.
=head1 SYNOPSIS
=head1 OVERVIEW
Building a CRUD controller would be easy, were it not for those stupid
-list actions. People unreasonable expect stuff like filtering, sorting,
+list actions. People unreasonably expect stuff like filtering, sorting,
paginating, exporting etc simply to work. Well, lets try to make it simply work
a little.
the means to retrieve the information when needed to display sort headers or
paginating footers.
-Information about the requested data query can be stored into the object up to
+Information about the requested data query can be stored in the object up to
a certain point, from which on the object becomes locked and can only be
accessed for information. (See C<STATES>).
Enable or disable the specified plugin. Useful to disable paginating for
exports for example. C<is_enabled_plugin> can be used to check the current
-state fo a plugin.
+state of a plugin.
Must not be finalized to use this.
Note that most higher functions will call this themselves to force a finalized
state. If you do use it it must come before any other finalizing methods, and
-will most likely function as a reminder or maintainers where your codes
+will most likely function as a reminder for maintainers where your code
switches from configuration to finalized state.
=item source HASHREF
=item Init
-In this state every information needed from the source ($::form) has been read
+In this state all the information needed from the source ($::form) has been read
and subsequent changes to the source have no effect. In the current
implementation this will happen during creation, so that the return value of
C<new> is already in state C<Init>.
The name of the model for this GetModels instance. If none is given, the model
is inferred from the name of the controller class.
+=item list_action ACTION
+
+If callbacks are generated, use this action instead of the current action.
+Usually you can omit this. In case the reporting is done without redirecting
+from a mutating action, this is necessary to have callbacks for paginating and
+sorting point to the correct action.
+
=item sorted PARAMS
=item paginated PARAMS
=item filtered PARAMS
Configuration for plugins. If the option for any plugin is omitted, it defaults
-to enabled and configured by default. Giving a falsish value as first argument
+to enabled and is configured by default. Giving a falsish value as first argument
will disable the plugin.
If the value is a hashref, it will be passed to the plugin's C<init> method.