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 */ /* template/en/global/menuforusers.html.tmpl */
function menuforusers_initcombo(id) function menuforusers_initcombo(id, multi)
{ {
var sel = document.getElementById(id+"_s"); var sel = document.getElementById(id+"_s");
var ed = document.getElementById(id); var ed = document.getElementById(id);
@ -124,31 +124,65 @@ function menuforusers_initcombo(id)
menuforusers_tocombo(id); menuforusers_tocombo(id);
} }
function menuforusers_tocombo(id) RegExp.escape = function(text) {
{ if (!arguments.callee.sRE) {
var sel = document.getElementById(id+"_s"); var specials = [
var ed = document.getElementById(id); '/', '.', '*', '+', '?', '|',
if (!sel || !ed) '(', ')', '[', ']', '{', '}', '\\'
return; ];
var v = ed.value.toLowerCase(); arguments.callee.sRE = new RegExp(
for (var i = 0; i < sel.options.length; i++) '(\\' + specials.join('|\\') + ')', 'g'
{ );
if (sel.options[i].value.toLowerCase().indexOf(v) >= 0 ||
sel.options[i].text.toLowerCase().indexOf(v) >= 0)
{
sel.selectedIndex = i;
menuforusers_fromcombo(id);
break;
}
} }
return text.replace(arguments.callee.sRE, '\\$1');
} }
function menuforusers_fromcombo(id) function menuforusers_tocombo(id, multi)
{ {
var sel = document.getElementById(id+"_s"); var sel = document.getElementById(id+"_s");
var ed = document.getElementById(id); var ed = document.getElementById(id);
if (!sel || !ed) if (!sel || !ed)
return; return;
if (sel.selectedIndex >= 0) var v = ed.value.toLowerCase().split(/[\s,]+/);
ed.value = sel.options[sel.selectedIndex].value; 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"> <div style="position: relative">
[% SET id="userselect_" _ name IF !id %] [% SET id="userselect_" _ name IF !id %]
[% UNLESS multiple %]
<div class="selectfree_ie" style="position:absolute;top:1px;left:1px;z-index:20;overflow:hidden"> <div class="selectfree_ie" style="position:absolute;top:1px;left:1px;z-index:20;overflow:hidden">
<input <input
name="[% name | html %]" name="[% name | html %]"
@ -35,15 +36,14 @@
[% IF disabled %] disabled="[% disabled | html %]" [% END %] [% IF disabled %] disabled="[% disabled | html %]" [% END %]
[% IF accesskey %] accesskey="[% accesskey | html %]" [% END %] [% IF accesskey %] accesskey="[% accesskey | html %]" [% END %]
id="[% id | html %]" 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 %] [%# 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]--> <!--[if lte IE 6.5]><iframe style="width: 800px; height: 200px;"></iframe><![endif]-->
</div> </div>
<select style="top: 0; left: 0; position: relative; z-index: 10" <select style="top: 0; left: 0; position: relative; z-index: 10"
id="[% id | html %]_s" id="[% id | html %]_s"
[% IF disabled %] disabled="[% disabled | html %]" [% END %] [% 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 %] [% IF emptyok %]<option value=""></option>[% END %]
[% SET custom_userlist=user.get_userlist UNLESS custom_userlist %] [% SET custom_userlist=user.get_userlist UNLESS custom_userlist %]
@ -51,6 +51,29 @@
<option value="[% tmpuser.login | html %]">[% tmpuser.identity | html %]</option> <option value="[% tmpuser.login | html %]">[% tmpuser.identity | html %]</option>
[% END %] [% END %]
</select> </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"> <script language="JavaScript">
YAHOO.util.Event.addListener(window, "load", function() { menuforusers_initcombo("[% id | js %]", [% multiple ? 1 : 0 %]) }, null); YAHOO.util.Event.addListener(window, "load", function() { menuforusers_initcombo("[% id | js %]", [% multiple ? 1 : 0 %]) }, null);
</script> </script>

View File

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