1 package Reaction::UI::Window;
4 use Reaction::UI::FocusStack;
8 has ctx => (isa => 'Catalyst', is => 'ro', required => 1);
9 has view_name => (isa => 'Str', is => 'ro', lazy_fail => 1);
10 has content_type => (isa => 'Str', is => 'ro', lazy_fail => 1);
11 has title => (isa => 'Str', is => 'rw', default => sub { 'Untitled window' });
13 # XXX compile failure because the Catalyst::View constraint would be
14 # auto-generated which doesn't work with unions. ::Types::Catalyst needed.
15 #isa => 'Catalyst::View|Reaction::UI::View',
16 isa => 'Object', is => 'ro', lazy_build => 1
19 isa => 'Reaction::UI::FocusStack',
20 is => 'ro', required => 1,
21 default => sub { Reaction::UI::FocusStack->new },
24 implements build_view => as {
26 return $self->ctx->view($self->view_name);
29 implements flush => as {
35 implements flush_events => as {
38 foreach my $type (qw/query body/) {
39 my $meth = "${type}_parameters";
40 my $param_hash = $ctx->req->$meth;
41 $self->focus_stack->apply_events($ctx, $param_hash);
45 implements flush_view => as {
47 return if $self->ctx->res->status =~ /^3/ || length($self->ctx->res->body);
48 $self->ctx->res->body(
49 $self->view->render_window($self)
51 $self->ctx->res->content_type($self->content_type);
54 # required by old Renderer::XHTML
56 implements render_viewport => as {
59 return $self->view->render_viewport($self, $vp);
68 Reaction::UI::Window - Container for rendering the UI elements in
72 my $window = Reaction::UI::Window->new(
74 view_name => $view_name,
75 content_type => $content_type,
76 title => $window_title,
79 # More commonly, as Reaction::UI::RootController creates one for you:
80 my $window = $ctx->stash->{window};
82 # Resolve current events and render the view of the UI
83 # elements of this Window:
84 # This is called by the end action of Reaction::UI::RootController
87 # Resolve current events:
88 $window->flush_events();
90 # Render the top ViewPort in the FocusStack of this Window:
91 $window->flush_view();
93 # Render a particular ViewPort:
94 $window->render_viewport($viewport);
97 [% window.render_viewport(self.inner) %]
99 # Add a ViewPort to the UI:
100 $window->focus_stack->push_viewport('Reaction::UI::ViewPort');
104 A Window object is created and stored in the stash by
105 L<Reaction::UI::RootController>, it is used to contain all the
106 elements (ViewPorts) that make up the UI. The Window is rendered in
107 the end action of the RootController to make up the page.
109 To add L<ViewPorts|Reaction::UI::ViewPort> to the stack, read the
110 L<Reaction::UI::FocusStack> and L<Reaction::UI::ViewPort> documentation.
112 Several Window attributes are set by
113 L<Reaction::UI::RootController/begin> when a new Window is created,
114 these are as follows:
120 The current L<Catalyst> context object is set.
124 The view_name is set from the L<Reaction::UI::RootController> attributes.
128 The content_type is set from the L<Reaction::UI::RootController> attributes.
132 The window_title is set from the L<Reaction::UI::RootController> attributes.
142 =item Arguments: none
146 Retrieve the current L<Catalyst> context object.
152 =item Arguments: none
156 Retrieve the name of the L<Catalyst::View> component used to render
157 this Window. If this has not been set, rendering the Window will fail.
163 =item Arguments: none
167 Retrieve the content_type for the page. If this has not been set,
168 rendering the Window will fail.
174 =item Arguments: $title?
180 Retrieve the title of this page, if not set, it will default to
187 =item Arguments: none
191 Retrieve the L<Catalyst::View> instance, this can be set, or will be
192 instantiated using the L<view_name> class.
198 =item Arguments: none
202 $window->focus_stack->push_viewport('Reaction::UI::ViewPort');
204 Retrieve the L<stack|Reaction::UI::FocusStack> of
205 L<ViewPorts|Reaction::UI::ViewPorts> that contains all the UI elements
206 for this Window. Use L<Reaction::UI::FocusStack/push_viewport> on this
207 to create more elements. An empty FocusStack is created by the
208 RootController when the Window is created.
210 =head2 render_viewport
214 =item Arguments: $viewport
218 $window->render_viewport($viewport);
220 [% window.render_viewport(self.inner) %]
222 Calls render on the L<view> object used by this Window. The following
229 The L<Catalyst> context object.
233 The ViewPort object to be rendered.
241 The string that describes the layout from L<Reaction::UI::ViewPort/layout>.
249 =item Arguments: none
253 Synchronize the current events with all the L<Reaction::UI::ViewPort>
254 objects in the UI, then render the root ViewPort. This is called for
255 you by L<Reaction::UI::RootController/end>.
261 =item Arguments: none
265 Resolves all the current events, first the query parameters then the
266 body parameters, with all the L<Reaction::UI::ViewPort> objects in the
267 UI. This calls L<Reaction::UI::FocusStack/apply_events>. This method
268 is called by L<flush>.
274 =item Arguments: none
278 Renders the page into the L<Catalyst::Response> body, unless the
279 response status is already set to 3xx, or the body has already been
280 filled. This calls L<render_viewport> with the root
281 L<Reaction::UI::ViewPort> from the L<focus_stack>. This method is
286 See L<Reaction::Class> for authors.
290 See L<Reaction::Class> for the license.