Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Load more data in select

  • Loading branch information...
commit 72b801513b84621855979c599926c887da4bbe88 1 parent fc689f5
Jakub Vrána authored August 19, 2012
7  adminer/include/functions.inc.php
@@ -937,3 +937,10 @@ function cancel_kill_timeout() {
937 937
 		}
938 938
 	}
939 939
 }
  940
+
  941
+/** Callback registered to erase output buffer in AJAX calls
  942
+* @return string
  943
+*/
  944
+function clean_output() {
  945
+	return '';
  946
+}
2  adminer/include/version.inc.php
... ...
@@ -1,2 +1,2 @@
1 1
 <?php
2  
-$VERSION = "3.5.2-dev";
  2
+$VERSION = "3.6.0-dev";
2  adminer/lang/cs.inc.php
@@ -234,6 +234,8 @@
234 234
 	'Page' => 'Stránka',
235 235
 	'last' => 'poslední',
236 236
 	'Last page' => 'Poslední stránka',
  237
+	'Load more data' => 'Nahrát další data',
  238
+	'Loading' => 'Nahrává se',
237 239
 	'whole result' => 'celý výsledek',
238 240
 	'%d byte(s)' => array('%d bajt', '%d bajty', '%d bajtů'),
239 241
 	
21  adminer/select.inc.php
@@ -188,6 +188,9 @@
188 188
 }
189 189
 
190 190
 $table_name = $adminer->tableName($table_status);
  191
+if (is_ajax()) {
  192
+	ob_start('clean_output');
  193
+}
191 194
 page_header(lang('Select') . ": $table_name", $error);
192 195
 
193 196
 $set = null;
@@ -258,7 +261,7 @@
258 261
 		} else {
259 262
 			$backward_keys = $adminer->backwardKeys($TABLE, $table_name);
260 263
 			
261  
-			echo "<table cellspacing='0' class='nowrap checkable' onclick='tableClick(event);' onkeydown='return editingKeydown(event);'>\n";
  264
+			echo "<table id='table' cellspacing='0' class='nowrap checkable' onclick='tableClick(event);' onkeydown='return editingKeydown(event);'>\n";
262 265
 			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>");
263 266
 			$names = array();
264 267
 			$functions = array();
@@ -298,6 +301,12 @@
298 301
 				}
299 302
 			}
300 303
 			echo ($backward_keys ? "<th>" . lang('Relations') : "") . "</thead>\n";
  304
+			if (is_ajax()) {
  305
+				if ($limit % 2 == 1 && $page % 2 == 1) {
  306
+					odd();
  307
+				}
  308
+				ob_end_clean();
  309
+			}
301 310
 			foreach ($adminer->rowDescriptions($rows, $foreign_keys) as $n => $row) {
302 311
 				$unique_array = unique_array($rows[$n], $indexes);
303 312
 				$unique_idf = "";
@@ -383,6 +392,9 @@
383 392
 				$adminer->backwardKeysPrint($backward_keys, $rows[$n]);
384 393
 				echo "</tr>\n"; // close to allow white-space: pre
385 394
 			}
  395
+			if (is_ajax()) {
  396
+				exit;
  397
+			}
386 398
 			echo "</table>\n";
387 399
 			echo (!$group && $select ? "" : "<script type='text/javascript'>tableCheck();</script>\n");
388 400
 		}
@@ -413,6 +425,9 @@
413 425
 					echo pagination($i, $page);
414 426
 				}
415 427
 				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>");
  428
+				if (count($rows) >= $limit) {
  429
+					echo ' <a href="' . h(remove_from_uri("page") . "&page=" . ($page + 1)) . '" onclick="return !selectLoadMore(this, ' . (+$limit) . ', \'' . lang('Loading') . '\');">' . lang('Load more data') . '</a>';
  430
+				}
416 431
 			}
417 432
 			echo ($found_rows !== false ? " (" . ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) . ")" : "") . " " . checkbox("all", 1, 0, lang('whole result')) . "\n";
418 433
 			
@@ -450,3 +465,7 @@
450 465
 		echo "</form>\n";
451 466
 	}
452 467
 }
  468
+
  469
+if (is_ajax()) {
  470
+	exit;
  471
+}
32  adminer/static/functions.js
@@ -446,6 +446,38 @@ function selectDblClick(td, event, text) {
446 446
 
447 447
 
448 448
 
  449
+/** Load and display next page in select
  450
+* @param HTMLLinkElement
  451
+* @param string
  452
+* @param number
  453
+* @return boolean
  454
+*/
  455
+function selectLoadMore(a, limit, loading) {
  456
+	var title = a.innerHTML;
  457
+	var href = a.href;
  458
+	a.innerHTML = loading;
  459
+	if (href) {
  460
+		a.removeAttribute('href');
  461
+		return ajax(href, function (request) {
  462
+			document.getElementById('table').innerHTML += request.responseText;
  463
+			var rows = 0;
  464
+			request.responseText.replace(/(^|\n)<tr/g, function () {
  465
+				rows++;
  466
+			});
  467
+			if (rows < limit) {
  468
+				a.parentNode.removeChild(a);
  469
+			} else {
  470
+				a.href = href.replace(/\d+$/, function (page) {
  471
+					return +page + 1;
  472
+				});
  473
+				a.innerHTML = title;
  474
+			}
  475
+		});
  476
+	}
  477
+}
  478
+
  479
+
  480
+
449 481
 /** Stop event propagation
450 482
 * @param Event
451 483
 */
3  changes.txt
... ...
@@ -1,4 +1,5 @@
1  
-Adminer 3.5.2-dev:
  1
+Adminer 3.6.0-dev:
  2
+Load more data in select
2 3
 Edit strings with \n in textarea
3 4
 Time out long running database list and select count
4 5
 Use VALUES() in INSERT+UPDATE export

0 notes on commit 72b8015

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