+-html node------+ | Instructions | +----------------+ ↓ +-form node------+ | Data entry | +----------------+ ↓ +-task node------+ | Database add | +----------------+ ↓ +-html node------+ | Response | +----------------+In this wizard, a user is first presented with a set of instructions, and (typically) a 'Next' button. On clicking the button, they are taken to a form where they can enter information to insert into the database, a 'Back' button to return to the instructions, and a 'Save' button to proceed to the next stage: the task node. This node attempts to add the information from the data entry node into the database and records the response (or any other information from the database). It then forwards the user to the final response node, which displays the success (or otherwise) of the database access.
EnsEMBL::Web::Wizard
class. Typically, the Wizard's are named after the data types which are often seen elsewhere in Ensembl: EnsEMBL::Web::Wizard::Chromosome
, EnsEMBL::Web::Feature
, EnsEMBL::Web::Wizard::User
.
Wizard
module contains all the information required for all possible steps in a wizard guide. Each step (ie, each node) has a name associated with it, and are defined in the %all_nodes
hash. In addition to all nodes being defined, all form elements appearing within all nodes are also defined, in the %form_fields
. All possible messages are also stored in the Wizard
module, in the %messages
hash.
_init
method is called on instantiation. Setting up the %all_nodes
, %form_fields
and %messages
hashes (along with some other configuration options) should be done here. For example, our database addition wizard (for storing names and organisations) could be configured like this:
my %form_fields = (
'user_id' => {
'type'=>'Integer',
'label'=>'',
},
'email' => {
'type'=>'Email',
'label'=>'Email address',
'required'=>'yes',
},
'password' => {
'type'=>'Password',
'label'=>'New Password',
'required'=>'yes',
},
'confirm_password' => {
'type'=>'Password',
'label'=>'Confirm Password',
'required'=>'yes',
},
'name' => {
'type'=>'String',
'label'=>'Your Name',
'required'=>'yes',
},
'org' => {
'type'=>'String',
'label'=>'Organisation',
}
);
my %all_nodes = (
'instructions' => {'title' => 'Add new name wizard',
'page' => 1,
},
'data_entry' => {
'form' => 1,
'title' => 'Please enter your details',
'input_fields' => [qw(name password email org)],
},
'database' => {},
'response' => {'title' => 'Database response',
'page' => 1,
},
);
my %message = (
'success' => "Thank you. Your details were added to the database",
'failure' => 'Sorry. Your request failed.',
);
Wizard
node definitions are in place, the actual logic for each node should to be added.
all_nodes
hash. In this example, the names would be instructions
, data_entry
, database
and response
. A method call is made when each node is processed, depending on the node's name. In this example, each node should also have a similarly named method included in the Wizard
module.
package EnsEMBL::Web::Wizard:DatabaseAdd.pm;
sub _init {
## node definitions and initialisation
...
}
sub instructions {
## empty method - output is determined by
## the component
}
sub data_entry {
my ($self, $object) = @_;
my $wizard = $self->{wizard};
my $node = 'enter_details';
my $form = EnsEMBL::Web::Form->new($node, "/$species/$script", 'post' );
$wizard->add_title($node, $form, $object);
$wizard->add_widgets($node, $form, $object);
$wizard->add_buttons($node, $form, $object);
return $form;
}
sub database {
## database connectivity
...
}
sub response {
## empty method - output is determined by
## the component
}
1;
See the Wizard API documentation for more information.
Wizard
module, the wizard should be configured to be displayed for particular requests. This is done in the corresponding Configuration
module. For example:
sub add {
my $self = shift;
my $object = $self->{'object'};
my $wizard = EnsEMBL::Web::Wizard::User->new($object);
$wizard->add_nodes([qw(introduction data_entry database response)]);
$wizard->default_node('introduction');
$wizard->add_outgoing_edges([
['introduction' => 'data_entry'],
['data_entry' => 'database'],
['database' => 'response'],
]);
$self->add_wizard($wizard);
$self->wizard_panel('Add data');
}
Wizard
's HTML output is determined by the appropriate Component
module. For example, the EnsEMBL::Web::Component::User
component is responsible for displaying information relating to the EnsEMBL::Web::Wizard::User
wizard.
Wizard
(see sub introduction
and sub response
above). Their companion Component
methods determine how these nodes are displayed:
sub introduction {
my ($panel, $object) = @_;
my $html = "..."
## Setup HTML for output
...
$panel->print($html);
return 1;
}
sub data_entry {
my ($panel, $object) = @_;
my $html = "..."
## Setup HTML for output
...
$html .= $panel->form('data_entry')->render();
$panel->print($html);
return 1;
}
page | Sets the node to be an HTML page. |
form | Sets the node to be include a form. |
title | Determines the title of the form for use in Component rendering. |
input_fields | An array of field element names for inclusion in the node's form |
pass_fields | An array of field element names to be passed along to the next node. |
show_fields | An array of field element names for display. These have usually been passed from the previous node. |
button | The label of the button used to arrive at the node. This is displayed on the previous node's page. |
© 2024 Inserm. Hosted by genouest.org. This product includes software developed by Ensembl.