Skip to content

Commit

Permalink
alias_mgm: auto-complete field in select form, when only one or zero …
Browse files Browse the repository at this point in the history
…values are available
  • Loading branch information
dariusstefan authored and razvancrainea committed Aug 14, 2024
1 parent dc8e626 commit b3c7a9d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 16 deletions.
56 changes: 40 additions & 16 deletions web/common/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,25 +459,49 @@ function form_generate_select($title,$tip,$id,$mlen,$val,$vals,$texts=null,$is_o
if (!is_null($tip))
print(" <div class='tooltip'><sup>?</sup>
<span class='tooltiptext'>".$tip."</span>
</div> ");
</div>");
print("
</td>
<td class='dataRecord' width='250'>
<table style='width:100%'><tr><td>
<select name='".$id."' id='".$id."' style='width: ".$mlen."px;' class='dataSelect'>");
if ($is_optional) {
print(" <option value=''".(($val=="")?" selected":"").">Empty ...</option>");
}
for($i = 0; $i < count($vals); ++$i){
print("
<option value='".$vals[$i]."'".(($val==$vals[$i])?" selected":"").">".($texts[$i]?$texts[$i]:$vals[$i])."</option>");
}
print("
</select>
</td>
<td width='20'>
<div id='".$id."_ok'></div>
</td></tr></table>
<table style='width:100%'>
<tr>
<td>");

$options_count = count($vals);
if ($options_count == 1 && !$is_optional) {
print(" <input type='text' name='".$id."' value='".$vals[0]."' readonly style='width: 205px' class='dataSelect'>");
} else {
if ($options_count == 0) {
$text = $is_optional ? "Empty ..." : "No options available";

if (!$is_optional) {
print(" <select name='".$id."' id='".$id."' style='width: ".$mlen."px;' class='dataSelect' disabled>");
print(" <option value=''>".$text."</option>");
print(" </select>");
} else {
print(" <input type='text' name='".$id."' value='' readonly style='width: 205px' class='dataSelect' placeholder='".$text."'>");
}
} else {
print(" <select name='".$id."' id='".$id."' style='width: ".$mlen."px;' class='dataSelect'>");

if ($is_optional) {
print(" <option value=''".(($val=="")?" selected":"").">Empty ...</option>");
}

for($i = 0; $i < count($vals); ++$i){
print(" <option value='".$vals[$i]."'".(($val==$vals[$i])?" selected":"").">".($texts[$i]?$texts[$i]:$vals[$i])."</option>");
}

print(" </select>");
}
}

print(" </td>
<td width='20'>
<div id='".$id."_ok'></div>
</td>
</tr>
</table>
</td>
</tr>");
}
Expand Down
16 changes: 16 additions & 0 deletions web/tools/users/alias_management/lib/functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ function print_domains($type,$value,$has_any)
$temp ='';
$end_index = sizeof($options);

if ($end_index == 0)
return;

if ($end_index == 1) {
echo('<input type="text" name="'.$type.'" value="'.$options[0][value].'" readonly style="width: 205px" class="dataSelect">');
return;
}

echo('<select ');
if (isset($_SESSION['fromusrmgmt']) && ($_SESSION['fromusrmgmt'])) echo "disabled ";
echo('name='.$type.' id='.$type.' size="1" style="width: 205px" class="dataSelect">');
Expand Down Expand Up @@ -78,6 +86,14 @@ function print_aliasType($value, $has_any)
}
$start_index = 0;
$end_index = sizeof($options);

if ($end_index == 0)
return;

if ($end_index == 1) {
echo('<input type="text" name="'.$type.'" value="'.$options[0][label].'" readonly style="width: 205px" class="dataSelect">');
return;
}
?>
<select name="alias_type" id="alias_type" size="1" style="width: 190px" class="dataSelect">
<?php
Expand Down
16 changes: 16 additions & 0 deletions web/tools/users/user_management/lib/functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ function print_aliasType($value)
$options = get_alias_types();
$start_index = 0;
$end_index = sizeof($options);

if ($end_index == 0)
return;

if ($end_index == 1) {
echo('<input type="text" name="'.$type.'" value="'.$options[0][label].'" readonly style="width: 205px" class="dataSelect">');
return;
}
?>
<select name="alias_type" id="alias_type" size="1" style="width: 205px" class="dataSelect">
<?php
Expand Down Expand Up @@ -67,6 +75,14 @@ function print_domains($type,$value,$has_any)
$temp = '';
$end_index = sizeof($domains);

if ($end_index == 0)
return;

if ($end_index == 1) {
echo('<input type="text" name="'.$type.'" value="'.$domains[0].'" readonly style="width: 205px" class="dataSelect">');
return;
}

echo('<select name='.$type.' id='.$type.' size="1" style="width: 205px" class="dataSelect">');
if ($value!=NULL && $value!="") {
echo('<option value="'.$value. '" selected > '.$value.'</option>');
Expand Down

0 comments on commit b3c7a9d

Please sign in to comment.