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