Revision 386 (by ahitrov, 2013/10/17 15:02:43) Section tree control (parent.pm) optimization.
jQuery 1.9.1, jQuery 1.8.3
jQuery-UI and ajax search (/ajax/document_search.html) for autocomplete
Inline control for pickup and autocomplete (future use control)
Minor improvements and bug fixes
<style>
.td { font:11px Verdana; padding:2px 4px; }
.th { padding:4px 4px; }
</style>
% unless ($error) {

%	if (@ids) {
<table width="95%" cellpadding="2" cellspacing="1" bgcolor="gray">
<tr bgcolor="silver"><th width="99%" class="th">Название</th><th width="1%" class="th">Удалить?</th></tr>
%		my $i = 0;
%		foreach my $obj_id (@ids) {
%			my $obj = ref $objects eq 'HASH' && exists $objects->{$obj_id} ? $objects->{$obj_id} : undef;
<tr bgcolor="<% $i++ % 2 ? '#e0e0e0' : 'white' %>"><td class="td">
<input type="hidden" name="<% $name %>_<% $obj_id %>_id" value="<% $obj_id %>">
%			if ( ref $obj ) {
%				my ($a1, $a2) = $obj->id ? ('<a href="document.html?id='.$obj->id.'&class='.$obj->class.'" target="_blank">','</a>') : ('','');
<% $a1.($obj->name || 'Безымянный документ #'.$obj->id).$a2 %></a>
%			} else {
<span style="color:red;">Неверная ссылка!!!</span>
%			}
</td><td align="center"><input type="checkbox" name="<% $name %>_<% $obj_id %>_delete" value="<% $obj_id %>"/></td></tr>
%               }
</table>
%	}

<table width="100%" cellspacing="1" cellpadding="0" border="0">
<tr><td width="5%">
<input type="text" name="<% $name %>_addanotheritem" id="<% $name %>_value"
 value="" style="width:100px;">
</td><td width="94%" class="td">
<input type="text" name="<% $name %>_docname" id="<% $name %>_docname"
 value="" style="width:100%;" onclick="lookfor_<% $name %>()"
 style="width:100%; color:blue; text-decoration:underline;" readonly>
</td><td width="1%" class="td"><a href="#top"
 onclick="search_<% $name %>();">
<img src="/contenido/i/lookup-19x19.gif" width="19" height="19" class="bb gb"></a>
</td></tr>
<tr id="<% $name %>_prev_table" style="display: none;">
<td id="<% $name %>_prev_value" class="bb undo" style="padding:3px;">&nbsp;</td>
<td id="<% $name %>_prev_docname" class="bb undo" style="padding:3px;">&nbsp;</td>
<td style="padding-left: 3px; vertical-align: top;"><a href="#"
 onclick="return <% $name %>_undo();" title="Отменить изменения"><img
 src="/contenido/i/undo-19x19.gif" width="19" height="19" class="bb gb"></a></td>
</tr>
</table>

% } else {
	<font color="red"><% $error %></font>
% }

<script type="text/javascript">
<!--
  var key_flag_<% $name %> = 1;
  var <% $name %>_prev_value = document.getElementById('<% $name %>_value').value;
  var <% $name %>_prev_docname = document.getElementById('<% $name %>_docname').value;

  function search_<% $name %>() {
	document.getElementById('DocFinder').style.height = 470;
	document.getElementById('DocFinder').src = '<% $lookup_string %>';
  }

  function lookfor_<% $name %>() {
        var id = document.getElementById('<% $name %>_value').value;
	if (id) {
% if ( exists $prop->{lookup_opts}{class} ) {
		var Class = '<% $prop->{lookup_opts}{class} %>';
		var Uri = 'document.html?id=' + id + '&class=' + Class;
% } elsif ( exists $prop->{lookup_opts}{table} ) {
		var Class = '<% $prop->{lookup_opts}{table} %>';
		var Uri = 'document.html?id=' + id + '&table=' + Class;
% }
		var Width = screen.width;
		var Height = screen.height;
		window.open(Uri,'Interface','width='+Width+',height='+Height+',top=0,left=0,location=1,menubar=1,resizable=0,scrollbars=1,status=1,titlebar=1,toolbar=1,directories=1,hotkeys=1');
	}
  }

  function lookthrough_<% $name %>(id) {
	if (id) {
% if ( exists $prop->{lookup_opts}{class} ) {
		var Class = '<% $prop->{lookup_opts}{class} %>';
		var Uri = 'document.html?id=' + id + '&class=' + Class;
% } elsif ( exists $prop->{lookup_opts}{table} ) {
		var Class = '<% $prop->{lookup_opts}{table} %>';
		var Uri = 'document.html?id=' + id + '&table=' + Class;
% }
		var Width = screen.width;
		var Height = screen.height;
		window.open(Uri,'Interface','width='+Width+',height='+Height+',top=0,left=0,location=1,menubar=1,resizable=0,scrollbars=1,status=1,titlebar=1,toolbar=1,directories=1,hotkeys=1');
	}
  }

  function <% $name %>_changed() {
	var t = document.getElementById('<% $name %>_prev_table');
	var v = document.getElementById('<% $name %>_value');
	if (v.value == <% $name %>_prev_value) {
		if (t.style.display!='none') {
			t.style.display = 'none';
		}
		return;
	}
	if (t.style.display=='none') {
		t.style.display = '';
	}
  }

  function <% $name %>_undo() {
	document.getElementById('<% $name %>_value').value = <% $name %>_prev_value;
	document.getElementById('<% $name %>_docname').value = <% $name %>_prev_docname;
	<% $name %>_changed();
	return false;
  }

//-->
</script>
<%args>
	$object
	$name => undef
	$check => undef
	$prop => {}
</%args>
<%init>

  my ($objects, $lookup_string, $error);

  # Если оно хранится в поле типа integer[] то нам вернется массив, если в data, то ссылка на массив.
  # Просекаем фишку
  my @ids = ref($object->$name) eq 'ARRAY' ? @{ $object->$name } : $object->$name ? $object->$name : ();

  if ($prop && ref($prop) && exists $prop->{lookup_opts} && ref $prop->{lookup_opts} eq 'HASH') {
	if ( @ids ) {
		$objects = $keeper->get_documents (
			in_id	=> \@ids,
			%{$prop->{lookup_opts}},
			return_mode	=> 'hash_ref',
		);
	}
	$lookup_string = '/contenido/find_document.html?nf='.$name.'_docname&vf='.$name.'_value';
	while ( my ($param, $value) = each %{ $prop->{lookup_opts} } ) {
		$lookup_string .= '&'.$param.'='.$value;
	}
  }else{
	$error = 'Похоже неверное описание lookup_opts в документе';
  }

</%init>