Skip to content

Commit

Permalink
Highlight checked rows
Browse files Browse the repository at this point in the history
  • Loading branch information
vrana committed Aug 11, 2011
1 parent bf8b620 commit 023b62a
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 10 deletions.
3 changes: 2 additions & 1 deletion adminer/db.inc.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
if ($_POST["search"] && $_POST["query"] != "") { if ($_POST["search"] && $_POST["query"] != "") {
search_tables(); search_tables();
} }
echo "<table cellspacing='0' class='nowrap' onclick='tableClick(event);'>\n"; echo "<table cellspacing='0' class='nowrap checkable' onclick='tableClick(event);'>\n";
echo '<thead><tr class="wrap"><td><input id="check-all" type="checkbox" onclick="formCheck(this, /^(tables|views)\[/);">'; echo '<thead><tr class="wrap"><td><input id="check-all" type="checkbox" onclick="formCheck(this, /^(tables|views)\[/);">';
echo '<th>' . lang('Table'); echo '<th>' . lang('Table');
echo '<td>' . lang('Engine'); echo '<td>' . lang('Engine');
Expand Down Expand Up @@ -89,6 +89,7 @@
echo "<td align='right' id='sum-$key'>&nbsp;"; echo "<td align='right' id='sum-$key'>&nbsp;";
} }
echo "</table>\n"; echo "</table>\n";
echo "<script type='text/javascript'>tableCheck();</script>\n";
if (!information_schema(DB)) { if (!information_schema(DB)) {
echo "<p>" . ($jush == "sql" ? "<input type='submit' value='" . lang('Analyze') . "'> <input type='submit' name='optimize' value='" . lang('Optimize') . "'> <input type='submit' name='check' value='" . lang('Check') . "'> <input type='submit' name='repair' value='" . lang('Repair') . "'> " : "") . "<input type='submit' name='truncate' value='" . lang('Truncate') . "'" . confirm("formChecked(this, /tables/)") . "> <input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm("formChecked(this, /tables|views/)", 1) . ">\n"; // 1 - eventStop echo "<p>" . ($jush == "sql" ? "<input type='submit' value='" . lang('Analyze') . "'> <input type='submit' name='optimize' value='" . lang('Optimize') . "'> <input type='submit' name='check' value='" . lang('Check') . "'> <input type='submit' name='repair' value='" . lang('Repair') . "'> " : "") . "<input type='submit' name='truncate' value='" . lang('Truncate') . "'" . confirm("formChecked(this, /tables/)") . "> <input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm("formChecked(this, /tables|views/)", 1) . ">\n"; // 1 - eventStop
$databases = (support("scheme") ? schemas() : get_databases()); $databases = (support("scheme") ? schemas() : get_databases());
Expand Down
3 changes: 2 additions & 1 deletion adminer/include/connect.inc.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function connect_error() {
$scheme = support("scheme"); $scheme = support("scheme");
$collations = collations(); $collations = collations();
echo "<form action='' method='post'>\n"; echo "<form action='' method='post'>\n";
echo "<table cellspacing='0' onclick='tableClick(event);'>\n"; echo "<table cellspacing='0' class='checkable' onclick='tableClick(event);'>\n";
echo "<thead><tr><td>&nbsp;<th>" . lang('Database') . "<td>" . lang('Collation') . "<td>" . lang('Tables') . "</thead>\n"; echo "<thead><tr><td>&nbsp;<th>" . lang('Database') . "<td>" . lang('Collation') . "<td>" . lang('Tables') . "</thead>\n";
foreach ($databases as $db) { foreach ($databases as $db) {
$root = h(ME) . "db=" . urlencode($db); $root = h(ME) . "db=" . urlencode($db);
Expand All @@ -42,6 +42,7 @@ function connect_error() {
echo "\n"; echo "\n";
} }
echo "</table>\n"; echo "</table>\n";
echo "<script type='text/javascript'>tableCheck();</script>\n";
echo "<p><input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm("formChecked(this, /db/)", 1) . ">\n"; // 1 - eventStop echo "<p><input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm("formChecked(this, /db/)", 1) . ">\n"; // 1 - eventStop
echo "<input type='hidden' name='token' value='$token'>\n"; echo "<input type='hidden' name='token' value='$token'>\n";
echo "<a href='" . h(ME) . "refresh=1' onclick='eventStop(event);'>" . lang('Refresh') . "</a>\n"; echo "<a href='" . h(ME) . "refresh=1' onclick='eventStop(event);'>" . lang('Refresh') . "</a>\n";
Expand Down
3 changes: 2 additions & 1 deletion adminer/processlist.inc.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
?> ?>


<form action="" method="post"> <form action="" method="post">
<table cellspacing="0" onclick="tableClick(event);" class="nowrap"> <table cellspacing="0" onclick="tableClick(event);" class="nowrap checkable">
<?php <?php
// HTML valid because there is always at least one process // HTML valid because there is always at least one process
$i = -1; $i = -1;
Expand All @@ -29,6 +29,7 @@
} }
?> ?>
</table> </table>
<script type='text/javascript'>tableCheck();</script>
<p> <p>
<?php <?php
if (support("kill")) { if (support("kill")) {
Expand Down
3 changes: 2 additions & 1 deletion adminer/select.inc.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
} else { } else {
$backward_keys = $adminer->backwardKeys($TABLE, $table_name); $backward_keys = $adminer->backwardKeys($TABLE, $table_name);


echo "<table cellspacing='0' class='nowrap' onclick='tableClick(event);' onkeydown='return editingKeydown(event);'>\n"; echo "<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>"); 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(); $names = array();
$functions = array(); $functions = array();
Expand Down Expand Up @@ -368,6 +368,7 @@
echo "</tr>\n"; // close to allow white-space: pre echo "</tr>\n"; // close to allow white-space: pre
} }
echo "</table>\n"; echo "</table>\n";
echo (!$group && $select ? "" : "<script type='text/javascript'>tableCheck();</script>\n");
} }


