mirror of
https://github.com/vrana/adminer.git
synced 2025-08-31 18:11:52 +02:00
Hide edited value if selected function will not use it
This commit is contained in:
@@ -751,7 +751,7 @@ class Adminer {
|
|||||||
* @param string
|
* @param string
|
||||||
* @return string custom input field or empty string for default
|
* @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") {
|
if ($field["type"] == "enum") {
|
||||||
return (isset($_GET["select"]) ? "<label><input type='radio'$attrs value='-1' checked><i>" . lang('original') . "</i></label> " : "")
|
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> " : "")
|
. ($field["null"] ? "<label><input type='radio'$attrs value=''" . ($value !== null || isset($_GET["select"]) ? "" : " checked") . "><i>NULL</i></label> " : "")
|
||||||
|
@@ -963,7 +963,7 @@ function input($field, $value, $function) {
|
|||||||
echo "<td class='function'>";
|
echo "<td class='function'>";
|
||||||
|
|
||||||
if ($field["type"] == "enum") {
|
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 {
|
} else {
|
||||||
$has_function = (in_array($function, $functions) || isset($functions[$function]));
|
$has_function = (in_array($function, $functions) || isset($functions[$function]));
|
||||||
echo (count($functions) > 1
|
echo (count($functions) > 1
|
||||||
@@ -972,7 +972,7 @@ function input($field, $value, $function) {
|
|||||||
. script("qsl('select').onchange = functionChange;", "")
|
. script("qsl('select').onchange = functionChange;", "")
|
||||||
: h(reset($functions))
|
: h(reset($functions))
|
||||||
) . '<td>';
|
) . '<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 != "") {
|
if ($input != "") {
|
||||||
echo $input;
|
echo $input;
|
||||||
} elseif (preg_match('~bool~', $field["type"])) {
|
} 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
|
// type='date' and type='time' display localized value which may be confusing, type='datetime' uses 'T' as date and time separator
|
||||||
echo "<input"
|
echo "<input"
|
||||||
. ((!$has_function || $function === "") && preg_match('~(?<!o)int(?!er)~', $field["type"]) && !preg_match('~\[\]~', $field["full_type"]) ? " type='number'" : "")
|
. ((!$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'" : "")
|
. (preg_match('~char|binary~', $field["type"]) && $maxlength > 20 ? " size='40'" : "")
|
||||||
. "$attrs>"
|
. "$attrs>"
|
||||||
;
|
;
|
||||||
@@ -1020,11 +1021,9 @@ function input($field, $value, $function) {
|
|||||||
}
|
}
|
||||||
$first++;
|
$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(); }});");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/** Process edit input field
|
/** Process edit input field
|
||||||
* @param one field from fields()
|
* @param one field from fields()
|
||||||
|
@@ -547,17 +547,27 @@ function editingKeydown(event) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Disable maxlength for functions
|
/**
|
||||||
|
* Disables maxlength for functions and manages value visibility.
|
||||||
|
*
|
||||||
* @this HTMLSelectElement
|
* @this HTMLSelectElement
|
||||||
*/
|
*/
|
||||||
function functionChange() {
|
function functionChange() {
|
||||||
var input = this.form[this.name.replace(/^function/, 'fields')];
|
const input = this.form[this.name.replace(/^function/, 'fields')];
|
||||||
if (input) { // undefined with the set data type
|
const value = selectValue(this);
|
||||||
if (selectValue(this)) {
|
|
||||||
|
// Undefined with the set data type.
|
||||||
|
if (!input) {
|
||||||
|
helpClose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value) {
|
||||||
if (input.origType === undefined) {
|
if (input.origType === undefined) {
|
||||||
input.origType = input.type;
|
input.origType = input.type;
|
||||||
input.origMaxLength = input.getAttribute('data-maxlength');
|
input.origMaxLength = input.getAttribute('data-maxlength');
|
||||||
}
|
}
|
||||||
|
|
||||||
input.removeAttribute('data-maxlength');
|
input.removeAttribute('data-maxlength');
|
||||||
input.type = 'text';
|
input.type = 'text';
|
||||||
} else if (input.origType) {
|
} else if (input.origType) {
|
||||||
@@ -566,18 +576,33 @@ function functionChange() {
|
|||||||
input.setAttribute('data-maxlength', input.origMaxLength);
|
input.setAttribute('data-maxlength', input.origMaxLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oninput({target: input});
|
|
||||||
|
// 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();
|
helpClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Skip 'original' when typing
|
/**
|
||||||
* @param number
|
* Unset 'original', 'NULL' and 'now' functions when typing.
|
||||||
|
*
|
||||||
|
* @param first number
|
||||||
* @this HTMLTableCellElement
|
* @this HTMLTableCellElement
|
||||||
*/
|
*/
|
||||||
function skipOriginal(first) {
|
function skipOriginal(first) {
|
||||||
var fnSelect = this.previousSibling.firstChild;
|
const fnSelect = this.previousSibling.firstChild;
|
||||||
if (fnSelect.selectedIndex < first) {
|
const value = selectValue(fnSelect);
|
||||||
|
|
||||||
|
if (fnSelect.selectedIndex < first || value === "NULL" || value === "now") {
|
||||||
fnSelect.selectedIndex = first;
|
fnSelect.selectedIndex = first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -483,7 +483,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
|
|||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function editInput($table, $field, $attrs, $value) {
|
function editInput($table, $field, $attrs, $value, $function) {
|
||||||
if ($field["type"] == "enum") {
|
if ($field["type"] == "enum") {
|
||||||
return (isset($_GET["select"]) ? "<label><input type='radio'$attrs value='-1' checked><i>" . lang('original') . "</i></label> " : "")
|
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))
|
. 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]" : "");
|
$hint = lang('[yyyy]-mm-dd') . ($hint ? " [$hint]" : "");
|
||||||
}
|
}
|
||||||
if ($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"])) {
|
if (preg_match('~_(md5|sha1)$~i', $field["field"])) {
|
||||||
return "<input type='password' value='" . h($value) . "'$attrs>";
|
return "<input type='password' value='" . h($value) . "'$attrs>";
|
||||||
|
@@ -335,7 +335,7 @@ class AdminerPlugin extends Adminer {
|
|||||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
function editInput($table, $field, $attrs, $value) {
|
function editInput($table, $field, $attrs, $value, $function) {
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
return $this->_applyPlugin(__FUNCTION__, $args);
|
return $this->_applyPlugin(__FUNCTION__, $args);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user