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