From 72b801513b84621855979c599926c887da4bbe88 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Sun, 19 Aug 2012 20:32:53 -0700 Subject: [PATCH] Load more data in select --- adminer/include/functions.inc.php | 7 +++++++ adminer/include/version.inc.php | 2 +- adminer/lang/cs.inc.php | 2 ++ adminer/select.inc.php | 21 +++++++++++++++++++- adminer/static/functions.js | 32 +++++++++++++++++++++++++++++++ changes.txt | 3 ++- 6 files changed, 64 insertions(+), 3 deletions(-) diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 03a50d13..90a27037 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -937,3 +937,10 @@ function cancel_kill_timeout() { } } } + +/** Callback registered to erase output buffer in AJAX calls +* @return string +*/ +function clean_output() { + return ''; +} diff --git a/adminer/include/version.inc.php b/adminer/include/version.inc.php index 469754a4..75ce5ced 100644 --- a/adminer/include/version.inc.php +++ b/adminer/include/version.inc.php @@ -1,2 +1,2 @@ '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ů'), diff --git a/adminer/select.inc.php b/adminer/select.inc.php index dfdc5b43..c08ab143 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -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 "\n"; + echo "
\n"; echo "" . (!$group && $select ? "" : "\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 "\n"; // close to allow white-space: pre } + if (is_ajax()) { + exit; + } echo "
" . lang('edit') . ""); $names = array(); $functions = array(); @@ -298,6 +301,12 @@ if (!$columns) { } } echo ($backward_keys ? "" . lang('Relations') : "") . "
\n"; echo (!$group && $select ? "" : "\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) : ' ' . lang('last') . ""); + if (count($rows) >= $limit) { + echo ' ' . lang('Load more data') . ''; + } } 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 "\n"; } } + +if (is_ajax()) { + exit; +} diff --git a/adminer/static/functions.js b/adminer/static/functions.js index b731c97d..d502540b 100644 --- a/adminer/static/functions.js +++ b/adminer/static/functions.js @@ -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)