diff --git a/html/js/scripts.js b/html/js/scripts.js index f10662b80..719286bb8 100644 --- a/html/js/scripts.js +++ b/html/js/scripts.js @@ -2157,7 +2157,49 @@ function filter_table(phrase, _id, colnr, start_row) { } } } +/** + * @brief filter quickly a list + * @param phrase : DOM id of the input text where we find the word to seach + * @param _id : id of the list + * @returns nothing + * @see HtmlInput::filter_list + */ +function filter_list(phrase, _id) { + $('info_div').innerHTML = content[65]; + $('info_div').style.display = "block"; + var words = $(phrase).value.toLowerCase(); + var l_list = document.getElementById(_id); + var ele; + var tot_found = 0; + + for (var r = 0; r < l_list.childNodes.length; r++) { + var found = 0; + if ( l_list.childNodes[r].childElementCount == 0 ) + { + ele = l_list.childNodes[r].innerHTML; + } else { + ele = l_list.childNodes[r].childNodes[0].innerHTML; + } + if ( ele.toLowerCase().indexOf(words) >= 0) { + tot_found++; + l_list.childNodes[r].style.display='block'; + } else { + l_list.childNodes[r].style.display='none'; + } + $('info_div').style.display = "none"; + $('info_div').innerHTML = ""; + } + if (tot_found == 0) { + if ($('info_' + _id)) { + $('info_' + _id).innerHTML = content[69] + } + } else { + if ($('info_' + _id)) { + $('info_' + _id).innerHTML = " "; + } + } +} /** * @brief * Display the task late or for today in dashboard diff --git a/include/lib/html_input.class.php b/include/lib/html_input.class.php index 815ea07ff..41c118352 100755 --- a/include/lib/html_input.class.php +++ b/include/lib/html_input.class.php @@ -975,6 +975,21 @@ class HtmlInput $r.=' '; return $r; } + /** + * Display a field for searching an element in a list + * @param string $p_list_id DOM ID of the list (ul or ol) + * @return string + */ + static function filter_list($p_list_id) + { + $r=""; + $r.=sprintf('', + $p_list_id,$p_list_id,$p_list_id); + + $r.=sprintf('',$p_list_id,$p_list_id); + $r.=''; + return $r; + } static function show_reconcile($p_div, $let, $span="") { diff --git a/include/lib/select_box.class.php b/include/lib/select_box.class.php index 9e07d6e74..c2eb361c3 100644 --- a/include/lib/select_box.class.php +++ b/include/lib/select_box.class.php @@ -34,6 +34,7 @@ class Select_Box var $id; var $item; private $cnt; + private $filter; //!< allow a dynamic not case sensitive search var $default_value; /** @@ -50,22 +51,27 @@ class Select_Box $this->cnt=0; $this->default_value=-1; $this->style_box=""; + $this->filter=""; } function input() { + $list_id=sprintf('%s_list',$this->id); + // Show when click $javascript=sprintf('$("%s_bt").onclick=function() { try { var newDiv=$("select_box%s"); var pos=$("%s_bt").cumulativeOffset(); newDiv.setStyle({display:"block",position:"fixed",top:pos.top+25+"px",left:pos.left+5+"px"}); + + if ( $("search_%s") ) { $("search_%s").focus();} } catch(e) { alert(e.message); } } - ', $this->id, $this->id, $this->id, $this->id); + ', $this->id, $this->id, $this->id, $list_id,$list_id); // Hide when out of the zone $javascript.=sprintf('$("select_box%s").onmouseleave=function() { @@ -85,9 +91,14 @@ class Select_Box printf('
', $this->id, $this->style_box); - + // Show the filter if there is one, + if ( $this->filter != "" ) { + echo $this->filter; + echo HtmlInput::filter_list($list_id); + } + // Print the list of possible options - printf('