1 |
<%args> |
2 |
$page => 1 |
3 |
$show_description => 0 |
4 |
$show_comment => 0 |
5 |
$order => 'date' |
6 |
</%args> |
7 |
<%init> |
8 |
|
9 |
my $u = Jifty->web->current_user; |
10 |
|
11 |
warn "user->id: ", $u->id, " ", $u->admin ? 'admin' : '', "\n"; |
12 |
|
13 |
use Data::Dumper; |
14 |
warn Dumper( $u->admin ); |
15 |
|
16 |
my $transports = Transports::Model::TransportCollection->new(); |
17 |
if (Jifty->web->current_user->admin) { |
18 |
$transports->unlimit(); |
19 |
} elsif (Jifty->web->current_user->can_import) { |
20 |
$transports->limit( |
21 |
column => 'return_code', |
22 |
operator => 'is', |
23 |
value => 'null', |
24 |
); |
25 |
} else { |
26 |
$transports->limit( |
27 |
column => 'created_by', |
28 |
value => Jifty->web->current_user->id, |
29 |
); |
30 |
} |
31 |
$transports->order_by({ column => $order }); |
32 |
$transports->set_page_info( |
33 |
current_page => $page, |
34 |
per_page => 10, |
35 |
); |
36 |
if (my $nr = $transports->pager->total_entries) { |
37 |
$m->out("Showing $nr transports.") |
38 |
|
39 |
} elsif ( Jifty->web->current_user->can_import ) { |
40 |
$m->out("No transports waiting for import."); |
41 |
} else { |
42 |
$m->out("No transports found.") |
43 |
} |
44 |
|
45 |
</%init> |
46 |
|
47 |
<% Jifty->web->link( |
48 |
label => ( $show_description ? 'no ' : '' ) . ' description', |
49 |
onclick => { |
50 |
replace_with => '/transports/table', |
51 |
args => { show_description => $show_description ? 0 : 1 }, |
52 |
} |
53 |
) %> |
54 |
|
55 |
<% Jifty->web->link( |
56 |
label => ( $show_comment ? 'no ' : '' ) . ' import comment', |
57 |
onclick => { |
58 |
replace_with => '/transports/table', |
59 |
args => { show_comment => $show_comment ? 0 : 1 }, |
60 |
} |
61 |
) %> |
62 |
|
63 |
<%perl> |
64 |
use Data::Dumper; |
65 |
my $t = $transports->first; |
66 |
$transports->goto_first_item; |
67 |
warn Dumper( $t->id ); |
68 |
|
69 |
sub th { |
70 |
my ($label, $this_order, $order) = @_; |
71 |
warn "order: $order this_order: $this_order\n"; |
72 |
if ($order eq $this_order) { |
73 |
return $label; |
74 |
} else { |
75 |
return Jifty->web->link( |
76 |
label => $label, |
77 |
onclick => { |
78 |
args => { order => $this_order }, |
79 |
} |
80 |
); |
81 |
} |
82 |
} |
83 |
|
84 |
</%perl> |
85 |
|
86 |
<table> |
87 |
<tr> |
88 |
<th><% th('src','source',$order) %></th> |
89 |
<th><% th('dest','destination',$order) %></th> |
90 |
<th><% th('class','class',$order) %></th> |
91 |
<th><% th('req.nr','request_nr',$order) %></th> |
92 |
<th><% th('dep','client_dependent',$order) %></th> |
93 |
<th><% th('created by','created_by',$order) %></th> |
94 |
% if ($show_description) { |
95 |
<th>description</th> |
96 |
% } |
97 |
<th><% th('import','return_code',$order) %></th> |
98 |
% if ($show_comment) { |
99 |
<th>comment</th> |
100 |
% } |
101 |
</th> |
102 |
% if (Jifty->web->current_user->admin) { |
103 |
<th> </th> |
104 |
% } |
105 |
</tr> |
106 |
|
107 |
% my $i = 0; $transports->goto_first_item; |
108 |
% while (my $t = $transports->next) { |
109 |
|
110 |
<tr class="<% ++$i % 2 == 0 ? 'alt' : '' %>"> |
111 |
<td><% $t->source->name %></td> |
112 |
<td><% $t->destination->name %></td> |
113 |
<td><% $t->class->name %></td> |
114 |
<td><tt><% $t->request_nr %></tt></td> |
115 |
<td> |
116 |
<% $t->client_dependent ? 'client' : 'none' %> |
117 |
</td> |
118 |
<td><em><% $t->created_by->name %></em></td> |
119 |
% if ($show_description) { |
120 |
<td><% $t->description || '' %></td> |
121 |
% } |
122 |
<td> |
123 |
% if ($t->return_code && $t->return_code->name) { |
124 |
<% $t->return_code->name %> |
125 |
% } elsif (Jifty->web->current_user->can_import) { |
126 |
<% Jifty->web->link( label => 'import', onclick => { |
127 |
replace_with => '/transports/import', |
128 |
args => { id => $t->id }, |
129 |
} ) %> |
130 |
% } else { |
131 |
pending |
132 |
% } |
133 |
</td> |
134 |
% if ($show_comment) { |
135 |
<td><% $t->comment || '' %></td> |
136 |
% } |
137 |
% if (Jifty->web->current_user->admin) { |
138 |
<td><% Jifty->web->link( label => 'edit', onclick => { |
139 |
replace_with => '/transports/edit', |
140 |
args => { id => $t->id }, |
141 |
} ) %></td> |
142 |
% } |
143 |
</tr> |
144 |
% } |
145 |
</table> |
146 |
|
147 |
% if ($transports->pager->previous_page) { |
148 |
<% Jifty->web->link( |
149 |
label => "Previous", |
150 |
onclick => { args => { page => $transports->pager->previous_page } } |
151 |
) %> |
152 |
% } |
153 |
|
154 |
% if ($transports->pager->last_page > 1) { |
155 |
page <% $page %> of <% $transports->pager->last_page %> |
156 |
% } |
157 |
|
158 |
% if ($transports->pager->next_page) { |
159 |
<% Jifty->web->link( |
160 |
label => "Next", |
161 |
onclick => { args => { page => $transports->pager->next_page } } |
162 |
) %> |
163 |
% } |
164 |
|