if ($rows || $page) { if ($rows || $page) {
Expand Down
3 changes: 2 additions & 1 deletion adminer/static/default.css
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ p { margin: .8em 20px 0 0; }
img { vertical-align: middle; border: 0; } img { vertical-align: middle; border: 0; }
td img { max-width: 200px; max-height: 200px; } td img { max-width: 200px; max-height: 200px; }
code { background: #eee; } code { background: #eee; }
tr:hover td, tr:hover th { background: #ddf; } tbody tr:hover td, tbody tr:hover th { background: #eee; }
pre { margin: 1em 0 0; } pre { margin: 1em 0 0; }
input[type=image] { vertical-align: middle; } input[type=image] { vertical-align: middle; }
.version { color: #777; font-size: 67%; } .version { color: #777; font-size: 67%; }
Expand All @@ -33,6 +33,7 @@ input[type=image] { vertical-align: middle; }
.enum { color: #007F7F; } .enum { color: #007F7F; }
.binary { color: red; } .binary { color: red; }
.odd td { background: #F5F5F5; } .odd td { background: #F5F5F5; }
.js .checked td, .js .checked th { background: #ddf; }
.time { color: silver; font-size: 70%; } .time { color: silver; font-size: 70%; }
.function { text-align: right; } .function { text-align: right; }
.number { text-align: right; } .number { text-align: right; }
Expand Down
40 changes: 36 additions & 4 deletions adminer/static/functions.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ function selectValue(select) {
return ((selected.attributes.value || {}).specified ? selected.value : selected.text); return ((selected.attributes.value || {}).specified ? selected.value : selected.text);
} }


/** Set checked class
* @param HTMLInputElement
*/
function trCheck(el) {
var tr = el.parentNode.parentNode;
tr.className = tr.className.replace(/(^|\s)checked(\s|$)/, '$2') + (el.checked ? ' checked' : '');
}

/** Check all elements matching given name /** Check all elements matching given name
* @param HTMLInputElement * @param HTMLInputElement
* @param RegExp * @param RegExp
Expand All @@ -47,6 +55,21 @@ function formCheck(el, name) {
for (var i=0; i < elems.length; i++) { for (var i=0; i < elems.length; i++) {
if (name.test(elems[i].name)) { if (name.test(elems[i].name)) {
elems[i].checked = el.checked; elems[i].checked = el.checked;
trCheck(elems[i]);
}
}
}

/** Check all rows in <table class="checkable">
*/
function tableCheck() {
var tables = document.getElementsByTagName('table');
for (var i=0; i < tables.length; i++) {
if (/(^|\s)checkable(\s|$)/.test(tables[i].className)) {
var trs = tables[i].getElementsByTagName('tr');
for (var j=0; j < trs.length; j++) {
trCheck(trs[j].firstChild.firstChild);
}
} }
} }
} }
Expand All @@ -55,7 +78,9 @@ function formCheck(el, name) {
* @param string * @param string
*/ */
function formUncheck(id) { function formUncheck(id) {
document.getElementById(id).checked = false; var el = document.getElementById(id);
el.checked = false;
trCheck(el);
} }


/** Get number of checked elements matching given name /** Get number of checked elements matching given name
Expand All @@ -78,16 +103,23 @@ function formChecked(el, name) {
* @param MouseEvent * @param MouseEvent
*/ */
function tableClick(event) { function tableClick(event) {
var click = true;
var el = event.target || event.srcElement; var el = event.target || event.srcElement;
while (!/^tr$/i.test(el.tagName)) { while (!/^tr$/i.test(el.tagName)) {
if (/^(table|a|input|textarea)$/i.test(el.tagName)) { if (/^table$/i.test(el.tagName)) {
return; return;
} }
if (/^(a|input|textarea)$/i.test(el.tagName)) {
click = false;
}
el = el.parentNode; el = el.parentNode;
} }
el = el.firstChild.firstChild; el = el.firstChild.firstChild;
el.click && el.click(); if (click) {
el.onclick && el.onclick(); el.click && el.click();
el.onclick && el.onclick();
}
trCheck(el);
} }


/** Set HTML code of an element /** Set HTML code of an element
Expand Down
1 change: 1 addition & 0 deletions changes.txt
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,5 @@
Adminer 3.3.3-dev: Adminer 3.3.3-dev:
Highlight checked rows
Titles of links in database overview and navigation Titles of links in database overview and navigation
Fix trigger export (SQLite) Fix trigger export (SQLite)
Default trigger statement (SQLite, PostgreSQL) Default trigger statement (SQLite, PostgreSQL)
Expand Down
3 changes: 2 additions & 1 deletion editor/db.inc.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
if ($_POST["query"] != "") { if ($_POST["query"] != "") {
search_tables(); search_tables();
} }
echo "<table cellspacing='0' class='nowrap' onclick='tableClick(event);'>\n"; echo "<table cellspacing='0' class='nowrap checkable' onclick='tableClick(event);'>\n";
echo '<thead><tr class="wrap"><td><input id="check-all" type="checkbox" onclick="formCheck(this, /^tables\[/);"><th>' . lang('Table') . '<td>' . lang('Rows') . "</thead>\n"; echo '<thead><tr class="wrap"><td><input id="check-all" type="checkbox" onclick="formCheck(this, /^tables\[/);"><th>' . lang('Table') . '<td>' . lang('Rows') . "</thead>\n";
foreach (table_status() as $table => $row) { foreach (table_status() as $table => $row) {
$name = $adminer->tableName($row); $name = $adminer->tableName($row);
Expand All @@ -19,5 +19,6 @@
} }
} }
echo "</table>\n"; echo "</table>\n";
echo "<script type='text/javascript'>tableCheck();</script>\n";
echo "</form>\n"; echo "</form>\n";
} }

0 comments on commit 023b62a

Please sign in to comment.