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