Revision 505 (by ahitrov, 2015/07/01 17:41:55) In-line editing for fields with type => 'text', some inline bug fixes

<script type="text/javascript">
<!--
function checkbox_common_toggle ( sClassSelector ) {
   $('.' + sClassSelector).each(function(){
	var oField = $(this)[0];
	if ( oField.checked ) {
		oField.checked = 0;
	} else {
		oField.checked = 1;
	}
   });
}
% if ( @inline_pickups ) {
$().ready(function() {
%	foreach my $pickup ( @inline_pickups ) {
%		my $lookup_opts = $pickup->{lookup_opts};
%		my $search_opts = join( '&', map { $_.'='.$lookup_opts->{$_} } keys %$lookup_opts );

    $('.autocomplete_<% $pickup->{attr} %>').autocomplete({
		minLength : 2,
		source	: '/contenido/ajax/document_search.html?<% $search_opts %>',
		select	: function( event, ui )
		{
			var sStoreId = $(this).attr('rel');
			var item = ui.item;
//			alert(mydump(item));
			$('#' + sStoreId).val( item.id );
//			$(this).val(item.label);
//			alert( $('#' + sStoreId).val() );
		},
		change	: function( event, ui )
		{
			var sStoreId = $(this).attr('rel');
			var sValue = $(this).val();
			if ( sValue == '' ) {
				$('#' + sStoreId).val('');
			}
		}
    });

%	}    
});
% }


function mydump(arr,level) {
    var dumped_text = "";
    if(!level) level = 0;

    var level_padding = "";
    for(var j=0;j<level+1;j++) level_padding += "    ";

    if(typeof(arr) == 'object') {  
        for(var item in arr) {
            var value = arr[item];

            if(typeof(value) == 'object') { 
                dumped_text += level_padding + "'" + item + "' ...\n";
                dumped_text += mydump(value,level+1);
            } else {
                dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
            }
        }
    } else { 
        dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
    }
    return dumped_text;
}


