1 |
8 |
ahitrov@rambler.ru |
%# vim:syn=mason |
2 |
|
|
<style> |
3 |
|
|
.td { font:11px Verdana; padding:2px 4px; } |
4 |
|
|
</style> |
5 |
|
|
% unless ($error) { |
6 |
|
|
|
7 |
|
|
% if (@ids) { |
8 |
|
|
<table width="95%" cellpadding="2" cellspacing="1" bgcolor="gray"> |
9 |
|
|
<tr bgcolor="silver"><th width="99%">Название</th><th width="1%">Удалить?</th></tr> |
10 |
|
|
% my $i = 0; |
11 |
|
|
% foreach my $id (@ids) { |
12 |
|
|
<tr bgcolor="<% $i++ % 2 ? '#f0f0f0' : 'white' %>"> |
13 |
|
|
<td class="td"><% (ref($list{$id}) && $list{$id}->name) || 'неизвестно' %></td> |
14 |
|
|
<td align="center"><input type="checkbox" name="<% $name %>_delete" value="<% $id %>"/></td></tr> |
15 |
|
|
% } |
16 |
|
|
</table> |
17 |
|
|
% } |
18 |
|
|
|
19 |
|
|
<table cellspacing="0" cellpadding="2" border="0" width="95%" |
20 |
|
|
style="border-bottom:1px solid gray; border-left:1px solid gray; border-right:1px solid gray;"> |
21 |
|
|
<tr bgcolor="#e0e0f0"><td class="td" width="5%" nowrap><b>Добавить:</b> |
22 |
|
|
<input onkeyup="find_word_<% $name %>()" type="text" name="<% $name %>_tmp" size="10" onfocus="key_flag_<% $name %> = 0;" onblur="key_flag_<% $name %> = 1;"> |
23 |
|
|
</td> |
24 |
|
|
<td width="94%"> |
25 |
|
|
<input type="hidden" name="<% $name %>_add" id="<% $name %>_hidden"> |
26 |
|
|
<select id="<% $name %>_select" class="selects" onchange="<% $name %>_changed();" style="width:100%"> |
27 |
|
|
<option value=""></option> |
28 |
|
|
% for ( sort { $sort{$a->id} <=> $sort{$b->id} } values %list ) { |
29 |
|
|
<option value="<% $_->id %> <% $_->class %>"><% $_->name . '(' . ( $prop->{lookup_opts}->{show_in_select} ? $_->{$prop->{lookup_opts}->{show_in_select}} : 'no' ) . ')' %></option> |
30 |
|
|
% } |
31 |
|
|
</select> |
32 |
|
|
</td> |
33 |
|
|
<td width="1%" style="padding:0 7px;"><a href="#" onclick="return <% $name %>_popup();" title="Найти документ"><img src="/contenido/i/lookup-19x19.gif" width="19" height="19" class="bb gb"></a></td> |
34 |
|
|
</tr> |
35 |
|
|
</table> |
36 |
|
|
|
37 |
|
|
<script type="text/javascript"> |
38 |
|
|
var key_flag_<% $name %> = 1; |
39 |
|
|
|
40 |
|
|
if (navigator.appName == "Netscape") { |
41 |
|
|
document.captureEvents(Event.KEYUP); |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
function find_word_<% $name %>() { |
45 |
|
|
var str1 = document.form.<% $name %>_tmp.value; |
46 |
|
|
if (str1 == "" || key_flag_<% $name %>) return; |
47 |
|
|
|
48 |
|
|
for (var i = 0; i < document.form.<% $name %>_select.options.length; i++) { |
49 |
|
|
var source = document.form.<% $name %>_select.options[i].text; |
50 |
|
|
source = source.toLowerCase(); |
51 |
|
|
str1 = str1.toLowerCase(); |
52 |
|
|
if ( source.indexOf(str1) > -1) { |
53 |
|
|
document.form.<% $name %>_select.options[i].selected=true; |
54 |
|
|
<% $name %>_changed(); |
55 |
|
|
break; |
56 |
|
|
} |
57 |
|
|
} |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
function <% $name %>_popup() { |
61 |
|
|
var s = document.getElementById('<% $name %>_select'); |
62 |
|
|
if (!s.value) { |
63 |
|
|
alert('Нет выбранного значения'); |
64 |
|
|
return false; |
65 |
|
|
} |
66 |
|
|
var re = /^(\d+)\s+(.+)$/; |
67 |
|
|
var matches = re.exec(s.value); |
68 |
|
|
window.open('/contenido/document.html?class=' + matches[2] + '&id=' + matches[1]); |
69 |
|
|
return false; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
function <% $name %>_changed() { |
73 |
|
|
var h = document.getElementById('<% $name %>_hidden'); |
74 |
|
|
var s = document.getElementById('<% $name %>_select'); |
75 |
|
|
|
76 |
|
|
if (s.value) { |
77 |
|
|
var re = /^(\d+)\s+(.+)$/; |
78 |
|
|
var matches = re.exec(s.value); |
79 |
|
|
h.value = matches[1]; |
80 |
|
|
} else { |
81 |
|
|
h.value = ''; |
82 |
|
|
} |
83 |
|
|
} |
84 |
|
|
</script> |
85 |
|
|
|
86 |
|
|
% } else { |
87 |
|
|
<font color="red"><% $error %></font> |
88 |
|
|
% } |
89 |
|
|
|
90 |
|
|
<%args> |
91 |
|
|
$object |
92 |
|
|
$name => undef |
93 |
|
|
$check => undef |
94 |
|
|
$prop => {} |
95 |
|
|
</%args> |
96 |
|
|
<%init> |
97 |
|
|
my (%list, %sort, $error); |
98 |
|
|
|
99 |
|
|
# Если оно хранится в поле типа integer[] то нам вернется массив, если в data, то ссылка на массив. |
100 |
|
|
# Просекаем фишку |
101 |
|
|
my @ids = ref($object->$name) eq 'ARRAY' ? @{ $object->$name } : $object->$name; |
102 |
|
|
|
103 |
|
|
if ($prop && ref($prop) && ref($prop->{lookup_opts}) eq 'HASH') { |
104 |
|
|
my $i = 0; |
105 |
|
|
foreach my $obj ($keeper->get_documents(%{$prop->{lookup_opts}}, order => ['name','reverse'])) { |
106 |
|
|
$list{$obj->id} = $obj; |
107 |
|
|
$sort{$obj->id} = $i++; |
108 |
|
|
} |
109 |
|
|
} else { |
110 |
|
|
$error = 'Похоже неверное описание lookup_opts в документе'; |
111 |
|
|
} |
112 |
|
|
</%init> |