Skip to content
Browse files

Load long texts for inline-edit by AJAX

Display link to current page only under AJAX
  • Loading branch information...
1 parent 78adfc2 commit 390e38b8f5137518be1738ea96c50f65ea2ef306 @vrana committed
View
2 adminer/edit.inc.php
@@ -107,7 +107,7 @@
echo "<input type='submit' name='delete' value='" . lang('Delete') . "' onclick=\"return confirm('" . lang('Are you sure?') . "')" . (isset($_GET["select"]) ? " &amp;&amp; !ajaxForm(this.form, 'delete=1')" : "") . ";\">\n";
}
if (isset($_GET["select"])) {
- echo "<a href='" . h($_SERVER["REQUEST_URI"]) . "' onclick='return !ajax(this.href);'>" . lang('Cancel') . "</a>\n";
+ echo "<a href='" . h($_SERVER["REQUEST_URI"]) . "' onclick='return !ajaxMain(this.href);'>" . lang('Cancel') . "</a>\n";
}
?>
</form>
View
2 adminer/include/adminer.inc.php
@@ -130,7 +130,7 @@ function backwardKeysPrint($backwardKeys, $row) {
*/
function selectQuery($query) {
global $jush;
- return "<p><a href='" . h(remove_from_uri("page")) . "&amp;page=last' title='" . lang('Page') . ": " . lang('last') . "'>&gt;&gt;</a> <code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a> <a href='" . h($_SERVER["REQUEST_URI"]) . "'>#</a>\n";
+ return "<p><a href='" . h(remove_from_uri("page")) . "&amp;page=last' title='" . lang('Page') . ": " . lang('last') . "'>&gt;&gt;</a> <code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>" . (is_ajax() ? " <a href='" . h($_SERVER["REQUEST_URI"]) . "'>#</a>" : "") . "\n";
}
/** Description of a row in a table
View
4 adminer/include/design.inc.php
@@ -10,7 +10,7 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
global $LANG, $HTTPS, $adminer, $connection, $drivers;
header("Content-Type: text/html; charset=utf-8");
$adminer->headers();
- if ($_SERVER["HTTP_X_REQUESTED_WITH"] != "XMLHttpRequest") {
+ if (!is_ajax()) {
$title_all = $title . ($title2 != "" ? ": " . h($title2) : "");
$protocol = ($HTTPS ? "https" : "http");
?>
@@ -81,7 +81,7 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
*/
function page_footer($missing = "") {
global $adminer;
- if ($_SERVER["HTTP_X_REQUESTED_WITH"] != "XMLHttpRequest") {
+ if (!is_ajax()) {
?>
</div>
</div>
View
9 adminer/include/functions.inc.php
@@ -335,6 +335,13 @@ function auth_url($driver, $server, $username) {
;
}
+/** Find whether it is an AJAX request
+* @return bool
+*/
+function is_ajax() {
+ return ($_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest");
+}
+
/** Send Location header and exit
* @param string null to only set a message
* @param string
@@ -346,7 +353,7 @@ function redirect($location, $message = null) {
$_SESSION["messages"][] = $message;
}
if (isset($location)) {
- if ($_SERVER["HTTP_X_REQUESTED_WITH"] != "XMLHttpRequest") {
+ if (!is_ajax()) {
header("Location: " . ($location != "" ? $location : "."));
exit;
}
View
1 adminer/lang/ca.inc.php
@@ -235,7 +235,6 @@
'Databases have been dropped.' => 'S\'han suprimit les bases de dades.',
'File exists.' => 'El fitxer ja existeix.',
'Double click on a value to modify it.' => 'Fes un doble clic a un valor per modificar-lo.',
- 'Increase Text length to modify this value.' => 'Incrementa la Longitud del text per modificar aquest valor.',
'Use edit link to modify this value.' => 'Utilitza l\'enllaç d\'edició per modificar aquest valor.',
'Alter schema' => 'Modifica l\'esquema',
'Create schema' => 'Crea un esquema',
View
1 adminer/lang/cs.inc.php
@@ -251,7 +251,6 @@
// selects now support in-place editing
'Double click on a value to modify it.' => 'Dvojklikněte na políčko, které chcete změnit.',
- 'Increase Text length to modify this value.' => 'Ke změně této hodnoty zvyšte Délku textů.',
'Use edit link to modify this value.' => 'Ke změně této hodnoty použijte odkaz upravit.',
// PostgreSQL and MS SQL schema support
View
1 adminer/lang/de.inc.php
@@ -246,7 +246,6 @@
'Type has been dropped.' => 'Typ gelöscht.',
'Type has been created.' => 'Typ erstellt.',
'Double click on a value to modify it.' => 'Doppelklick zum Bearbeiten des Wertes.',
- 'Increase Text length to modify this value.' => 'Vergrössern Sie die Textlänge um den Wert ändern zu können.',
'Use edit link to modify this value.' => 'Benutzen Sie den Link zum editieren dieses Wertes.',
'last' => 'letzte',
'From server' => 'Auf Server',
View
1 adminer/lang/es.inc.php
@@ -246,7 +246,6 @@
'Type has been dropped.' => 'Tipo eliminado.',
'Type has been created.' => 'Tipo creado.',
'Double click on a value to modify it.' => 'Doble-clic sobre el valor para editarlo.',
- 'Increase Text length to modify this value.' => 'Aumente el tamaño del campo de texto para modificar este valor.',
'Use edit link to modify this value.' => 'Utilice el enlace de modificar para realizar los cambios.',
'last' => 'último',
'From server' => 'Desde servidor',
View
1 adminer/lang/et.inc.php
@@ -246,7 +246,6 @@
'Type has been dropped.' => 'Tüüp on edukalt kustutatud.',
'Type has been created.' => 'Tüüp on edukalt loodud.',
'Double click on a value to modify it.' => 'Väärtuse muutmiseks topelt-kliki sellel.',
- 'Increase Text length to modify this value.' => 'Väärtuse muutmiseks suurenda Tekstiveeru pikkust.',
'Use edit link to modify this value.' => 'Väärtuse muutmiseks kasuta muutmislinki.',
'last' => 'viimane',
'From server' => 'Serverist',
View
1 adminer/lang/fr.inc.php
@@ -245,7 +245,6 @@
'Type has been dropped.' => 'Le type a été supprimé.',
'Type has been created.' => 'Le type a été créé.',
'Double click on a value to modify it.' => 'Double-cliquez sur une valeur pour la modifier.',
- 'Increase Text length to modify this value.' => 'Augmentez la Longueur de texte affiché pour modifier cette valeur.',
'Use edit link to modify this value.' => 'Utilisez le lien "modifier" pour modifier cette valeur.',
'last' => 'dernière',
'From server' => 'Depuis le serveur',
View
1 adminer/lang/hu.inc.php
@@ -235,7 +235,6 @@
'Databases have been dropped.' => 'Adatbázis eldobva.',
'File exists.' => 'A fájl létezik.',
'Double click on a value to modify it.' => 'Kattints kétszer az értékre a szerkesztéshez.',
- 'Increase Text length to modify this value.' => 'Növeld a Szöveg hosszát, hogy módosítani tudd ezt az értéket.',
'Use edit link to modify this value.' => 'Használd a szerkesztés hivatkozást ezen érték módosításához.',
'Alter schema' => 'Séma módosítása',
'Create schema' => 'Séma létrehozása',
View
1 adminer/lang/it.inc.php
@@ -246,7 +246,6 @@
'Type has been dropped.' => 'Tipo definito dall\'utente eliminato.',
'Type has been created.' => 'Tipo definito dall\'utente creato.',
'Double click on a value to modify it.' => 'Fai doppio click su un valore per modificarlo.',
- 'Increase Text length to modify this value.' => 'Aumenta la Lunghezza del testo per modificare questo valore.',
'Use edit link to modify this value.' => 'Usa il link modifica per modificare questo valore.',
'last' => 'ultima',
'From server' => 'Dal server',
View
1 adminer/lang/ja.inc.php
@@ -247,7 +247,6 @@
'Type has been dropped.' => 'ユーザー定義型を削除しました',
'Type has been created.' => 'ユーザー定義型を追加しました',
'Double click on a value to modify it.' => 'ダブルクリックして編集',
- 'Increase Text length to modify this value.' => '編集枠を広げる',
'Use edit link to modify this value.' => 'リンクを編集する',
'last' => '最終',
'From server' => 'サーバーから実行',
View
1 adminer/lang/nl.inc.php
@@ -246,7 +246,6 @@
'Type has been dropped.' => 'Type verwijderd.',
'Type has been created.' => 'Type aangemaakt.',
'Double click on a value to modify it.' => 'Dubbelklik op een waarde om deze te bewerken.',
- 'Increase Text length to modify this value.' => 'Verhoog de lengte om deze waarde te bewerken.',
'Use edit link to modify this value.' => 'Gebruik de link "bewerk" om deze waarde te wijzigen.',
'last' => 'laatste',
'From server' => 'Van server',
View
1 adminer/lang/ru.inc.php
@@ -246,7 +246,6 @@
'Type has been dropped.' => 'Тип удален.',
'Type has been created.' => 'Создан новый тип.',
'Double click on a value to modify it.' => 'Кликни два раза по значению, чтобы его изменить.',
- 'Increase Text length to modify this value.' => 'Увеличь Длину текста, чтобы изменить это значение.',
'Use edit link to modify this value.' => 'Изменить это значение можно с помощью ссылки «изменить».',
'last' => 'последняя',
'From server' => 'С сервера',
View
1 adminer/lang/sk.inc.php
@@ -246,7 +246,6 @@
'Type has been created.' => 'Typ bol vytvorený.',
'Alter type' => 'Pozmeniť typ',
'Double click on a value to modify it.' => 'Dvojkliknite na políčko, ktoré chcete zmeniť.',
- 'Increase Text length to modify this value.' => 'Pre zmenu tejto hodnoty zvýšte Dĺžku textov.',
'Use edit link to modify this value.' => 'Pre zmenu tejto hodnoty použite odkaz upraviť.',
'last' => 'posledný',
'From server' => 'Zo serveru',
View
1 adminer/lang/ta.inc.php
@@ -236,7 +236,6 @@
'Schema has been created.' => 'அமைப்புமுறை உருவாக்க‌ப்ப‌ட்ட‌து.',
'Schema has been altered.' => 'அமைப்புமுறை மாற்ற‌ப்ப‌ட்ட‌து.',
'Double click on a value to modify it.' => 'ம‌திப்பினை மாற்ற அத‌ன் மீது இருமுறை சொடுக்க‌வும் (Double click).',
- 'Increase Text length to modify this value.' => 'இந்த‌ ம‌திப்பினை மாற்ற, டெக்ஸ்ட் நீள‌த்தினை அதிக‌ரிக்க‌வும்.',
'Use edit link to modify this value.' => 'இந்த‌ ம‌திப்பினை மாற்ற‌, தொகுப்பு இணைப்பினை உப‌யோகிக்க‌வும்.',
'last' => 'க‌டைசி',
'Sequence has been dropped.' => 'வ‌ரிசைமுறை நீக்க‌ப்ப‌ட்ட‌து.',
View
1 adminer/lang/zh-tw.inc.php
@@ -246,7 +246,6 @@
'Type has been dropped.' => '已刪除類型。',
'Type has been created.' => '已建立類型。',
'Double click on a value to modify it.' => '雙擊以進行修改。',
- 'Increase Text length to modify this value.' => '增加字串長度來修改。',
'Use edit link to modify this value.' => '使用編輯連結來修改。',
'last' => '最後一頁',
'From server' => '從伺服器',
View
1 adminer/lang/zh.inc.php
@@ -246,7 +246,6 @@
'Type has been dropped.' => '已丢弃类型。',
'Type has been created.' => '已创建类型。',
'Double click on a value to modify it.' => '在值上双击类修改它。',
- 'Increase Text length to modify this value.' => '增加文本长度以修改该值。',
'Use edit link to modify this value.' => '使用编辑链接来修改该值。',
'last' => '最后',
'From server' => '来自服务器',
View
14 adminer/select.inc.php
@@ -26,6 +26,14 @@
$from = ($select ? implode(", ", $select) : "*") . "\nFROM " . table($TABLE);
$group_by = ($group && count($group) < count($select) ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : "");
+if ($_GET["val"] && is_ajax()) {
+ header("Content-Type: text/plain; charset=utf-8");
+ foreach ($_GET["val"] as $unique_idf => $row) {
+ echo $connection->result("SELECT" . limit(idf_escape(key($row)) . " FROM " . table($TABLE), " WHERE " . where_check($unique_idf) . ($where ? " AND " . implode(" AND ", $where) : "") . ($order ? " ORDER BY " . implode(", ", $order) : ""), 1));
+ }
+ exit;
+}
+
if ($_POST && !$error) {
$where_check = "(" . implode(") OR (", array_map('where_check', (array) $_POST["check"])) . ")";
$primary = $unselected = null;
@@ -254,7 +262,7 @@
if ($name != "") {
$order++;
$names[$key] = $name;
- echo '<th><a href="' . h(remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key) . ($_GET["order"][0] == $key && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '')) . '" onclick="return !ajax(this.href);">' . apply_sql_function($val["fun"], $name) . "</a>"; //! columns looking like functions
+ echo '<th><a href="' . h(remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key) . ($_GET["order"][0] == $key && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '')) . '" onclick="return !ajaxMain(this.href);">' . apply_sql_function($val["fun"], $name) . "</a>"; //! columns looking like functions
}
$functions[$key] = $val["fun"];
next($select);
@@ -336,11 +344,11 @@
$value = $_POST["val"][$unique_idf][bracket_escape($key)];
$h_value = h(isset($value) ? $value : $row[$key]);
$long = strpos($val, "<i>...</i>");
- $editable = is_utf8($val) && !$long && $rows[$n][$key] == $row[$key] && !$functions[$key];
+ $editable = is_utf8($val) && $rows[$n][$key] == $row[$key] && !$functions[$key];
$text = ereg('text|lob', $field["type"]);
echo (($_GET["modify"] && $editable) || isset($value)
? "<td>" . ($text ? "<textarea name='$id' cols='30' rows='" . (substr_count($row[$key], "\n") + 1) . "' onkeydown='return textareaKeydown(this, event);'>$h_value</textarea>" : "<input name='$id' value='$h_value' size='$lengths[$key]'>")
- : "<td id='$id' ondblclick=\"" . ($editable ? "selectDblClick(this, event" . ($text ? ", 1" : "") . ")" : "alert('" . h($long ? lang('Increase Text length to modify this value.') : lang('Use edit link to modify this value.')) . "')") . ";\">" . $adminer->selectVal($val, $link, $field)
+ : "<td id='$id' ondblclick=\"" . ($editable ? "selectDblClick(this, event" . ($long ? ", 2" : ($text ? ", 1" : "")) . ")" : "alert('" . h(lang('Use edit link to modify this value.')) . "')") . ";\">" . $adminer->selectVal($val, $link, $field)
);
}
}
View
66 adminer/static/functions.js
@@ -163,36 +163,23 @@ function textareaKeydown(target, event, tab, button) {
-var ajaxState = 0;
-var ajaxTimeout;
-
/** Create AJAX request
* @param string
+* @param function (text)
* @param [string]
* @return XMLHttpRequest or false in case of an error
*/
-function ajax(url, data) {
+function ajax(url, callback, data) {
var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : false));
if (xmlhttp) {
- var currentState = ++ajaxState;
- clearTimeout(ajaxTimeout);
- ajaxTimeout = setTimeout(function () {
- setHtml('main', '<img src="../adminer/static/loader.gif" alt="">');
- }, 500); // defer displaying loader
- var method = (data === undefined ? 'GET' : 'POST');
- xmlhttp.open(method, url);
- if (method == 'POST') {
+ xmlhttp.open((data === undefined ? 'GET' : 'POST'), url);
+ if (data) {
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
xmlhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
- xmlhttp.onreadystatechange = function () {
- if (xmlhttp.readyState == 4 && currentState == ajaxState) {
- clearTimeout(ajaxTimeout);
- setHtml('main', xmlhttp.responseText);
- if (window.jush) {
- jush.highlight_tag('code');
- jush.highlight_tag('pre', 0);
- }
+ xmlhttp.onreadystatechange = function (text) {
+ if (xmlhttp.readyState == 4) {
+ callback(xmlhttp.responseText);
}
};
xmlhttp.send(data);
@@ -200,6 +187,32 @@ function ajax(url, data) {
return xmlhttp;
}
+var ajaxState = 0;
+var ajaxTimeout;
+
+/** Load content to #main
+* @param string
+* @param [string]
+* @return XMLHttpRequest or false in case of an error
+*/
+function ajaxMain(url, data) {
+ var currentState = ++ajaxState;
+ clearTimeout(ajaxTimeout);
+ ajaxTimeout = setTimeout(function () {
+ setHtml('main', '<img src="../adminer/static/loader.gif" alt="">');
+ }, 500); // defer displaying loader
+ return ajax(url, function (text) {
+ if (currentState == ajaxState) {
+ clearTimeout(ajaxTimeout);
+ setHtml('main', text);
+ if (window.jush) {
+ jush.highlight_tag('code');
+ jush.highlight_tag('pre', 0);
+ }
+ }
+ }, data);
+}
+
/** Send form by AJAX GET
* @param HTMLFormElement
* @param [string]
@@ -217,9 +230,9 @@ function ajaxForm(form, data) {
params.push(data);
}
if (form.method == 'post') {
- return ajax(form.action || location.href, params.join('&'));
+ return ajaxMain(form.action || location.href, params.join('&'));
} else {
- return ajax((form.action || location.pathname) + '?' + params.join('&'));
+ return ajaxMain((form.action || location.pathname) + '?' + params.join('&'));
}
}
@@ -228,14 +241,13 @@ function ajaxForm(form, data) {
/** Display edit field
* @param HTMLElement
* @param MouseEvent
-* @param boolean display textarea instead of input
+* @param number display textarea instead of input, 2 - load long text
*/
function selectDblClick(td, event, text) {
var pos = event.rangeOffset;
var value = (td.firstChild.firstChild ? td.firstChild.firstChild.data : (td.firstChild.alt ? td.firstChild.alt : td.firstChild.data));
var input = document.createElement(text ? 'textarea' : 'input');
input.name = td.id;
- input.value = (value == '\u00A0' || td.getElementsByTagName('i').length ? '' : value); // &nbsp; or i - NULL
input.style.width = Math.max(td.clientWidth - 14, 20) + 'px'; // 14 = 2 * (td.border + td.padding + input.border)
if (text) {
var rows = 1;
@@ -258,6 +270,12 @@ function selectDblClick(td, event, text) {
td.innerHTML = '';
td.appendChild(input);
input.focus();
+ if (text == 2) { // long text
+ return ajax(location.href + '&' + encodeURIComponent(td.id) + '=', function (text) {
+ input.value = text;
+ });
+ }
+ input.value = (value == '\u00A0' || td.getElementsByTagName('i').length ? '' : value); // &nbsp; or i - NULL
input.selectionStart = pos;
input.selectionEnd = pos;
if (document.selection) {
View
4 editor/include/adminer.inc.php
@@ -62,7 +62,9 @@ function selectLinks($tableStatus, $set = "") {
echo '<p class="tabs"><a href="' . h(ME . 'edit=' . urlencode($TABLE) . $set) . '">' . lang('New item') . "</a>\n";
}
echo "<a href='" . h(remove_from_uri("page")) . "&amp;page=last' title='" . lang('Page') . ": " . lang('last') . "'>&gt;&gt;</a>\n";
- echo "<a href='" . h($_SERVER["REQUEST_URI"]) . "'>#</a>\n";
+ if (is_ajax()) {
+ echo "<a href='" . h($_SERVER["REQUEST_URI"]) . "'>#</a>\n";
+ }
}
function backwardKeys($table, $tableName) {

0 comments on commit 390e38b

Please sign in to comment.
Something went wrong with that request. Please try again.