1 |
8 |
ahitrov@rambler.ru |
<script type="text/javascript"> |
2 |
|
|
<!-- |
3 |
421 |
ahitrov |
function checkbox_common_toggle ( sClassSelector ) { |
4 |
|
|
$('.' + sClassSelector).each(function(){ |
5 |
|
|
var oField = $(this)[0]; |
6 |
8 |
ahitrov@rambler.ru |
if ( oField.checked ) { |
7 |
|
|
oField.checked = 0; |
8 |
|
|
} else { |
9 |
|
|
oField.checked = 1; |
10 |
|
|
} |
11 |
421 |
ahitrov |
}); |
12 |
8 |
ahitrov@rambler.ru |
} |
13 |
386 |
ahitrov |
% if ( @inline_pickups ) { |
14 |
522 |
ahitrov |
$(document).ready(function() { |
15 |
386 |
ahitrov |
% foreach my $pickup ( @inline_pickups ) { |
16 |
|
|
% my $lookup_opts = $pickup->{lookup_opts}; |
17 |
|
|
% my $search_opts = join( '&', map { $_.'='.$lookup_opts->{$_} } keys %$lookup_opts ); |
18 |
|
|
|
19 |
|
|
$('.autocomplete_<% $pickup->{attr} %>').autocomplete({ |
20 |
|
|
minLength : 2, |
21 |
|
|
source : '/contenido/ajax/document_search.html?<% $search_opts %>', |
22 |
|
|
select : function( event, ui ) |
23 |
|
|
{ |
24 |
|
|
var sStoreId = $(this).attr('rel'); |
25 |
|
|
var item = ui.item; |
26 |
|
|
$('#' + sStoreId).val( item.id ); |
27 |
|
|
}, |
28 |
|
|
change : function( event, ui ) |
29 |
|
|
{ |
30 |
|
|
var sStoreId = $(this).attr('rel'); |
31 |
|
|
var sValue = $(this).val(); |
32 |
|
|
if ( sValue == '' ) { |
33 |
|
|
$('#' + sStoreId).val(''); |
34 |
|
|
} |
35 |
|
|
} |
36 |
|
|
}); |
37 |
|
|
|
38 |
|
|
% } |
39 |
|
|
}); |
40 |
|
|
% } |
41 |
|
|
|
42 |
|
|
function mydump(arr,level) { |
43 |
|
|
var dumped_text = ""; |
44 |
|
|
if(!level) level = 0; |
45 |
|
|
|
46 |
|
|
var level_padding = ""; |
47 |
|
|
for(var j=0;j<level+1;j++) level_padding += " "; |
48 |
|
|
|
49 |
|
|
if(typeof(arr) == 'object') { |
50 |
|
|
for(var item in arr) { |
51 |
|
|
var value = arr[item]; |
52 |
|
|
|
53 |
|
|
if(typeof(value) == 'object') { |
54 |
|
|
dumped_text += level_padding + "'" + item + "' ...\n"; |
55 |
|
|
dumped_text += mydump(value,level+1); |
56 |
|
|
} else { |
57 |
|
|
dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n"; |
58 |
|
|
} |
59 |
|
|
} |
60 |
|
|
} else { |
61 |
|
|
dumped_text = "===>"+arr+"<===("+typeof(arr)+")"; |
62 |
|
|
} |
63 |
|
|
return dumped_text; |
64 |
|
|
} |
65 |
|
|
|
66 |
618 |
ahitrov |
var oMenus = { |
67 |
|
|
% my $cls_count = scalar keys %document_classes; |
68 |
616 |
ahitrov |
% foreach my $class ( keys %document_classes ) { |
69 |
618 |
ahitrov |
% $cls_count--; |
70 |
616 |
ahitrov |
% my $class_name = $class; |
71 |
|
|
% $class_name =~ s/:/-/g; |
72 |
|
|
% my ($prop) = grep { $_->{attr} eq 'status' } $class->new( $keeper )->structure; |
73 |
620 |
ahitrov |
% if ( ref $prop && $prop->{type} eq 'status' ) { |
74 |
616 |
ahitrov |
% my @menu; |
75 |
620 |
ahitrov |
% foreach my $case ( @{ref $prop->{cases} eq 'ARRAY' ? $prop->{cases} : $keeper->default_status()} ) { |
76 |
616 |
ahitrov |
% my $name = $case->[1]; |
77 |
|
|
% $name =~ s/'/\\'/g; |
78 |
|
|
% my $key = $case->[0]; |
79 |
|
|
% if ( $key =~ /^\d+$/ && $key >= 0 && $key <= 10 ) { |
80 |
|
|
% push @menu, "'$key' : { 'name' : '$name', icon: '$key' }"; |
81 |
|
|
% } else { |
82 |
|
|
% push @menu, "'$key' : { 'name' : '$name' }"; |
83 |
|
|
% } |
84 |
|
|
% } |
85 |
618 |
ahitrov |
'<% $class_name %>' : { <% join(", ", @menu) %> }<% $cls_count ? ',' : '' %> |
86 |
|
|
% } |
87 |
|
|
% } |
88 |
|
|
|
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
function set_status_toggle( ev, nID, $class_name ) { |
92 |
|
|
ev.preventDefault(); |
93 |
|
|
$.ajax({ |
94 |
|
|
'url' : '/contenido/ajax/document_status.html', |
95 |
|
|
'data' : { 'class' : $class_name, 'id' : nID, 'toggle' : 1, 's' : <% ref $section ? $section->id : 0 %>, 'params' : '<% $params %>' }, |
96 |
|
|
'dataType' : 'json', |
97 |
|
|
'success' : function( data ) { |
98 |
|
|
if ( data.error ) { |
99 |
|
|
alert( data.error ); |
100 |
|
|
} |
101 |
|
|
if ( data.success ) { |
102 |
|
|
$('#row-' + nID).html(data.html); |
103 |
|
|
$('#status-set-'+ nID).on('click', function( ev ) { |
104 |
|
|
set_status_toggle(ev, nID, $class_name) |
105 |
|
|
}); |
106 |
|
|
} |
107 |
|
|
} |
108 |
|
|
}); |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
function set_status( $selector, $class_name ) { |
112 |
|
|
var oMenu = oMenus[$class_name]; |
113 |
|
|
$.contextMenu({ |
114 |
|
|
selector: $selector, |
115 |
|
|
trigger: 'left', |
116 |
|
|
callback: function(key, options) { |
117 |
|
|
var nID = parseInt($(this).data('id')); |
118 |
|
|
if ( nID != key ) { |
119 |
|
|
$.ajax({ |
120 |
|
|
'url' : '/contenido/ajax/document_status.html', |
121 |
|
|
'data' : { 'class' : $class_name, 'id' : nID, 'status' : key, 's' : <% ref $section ? $section->id : 0 %>, 'params' : '<% $params %>' }, |
122 |
|
|
'dataType' : 'json', |
123 |
|
|
'success' : function( data ) { |
124 |
|
|
if ( data.error ) { |
125 |
|
|
alert( data.error ); |
126 |
|
|
} |
127 |
|
|
if ( data.success ) { |
128 |
|
|
$('#row-' + nID).html(data.html); |
129 |
|
|
set_status( '#status-set-'+ nID, $class_name); |
130 |
|
|
} |
131 |
616 |
ahitrov |
} |
132 |
618 |
ahitrov |
}); |
133 |
|
|
} |
134 |
|
|
}, |
135 |
|
|
items: oMenu |
136 |
|
|
}); |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
$(document).ready(function(){ |
140 |
|
|
$('.move-up').on('click', function( ev ){ |
141 |
|
|
ev.preventDefault(); |
142 |
|
|
var $nID = $(this).data('id'); |
143 |
|
|
$.ajax({ |
144 |
|
|
'url' : '/contenido/ajax/document_move.html', |
145 |
|
|
'data' : { 's' : <% ref $section ? $section->id : 0 %>, 'id' : $nID, 'move' : 'up' }, |
146 |
|
|
'dataType' : 'json', |
147 |
|
|
'success' : function( data ){ |
148 |
|
|
if ( data.error ) { |
149 |
|
|
alert( data.error ); |
150 |
|
|
} else if ( data.before ) { |
151 |
|
|
var $nBefore = data.before; |
152 |
|
|
$('#row-' + $nID).insertBefore('#row-' + $nBefore); |
153 |
616 |
ahitrov |
} |
154 |
618 |
ahitrov |
} |
155 |
|
|
}); |
156 |
|
|
}); |
157 |
|
|
|
158 |
|
|
$('.move-down').on('click', function( ev ){ |
159 |
|
|
ev.preventDefault(); |
160 |
|
|
var $nID = $(this).data('id'); |
161 |
|
|
$.ajax({ |
162 |
|
|
'url' : '/contenido/ajax/document_move.html', |
163 |
|
|
'data' : { 's' : <% ref $section ? $section->id : 0 %>, 'id' : $nID, 'move' : 'down' }, |
164 |
|
|
'dataType' : 'json', |
165 |
|
|
'success' : function( data ){ |
166 |
|
|
if ( data.error ) { |
167 |
|
|
alert( data.error ); |
168 |
|
|
} else if ( data.after ) { |
169 |
|
|
var $nAfter = data.after; |
170 |
|
|
$('#row-' + $nID).insertAfter('#row-' + $nAfter); |
171 |
|
|
} |
172 |
|
|
} |
173 |
|
|
}); |
174 |
|
|
}); |
175 |
|
|
|
176 |
|
|
% foreach my $class ( keys %document_classes ) { |
177 |
|
|
% my $class_name = $class; |
178 |
|
|
% $class_name =~ s/:/-/g; |
179 |
|
|
% my ($prop) = grep { $_->{attr} eq 'status' } $class->new( $keeper )->structure; |
180 |
620 |
ahitrov |
% if ( ref $prop && $prop->{type} eq 'status' ) { |
181 |
|
|
% my @cases = @{ref $prop->{cases} eq 'ARRAY' ? $prop->{cases} : $keeper->default_status()}; |
182 |
|
|
% if ( @cases > 2 ) { |
183 |
618 |
ahitrov |
set_status( '.context-menu-<% $class_name %>', '<% $class_name %>' ); |
184 |
|
|
% } else { |
185 |
|
|
$('.context-menu-<% $class_name %>').on('click', function( ev ) { |
186 |
|
|
var nID = parseInt($(this).data('id')); |
187 |
|
|
set_status_toggle(ev, nID, '<% $class_name %>') |
188 |
|
|
}); |
189 |
|
|
% } |
190 |
616 |
ahitrov |
% } |
191 |
|
|
% } |
192 |
609 |
ahitrov |
}); |
193 |
8 |
ahitrov@rambler.ru |
//--> |
194 |
|
|
</script> |
195 |
|
|
<form name="section_browse" action="sections.html" method="POST"> |
196 |
|
|
<table width="100%" border="0" cellpadding="4" cellspacing="0" class="tlistdocs"> |
197 |
|
|
<tr bgcolor="#efefef"> |
198 |
421 |
ahitrov |
<th><a href="javascript:void(0)" onclick="checkbox_common_toggle('common-check'); return false;"><img src="/contenido/i/checkbox-14x14-green.gif" width="14" height="14" title="Выбор документов для групповых операций" align="absmiddle" border="0" style="margin-left:3px;"></a></th> |
199 |
8 |
ahitrov@rambler.ru |
% |
200 |
|
|
% foreach (@$columns) { |
201 |
421 |
ahitrov |
<th>\ |
202 |
|
|
% if ( $_->{inline} && $_->{type} eq 'checkbox' ) { |
203 |
|
|
<a href="javascript:void(0)" onclick="checkbox_common_toggle('<% $_->{attr} %>-check'); return false;"><img src="/contenido/i/checkbox-14x14-green.gif" width="14" height="14" title="Выбор документов для групповых операций" align="absmiddle" border="0" style="margin:0 5px 0 2px;"></a>\ |
204 |
|
|
% } |
205 |
|
|
<% $_->{shortname} || $_->{rusname} %></th> |
206 |
8 |
ahitrov@rambler.ru |
% } |
207 |
|
|
% |
208 |
|
|
</tr> |
209 |
|
|
% |
210 |
|
|
% unless (@$documents) { |
211 |
|
|
<tr><td align="center" colspan="<% scalar @$columns %>">Документы не найдены</td></tr> |
212 |
|
|
% } |
213 |
|
|
% foreach my $document (@$documents) { |
214 |
|
|
% |
215 |
|
|
% next unless ref($document); |
216 |
|
|
% my $document_access = $user->section_accesses($user, $document->section); |
217 |
|
|
% |
218 |
607 |
ahitrov |
<& /contenido/components/section_browse_row.msn, document => $document, columns => $columns, section => $section, |
219 |
|
|
toopi => $toopi, inline_status => $inline_status, lookup_elemets => \%lookup_elements, |
220 |
|
|
filter => $filter, params_unsection => $params_unsection, params_unclassed => $params_unclassed |
221 |
|
|
&> |
222 |
8 |
ahitrov@rambler.ru |
% } #- foreach @documents |
223 |
|
|
</table> |
224 |
|
|
<input type="hidden" name="id" value="<% $section->id %>"> |
225 |
|
|
% if ( ref $filter eq 'HASH' ) { |
226 |
|
|
% while ( my ($key, $value) = each %$filter ) { |
227 |
|
|
% next if $key eq 's'; |
228 |
|
|
<input type="hidden" name="<% $key %>" value="<% $value |h %>"> |
229 |
|
|
% } |
230 |
|
|
% } |
231 |
522 |
ahitrov |
% if ( $section->default_document_class || $section->default_table_class ) { |
232 |
|
|
<div style="display:inline-block; width:45%; margin:10px 0; min-height:80px; vertical-align:top;"> |
233 |
|
|
<& /contenido/components/inputs/parent.msn, name => 'tree', check => $section->id, style => 'width:100%;' &> |
234 |
|
|
<div style="text-align:left; margin-top:5px;"> |
235 |
|
|
<input type="submit" name="move" value="Перенести" class="input_btn"><input |
236 |
|
|
type="submit" name="link" value="Привязать" class="input_btn"><input |
237 |
|
|
type="submit" name="unlink" value="Отвязать от текущей" class="input_btn" onclick="return confirm('Объекты, не привязанные к другим секциям могут быть потеряны');"> |
238 |
|
|
</div> |
239 |
|
|
</div> |
240 |
|
|
% } |
241 |
8 |
ahitrov@rambler.ru |
% if ( $inline_status || $delete_status ) { |
242 |
522 |
ahitrov |
<div style="display:inline-block; width:45%; text-align:right; margin:5px; padding-top:29px; vertical-align:top;"> |
243 |
8 |
ahitrov@rambler.ru |
% if ( $inline_status ) { |
244 |
522 |
ahitrov |
<input type="submit" name="update" value="Сохранить изменения" class="input_btn">\ |
245 |
8 |
ahitrov@rambler.ru |
% } |
246 |
|
|
% if ( $delete_status ) { |
247 |
|
|
<input type="submit" name="delete" value="Удалить выбранные" class="input_btn" onclick="return confirm('Все отмеченные позиции будут удалены');"> |
248 |
|
|
% } |
249 |
|
|
</div> |
250 |
|
|
% } |
251 |
386 |
ahitrov |
<br clear="all"> |
252 |
8 |
ahitrov@rambler.ru |
</form> |
253 |
|
|
<%args> |
254 |
|
|
|
255 |
|
|
$section => undef |
256 |
|
|
$documents => undef |
257 |
|
|
$columns => undef |
258 |
|
|
$id => undef |
259 |
|
|
$filter => undef |
260 |
|
|
|
261 |
|
|
</%args> |
262 |
|
|
<%init> |
263 |
|
|
|
264 |
|
|
return unless ref $documents eq 'ARRAY'; |
265 |
|
|
return unless ref $columns eq 'ARRAY'; |
266 |
|
|
return unless ref $section; |
267 |
|
|
|
268 |
|
|
my $toopi = $project->documents(); |
269 |
|
|
my $inline_status = 0; |
270 |
|
|
my $delete_status = 0; |
271 |
|
|
my $params = ref $filter eq 'HASH' ? join ('&', map { $_.'='.$filter->{$_} } keys %$filter ) : ''; |
272 |
|
|
my $params_unclassed = ref $filter eq 'HASH' ? join ('&', map { $_.'='.$filter->{$_} } grep { $_ ne 'class' } keys %$filter ) : ''; |
273 |
|
|
my $params_unsection = ref $filter eq 'HASH' ? join ('&', map { $_.'='.$filter->{$_} } grep { $_ ne 's' } keys %$filter ) : ''; |
274 |
|
|
|
275 |
386 |
ahitrov |
my %lookup_elements; |
276 |
616 |
ahitrov |
my %document_classes; |
277 |
609 |
ahitrov |
my @inline_pickups = grep { |
278 |
|
|
my $type = exists $_->{inline_type} ? $_->{inline_type} : $_->{type}; |
279 |
|
|
exists $_->{inline} && ($type eq 'pickup' || $type eq 'autocomplete') |
280 |
|
|
} @$columns; |
281 |
8 |
ahitrov@rambler.ru |
|
282 |
607 |
ahitrov |
map { |
283 |
|
|
$_->{document_access} = $user->section_accesses($user, $_->section); |
284 |
|
|
if ( $_->{document_access} == 2 ) { |
285 |
|
|
$delete_status = 1; |
286 |
|
|
} |
287 |
616 |
ahitrov |
$document_classes{$_->class} = 1; |
288 |
607 |
ahitrov |
} @$documents; |
289 |
|
|
map { |
290 |
|
|
if ( exists $_->{inline} && $_->{inline} ) { |
291 |
|
|
$inline_status = 1; |
292 |
|
|
} |
293 |
|
|
} @$columns; |
294 |
|
|
|
295 |
8 |
ahitrov@rambler.ru |
</%init> |