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 |
|
|
% if ( ref $prop && exists $prop->{cases} && ref $prop->{cases} eq 'ARRAY' ) { |
74 |
|
|
% my @menu; |
75 |
|
|
% foreach my $case ( @{$prop->{cases}} ) { |
76 |
|
|
% 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 |
|
|
% if ( ref $prop && exists $prop->{cases} && ref $prop->{cases} eq 'ARRAY' ) { |
181 |
|
|
% if ( scalar @{$prop->{cases}} > 2 ) { |
182 |
|
|
set_status( '.context-menu-<% $class_name %>', '<% $class_name %>' ); |
183 |
|
|
% } else { |
184 |
|
|
$('.context-menu-<% $class_name %>').on('click', function( ev ) { |
185 |
|
|
var nID = parseInt($(this).data('id')); |
186 |
|
|
set_status_toggle(ev, nID, '<% $class_name %>') |
187 |
|
|
}); |
188 |
|
|
% } |
189 |
616 |
ahitrov |
% } |
190 |
|
|
% } |
191 |
609 |
ahitrov |
}); |
192 |
8 |
ahitrov@rambler.ru |
//--> |
193 |
|
|
</script> |
194 |
|
|
<form name="section_browse" action="sections.html" method="POST"> |
195 |
|
|
<table width="100%" border="0" cellpadding="4" cellspacing="0" class="tlistdocs"> |
196 |
|
|
<tr bgcolor="#efefef"> |
197 |
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> |
198 |
8 |
ahitrov@rambler.ru |
% |
199 |
|
|
% foreach (@$columns) { |
200 |
421 |
ahitrov |
<th>\ |
201 |
|
|
% if ( $_->{inline} && $_->{type} eq 'checkbox' ) { |
202 |
|
|
<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>\ |
203 |
|
|
% } |
204 |
|
|
<% $_->{shortname} || $_->{rusname} %></th> |
205 |
8 |
ahitrov@rambler.ru |
% } |
206 |
|
|
% |
207 |
|
|
</tr> |
208 |
|
|
% |
209 |
|
|
% unless (@$documents) { |
210 |
|
|
<tr><td align="center" colspan="<% scalar @$columns %>">Документы не найдены</td></tr> |
211 |
|
|
% } |
212 |
|
|
% foreach my $document (@$documents) { |
213 |
|
|
% |
214 |
|
|
% next unless ref($document); |
215 |
|
|
% my $document_access = $user->section_accesses($user, $document->section); |
216 |
|
|
% |
217 |
607 |
ahitrov |
<& /contenido/components/section_browse_row.msn, document => $document, columns => $columns, section => $section, |
218 |
|
|
toopi => $toopi, inline_status => $inline_status, lookup_elemets => \%lookup_elements, |
219 |
|
|
filter => $filter, params_unsection => $params_unsection, params_unclassed => $params_unclassed |
220 |
|
|
&> |
221 |
8 |
ahitrov@rambler.ru |
% } #- foreach @documents |
222 |
|
|
</table> |
223 |
|
|
<input type="hidden" name="id" value="<% $section->id %>"> |
224 |
|
|
% if ( ref $filter eq 'HASH' ) { |
225 |
|
|
% while ( my ($key, $value) = each %$filter ) { |
226 |
|
|
% next if $key eq 's'; |
227 |
|
|
<input type="hidden" name="<% $key %>" value="<% $value |h %>"> |
228 |
|
|
% } |
229 |
|
|
% } |
230 |
522 |
ahitrov |
% if ( $section->default_document_class || $section->default_table_class ) { |
231 |
|
|
<div style="display:inline-block; width:45%; margin:10px 0; min-height:80px; vertical-align:top;"> |
232 |
|
|
<& /contenido/components/inputs/parent.msn, name => 'tree', check => $section->id, style => 'width:100%;' &> |
233 |
|
|
<div style="text-align:left; margin-top:5px;"> |
234 |
|
|
<input type="submit" name="move" value="Перенести" class="input_btn"><input |
235 |
|
|
type="submit" name="link" value="Привязать" class="input_btn"><input |
236 |
|
|
type="submit" name="unlink" value="Отвязать от текущей" class="input_btn" onclick="return confirm('Объекты, не привязанные к другим секциям могут быть потеряны');"> |
237 |
|
|
</div> |
238 |
|
|
</div> |
239 |
|
|
% } |
240 |
8 |
ahitrov@rambler.ru |
% if ( $inline_status || $delete_status ) { |
241 |
522 |
ahitrov |
<div style="display:inline-block; width:45%; text-align:right; margin:5px; padding-top:29px; vertical-align:top;"> |
242 |
8 |
ahitrov@rambler.ru |
% if ( $inline_status ) { |
243 |
522 |
ahitrov |
<input type="submit" name="update" value="Сохранить изменения" class="input_btn">\ |
244 |
8 |
ahitrov@rambler.ru |
% } |
245 |
|
|
% if ( $delete_status ) { |
246 |
|
|
<input type="submit" name="delete" value="Удалить выбранные" class="input_btn" onclick="return confirm('Все отмеченные позиции будут удалены');"> |
247 |
|
|
% } |
248 |
|
|
</div> |
249 |
|
|
% } |
250 |
386 |
ahitrov |
<br clear="all"> |
251 |
8 |
ahitrov@rambler.ru |
</form> |
252 |
|
|
<%args> |
253 |
|
|
|
254 |
|
|
$section => undef |
255 |
|
|
$documents => undef |
256 |
|
|
$columns => undef |
257 |
|
|
$id => undef |
258 |
|
|
$filter => undef |
259 |
|
|
|
260 |
|
|
</%args> |
261 |
|
|
<%init> |
262 |
|
|
|
263 |
|
|
return unless ref $documents eq 'ARRAY'; |
264 |
|
|
return unless ref $columns eq 'ARRAY'; |
265 |
|
|
return unless ref $section; |
266 |
|
|
|
267 |
|
|
my $toopi = $project->documents(); |
268 |
|
|
my $inline_status = 0; |
269 |
|
|
my $delete_status = 0; |
270 |
|
|
my $params = ref $filter eq 'HASH' ? join ('&', map { $_.'='.$filter->{$_} } keys %$filter ) : ''; |
271 |
|
|
my $params_unclassed = ref $filter eq 'HASH' ? join ('&', map { $_.'='.$filter->{$_} } grep { $_ ne 'class' } keys %$filter ) : ''; |
272 |
|
|
my $params_unsection = ref $filter eq 'HASH' ? join ('&', map { $_.'='.$filter->{$_} } grep { $_ ne 's' } keys %$filter ) : ''; |
273 |
|
|
|
274 |
386 |
ahitrov |
my %lookup_elements; |
275 |
616 |
ahitrov |
my %document_classes; |
276 |
609 |
ahitrov |
my @inline_pickups = grep { |
277 |
|
|
my $type = exists $_->{inline_type} ? $_->{inline_type} : $_->{type}; |
278 |
|
|
exists $_->{inline} && ($type eq 'pickup' || $type eq 'autocomplete') |
279 |
|
|
} @$columns; |
280 |
8 |
ahitrov@rambler.ru |
|
281 |
607 |
ahitrov |
map { |
282 |
|
|
$_->{document_access} = $user->section_accesses($user, $_->section); |
283 |
|
|
if ( $_->{document_access} == 2 ) { |
284 |
|
|
$delete_status = 1; |
285 |
|
|
} |
286 |
616 |
ahitrov |
$document_classes{$_->class} = 1; |
287 |
607 |
ahitrov |
} @$documents; |
288 |
|
|
map { |
289 |
|
|
if ( exists $_->{inline} && $_->{inline} ) { |
290 |
|
|
$inline_status = 1; |
291 |
|
|
} |
292 |
|
|
} @$columns; |
293 |
|
|
|
294 |
8 |
ahitrov@rambler.ru |
</%init> |