Load more data in select

This commit is contained in:
Jakub Vrana 2012-08-19 20:32:53 -07:00
parent fc689f5953
commit 72b801513b
6 changed files with 64 additions and 3 deletions

View file

@ -937,3 +937,10 @@ function cancel_kill_timeout() {
}
}
}
/** Callback registered to erase output buffer in AJAX calls
* @return string
*/
function clean_output() {
return '';
}

View file

@ -1,2 +1,2 @@
<?php
$VERSION = "3.5.2-dev";
$VERSION = "3.6.0-dev";

View file

@ -234,6 +234,8 @@ $translations = array(
'Page' => 'Stránka',
'last' => 'poslední',
'Last page' => 'Poslední stránka',
'Load more data' => 'Nahrát další data',
'Loading' => 'Nahrává se',
'whole result' => 'celý výsledek',
'%d byte(s)' => array('%d bajt', '%d bajty', '%d bajtů'),

View file

@ -188,6 +188,9 @@ if ($_POST && !$error) {
}
$table_name = $adminer->tableName($table_status);
if (is_ajax()) {
ob_start('clean_output');
}
page_header(lang('Select') . ": $table_name", $error);
$set = null;
@ -258,7 +261,7 @@ if (!$columns) {
} else {
$backward_keys = $adminer->backwardKeys($TABLE, $table_name);
echo "<table cellspacing='0' class='nowrap checkable' onclick='tableClick(event);' onkeydown='return editingKeydown(event);'>\n";
echo "<table id='table' cellspacing='0' class='nowrap checkable' onclick='tableClick(event);' onkeydown='return editingKeydown(event);'>\n";
echo "<thead><tr>" . (!$group && $select ? "" : "<td><input type='checkbox' id='all-page' onclick='formCheck(this, /check/);'> <a href='" . h($_GET["modify"] ? remove_from_uri("modify") : $_SERVER["REQUEST_URI"] . "&modify=1") . "'>" . lang('edit') . "</a>");
$names = array();
$functions = array();
@ -298,6 +301,12 @@ if (!$columns) {
}
}
echo ($backward_keys ? "<th>" . lang('Relations') : "") . "</thead>\n";
if (is_ajax()) {
if ($limit % 2 == 1 && $page % 2 == 1) {
odd();
}
ob_end_clean();
}
foreach ($adminer->rowDescriptions($rows, $foreign_keys) as $n => $row) {
$unique_array = unique_array($rows[$n], $indexes);
$unique_idf = "";
@ -383,6 +392,9 @@ if (!$columns) {
$adminer->backwardKeysPrint($backward_keys, $rows[$n]);
echo "</tr>\n"; // close to allow white-space: pre
}
if (is_ajax()) {
exit;
}
echo "</table>\n";
echo (!$group && $select ? "" : "<script type='text/javascript'>tableCheck();</script>\n");
}
@ -413,6 +425,9 @@ if (!$columns) {
echo pagination($i, $page);
}
echo ($page + 5 < $max_page ? " ..." : "") . ($exact_count && $found_rows !== false ? pagination($max_page, $page) : ' <a href="' . h(remove_from_uri("page") . "&page=last") . '">' . lang('last') . "</a>");
if (count($rows) >= $limit) {
echo ' <a href="' . h(remove_from_uri("page") . "&page=" . ($page + 1)) . '" onclick="return !selectLoadMore(this, ' . (+$limit) . ', \'' . lang('Loading') . '\');">' . lang('Load more data') . '</a>';
}
}
echo ($found_rows !== false ? " (" . ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) . ")" : "") . " " . checkbox("all", 1, 0, lang('whole result')) . "\n";
@ -450,3 +465,7 @@ if (!$columns) {
echo "</form>\n";
}
}
if (is_ajax()) {
exit;
}

View file

@ -446,6 +446,38 @@ function selectDblClick(td, event, text) {
/** Load and display next page in select
* @param HTMLLinkElement
* @param string
* @param number
* @return boolean
*/
function selectLoadMore(a, limit, loading) {
var title = a.innerHTML;
var href = a.href;
a.innerHTML = loading;
if (href) {
a.removeAttribute('href');
return ajax(href, function (request) {
document.getElementById('table').innerHTML += request.responseText;
var rows = 0;
request.responseText.replace(/(^|\n)<tr/g, function () {
rows++;
});
if (rows < limit) {
a.parentNode.removeChild(a);
} else {
a.href = href.replace(/\d+$/, function (page) {
return +page + 1;
});
a.innerHTML = title;
}
});
}
}
/** Stop event propagation
* @param Event
*/

View file

@ -1,4 +1,5 @@
Adminer 3.5.2-dev:
Adminer 3.6.0-dev:
Load more data in select
Edit strings with \n in textarea
Time out long running database list and select count
Use VALUES() in INSERT+UPDATE export