Line # Revision Author
1 198 ahitrov <script type="text/javascript">
2 <!--
3 var aIDs = new Array (<% scalar @$documents ? join (',', map { $_->id } @$documents) : '' %>);
4 function delete_check () {
5 for ( var i = 0; i < aIDs.length; i++ ) {
6 var sFieldName = 'delete_' + aIDs[i] + '_id';
7 var oField = document.forms['section_browse'].elements[sFieldName];
8 if ( oField.checked ) {
9 oField.checked = 0;
10 } else {
11 oField.checked = 1;
12 }
13 }
14 }
15 //-->
16 </script>
17 <form name="section_browse" action="./" method="POST">
18 <table width="100%" border="0" cellpadding="4" cellspacing="0" class="tlistdocs">
19 <tr bgcolor="#efefef">
20 628 ahitrov % unless ( $no_inline ) {
21 198 ahitrov <th><a href="javascript:delete_check()" onclick="delete_check(); return false;"><img src="/contenido/i/actions/delete.gif" width="14" height="17" alt="Удаление документов" align="absmiddle" border="0" hspace="1"></a></th>
22 628 ahitrov % }
23 256 ahitrov <th>#</th>
24 198 ahitrov %
25 % foreach (@$columns) {
26 <th><% $_->{shortname} || $_->{rusname} %></th>
27 % }
28 %
29 </tr>
30 %
31 % unless (@$documents) {
32 <tr><td align="center" colspan="<% scalar @$columns %>">Документы не найдены</td></tr>
33 % }
34 % foreach my $document (@$documents) {
35 638 ahitrov % unless ( defined $status ) {
36 % if ( ($document->status == 1 || $document->status == 6 || $document->status == 7 || $document->status == 8) && (!$active_rights || $active_rights == 1) ) {
37 % $href = 'take_care.html';
38 % @actions = { href => $href, name => 'обработать' };
39 % $user_id = 'manager_id';
40 % } elsif ( $document->status == 2 && (!$active_rights || $active_rights == 2) ) {
41 % $href = 'facility.html';
42 % @actions = { href => $href, name => 'собрать' };
43 % $user_id = 'vault_id';
44 % } elsif ( $document->status == 3 && (!$active_rights || $active_rights == 3) ) {
45 % $href = 'delivery.html';
46 % @actions = { href => $href, name => 'доставить' };
47 % $user_id = 'postman_id';
48 % } elsif ( $document->status == 4 && !$active_rights ) {
49 % $href = 'delivery.html';
50 % @actions = { href => $href, name => 'просмотр' };
51 % $user_id = 'postman_id';
52 % } elsif ( $document->status == 5 && !$active_rights ) {
53 % $href = 'delivery.html';
54 % @actions = { href => $href, name => 'просмотр' };
55 % $user_id = 'postman_id';
56 % }
57 % }
58 198 ahitrov % next unless ref($document);
59 % my $document_access = $user->section_accesses($user, $document->section);
60 256 ahitrov % my $style = $document->contenido_status_style ? ' style="'.$document->contenido_status_style.'"' : '';
61 % my ($a1, $a2) = $href ? ('<a href="./'.$href.'?id='.$document->id.($params_unclassed ? '&'.$params_unclassed : '').'"'.$style.'>','</a>') : ('','');
62 754 ahitrov % my $tr_style = $document->company_id ? ' style="background:#d6eaf8;"' : '';
63 <tr valign="top"<% $tr_style %>>
64 628 ahitrov % unless ( $no_inline ) {
65 198 ahitrov <td nowrap>\
66 628 ahitrov % if ($document_access == 2) {
67 % $delete_status = 1;
68 198 ahitrov <input type="checkbox" name="<% 'delete_'.$document->id.'_id' %>">
69 628 ahitrov % } else {
70 198 ahitrov &nbsp;
71 628 ahitrov % }
72 </td>
73 198 ahitrov % }
74 256 ahitrov <td><span<% $style %> class="<% $document->status ? '':'hiddensect' %>"><% $a1.$document->id.$a2 %></span></td>
75 198 ahitrov %
76 % for my $col (@$columns) {
77 270 ahitrov % my $attr = $col->{attr};
78 % if ($attr eq 'dtime') {
79 198 ahitrov %
80 <td nowrap><& "/contenido/components/show_dtime.msn", dtime=>$document->{dtime} &>\
81 % if ($document->{ctime} ne $document->{mtime}) {
82 % my $colortime = '#c66';
83 <div style="color:<% $colortime %>;"><& "/contenido/components/show_dtime.msn", dtime=>$document->{mtime} &></div>\
84 % }
85 %
86 270 ahitrov % } elsif ($attr eq 'name') {
87 198 ahitrov <td><span<% $style %> class="<% $document->status ? '':'hiddensect' %>">\
88 %
89 % my $name=$document->name ? $document->name : 'Безымянный документ N'.$document->id;
90 <% $a1 %><% $name | h %><% $a2 %>\
91 %
92 </span>\
93 %
94 270 ahitrov % } elsif ($attr eq 'id') {
95 198 ahitrov %
96 <td><span class="<% $document->status ? '':'hiddensect' %>">\
97 % if ($document_access == 2) {
98 <a href="document.html?id=<% $document->id %>&class=<% $document->class %><% $params_unclassed ? '&'.$params_unclassed : '' %>"><% $document->id %>&nbsp;</a>\
99 % } else {
100 <% $document->id %>&nbsp;\
101 % }
102 </span>\
103 %
104 % } elsif ( exists $col->{inline} && $col->{inline} ) {
105 % $inline_status = 1;
106 % if ( $col->{type} =~ /^(string|integer|float)$/ && $col->{inline} ) {
107 % my $style = $col->{inline_style} ? $col->{inline_style} : ($col->{type} =~ /^(integer|float)$/ ? 'text-align:right; ' : '' );
108 <td><input type="text" name="<% 'update_'.$document->id.'_'.$attr %>" value="<% $document->$attr %>" style="<% $col->{inline_width} ? 'width:'.$col->{inline_width}.'px;' : 'width:65px; ' %> <% $col->{inline_style} || '' %>">
109 % } elsif ($col->{type} eq 'checkbox') {
110 % my $checked = $document->$attr ? ' checked' : '';
111 <td align="center"><input type="checkbox" name="<% 'update_'.$document->id.'_'.$attr %>"<% $checked %>>
112 % } elsif ($col->{type} eq 'select') {
113 % my $options = {};
114 % if ($toopi && (ref($toopi) eq 'HASH') && (exists($toopi->{$document->class}))) {
115 % %{ $options } = %{ $toopi->{$document->class} };
116 % }
117 270 ahitrov % my $values = $options->{$attr};
118 198 ahitrov <td><select name="<% 'update_'.$document->id.'_'.$attr %>">
119 % if ( ref $values eq 'ARRAY' ) {
120 % foreach my $val ( @$values ) {
121 % my $selected = $val eq $document->$attr ? ' selected' : '';
122 <option value="<% $val %>"<% $selected %>><% $val %>
123 % }
124 % }
125 </select>
126 % } elsif ($col->{type} eq 'status') {
127 % my $cases = $col->{cases};
128 % if ( ref $cases eq 'ARRAY' ) {
129 <td><select name="<% 'update_'.$document->id.'_'.$attr %>" style="<% $col->{inline_width} ? 'width:'.$col->{inline_width}.'px;' : '' %> <% $col->{inline_style} || '' %>">
130 % foreach my $case ( @$cases ) {
131 % my $selected = $case->[0] eq $document->$attr ? ' selected' : '';
132 <option value="<% $case->[0] %>"<% $selected %>><% $case->[1] %>
133 % }
134 </select>
135 % }
136 % }
137 %
138 270 ahitrov % } elsif ($attr eq 'class') {
139 198 ahitrov %
140 <td><% $document->class_name %>&nbsp;<font color="#999999">(<% $document->class %>)</font>\
141 %
142 % } elsif ($col->{type} eq 'datetime') {
143 %
144 270 ahitrov <td nowrap><& "/contenido/components/show_dtime.msn", dtime=>$document->$attr &>\
145 198 ahitrov %
146 270 ahitrov % } elsif ($attr eq '_act_') {
147 198 ahitrov % my $actions;
148 % if ( $document->$user_id == $user->id ) {
149 % $actions = join (' | ', map { '<a href="./'.$_->{href}.'?id='.$document->id.($params_unclassed ? '&'.$params_unclassed : '').'">'.$_->{name}.'</a>' } @actions);
150 % } else {
151 % my $profile = exists $users{$document->$user_id} ? $users{$document->$user_id} : undef;
152 % unless ( ref $profile ) {
153 % $profile = $keeper->get_user_by_id( $document->$user_id );
154 % $users{$profile->id} = $profile if ref $profile;
155 % }
156 % if ( ref $profile ) {
157 % $actions = $profile->name;
158 % } else {
159 % $actions = join (' | ', map { '<a href="./'.$_->{href}.'?id='.$document->id.($params_unclassed ? '&'.$params_unclassed : '').'">'.$_->{name}.'</a>' } @actions);
160 % }
161 % }
162 303 ahitrov % if ( $active_rights == 0 ) {
163 638 ahitrov % if ( $user_id && $user_id eq 'manager_id' && $document->$user_id && $document->$user_id != $user->id ) {
164 303 ahitrov % $actions .= ' (<a href="/contenido/webshop/?drop_owner=1&id='.$document->id.($params_unclassed ? '&'.$params_unclassed : '').'&field='.$user_id.'">unlock</a>)'
165 % } else {
166 % $actions = join (' | ', map { '<a href="./'.$_->{href}.'?id='.$document->id.($params_unclassed ? '&'.$params_unclassed : '').'">'.$_->{name}.'</a>' } @actions);
167 % }
168 % }
169 198 ahitrov <td nowrap><% $actions %>\
170 % if ( $inline_status ) {
171 <input type="hidden" name="update_<% $document->id %>_class" value="<% $document->class %>">
172 % }
173 % if ( $delete_status ) {
174 <input type="hidden" name="delete_<% $document->id %>_class" value="<% $document->class %>">
175 % }
176 %
177 % } else {
178 %
179 % if ($col->{type} eq 'date') {
180 270 ahitrov % my $date=$document->$attr;
181 198 ahitrov % $date=~/(\d{4}-\d{2}-\d{2})/;
182 <td nowrap align="right"><% $1 || '&nbsp;' %>\
183 % } elsif ($col->{type} eq 'datetime') {
184 270 ahitrov <td nowrap align="right"><% $document->$attr || '&nbsp;' %>\
185 198 ahitrov % } elsif ($col->{type} eq 'integer') {
186 270 ahitrov <td align="right"><% $document->$attr %>&nbsp;\
187 198 ahitrov % } elsif ($col->{type} eq 'lookup') {
188 <td align="left">\
189 270 ahitrov % my $id = $document->$attr;
190 198 ahitrov % if ($id) {
191 % my ($doc)=$keeper->get_documents( ( ref($col->{lookup_opts}) ? %{$col->{lookup_opts}} : () ), id=>$id);
192 % if ($doc) {
193 270 ahitrov <a href="/contenido/document.html?id=<% $doc->id %>&class=<% $doc->class %><% $params_unclassed ? '&'.$params_unclassed : '' %>"><% $doc->name || $doc->id %></a>&nbsp;\
194 198 ahitrov % } else {
195 270 ahitrov <span class="hiddensect"><% $document->$attr %>???</span>\
196 198 ahitrov % }
197 % } else {
198 <span class="hiddensect">NULL</span>\
199 % }
200 % } elsif ($col->{type} eq 'status') {
201 % my $status_map = ref $col->{cases} eq 'ARRAY' ? $col->{cases} : $keeper->default_status();
202 270 ahitrov % my ($doc_status) = grep { $_->[0] eq $document->$attr } @$status_map;
203 % $doc_status ||= [$document->$attr, 'Неизвестный'];
204 198 ahitrov <td nowrap><% $doc_status->[1].'('.$doc_status->[0].')' %>\
205 % } else {
206 270 ahitrov <td><% defined($document->$attr) ? $document->$attr : '&nbsp;' %>\
207 198 ahitrov % }
208 % }
209 </td>
210 %
211 % } #- for @columns
212 %
213 </tr>
214 % } #- foreach @documents
215 </table>
216 % if ( ref $filter eq 'HASH' ) {
217 % while ( my ($key, $value) = each %$filter ) {
218 % next if $key eq 's';
219 <input type="hidden" name="<% $key %>" value="<% $value |h %>">
220 % }
221 % }
222 628 ahitrov % if ( !$no_inline && ($inline_status || $delete_status) ) {
223 198 ahitrov <div style="text-align:right; padding:10px 0;">
224 % if ( $inline_status ) {
225 <input type="submit" name="update" value="Сохранить изменения" class="input_btn">
226 % }
227 % if ( $delete_status ) {
228 <input type="submit" name="delete" value="Удалить выбранные" class="input_btn" onclick="return confirm('Все отмеченные позиции будут удалены');">
229 % }
230 </div>
231 % }
232 </form>
233 <%args>
234
235 $section => undef
236 $documents => undef
237 $columns => undef
238 $id => undef
239 $filter => undef
240 $status => undef
241 628 ahitrov $no_inline => undef
242 198 ahitrov
243 </%args>
244 <%init>
245
246 return unless ref $documents eq 'ARRAY';
247 return unless ref $columns eq 'ARRAY';
248
249 my $toopi = $project->documents();
250 my $inline_status = 0;
251 my $delete_status = 0;
252 my $params = ref $filter eq 'HASH' ? join ('&', map { $_.'='.$filter->{$_} } keys %$filter ) : '';
253 my $params_unclassed = ref $filter eq 'HASH' ? join ('&', map { $_.'='.$filter->{$_} } grep { $_ ne 'class' } keys %$filter ) : '';
254 my $params_unsection = ref $filter eq 'HASH' ? join ('&', map { $_.'='.$filter->{$_} } grep { $_ ne 's' } keys %$filter ) : '';
255
256 my $active_rights = $m->comp('/contenido/webshop/subs/user_rights.msn');
257
258 my %users;
259 my ($href, @actions, $user_id);
260 638 ahitrov if ( defined $status ) {
261 @$columns = grep { $_->{attr} ne 'status' } @$columns;
262 if ( ($status == 1 || $status == 6 || $status == 7 || $status == 8) && (!$active_rights || $active_rights == 1) ) {
263 $href = 'take_care.html';
264 @actions = { href => $href, name => 'обработать' };
265 $user_id = 'manager_id';
266 } elsif ( $status == 2 && (!$active_rights || $active_rights == 2) ) {
267 $href = 'facility.html';
268 @actions = { href => $href, name => 'собрать' };
269 $user_id = 'vault_id';
270 } elsif ( $status == 3 && (!$active_rights || $active_rights == 3) ) {
271 $href = 'delivery.html';
272 @actions = { href => $href, name => 'доставить' };
273 $user_id = 'postman_id';
274 } elsif ( $status == 4 && !$active_rights ) {
275 $href = 'delivery.html';
276 @actions = { href => $href, name => 'просмотр' };
277 $user_id = 'postman_id';
278 } elsif ( $status == 5 && !$active_rights ) {
279 $href = 'delivery.html';
280 @actions = { href => $href, name => 'просмотр' };
281 $user_id = 'postman_id';
282 }
283 198 ahitrov }
284
285 </%init>