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