Bug 57482

Multiple-selection combobox


git-svn-id: svn://svn.office.custis.ru/3rdparty/bugzilla.org/trunk@553 6955db30-a419-402b-8a0d-67ecbb4d7f56
master
vfilippov 2009-11-30 19:24:29 +00:00
parent b0385802a3
commit 2bdc651e4c
5 changed files with 81 additions and 23 deletions

BIN
images/dn.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 B

BIN
images/dnpush.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 B

View File

@ -113,7 +113,7 @@ function check_mini_login_fields( suffix ) {
/* template/en/global/menuforusers.html.tmpl */
function menuforusers_initcombo(id)
function menuforusers_initcombo(id, multi)
{
var sel = document.getElementById(id+"_s");
var ed = document.getElementById(id);
@ -124,31 +124,65 @@ function menuforusers_initcombo(id)
menuforusers_tocombo(id);
}
function menuforusers_tocombo(id)
{
var sel = document.getElementById(id+"_s");
var ed = document.getElementById(id);
if (!sel || !ed)
return;
var v = ed.value.toLowerCase();
for (var i = 0; i < sel.options.length; i++)
{
if (sel.options[i].value.toLowerCase().indexOf(v) >= 0 ||
sel.options[i].text.toLowerCase().indexOf(v) >= 0)
{
sel.selectedIndex = i;
menuforusers_fromcombo(id);
break;
}
RegExp.escape = function(text) {
if (!arguments.callee.sRE) {
var specials = [
'/', '.', '*', '+', '?', '|',
'(', ')', '[', ']', '{', '}', '\\'
];
arguments.callee.sRE = new RegExp(
'(\\' + specials.join('|\\') + ')', 'g'
);
}
return text.replace(arguments.callee.sRE, '\\$1');
}
function menuforusers_fromcombo(id)
function menuforusers_tocombo(id, multi)
{
var sel = document.getElementById(id+"_s");
var ed = document.getElementById(id);
if (!sel || !ed)
return;
if (sel.selectedIndex >= 0)
ed.value = sel.options[sel.selectedIndex].value;
var v = ed.value.toLowerCase().split(/[\s,]+/);
for (var i = 0; i < v.length; i++)
v[i] = RegExp.escape(v[i].replace(/^\s+|\s+$/, ''));
v = v.join('|');
v = new RegExp(v);
for (var i = 0; i < sel.options.length; i++)
{
if (sel.options[i].value.toLowerCase().match(v) ||
sel.options[i].text.toLowerCase().match(v))
{
sel.options[i].selected = true;
if (!multi)
break;
}
else if (multi)
sel.options[i].selected = false;
}
menuforusers_fromcombo(id);
}
function menuforusers_fromcombo(id, multi)
{
var sel = document.getElementById(id+"_s");
var ed = document.getElementById(id);
if (!sel || !ed)
return;
v = [];
for (var i = 0; i < sel.options.length; i++)
if (sel.options[i].selected)
v.push(sel.options[i].value);
ed.value = v.join(', ');
}
function menuforusers_showmulti(id)
{
var sel = document.getElementById(id+"_s");
var btn = document.getElementById(id+"_b");
if (!sel || !btn)
return;
var show = sel.style.visibility == 'hidden' && !sel.disabled;
sel.style.visibility = show ? '' : 'hidden';
btn.src = 'images/dn' + (show ? 'push' : '') + '.gif';
}

View File

@ -28,6 +28,7 @@
<div style="position: relative">
[% SET id="userselect_" _ name IF !id %]
[% UNLESS multiple %]
<div class="selectfree_ie" style="position:absolute;top:1px;left:1px;z-index:20;overflow:hidden">
<input
name="[% name | html %]"
@ -35,15 +36,14 @@
[% IF disabled %] disabled="[% disabled | html %]" [% END %]
[% IF accesskey %] accesskey="[% accesskey | html %]" [% END %]
id="[% id | html %]"
onchange="menuforusers_tocombo('[% id | js %]', [% multiple ? 1 : 0 %]); [% onchange | html %]"
>
onchange="menuforusers_tocombo('[% id | js %]', 0); [% onchange | html %]" />[% IF multiple %]<img style="margin-bottom:-4px" src="images/dn.gif" alt="dropdown list" title="dropdown list" onclick="menuforusers_showmulti('[% id | js %]')" />[% END %]
[%# http://anton-egorov.blogspot.com/2007/11/ie-select-z-index.html %]
<!--[if lte IE 6.5]><iframe style="width: 800px; height: 200px;"></iframe><![endif]-->
</div>
<select style="top: 0; left: 0; position: relative; z-index: 10"
id="[% id | html %]_s"
[% IF disabled %] disabled="[% disabled | html %]" [% END %]
onchange="menuforusers_fromcombo('[% id | js %]', [% multiple ? 1 : 0 %])"
onchange="menuforusers_fromcombo('[% id | js %]', 0)"
>
[% IF emptyok %]<option value=""></option>[% END %]
[% SET custom_userlist=user.get_userlist UNLESS custom_userlist %]
@ -51,6 +51,29 @@
<option value="[% tmpuser.login | html %]">[% tmpuser.identity | html %]</option>
[% END %]
</select>
[% ELSE %]
<div style="border: 1px solid gray">
<input
name="[% name | html %]"
value="[% value | html %]"
[% IF disabled %] disabled="[% disabled | html %]" [% END %]
[% IF accesskey %] accesskey="[% accesskey | html %]" [% END %]
id="[% id | html %]" style="height: 19px; padding: 0; margin: 0"
onchange="menuforusers_tocombo('[% id | js %]', 1); [% onchange | html %]" /><img id="[% id | html %]_b" style="margin-bottom:-4px" src="images/dn.gif" alt="dropdown list" title="dropdown list" onclick="menuforusers_showmulti('[% id | js %]')" />
<div class="selectfree_ie" style="position:relative:z-index:30;overflow:hidden">
<select id="[% id | html %]_s"
[% IF disabled %] disabled="[% disabled | html %]" [% END %]
onchange="menuforusers_fromcombo('[% id | js %]', 1)" multiple="multiple" size="4"
style="position:absolute;visibility:hidden">
[% IF emptyok %]<option value=""></option>[% END %]
[% SET custom_userlist=user.get_userlist UNLESS custom_userlist %]
[% FOREACH tmpuser = custom_userlist %]
<option value="[% tmpuser.login | html %]">[% tmpuser.identity | html %]</option>
[% END %]
</select>
</div>
</div>
[% END %]
<script language="JavaScript">
YAHOO.util.Event.addListener(window, "load", function() { menuforusers_initcombo("[% id | js %]", [% multiple ? 1 : 0 %]) }, null);
</script>

View File

@ -181,6 +181,7 @@
name => "requestee_type-$type.id"
id => "requestee_type-$type.id"
value => ""
multiple => type.is_multiplicable
emptyok => !type.is_multiplicable
usemenuforusers => type.custom_list
custom_userlist => type.custom_list