/[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 236 - (show annotations)
Sun Sep 7 21:22:10 2008 UTC (15 years, 7 months ago) by dpavlin
File size: 2280 byte(s)
move strix sites import into module Strix::Import so
that command-line script and action can re-use it,
creating on-demand sync for sites.
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 if ( $coll->count == 0 ) {
55 warn "SYNC sites for $instance\n";
56 Strix::Import->sites( $instance );
57 # FIXME re-run query?
58 $coll = A3C::Model::StrixSiteCollection->new;
59 $coll->limit( column => 'instance', value => $instance );
60 }
61
62 return [{ display => _('No sites') }] unless $coll->count;
63
64 #warn "# intance $instance as ",$coll->count," sites\n";
65
66 my $vv = [];
67 while ( my $i = $coll->next ) {
68 push @$vv, {
69 display => $i->naziv,
70 value => $i->site_id,
71 };
72 #warn "## added ",$i->site_id," to available values\n";
73 }
74 #warn "# $field vv = ",dump( $vv );
75 return $vv;
76 } else {
77 die "unknown field $field";
78 }
79 }
80
81 sub sticky_on_success { 1 }
82 sub sticky_on_failure { 1 }
83
84 =head2 take_action
85
86 =cut
87
88 sub take_action {
89 my $self = shift;
90
91 if ( $self->result->success ) {
92 $self->result->message(
93 _("Selected instance %1 site %2",
94 $self->argument_value('instance'),
95 $self->argument_value('site_id')
96 )
97 );
98 # XXX we can't really set two content fields in one pass!!
99 $self->result->content( 'instance' => $self->argument_value('instance') );
100 $self->result->content( 'site_id' => $self->argument_value('site_id') );
101 }
102
103 return 1;
104 }
105
106 1;

  ViewVC Help
Powered by ViewVC 1.1.26