Skip to content

Commit

Permalink
- fetching data too early error fixed (when xmlhttprequest not define…
Browse files Browse the repository at this point in the history
…d yet)

- autosubmit on/off (on: go to action url directly; off: insert suggestion)
- support for non-clickable suggestions (for ip/mac lookups)
- now whole suggest row is clickable (if action defined for a row)
  • Loading branch information
Konrad Rzentarzewski committed May 25, 2005
1 parent 89cff5a commit b59bcdd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
24 changes: 15 additions & 9 deletions img/autosuggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Licensed under GNU Lesser General Public License (LGPL).
Modified by kondi for LMS project (mailto:lms@kondi.net).
*******************************************************/

function AutoSuggest(form,elem,uri) {
function AutoSuggest(form,elem,uri,autosubmit) {

//The 'me' variable allow you to access the AutoSuggest object
//from the elem's event handlers defined below.
Expand All @@ -18,6 +18,7 @@ function AutoSuggest(form,elem,uri) {
this.elem = elem;
this.form = form;
this.uri = uri;
this.autosubmit = autosubmit;

//Arrow to store a subset of eligible suggestions that match the user's input
this.eligible = new Array();
Expand Down Expand Up @@ -118,7 +119,7 @@ function AutoSuggest(form,elem,uri) {
};

this.HTTPloaded = function () {
if (xmlhttp.readyState == 4) {
if ((xmlhttp)&&(xmlhttp.readyState == 4)) {
me.inputText = this.value;
me.getEligible();
if (me.eligible.length>0) {
Expand Down Expand Up @@ -148,7 +149,7 @@ function AutoSuggest(form,elem,uri) {
this.form.onsubmit = function () { return false; };
setTimeout("document.getElementById('" + this.form.id + "').onsubmit = function () { return true; }",10);
//Go to search results.
location.href = gotothisuri;
if (this.autosubmit == 1) location.href = gotothisuri;
}
};

Expand Down Expand Up @@ -214,17 +215,22 @@ function AutoSuggest(form,elem,uri) {
//Create an array of LI's for the words.
for (i in this.eligible) {
var word = this.eligible[i];
var desc = this.descriptions[i];
var dest = this.actions[i];
var desc = (this.descriptions[i])?this.descriptions[i]:'';
var dest = (this.actions[i])?this.actions[i]:'';

var ds = document.createElement('span');
var li = document.createElement('li');
var a = document.createElement('a');
a.href = dest;
a.innerHTML = word;
if (dest) {
a.href = dest;
a.innerHTML = word;
li.onclick = function() { location.href = dest; }
li.appendChild(a);
} else {
li.innerHTML = word;
}
ds.innerHTML = desc;
li.appendChild(a);
a.appendChild(ds);
li.appendChild(ds);

if (me.highlighted == i) {
li.className = "selected";
Expand Down
6 changes: 3 additions & 3 deletions templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<div class="tip" {tip text="<B>Enter customer ID, first/lastname, telephone or part of customer email address and press Enter</B>"}>
<br>&nbsp;&nbsp;<img src="img/user.gif" alt="*">&nbsp;<input type="text" id="userinput" name="what" value="" size="15"><input type="hidden" name="m" value="quicksearch"><input type="hidden" name="mode" value="user">
<script language="Javascript">
new AutoSuggest(document.getElementById('userform'),document.getElementById('userinput'),'?m=quicksearch&ajax=1&mode=user&what=');
new AutoSuggest(document.getElementById('userform'),document.getElementById('userinput'),'?m=quicksearch&ajax=1&mode=user&what=',1);
</script>
</div>
</td>
Expand All @@ -71,7 +71,7 @@
<div class="tip" {tip text="<B>Enter node ID, name, IP address or MAC address and press Enter</B>"}>
&nbsp;&nbsp;<img src="img/node.gif" alt="*">&nbsp;<input type="text" id="nodeinput" name="what" value="" size="15"><input type="hidden" name="m" value="quicksearch"><input type="hidden" name="mode" value="node">
<script language="Javascript">
new AutoSuggest(document.getElementById('nodeform'),document.getElementById('nodeinput'),'?m=quicksearch&ajax=1&mode=node&what=');
new AutoSuggest(document.getElementById('nodeform'),document.getElementById('nodeinput'),'?m=quicksearch&ajax=1&mode=node&what=',1);
</script>
</div>
</td>
Expand All @@ -83,7 +83,7 @@
<div class="tip" {tip text="<B>Enter request tracker ID or customer name and press Enter</B>"}>
&nbsp;&nbsp;<img src="img/ticket.gif" alt="*">&nbsp;<input type="text" id="rtinput" name="what" value="" size="15"><input type="hidden" name="m" value="quicksearch"><input type="hidden" name="mode" value="ticket">
<script language="Javascript">
new AutoSuggest(document.getElementById('rtform'),document.getElementById('rtinput'),'?m=quicksearch&ajax=1&mode=ticket&what=');
new AutoSuggest(document.getElementById('rtform'),document.getElementById('rtinput'),'?m=quicksearch&ajax=1&mode=ticket&what=',1);
</script>
</div>
</td>
Expand Down

0 comments on commit b59bcdd

Please sign in to comment.