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