1 |
dpavlin |
125 |
package A3C::View::Organization; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings; |
5 |
|
|
|
6 |
|
|
use Jifty::View::Declare -base; |
7 |
|
|
use base qw/ Jifty::View::Declare::CRUD /; |
8 |
|
|
|
9 |
|
|
use Data::Dump qw/dump/; |
10 |
|
|
|
11 |
|
|
sub display_columns { |
12 |
|
|
return ( |
13 |
|
|
'o', |
14 |
|
|
'cn', |
15 |
|
|
'hrEduOrgUniqueNumber', |
16 |
|
|
'hrEduOrgType', |
17 |
|
|
'postalAddress', |
18 |
|
|
'l', |
19 |
|
|
); |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
template 'search' => sub { |
23 |
|
|
my $self = shift; |
24 |
|
|
my ($object_type) = ( $self->object_type ); |
25 |
|
|
my $search = $self->record_class->as_search_action( |
26 |
|
|
moniker => 'search', |
27 |
|
|
sticky_on_success => 1, |
28 |
|
|
); |
29 |
|
|
|
30 |
|
|
div { |
31 |
|
|
{ class is "jifty_admin" }; |
32 |
|
|
render_action( $search => [ |
33 |
|
|
'o_contains', |
34 |
|
|
'dc_contains', |
35 |
|
|
'hrEduOrgUniqueNumber_contains', |
36 |
|
|
'l_contains', |
37 |
|
|
'hrEduOrgType', |
38 |
|
|
] ); |
39 |
|
|
|
40 |
|
|
$search->button( |
41 |
|
|
label => _('Search'), |
42 |
|
|
onclick => { |
43 |
|
|
submit => $search, |
44 |
|
|
# removed because we don't use search toggle region |
45 |
|
|
#refresh => Jifty->web->current_region->parent, |
46 |
|
|
args => { page => 1 } |
47 |
|
|
} |
48 |
|
|
); |
49 |
|
|
|
50 |
|
|
} |
51 |
|
|
}; |
52 |
|
|
|
53 |
|
|
|
54 |
|
|
template 'list' => sub { |
55 |
|
|
my $self = shift; |
56 |
|
|
|
57 |
|
|
my ( $page ) = get('page'); |
58 |
|
|
my $item_path = get('item_path') || $self->fragment_for("view"); |
59 |
|
|
my $collection = $self->_current_collection(); |
60 |
|
|
div { {class is 'crud-'.$self->object_type}; |
61 |
|
|
show('./search'); |
62 |
|
|
show( './paging_top', $collection, $page ); |
63 |
|
|
show( './list_items', $collection, $item_path ); |
64 |
|
|
show( './paging_bottom', $collection, $page ); |
65 |
|
|
}; |
66 |
|
|
}; |
67 |
|
|
|
68 |
|
|
|
69 |
|
|
private template 'list_items' => sub { |
70 |
|
|
my $self = shift; |
71 |
|
|
my $collection = shift; |
72 |
|
|
my $item_path = shift; |
73 |
|
|
my $callback = shift; |
74 |
|
|
my $object_type = $self->object_type; |
75 |
|
|
$collection->_do_search(); # we're going to need the results. |
76 |
|
|
# XXX TODO, should use a real API to force the search |
77 |
|
|
if ( $collection->count == 0 ) { |
78 |
|
|
show('./no_items_found'); |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
my $o = $self->record_class->new; |
82 |
|
|
my $name2label; |
83 |
|
|
map { |
84 |
|
|
$name2label->{ $_->name } = $_->label; |
85 |
|
|
} $o->columns; |
86 |
|
|
#warn "# name2label = ",dump( $name2label ); |
87 |
|
|
|
88 |
|
|
div { _('Found %1 results', $collection->count ) } |
89 |
|
|
table { |
90 |
|
|
{ class is 'list' }; |
91 |
|
|
row { |
92 |
|
|
th { $name2label->{$_} } foreach $self->display_columns; |
93 |
|
|
}; |
94 |
|
|
while (my $item = $collection->next) { |
95 |
|
|
row { |
96 |
|
|
cell { $item->$_ } foreach $self->display_columns; |
97 |
|
|
} |
98 |
|
|
} |
99 |
|
|
}; |
100 |
|
|
|
101 |
|
|
}; |
102 |
|
|
|
103 |
|
|
sub per_page { 10 } |
104 |
|
|
|
105 |
|
|
1; |