/[A3C]/lib/A3C/Action/StrixSelectSite.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/A3C/Action/StrixSelectSite.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 197 - (show annotations)
Tue Jun 17 21:32:12 2008 UTC (15 years, 10 months ago) by dpavlin
File size: 1995 byte(s)
implemented StrixSelectSite action with two drop-down
menus (which are kept in sync) to select site for
which to show navigation
1 use strict;
2 use warnings;
3
4 =head1 NAME
5
6 A3C::Action::StrixSelectSite
7
8 =cut
9
10 package A3C::Action::StrixSelectSite;
11 use base qw/A3C::Action Jifty::Action/;
12
13 use Data::Dump qw/dump/;
14
15 use Jifty::Param::Schema;
16 use Jifty::Action schema {
17
18 param instance =>
19 label is _('Strix instance'),
20 render as 'Select',
21 is mandatory;
22
23 param site_id =>
24 label is _('Strix site'),
25 render as 'Select',
26 is mandatory;
27
28 };
29
30 sub available_values {
31 my $self = shift;
32 my $field = shift;
33 warn "# available_values( $field )";
34 if ( $field eq 'instance' ) {
35 my $coll = A3C::Model::StrixInstanceCollection->new;
36 $coll->unlimit;
37 $coll->order_by( column => 'instance' );
38
39 my $vv = [];
40 while ( my $i = $coll->next ) {
41 push @$vv, {
42 display => ( $i->_site_name || '['.$i->instance.']' ),
43 value => $i->instance,
44 };
45 }
46 #warn "# $field vv = ",dump( $vv );
47 return $vv;
48 } elsif ( $field eq 'site_id' ) {
49 my $instance = $self->argument_value('instance');
50
51 my $coll = A3C::Model::StrixSiteCollection->new;
52 $coll->limit( column => 'instance', value => $instance );
53
54 return [{ display => _('No sites') }] unless $coll->count;
55
56 warn "# intance $instance as ",$coll->count," sites\n";
57
58 my $vv = [];
59 while ( my $i = $coll->next ) {
60 push @$vv, {
61 display => $i->naziv,
62 value => $i->site_id,
63 };
64 warn $i->site_id;
65 }
66 warn "# $field vv = ",dump( $vv );
67 return $vv;
68 } else {
69 die "unknown field $field";
70 }
71 }
72
73 sub sticky_on_success { 1 }
74 sub sticky_on_failure { 1 }
75
76 =head2 take_action
77
78 =cut
79
80 sub take_action {
81 my $self = shift;
82
83 if ( $self->result->success ) {
84 $self->result->message(
85 _("Selected instance %1 site %2",
86 $self->argument_value('instance'),
87 $self->argument_value('site_id')
88 )
89 );
90 # XXX we can't really set two content fields in one pass!!
91 $self->result->content( 'instance' => $self->argument_value('instance') );
92 $self->result->content( 'site_id' => $self->argument_value('site_id') );
93 }
94
95 return 1;
96 }
97
98 1;

  ViewVC Help
Powered by ViewVC 1.1.26