Skip to content

Commit

Permalink
added configuration options for auto suggest propositions
Browse files Browse the repository at this point in the history
  • Loading branch information
Łukasz Kosicki authored and chilek committed Mar 25, 2016
1 parent 5805d90 commit c3bed0a
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 28 deletions.
93 changes: 79 additions & 14 deletions img/autosuggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ function AutoSuggest(form,elem,uri,autosubmit) {

//A reference to the element we're binding the list to.
this.elem = elem;

if (/autosuggest-(left|top|right|bottom)/i.exec(elem.className) !== null)
this.placement = RegExp.$1;
else
this.placement = 'bottom';

this.form = form;
this.uri = uri;
this.autosubmit = autosubmit;
Expand All @@ -37,7 +43,9 @@ function AutoSuggest(form,elem,uri,autosubmit) {
var RET = 13;
var TAB = 9;
var ESC = 27;
var KEYLEFT = 37;
var KEYUP = 38;
var KEYRIGHT = 39;
var KEYDN = 40;

//The browsers' own autocomplete feature can be problematic, since it will
Expand All @@ -61,33 +69,67 @@ function AutoSuggest(form,elem,uri,autosubmit) {
********************************************************/
elem.onkeydown = function(ev) {
var key = me.getKeyCode(ev);

if (/autosuggest-(left|top|right|bottom)/i.exec(elem.className) !== null)
var suggest = RegExp.$1;
else
var suggest = 'bottom';

switch(key) {
case ENT:
case RET:
me.useSuggestion();
me.useSuggestion();
break;

case TAB:
me.useSuggestion();
if (me.highlighted == -1)
me.hideDiv();
else
me.useSuggestion();
break;

case ESC:
me.hideDiv();
me.hideDiv();
break;

case KEYUP:
if (me.highlighted > 0) {
me.highlighted--;
}
me.changeHighlight(key);
if (me.highlighted > 0)
me.highlighted--;
else if (me.highlighted == 0)
me.highlighted = (me.eligible.length - 1);

me.changeHighlight(key);
break;

case KEYDN:
if (me.highlighted < (me.eligible.length - 1)) {
me.highlighted++;
}
me.changeHighlight(key);
if (me.highlighted != -1 && me.highlighted < (me.eligible.length - 1))
me.highlighted++;
else if(me.highlighted == (me.eligible.length - 1))
me.highlighted = 0;

me.changeHighlight(key);
break;

case KEYLEFT:
if (suggest == 'left' && me.highlighted == -1 && me.highlighted < (me.eligible.length - 1)) {
me.highlighted++;
me.changeHighlight(key);
}
else if (suggest == 'right') {
me.highlighted = -1;
me.changeHighlight(key);
}
break;

case KEYRIGHT:
if (suggest == 'right' && me.highlighted == -1 && me.highlighted < (me.eligible.length - 1)) {
me.highlighted++;
me.changeHighlight(key);
}
else if (suggest == 'left') {
me.highlighted = -1;
me.changeHighlight(key);
}
break;
}
};
Expand Down Expand Up @@ -137,7 +179,7 @@ function AutoSuggest(form,elem,uri,autosubmit) {
remove the suggestion dropdown.
********************************************************/
this.useSuggestion = function() {
if (this.highlighted > -1) {
if (this.highlighted > -1 && this.div.style.display != 'none') {
this.elem.value = this.eligible[this.highlighted];
var gotothisuri = this.actions[this.highlighted];
this.hideDiv();
Expand All @@ -156,8 +198,31 @@ function AutoSuggest(form,elem,uri,autosubmit) {
/********************************************************
Display the dropdown. Pretty straightforward.
********************************************************/
this.showDiv = function() {
this.showDiv = function() {
this.div.style.visibility = 'hidden';
this.div.style.display = 'block';

var x = parseInt( this.div.style.left );
var y = parseInt( this.div.style.top );

switch (this.placement) {
case 'left':
x -= this.div.offsetWidth;
break;
case 'right':
x += this.elem.offsetWidth;
break;
case 'top':
y -= this.div.offsetHeight;
break;
default: // bottom
y += this.elem.offsetHeight;
break;
}

this.div.style.left = x + "px";
this.div.style.top = y + "px";
this.div.style.visibility = 'visible';
};

/********************************************************
Expand Down Expand Up @@ -190,7 +255,7 @@ function AutoSuggest(form,elem,uri,autosubmit) {
this.positionDiv = function() {
var el = this.elem;
var x = 0;
var y = el.offsetHeight;
var y = 0;

//Walk up the DOM and add up all of the offset positions.
while (el.offsetParent && el.tagName.toUpperCase() != 'BODY') {
Expand Down
2 changes: 2 additions & 0 deletions lib/locale/pl/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@
$_LANG['Deadline'] = 'Termin płatności';
$_LANG['Deadline:'] = 'Termin płatności:';
$_LANG['Default invoice issuer'] = 'Domyślna osoba tworząca fakturę';
$_LANG['Default position of auto suggest proposition while searching (left/right/top/bottom)'] = 'Domyślna pozycja auto podpowiedzi podczas wyszukiwania (left/right/top/bottom)';
$_LANG['Default zip code, city, street, used while inserting new customer. Useful if you add majority of customers with the same street.'] = 'Domyślny kod pocztowy, miasto, ulica pod czas dodawania nowego klienta. Przydatne kiedy mamy wielu klientów na tej samej ulicy.';
$_LANG['default<!paytime>'] = 'domyślny';
$_LANG['Delete'] = 'Usuń';
Expand Down Expand Up @@ -2140,6 +2141,7 @@
$_LANG['Avg [bit/s]'] = 'Średnio [bit/s]';
$_LANG['Last [bit/s]'] = 'Ostatnio [bit/s]';
$_LANG['Max [bit/s]'] = 'Maks. [bit/s]';
$_LANG['Max length of auto suggest proposal, further characters will be dotted.'] = 'Maksymalna długość wyświetlanych podpowiedzi, w przypadku przekroczenia dalszy napis zostanie zakropkowany.';
$_LANG['Transmitted [B]'] = 'Przesłane dane [B]';
$_LANG['Customer Timetable:'] = 'Terminarz klienta:';
$_LANG['last $a events'] = 'ostatnie $a zdarzeń';
Expand Down
14 changes: 13 additions & 1 deletion modules/configlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,19 @@ function GetConfigList($order='var,asc', $section='', $search='')
{
case 'phpui':
switch($item['var'])
{
{
case 'default_autosuggest_maxlength':
$config[$idx]['description'] = trans('Max length of auto suggest proposal, further characters will be dotted.');
break;

case 'default_autosuggest_placement':
$config[$idx]['description'] = trans('Default placement of suggestion window (left/right/top/bottom)');
break;

case 'allow_from2':
$config[$idx]['description'] = trans('List of networks and IP addresses, with access to LMS. If empty, every IP address has access to LMS. When you write list of addresses or address pools here, LMS will dismiss every unwanted user with HTTP 403 error.');
break;

case 'allow_from':
$config[$idx]['description'] = trans('List of networks and IP addresses, with access to LMS. If empty, every IP address has access to LMS. When you write list of addresses or address pools here, LMS will dismiss every unwanted user with HTTP 403 error.');
break;
Expand Down
5 changes: 3 additions & 2 deletions modules/netsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
ORDER BY
entries DESC, item ASC
LIMIT 15');

if ($mode == 'dns') {
$candidates2 = $DB->GetAll('SELECT
dns2 as item,
Expand All @@ -92,7 +92,7 @@
ORDER BY
entries DESC, item ASC
LIMIT 15');

$candidates = array_merge($candidates, $candidates2);
}
elseif ($mode == 'host') {
Expand Down Expand Up @@ -159,6 +159,7 @@
$layout['pagetitle'] = trans('IP Network Search');

$SESSION->remove('ndlsp');
$SMARTY->assign('autosuggest_placement', ConfigHelper::getConfig('phpui.default_autosuggest_placement'));
$SMARTY->assign('k',$k);
$SMARTY->display('net/netsearch.html');
}
Expand Down
2 changes: 2 additions & 0 deletions templates/default/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@
</tr>
</table>
<script type="text/javascript">
<!--//
var clickMenu1 = new ClickShowHideMenu('click-menu1');
clickMenu1.init();
//-->
</script>
</div>
<div id="pagecontent">
Expand Down
18 changes: 9 additions & 9 deletions templates/default/net/netsearch.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <H1>{$layout.pagetitle}</H1>
<TD WIDTH="1%">
<B>{trans("Network name:")}</B>
<TD WIDTH="98%">
<INPUT ID="networkname" TYPE="TEXT" NAME="search[network_name]" VALUE="" {tip text="Enter network name or it's fragment"}>
<INPUT ID="networkname" CLASS="autosuggest-{ConfigHelper::getConfig('phpui.default_autosuggest_placement')}" DATA-AUTOSUGGEST-MAXLENGTH="40" TYPE="TEXT" NAME="search[network_name]" VALUE="" {tip text="Enter network name or it's fragment"}>
</TD>
</TR>
<TR>
Expand Down Expand Up @@ -61,7 +61,7 @@ <H1>{$layout.pagetitle}</H1>
<B>{trans("Interface:")}</B>
</TD>
<TD WIDTH="98%">
<INPUT ID="netinterface" TYPE="TEXT" NAME="search[interface]" VALUE="" {tip text="Enter network interface (optional)"}>
<INPUT ID="netinterface" CLASS="autosuggest-{ConfigHelper::getConfig('phpui.default_autosuggest_placement')}" TYPE="TEXT" NAME="search[interface]" VALUE="" {tip text="Enter network interface (optional)"}>
</TD>
</TR>
<TR>
Expand All @@ -72,7 +72,7 @@ <H1>{$layout.pagetitle}</H1>
<B>{trans("Gateway:")}</B>
</TD>
<TD WIDTH="98%">
<INPUT ID="netgateway" TYPE="TEXT" NAME="search[gateway]" VALUE="" {tip text="Enter gateway address (optional)"}>
<INPUT ID="netgateway" CLASS="autosuggest-{ConfigHelper::getConfig('phpui.default_autosuggest_placement')}" TYPE="TEXT" NAME="search[gateway]" VALUE="" {tip text="Enter gateway address (optional)"}>
</TD>
</TR>
<TR>
Expand All @@ -83,7 +83,7 @@ <H1>{$layout.pagetitle}</H1>
<B>{trans("DNS Server:")}</B>
</TD>
<TD WIDTH="98%">
<INPUT ID="netdns" TYPE="TEXT" NAME="search[dns]" VALUE="" {tip text="Enter address or name of DNS server (optional)"}>
<INPUT ID="netdns" CLASS="autosuggest-{ConfigHelper::getConfig('phpui.default_autosuggest_placement')}" TYPE="TEXT" NAME="search[dns]" VALUE="" {tip text="Enter address or name of DNS server (optional)"}>
</TD>
</TR>
<TR>
Expand All @@ -94,7 +94,7 @@ <H1>{$layout.pagetitle}</H1>
<B>{trans("WINS:")}</B>
</TD>
<TD WIDTH="98%">
<INPUT ID="netwins" TYPE="TEXT" NAME="search[wins]" VALUE="" {tip text="Enter WINS address (optional)"}>
<INPUT ID="netwins" CLASS="autosuggest-{ConfigHelper::getConfig('phpui.default_autosuggest_placement')}" TYPE="TEXT" NAME="search[wins]" VALUE="" {tip text="Enter WINS address (optional)"}>
</TD>
</TR>
<TR>
Expand All @@ -105,18 +105,18 @@ <H1>{$layout.pagetitle}</H1>
<B>{trans("Domain:")}</B>
</TD>
<TD WIDTH="98%">
<INPUT ID="netdomain" TYPE="TEXT" NAME="search[domain]" VALUE="" {tip text="Enter network domain (optional)"}>
<INPUT ID="netdomain" CLASS="autosuggest-{ConfigHelper::getConfig('phpui.default_autosuggest_placement')}" TYPE="TEXT" NAME="search[domain]" VALUE="" {tip text="Enter network domain (optional)"}>
</TD>
</TR>
<TR>
<TD WIDTH="1%">
<IMG SRC="img/host.gif" ALT="">
</TD>
<TD WIDTH="1%" NOWRAP>
<B>{trans("List of Hosts:")}</B>
<B>{trans("Host:")}</B>
</TD>
<TD WIDTH="98%">
<INPUT ID="nethost" TYPE="TEXT" NAME="search[hostid]" VALUE="" {tip text="Enter host name (optional)"}>
<INPUT ID="nethost" CLASS="autosuggest-{ConfigHelper::getConfig('phpui.default_autosuggest_placement')}" TYPE="TEXT" NAME="search[hostid]" VALUE="" {tip text="Enter host name (optional)"}>
</TD>
</TR>
<TR>
Expand All @@ -127,7 +127,7 @@ <H1>{$layout.pagetitle}</H1>
<B>{trans("Description:")}</B>
</TD>
<TD WIDTH="98%">
<INPUT ID="netdesc" TYPE="TEXT" NAME="search[description]" VALUE="" {tip text="Enter additional information"}>
<INPUT ID="netdesc" CLASS="autosuggest-{ConfigHelper::getConfig('phpui.default_autosuggest_placement')}" TYPE="TEXT" NAME="search[description]" VALUE="" {tip text="Enter additional information"}>
</TD>
</TR>

Expand Down
2 changes: 0 additions & 2 deletions templates_c/.htaccess

This file was deleted.

0 comments on commit c3bed0a

Please sign in to comment.