To create a quick and easy Ajax popin you need to do three things - You can do them in basically whatever order you wish:
Specify the Remote Controller
Lets say we want to add a popin to our Account Screen application. Edit the config.xml file for that app.
You will need to add/edit the remotes section to define your remote call:
XML
<remotes>
<remote name=
"time_of_day"
>AccountScreen::Controller::Remote::TimeOfDay
</remote>
</remotes>
The name attribute allows you to specify which remote you want to run when you write your client-side code. The content of the remote tag is the package of the Controller that will run when someone hits your Ajax link.
Create the Remote Controller
We need to create the Controller that we specified in our config file. Mine looks like this:
Perl
package AccountScreen::Controller::Remote::TimeOfDay;
use strict;
use warnings;
use 5.006_000;
use base qw(Solstice::Controller::Remote);
use Solstice::DateTime;
sub new {
my $obj = shift;
return $obj->SUPER::new(@_);
}
sub runRemote {
my $self = shift;
$self->addContentUpdate('solstice_popin_title', 'Time of Day');
$self->addContentUpdate(
'solstice_popin_content',
Solstice::DateTime->new(time)->toCommon()
);
}
1;This is just a basic subclass of Solstice::Controller::Remote. The only special thing it does is sets content updates for two special values solstice_popin_title and solstice_popin_content.
You could also instantiate and paint a view in order to fill out the content.
Create the Popin Button
Finally, you need to create the button or link that triggers the popin, which is a flavor of the standard ButtonService button.
The generateParams method of the View in which I want to have my popin looks like this:
Perl
sub generateParams {
my $self = shift;
my $button_service = Solstice::ButtonService->new();
my $time_of_day_popin = $button_service->makePopinButton({
label => 'Time of Day',
client_action => "run_remote('AccountScreen', 'time_of_day');",
});
$self->setParam('time_of_day_popin', $time_of_day_popin->getTextLink());
}Note the run_remote client action's two arguments - the first is the application in which you define the remote handler, and the second is the name of the handler to run. These match up with the config file we edited above.
Of course, don't forget to add a <-- sol_var time_of_day_popin --> to your template.
That should do it!