1 |
package A3C::View::Organization; |
2 |
|
3 |
=head1 NAME |
4 |
|
5 |
A3C::View::Organization |
6 |
|
7 |
=head1 DESCRIPTION |
8 |
|
9 |
Provide search and display form using table |
10 |
|
11 |
=cut |
12 |
|
13 |
use strict; |
14 |
use warnings; |
15 |
|
16 |
use Jifty::View::Declare -base; |
17 |
use base qw/ Jifty::View::Declare::CRUD /; |
18 |
|
19 |
use Data::Dump qw/dump/; |
20 |
|
21 |
sub display_columns { |
22 |
return ( |
23 |
'o', |
24 |
'cn', |
25 |
'hrEduOrgUniqueNumber', |
26 |
# 'hrEduOrgType', |
27 |
'postalAddress', |
28 |
'l', |
29 |
); |
30 |
} |
31 |
|
32 |
sub create_columns { |
33 |
my $self = shift; |
34 |
my $action = shift; |
35 |
return $action->argument_names; |
36 |
#return grep { !( m/_confirm/ || $action->arguments->{$_}{unreadable} ) } $action->argument_names; |
37 |
} |
38 |
|
39 |
template 'search' => sub { |
40 |
my $self = shift; |
41 |
my ($object_type) = ( $self->object_type ); |
42 |
my $search = $self->record_class->as_search_action( |
43 |
moniker => 'search', |
44 |
sticky_on_success => 1, |
45 |
); |
46 |
|
47 |
div { |
48 |
{ class is "jifty_admin" }; |
49 |
render_action( $search => [ |
50 |
'o_contains', |
51 |
'dc_contains', |
52 |
'cn_contains', |
53 |
'hrEduOrgUniqueNumber_contains', |
54 |
'l_contains', |
55 |
'hrEduOrgType', |
56 |
] ); |
57 |
|
58 |
$search->button( |
59 |
label => _('Search'), |
60 |
onclick => { |
61 |
submit => $search, |
62 |
# removed because we don't use search toggle region |
63 |
#refresh => Jifty->web->current_region->parent, |
64 |
args => { page => 1 } |
65 |
} |
66 |
); |
67 |
|
68 |
} |
69 |
}; |
70 |
|
71 |
|
72 |
template 'list' => sub { |
73 |
my $self = shift; |
74 |
|
75 |
my ( $page ) = get('page'); |
76 |
my $item_path = get('item_path') || $self->fragment_for("view"); |
77 |
my $collection = $self->_current_collection(); |
78 |
div { {class is 'crud-'.$self->object_type}; |
79 |
show('./search'); |
80 |
show( './paging_top', $collection, $page ); |
81 |
show( './list_items', $collection, $item_path ); |
82 |
show( './paging_bottom', $collection, $page ); |
83 |
}; |
84 |
}; |
85 |
|
86 |
|
87 |
private template 'list_items' => sub { |
88 |
my $self = shift; |
89 |
my $collection = shift; |
90 |
my $item_path = shift; |
91 |
my $callback = shift; |
92 |
my $object_type = $self->object_type; |
93 |
$collection->_do_search(); # we're going to need the results. |
94 |
# XXX TODO, should use a real API to force the search |
95 |
if ( $collection->count == 0 ) { |
96 |
show('./no_items_found'); |
97 |
} |
98 |
|
99 |
my $o = $self->record_class->new; |
100 |
my $name2label; |
101 |
map { |
102 |
$name2label->{ $_->name } = $_->label; |
103 |
} $o->columns; |
104 |
#warn "# name2label = ",dump( $name2label ); |
105 |
|
106 |
div { class is 'note message'; _('Found %1 results', $collection->pager->total_entries ) } |
107 |
table { |
108 |
{ class is 'list' }; |
109 |
row { |
110 |
th { $name2label->{$_} } foreach $self->display_columns; |
111 |
}; |
112 |
while (my $item = $collection->next) { |
113 |
row { |
114 |
cell { $item->$_ } foreach $self->display_columns; |
115 |
} |
116 |
} |
117 |
}; |
118 |
|
119 |
}; |
120 |
|
121 |
sub per_page { 10 } |
122 |
|
123 |
template 'new' => page { |
124 |
my $self = shift; |
125 |
title is $self->object_type; |
126 |
form { |
127 |
render_region( |
128 |
name => $self->object_type.'-list', |
129 |
path => $self->fragment_base_path.'/new-list' |
130 |
); |
131 |
} |
132 |
}; |
133 |
|
134 |
# in Jifty's template, it's included on bottom of list |
135 |
template 'new-list' => sub { |
136 |
div { |
137 |
{ class is 'list' }; |
138 |
} |
139 |
show( './new_item_region'); |
140 |
}; |
141 |
|
142 |
1; |