1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-30 01:30:12 +02:00

Hide edited value if selected function will not use it

This commit is contained in:
Peter Knut
2024-10-02 11:08:13 +02:00
parent 1de9275f11
commit bf1d16cdb7
5 changed files with 61 additions and 35 deletions

View File

@@ -751,7 +751,7 @@ class Adminer {
* @param string
* @return string custom input field or empty string for default
*/
function editInput($table, $field, $attrs, $value) {
function editInput($table, $field, $attrs, $value, $function) {
if ($field["type"] == "enum") {
return (isset($_GET["select"]) ? "<label><input type='radio'$attrs value='-1' checked><i>" . lang('original') . "</i></label> " : "")
. ($field["null"] ? "<label><input type='radio'$attrs value=''" . ($value !== null || isset($_GET["select"]) ? "" : " checked") . "><i>NULL</i></label> " : "")

View File

@@ -963,7 +963,7 @@ function input($field, $value, $function) {
echo "<td class='function'>";
if ($field["type"] == "enum") {
echo h($functions[""]) . "<td>" . $adminer->editInput($_GET["edit"], $field, $attrs, $value);
echo h($functions[""]) . "<td>" . $adminer->editInput($_GET["edit"], $field, $attrs, $value, $function);
} else {
$has_function = (in_array($function, $functions) || isset($functions[$function]));
echo (count($functions) > 1
@@ -972,7 +972,7 @@ function input($field, $value, $function) {
. script("qsl('select').onchange = functionChange;", "")
: h(reset($functions))
) . '<td>';
$input = $adminer->editInput($_GET["edit"], $field, $attrs, $value); // usage in call is without a table
$input = $adminer->editInput($_GET["edit"], $field, $attrs, $value, $function); // usage in call is without a table
if ($input != "") {
echo $input;
} elseif (preg_match('~bool~', $field["type"])) {
@@ -1006,7 +1006,8 @@ function input($field, $value, $function) {
// type='date' and type='time' display localized value which may be confusing, type='datetime' uses 'T' as date and time separator
echo "<input"
. ((!$has_function || $function === "") && preg_match('~(?<!o)int(?!er)~', $field["type"]) && !preg_match('~\[\]~', $field["full_type"]) ? " type='number'" : "")
. " value='" . h($value) . "'" . ($maxlength ? " data-maxlength='$maxlength'" : "")
. ($function != "now" ? " value='" . h($value) . "'" : " data-last-value='" . h($value) . "'")
. ($maxlength ? " data-maxlength='$maxlength'" : "")
. (preg_match('~char|binary~', $field["type"]) && $maxlength > 20 ? " size='40'" : "")
. "$attrs>"
;
@@ -1020,9 +1021,7 @@ function input($field, $value, $function) {
}
$first++;
}
if ($first) {
echo script("mixin(qsl('td'), {onchange: partial(skipOriginal, $first), oninput: function () { this.onchange(); }});");
}
echo script("mixin(qsl('td'), {onchange: partial(skipOriginal, $first), oninput: function () { this.onchange(); }});");
}
}

View File

@@ -547,37 +547,62 @@ function editingKeydown(event) {
return true;
}
/** Disable maxlength for functions
* @this HTMLSelectElement
*/
/**
* Disables maxlength for functions and manages value visibility.
*
* @this HTMLSelectElement
*/
function functionChange() {
var input = this.form[this.name.replace(/^function/, 'fields')];
if (input) { // undefined with the set data type
if (selectValue(this)) {
if (input.origType === undefined) {
input.origType = input.type;
input.origMaxLength = input.getAttribute('data-maxlength');
}
input.removeAttribute('data-maxlength');
input.type = 'text';
} else if (input.origType) {
input.type = input.origType;
if (input.origMaxLength >= 0) {
input.setAttribute('data-maxlength', input.origMaxLength);
}
}
oninput({target: input});
const input = this.form[this.name.replace(/^function/, 'fields')];
const value = selectValue(this);
// Undefined with the set data type.
if (!input) {
helpClose();
return;
}
if (value) {
if (input.origType === undefined) {
input.origType = input.type;
input.origMaxLength = input.getAttribute('data-maxlength');
}
input.removeAttribute('data-maxlength');
input.type = 'text';
} else if (input.origType) {
input.type = input.origType;
if (input.origMaxLength >= 0) {
input.setAttribute('data-maxlength', input.origMaxLength);
}
}
// Hide input value if it will be not used by selected function.
if (value === "NULL" || value === "now") {
if (input.value !== "") {
input.dataset.lastValue = input.value;
input.value = "";
}
} else if (input.dataset.lastValue) {
input.value = input.dataset.lastValue;
}
oninput({target: input});
helpClose();
}
/** Skip 'original' when typing
* @param number
* @this HTMLTableCellElement
*/
/**
* Unset 'original', 'NULL' and 'now' functions when typing.
*
* @param first number
* @this HTMLTableCellElement
*/
function skipOriginal(first) {
var fnSelect = this.previousSibling.firstChild;
if (fnSelect.selectedIndex < first) {
const fnSelect = this.previousSibling.firstChild;
const value = selectValue(fnSelect);
if (fnSelect.selectedIndex < first || value === "NULL" || value === "now") {
fnSelect.selectedIndex = first;
}
}

View File

@@ -483,7 +483,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
return $return;
}
function editInput($table, $field, $attrs, $value) {
function editInput($table, $field, $attrs, $value, $function) {
if ($field["type"] == "enum") {
return (isset($_GET["select"]) ? "<label><input type='radio'$attrs value='-1' checked><i>" . lang('original') . "</i></label> " : "")
. enum_input("radio", $attrs, $field, ($value || isset($_GET["select"]) ? $value : 0), ($field["null"] ? "" : null))
@@ -511,7 +511,9 @@ qsl('div').onclick = whisperClick;", "")
$hint = lang('[yyyy]-mm-dd') . ($hint ? " [$hint]" : "");
}
if ($hint) {
return "<input value='" . h($value) . "'$attrs> ($hint)"; //! maxlength
return "<input"
. ($function != "now" ? " value='" . h($value) . "'" : " data-last-value='" . h($value) . "'")
. "$attrs> ($hint)"; //! maxlength
}
if (preg_match('~_(md5|sha1)$~i', $field["field"])) {
return "<input type='password' value='" . h($value) . "'$attrs>";

View File

@@ -335,7 +335,7 @@ class AdminerPlugin extends Adminer {
return $this->_applyPlugin(__FUNCTION__, $args);
}
function editInput($table, $field, $attrs, $value) {
function editInput($table, $field, $attrs, $value, $function) {
$args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args);
}