Line # Revision Author
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 843 ahitrov var checkedIds = [];
244 $('tr.data-row').each(function(index){
245 $checkInput = $(this).find('.common-check');
246 if ( $(this).data('id') == sourceID ) {
247 checkedIds.push($(this).data('id'));
248 $checkInput.prop('checked', true);
249 } else if ( $checkInput.prop('checked') ) {
250 checkedIds.push($(this).data('id'));
251 }
252 });
253 if ( sourceID != checkedIds[0] ) {
254 $source = $('#row-' + checkedIds[0]);
255 }
256 842 ahitrov $.ajax({
257 'url' : '/contenido/ajax/document_move.html',
258 843 ahitrov 'data' : { 's' : <% ref $section ? $section->id : 0 %>, 'id' : checkedIds.join(','), 'move' : 'after', 'aid' : targetID },
259 842 ahitrov 'dataType' : 'json',
260 'success' : function( data ){
261 if ( data.error ) {
262 alert( data.error );
263 } else if ( data.after ) {
264 843 ahitrov checkedIds.forEach(function(rowID, index, ids) {
265 $source = $('#row-' + rowID);
266 $source.detach().insertAfter($target);
267 $source.find('.common-check').attr('checked', false);
268 $target = $source;
269 });
270 842 ahitrov console.log('Moved after ' + data.after);
271 }
272 }
273 });
274
275
276 }
277 % }
278 609 ahitrov });
279 8 ahitrov@rambler.ru //-->
280 </script>
281 <form name="section_browse" action="sections.html" method="POST">
282 <table width="100%" border="0" cellpadding="4" cellspacing="0" class="tlistdocs">
283 <tr bgcolor="#efefef">
284 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>
285 8 ahitrov@rambler.ru %
286 % foreach (@$columns) {
287 421 ahitrov <th>\
288 % if ( $_->{inline} && $_->{type} eq 'checkbox' ) {
289 <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>\
290 % }
291 <% $_->{shortname} || $_->{rusname} %></th>
292 8 ahitrov@rambler.ru % }
293 %
294 </tr>
295 621 ahitrov <tbody class="section-content">
296 8 ahitrov@rambler.ru %
297 % unless (@$documents) {
298 <tr><td align="center" colspan="<% scalar @$columns %>">Документы не найдены</td></tr>
299 % }
300 % foreach my $document (@$documents) {
301 % next unless ref($document);
302 607 ahitrov <& /contenido/components/section_browse_row.msn, document => $document, columns => $columns, section => $section,
303 toopi => $toopi, inline_status => $inline_status, lookup_elemets => \%lookup_elements,
304 filter => $filter, params_unsection => $params_unsection, params_unclassed => $params_unclassed
305 &>
306 8 ahitrov@rambler.ru % } #- foreach @documents
307 621 ahitrov </tbody>
308 8 ahitrov@rambler.ru </table>
309 <input type="hidden" name="id" value="<% $section->id %>">
310 % if ( ref $filter eq 'HASH' ) {
311 % while ( my ($key, $value) = each %$filter ) {
312 % next if $key eq 's';
313 <input type="hidden" name="<% $key %>" value="<% $value |h %>">
314 % }
315 % }
316 522 ahitrov % if ( $section->default_document_class || $section->default_table_class ) {
317 <div style="display:inline-block; width:45%; margin:10px 0; min-height:80px; vertical-align:top;">
318 <& /contenido/components/inputs/parent.msn, name => 'tree', check => $section->id, style => 'width:100%;' &>
319 <div style="text-align:left; margin-top:5px;">
320 <input type="submit" name="move" value="Перенести" class="input_btn"><input
321 type="submit" name="link" value="Привязать" class="input_btn"><input
322 type="submit" name="unlink" value="Отвязать от текущей" class="input_btn" onclick="return confirm('Объекты, не привязанные к другим секциям могут быть потеряны');">
323 </div>
324 </div>
325 % }
326 8 ahitrov@rambler.ru % if ( $inline_status || $delete_status ) {
327 522 ahitrov <div style="display:inline-block; width:45%; text-align:right; margin:5px; padding-top:29px; vertical-align:top;">
328 8 ahitrov@rambler.ru % if ( $inline_status ) {
329 522 ahitrov <input type="submit" name="update" value="Сохранить изменения" class="input_btn">\
330 8 ahitrov@rambler.ru % }
331 % if ( $delete_status ) {
332 <input type="submit" name="delete" value="Удалить выбранные" class="input_btn" onclick="return confirm('Все отмеченные позиции будут удалены');">
333 % }
334 </div>
335 % }
336 386 ahitrov <br clear="all">
337 8 ahitrov@rambler.ru </form>
338 <%args>
339
340 $section => undef
341 $documents => undef
342 $columns => undef
343 $id => undef
344 $filter => undef
345
346 </%args>
347 <%init>
348
349 return unless ref $documents eq 'ARRAY';
350 return unless ref $columns eq 'ARRAY';
351 return unless ref $section;
352
353 my $toopi = $project->documents();
354 my $inline_status = 0;
355 my $delete_status = 0;
356 my $params = ref $filter eq 'HASH' ? join ('&', map { $_.'='.$filter->{$_} } keys %$filter ) : '';
357 my $params_unclassed = ref $filter eq 'HASH' ? join ('&', map { $_.'='.$filter->{$_} } grep { $_ ne 'class' } keys %$filter ) : '';
358 my $params_unsection = ref $filter eq 'HASH' ? join ('&', map { $_.'='.$filter->{$_} } grep { $_ ne 's' } keys %$filter ) : '';
359
360 386 ahitrov my %lookup_elements;
361 616 ahitrov my %document_classes;
362 609 ahitrov my @inline_pickups = grep {
363 my $type = exists $_->{inline_type} ? $_->{inline_type} : $_->{type};
364 exists $_->{inline} && ($type eq 'pickup' || $type eq 'autocomplete')
365 } @$columns;
366 8 ahitrov@rambler.ru
367 607 ahitrov map {
368 $_->{document_access} = $user->section_accesses($user, $_->section);
369 if ( $_->{document_access} == 2 ) {
370 $delete_status = 1;
371 }
372 616 ahitrov $document_classes{$_->class} = 1;
373 607 ahitrov } @$documents;
374 map {
375 if ( exists $_->{inline} && $_->{inline} ) {
376 $inline_status = 1;
377 }
378 } @$columns;
379
380 8 ahitrov@rambler.ru </%init>