//-->
</script>
<form name="section_browse" action="sections.html" method="POST">
<table width="100%" border="0" cellpadding="4" cellspacing="0" class="tlistdocs">
<tr bgcolor="#efefef">
<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>
%
%	foreach (@$columns) {
<th>\
%		if ( $_->{inline} && $_->{type} eq 'checkbox' ) {
<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>\
%		}
<% $_->{shortname} || $_->{rusname} %></th>
%	}
%
</tr>
%
%		unless (@$documents) {
<tr><td align="center" colspan="<% scalar @$columns %>">Документы не найдены</td></tr>
%		}
%		foreach my $document (@$documents) {
%
%			next unless ref($document);
%			my $document_access = $user->section_accesses($user, $document->section);
%
<tr valign="top">
<td nowrap>\
%			if ($document_access == 2) {
%				$delete_status = 1;
<input type="checkbox" class="common-check" name="<% 'delete_'.$document->id.'_id' %>">
%			} else {
&nbsp;
%			}
</td>
%
%			for my $col (@$columns) {
%				if ($col->{attr} eq '_sort_') {
%
<td width="20px"><% $document->{sorder} %>&nbsp;<a
 href="document_move.html?id=<% $document->{id} %>&move=up&s=<% $id %><% $params_unsection ? '&'.$params_unsection : '' %>"><img
 src="/contenido/i/ico-up-9x10.gif" border=0 alt="Переместить документ на шаг вверх"></a>&nbsp;<a
 href="document_move.html?id=<% $document->{id} %>&move=down&s=<% $id %><% $params_unsection ? '&'.$params_unsection : '' %>"><img
 src="/contenido/i/ico-down-9x10.gif" border=0 alt="Переместить документ на шаг вниз"></a>\
%
%				} elsif ($col->{attr} eq 'dtime') {
%
<td nowrap><& "/contenido/components/show_dtime.msn", dtime=>$document->{dtime} &>\
%
%					if ($document->{ctime} ne $document->{mtime}) {
%						my $colortime = '#c66';
%
<div style="color:<% $colortime %>;"><& "/contenido/components/show_dtime.msn", dtime=>$document->{mtime} &></div>\
%
%					}
%
%				} elsif ($col->{attr} eq 'name') {
%
<td><span<% $document->contenido_status_style ? ' style="' . $document->contenido_status_style . '"' : '' %> class="<% $document->status ? '':'hiddensect' %>">\
%
%					my $name=$document->name ? $document->name : 'Безымянный документ N'.$document->id;
%					if ($document_access == 2) {
%
<a<% $document->contenido_status_style ? ' style="' . $document->contenido_status_style . '"' : '' %> href="document.html?id=<% $document->id %>&class=<% $document->class %><% $params_unclassed ? '&'.$params_unclassed : '' %>"><% $name | h %>&nbsp;</a>\
%
%					} else {
%
<% $name | h %>\
%
%					}
%
</span>\
%
%				} elsif ($col->{attr} eq 'id') {
%
<td><span class="<% $document->status ? '':'hiddensect' %>">\
%					if ($document_access == 2) {
<a href="document.html?id=<% $document->id %>&class=<% $document->class %><% $params_unclassed ? '&'.$params_unclassed : '' %>"><% $document->id %>&nbsp;</a>\
%					} else {
<% $document->id %>&nbsp;\
%					}
</span>\
%
%				} elsif ( exists $col->{inline} && $col->{inline} ) {
%					$inline_status = 1;
%					my $attr = $col->{attr};
%					if ( $col->{type} =~ /^(string|integer|float)$/ && $col->{inline} ) {
%						my $style = $col->{inline_style} ? $col->{inline_style} : ($col->{type} =~ /^(integer|float)$/ ? 'text-align:right; ' : '' );
%						$style .= $col->{inline_width} ? ' width:'.$col->{inline_width}.'px; ' : ' width:65px; ';
<td><input type="text" name="<% 'update_'.$document->id.'_'.$attr %>" value="<% $document->$attr |h %>" style="<% $style %>">
%					} elsif ($col->{type} eq 'text') {
%						my $style = $col->{inline_style} ? $col->{inline_style} : '';
%						$style .= $col->{inline_width} ? ' width:'.$col->{inline_width}.'px; ' : ' width:100px; ';
%						$style .= $col->{inline_height} ? ' width:'.$col->{inline_height}.'px; ' : ' height:70px; ';
%						my $value = $document->$attr;
%						for ( $value ) {
%							s/</&lt;/sgi;
%							s/>/&gt;/sgi;
%						}
<td><textarea name="<% 'update_'.$document->id.'_'.$attr %>" style="<% $style %>"><% $value %></textarea>
%					} elsif ($col->{type} eq 'checkbox') {
%						my $checked = $document->$attr ? ' checked' : '';
<td align="center"><input type="checkbox" class="<% $attr %>-check" name="<% 'update_'.$document->id.'_'.$attr %>"<% $checked %>>
%					} elsif ($col->{type} eq 'select') {
%						my $options = {};
%						if ($toopi && (ref($toopi) eq 'HASH') && (exists($toopi->{$document->class}))) {
%							%{ $options } = %{ $toopi->{$document->class} };
%						}
%						my $values = $options->{$col->{attr}};
<td><select name="<% 'update_'.$document->id.'_'.$attr %>">
%						if ( ref $values eq 'ARRAY' ) {
%							foreach my $val ( @$values ) {
%								my $selected = $val eq $document->$attr ? ' selected' : '';
<option value="<% $val %>"<% $selected %>><% $val %>
%							}
%						}
</select>
%					} elsif ($col->{type} eq 'status') {
%						my $cases = $col->{cases};
%						if ( ref $cases eq 'ARRAY' ) {
<td><select name="<% 'update_'.$document->id.'_'.$attr %>" style="<% $col->{inline_width} ? 'width:'.$col->{inline_width}.'px;' : '' %> <% $col->{inline_style} || '' %>">
%							foreach my $case ( @$cases ) {
%								my $selected = $case->[0] eq $document->$attr ? ' selected' : '';
<option value="<% $case->[0] %>"<% $selected %>><% $case->[1] %>
%							}
</select>
%						}
%					} elsif ($col->{type} eq 'pickup' || $col->{type} eq 'autocomplete') {
%						my %opts = %{ $col->{lookup_opts} };
%						my $doc;
%						if ( $document->$attr ) {
%							$doc = $keeper->get_document_by_id( $document->$attr, %opts );
%						}
<td><input type="hidden" name="<% 'update_'.$document->id.'_'.$attr %>" id="<% 'update_'.$document->id.'_'.$attr %>" value="<% ($document->$attr || '') |h %>">
<input type="text" class="<% 'autocomplete_'.$attr %>" id="<% 'autocomplete_'.$document->id.'_'.$attr %>" value="<% (ref $doc ? $doc->name : '') |h %>"
 title="<% defined $document->$attr ? 'Значение: '.$document->$attr : '' %>"
 rel="<% 'update_'.$document->id.'_'.$attr %>" style="<% $col->{inline_width} ? 'width:'.$col->{inline_width}.'px;' : '' %> <% $col->{inline_style} || '' %>"
 old-value="<% (ref $doc ? $doc->name : '') |h %>" onfocus="" onblur="">
%					} elsif ($col->{type} eq 'lookup') {
%						my %opts = %{ $col->{lookup_opts} };
%						delete $opts{search_by}		if exists $opts{search_by};
%						my $docs;
%						if ( exists $lookup_elements{$col->{attr}} ) {
%							$docs = $lookup_elements{$col->{attr}};
%						} else {
%							$docs = $keeper->get_documents( %opts, return_mode => 'array_ref', names => 1 );
%							$lookup_elements{$col->{attr}} = $docs;
%						}
%						if ( ref $docs eq 'ARRAY' && @$docs ) {
<td><select name="<% 'update_'.$document->id.'_'.$attr %>" style="<% $col->{inline_width} ? 'width:'.$col->{inline_width}.'px;' : '' %> <% $col->{inline_style} || '' %>">
<option value="<% $col->{allow_null} ? '' : 0 %>"></option>
%							foreach my $case ( @$docs ) {
%								my $selected = $case->[0] eq $document->$attr ? ' selected' : '';
<option value="<% $case->[0] %>"<% $selected %>><% $case->[1] %>
%							}
</select>
%						} else {
<td><% $document->$attr %>\
%						}
%					} else {
<td><input type="hidden" name="<% 'update_'.$document->id.'_'.$attr %>" value="<% $document->$attr |h %>" style="<% $style %>">
%					}
%
%				} elsif ($col->{attr} eq 'class') {
%
<td><% $document->class_name %>&nbsp;<font color="#999999">(<% $document->class %>)</font>\
%
%				} elsif ($col->{type} eq 'datetime') {
%
<td nowrap><& "/contenido/components/show_dtime.msn", dtime=>$document->{$col->{attr}} &>\
%
%				} elsif ($col->{attr} eq '_act_') {
%
<td nowrap>\
%					if ($document_access == 2) {
%
<a href="document.html?id=<% $document->id %>&class=<% $document->class %><% $params_unclassed ? '&'.$params_unclassed : '' %>" title="Редактировать документ"><img
 src="/contenido/i/actions/edit.gif" width="15" height="17" alt="Редактировать документ" align="absmiddle" border="0" hspace="1"></a>\
<a href="document.html?clone=1&id=<% $document->id %>&class=<% $document->class %><% $params_unclassed ? '&'.$params_unclassed : '' %>" title="Копировать документ"><img
 src="/contenido/i/actions/copy.gif" width="15" height="17" alt="Копировать документ" align="absmiddle" border="0" hspace="1"></a>\
<a href="confirm.html?id=<% $document->id %>&action=documents_deletion&from=<% $section->id %>&class=<% $document->class %><% $params_unclassed ? '&'.$params_unclassed : '' %>" title="Удалить документ"><img
 src="/contenido/i/actions/delete.gif" width="14" height="17" alt="Удалить документ" align="absmiddle" border="0" hspace="1"></a>\
%						if ( $document->status != 0 ) {
<a href="document.html?deactivate=1&id=<% $document->id %>&class=<% $document->class %><% $params_unclassed ? '&'.$params_unclassed : '' %>" title="Скрыть/деактивировать документ"><img
 src="/contenido/i/actions/deactivate.gif" width="14" height="17" alt="Скрыть/деактивировать документ" align="absmiddle" border="0" hspace="1"></a>\
%						}
%						if ( $document->status != 1 ) {
<a href="document.html?activate=1&id=<% $document->id %>&class=<% $document->class %><% $params_unclassed ? '&'.$params_unclassed : '' %>" title="Присвоить документу статус=1"><img
 src="/contenido/i/actions/activate.gif" width="14" height="17" alt="Присвоить документу статус=1" align="absmiddle" border="0" hspace="1"></a>\
%						}
<br>\
%
%					} else {
&nbsp;\
%					}
%					if ( $inline_status ) {
<input type="hidden" name="update_<% $document->id %>_class" value="<% $document->class %>">
%					}
%					if ( $delete_status ) {
<input type="hidden" name="delete_<% $document->id %>_class" value="<% $document->class %>">
%					}
%
%				} else {
%					my $attr = $col->{attr};
%					if ($col->{type} eq 'date') {
%						my $date=$document->{$col->{attr}};
%						$date=~/(\d{4}-\d{2}-\d{2})/;
<td nowrap align="right"><% $1 || '&nbsp;' %>\
%					} elsif ($col->{type} eq 'datetime') {
<td nowrap align="right"><% $document->{$col->{attr}} || '&nbsp;' %>\
%					} elsif ($col->{type} eq 'integer') {
<td align="right"><% $document->{$col->{attr}} %>&nbsp;\
%					} elsif ($col->{type} eq 'lookup' || $col->{type} eq 'pickup' || $col->{type} eq 'autocomplete') {
<td align="left">\
%						my $id = $document->{$col->{attr}};
%						if ($id) {
%							my ($doc)=$keeper->get_documents( ( ref($col->{lookup_opts}) ? %{$col->{lookup_opts}} : () ), id=>$id);
%							if ($doc) {
<a href="document.html?id=<% $doc->id %>&class=<% $doc->class %><% $params_unclassed ? '&'.$params_unclassed : '' %>"><% $doc->name || $doc->id %></a>&nbsp;\
%							} else {
<span class="hiddensect"><% $document->{$col->{attr}} %>???</span>\
%							}
%						} else {
<span class="hiddensect">NULL</span>\
%						}
%					} elsif ($col->{type} eq 'checkbox') {
<td align="center"><% $document->$attr ? '<img src="/contenido/i/checked-16x16.png" width="16" height="16">' : '&nbsp;' %>\
%					} elsif ($col->{type} eq 'status') {
%						my $status_map = ref $col->{cases} eq 'ARRAY' ? $col->{cases} : $keeper->default_status();
%						my ($doc_status) = grep { $_->[0] eq $document->{$col->{attr}} } @$status_map; 
%						$doc_status ||= [$document->{$col->{attr}}, 'Неизвестный'];
		<td nowrap><% $doc_status->[1].'('.$doc_status->[0].')' %>\
%					} else {
<td><% defined($document->$attr) ? $document->$attr : '&nbsp;' %>\
%					}
%				}
</td>
%
%			} #- for @columns
%
</tr>
%		} #- foreach @documents
</table>
<input type="hidden" name="id" value="<% $section->id %>">
%	if ( ref $filter eq 'HASH' ) {
%		while ( my ($key, $value) = each %$filter ) {
%			next	if $key eq 's';
<input type="hidden" name="<% $key %>" value="<% $value |h %>">
%		}
%	}
%	if ( $inline_status || $delete_status ) {
<div style="float:right; text-align:right; padding:5px 0 5px 10px; width:280px;">
%		if ( $inline_status ) {
<input type="submit" name="update" value="Сохранить изменения" class="input_btn">
%		}
%		if ( $delete_status ) {
<input type="submit" name="delete" value="Удалить выбранные" class="input_btn" onclick="return confirm('Все отмеченные позиции будут удалены');">
%		}
</div>
%	}
%	if ( $section->default_document_class || $section->default_table_class ) {
<div style="float:left; width:450px; padding:5px 0;">
<& /contenido/components/inputs/parent.msn, name => 'tree', check => $section->id &>
<input type="submit" name="move" value="Перенести" class="input_btn"><input type="submit" name="link" value="Привязать" class="input_btn">
</div>
%	}
<br clear="all">
</form>
<%args>

	$section	=> undef
	$documents	=> undef
	$columns	=> undef
	$id		=> undef
	$filter		=> undef

</%args>
<%init>

   return	unless ref $documents eq 'ARRAY';
   return	unless ref $columns eq 'ARRAY';
   return	unless ref $section;

   my $toopi = $project->documents();
   my $inline_status = 0;
   my $delete_status = 0;
   my $params = ref $filter eq 'HASH' ? join ('&', map { $_.'='.$filter->{$_} } keys %$filter ) : '';
   my $params_unclassed = ref $filter eq 'HASH' ? join ('&', map { $_.'='.$filter->{$_} } grep { $_ ne 'class' } keys %$filter ) : '';
   my $params_unsection = ref $filter eq 'HASH' ? join ('&', map { $_.'='.$filter->{$_} } grep { $_ ne 's' } keys %$filter ) : '';

   my %lookup_elements;
   my @inline_pickups = grep { exists $_->{inline} && ($_->{type} eq 'pickup' || $_->{type} eq 'autocomplete') } @$columns;

</%init>