Commit cd48e69b authored by Dries's avatar Dries
Browse files

- Patches #6863 by Kristjan and Moshe: implemented pretty tables and fixed some tablesort glitches.

parent fbbf5105
......@@ -2,48 +2,57 @@
// $Id$
function tablesort_init($header) {
static $ts;
if (empty($ts)) {
$ts = tablesort_get_order($header);
$ts['sort'] = tablesort_get_sort($header);
$ts['query_string'] = tablesort_get_querystring();
}
$ts = tablesort_get_order($header);
$ts['sort'] = tablesort_get_sort($header);
$ts['query_string'] = tablesort_get_querystring();
return $ts;
}
function tablesort_pager() {
$cgi = $_SERVER['REQUEST_METHOD'] == 'GET' ? $_GET : $_POST;
unset($cgi['q'], $cgi["from"]);
unset($cgi['q'], $cgi['from']);
return $cgi;
}
function tablesort_sql($header) {
$ts = tablesort_init($header);
$sql = check_query($ts['sql']);
$sort = strtoupper(check_query($ts['sort']));
return " ORDER BY $sql $sort";
if ($ts['field']) {
$sql = check_query($ts['sql']);
$sort = strtoupper(check_query($ts['sort']));
return " ORDER BY $sql $sort";
}
}
function tablesort($cell, $header) {
$ts = tablesort_init($header);
$title = t("sort by %s", array("%s" => $cell['data']));
function tablesort_header($cell, $header, $ts) {
// special formatting for the currently sorted column header
if ($cell['data'] == $ts['name']) {
$ts['sort'] = (($ts['sort'] == 'asc') ? 'desc' : 'asc');
$cell['class'] = 'active';
$image = '&nbsp;<img src="' . theme('image', 'arrow-' . $ts['sort'] . '.gif') . '" alt="'. t('sort icon') .'" />';
$title = ($ts['sort'] == 'asc' ? t("sort ascending") : t("sort descending"));
}
else {
// If the user clicks a different header, we want to sort ascending initially.
$ts['sort'] = "asc";
}
if (is_array($cell) && $cell['field']) {
if ($cell['data'] == $ts['name']) {
$ts['sort'] = (($ts['sort'] == 'asc') ? 'desc' : 'asc');
$cell['class'] = 'active';
$image = '&nbsp;<img src="' . theme('image', 'arrow-' . $ts['sort'] . '.gif') . '" alt="'. t('sort icon') .'" />';
$title = ($ts['sort'] == 'asc' ? t('sort ascending') : t('sort descending'));
}
else {
// If the user clicks a different header, we want to sort ascending initially.
$ts['sort'] = 'asc';
}
$title = t('sort by %s', array('%s' => $cell['data']));
$cell['data'] = l($cell['data'] . $image, $_GET['q'], array('title' => $title), "sort=". $ts['sort']. "&amp;order=". urlencode($cell['data']). $ts['query_string']);
$cell['data'] = l($cell['data'] . $image, $_GET['q'], array("title" => $title), "sort=". $ts['sort']. "&amp;order=". urlencode($cell['data']). $ts['query_string']);
unset($cell['field'], $cell['sort']);
}
return $cell;
}
unset($cell['field'], $cell['sort']);
function tablesort_cell($cell, $header, $ts, $i) {
if ($header[$i]['data'] == $ts['name'] && $header[$i]['field']) {
if (is_array($cell)) {
$cell['class'] .= ' active';
}
else {
$cell = array('data' => $cell, 'class' => 'active');
}
}
return $cell;
}
......@@ -51,7 +60,7 @@ function tablesort_get_querystring() {
$cgi = $_SERVER['REQUEST_METHOD'] == 'GET' ? $_GET : $_POST;
foreach ($cgi as $key => $val) {
if ($key != 'order' && $key != 'sort' && $key != 'q') {
$query_string .= "&amp;". $key ."=". $val;
$query_string .= '&amp;'. $key .'='. $val;
}
}
return $query_string;
......@@ -67,6 +76,7 @@ function tablesort_get_order($headers) {
if ($header['sort'] == 'asc' || $header['sort'] == 'desc') {
$default = array('name' => $header['data'], 'sql' => $header['field']);
}
$i++;
}
if ($default) {
......@@ -75,7 +85,7 @@ function tablesort_get_order($headers) {
else {
// The first column specified is initial 'order by' field unless otherwise specified
if (is_array($headers[0])) {
return array('name' => $headers[0]['name'], 'sql' => $headers[0]['field']);
return array('name' => $headers[0]['data'], 'sql' => $headers[0]['field']);
}
else {
return array('name' => $headers[0]);
......
......@@ -322,9 +322,7 @@ function theme_table($header, $rows, $attributes = NULL) {
$ts = tablesort_init($header);
$output .= " <tr>";
foreach ($header as $cell) {
if (is_array($cell) && $cell['field']) {
$cell = tablesort($cell, $header);
}
$cell = tablesort_header($cell, $header, $ts);
$output .= _theme_table_cell($cell, 1);
}
$output .= " </tr>\n";
......@@ -345,14 +343,7 @@ function theme_table($header, $rows, $attributes = NULL) {
}
foreach ($row as $cell) {
if ($header[$i]['data'] == $ts['name'] && $header[$i]['field']) {
if (is_array($cell)) {
$cell['class'] .= ' active';
}
else {
$cell = array('data' => $cell, 'class' => 'active');
}
}
$cell = tablesort_cell($cell, $header, $ts, $i);
$output .= _theme_table_cell($cell, 0);
$i++;
}
......
......@@ -31,17 +31,18 @@ th {
border-bottom: 3px solid #ccc;
white-space: nowrap;
}
tr.dark {
background-color: #ddd;
th.active img {
display: inline;
}
tr.light {
tr.dark, tr.light {
background-color: #eee;
border-bottom: 1px solid #ccc;
}
tr.dark td, tr.light td {
padding: 0.1em 0.6em;
}
th.active img {
display: inline;
td.active {
background-color: #ddd;
}
/*
......@@ -383,4 +384,4 @@ td.watchdog-httpd {
td.watchdog-error {
background: #e44;
border: 1px solid #c22;
}
}
\ No newline at end of file
......@@ -1017,7 +1017,14 @@ function comment_admin_overview($status = 0) {
while ($comment = db_fetch_object($result)) {
$comment->name = $comment->registered_name ? $comment->registered_name : $comment->name;
$rows[] = array(l($comment->subject, "node/view/$comment->nid/$comment->cid", array("title" => htmlspecialchars(truncate_utf8($comment->comment, 128))), NULL, "comment-$comment->cid") ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme("mark") : ""), format_name($comment), ($comment->status == 0 ? t("published") : t("not published")) ."</td><td>". format_date($comment->timestamp, "small") ."</td><td>". l(t("edit comment"), "admin/comment/edit/$comment->cid"), l(t("delete comment"), "admin/comment/delete/$comment->cid"));
$rows[] = array(
l($comment->subject, "node/view/$comment->nid/$comment->cid", array("title" => htmlspecialchars(truncate_utf8($comment->comment, 128))), NULL, "comment-$comment->cid") ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme("mark") : ""),
format_name($comment),
($comment->status == 0 ? t("published") : t("not published")),
format_date($comment->timestamp, "small"),
l(t("edit comment"), "admin/comment/edit/$comment->cid"),
l(t("delete comment"), "admin/comment/delete/$comment->cid")
);
}
if ($pager = theme("pager", NULL, 50, 0, tablesort_pager())) {
......
......@@ -1017,7 +1017,14 @@ function comment_admin_overview($status = 0) {
while ($comment = db_fetch_object($result)) {
$comment->name = $comment->registered_name ? $comment->registered_name : $comment->name;
$rows[] = array(l($comment->subject, "node/view/$comment->nid/$comment->cid", array("title" => htmlspecialchars(truncate_utf8($comment->comment, 128))), NULL, "comment-$comment->cid") ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme("mark") : ""), format_name($comment), ($comment->status == 0 ? t("published") : t("not published")) ."</td><td>". format_date($comment->timestamp, "small") ."</td><td>". l(t("edit comment"), "admin/comment/edit/$comment->cid"), l(t("delete comment"), "admin/comment/delete/$comment->cid"));
$rows[] = array(
l($comment->subject, "node/view/$comment->nid/$comment->cid", array("title" => htmlspecialchars(truncate_utf8($comment->comment, 128))), NULL, "comment-$comment->cid") ." ". (node_is_new($comment->nid, $comment->timestamp) ? theme("mark") : ""),
format_name($comment),
($comment->status == 0 ? t("published") : t("not published")),
format_date($comment->timestamp, "small"),
l(t("edit comment"), "admin/comment/edit/$comment->cid"),
l(t("delete comment"), "admin/comment/delete/$comment->cid")
);
}
if ($pager = theme("pager", NULL, 50, 0, tablesort_pager())) {
......
......@@ -10,12 +10,6 @@ body {
background-color: #fff;
font: 76% Verdana, Arial, Helvetica, sans-serif;
}
tr.dark {
background-color: #ddd;
}
tr.light {
background-color: #eee;
}
tr.dark td, tr.light td {
padding: 0.3em;
}
......
......@@ -24,12 +24,6 @@ img {
display: block;
border: 0;
}
tr.dark {
background-color: #ddd;
}
tr.light {
background-color: #eee;
}
tr.dark td, tr.light td {
padding: 0.3em;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment