/[drupal]/contributions/sandbox/unconed/soc/jstablesort.patch
ViewVC logotype

Contents of /contributions/sandbox/unconed/soc/jstablesort.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Wed Aug 31 23:05:05 2005 UTC (4 years, 2 months ago) by unconed
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-patch
- Putting SoC stuff up
1 cvs diff: Diffing .
2 cvs diff: Diffing database
3 cvs diff: Diffing includes
4 Index: includes/tablesort.inc
5 ===================================================================
6 RCS file: /cvs/drupal/drupal/includes/tablesort.inc,v
7 retrieving revision 1.36
8 diff -u -r1.36 tablesort.inc
9 --- includes/tablesort.inc 25 Aug 2005 21:14:16 -0000 1.36
10 +++ includes/tablesort.inc 31 Aug 2005 23:01:45 -0000
11 @@ -20,6 +20,32 @@
12 }
13
14 /**
15 + * Set-up required attributes for Ajax tablesort and return whether we are
16 + * currently handling an Ajax request.
17 + */
18 +function tablesort_ajax($header, &$attributes) {
19 + // Tables with an id can be sorted through Ajax
20 + if (isset($attributes['id'])) {
21 + // Determine if there are any sortable columns.
22 + $tablesort = false;
23 + foreach ($header as $item) {
24 + if (is_array($item) && isset($item['field'])) {
25 + $tablesort = true;
26 + break;
27 + }
28 + }
29 + // Mark the table if needed
30 + if ($tablesort) {
31 + drupal_add_js('misc/tablesort.js');
32 + $attributes['class'] = trim($attributes['class'] .' tablesort');
33 + // Are we currently handling an Ajax request for this table?
34 + return $_GET['tablesort'] == $attributes['id'];
35 + }
36 + }
37 + return FALSE;
38 +}
39 +
40 +/**
41 * Fetch pager link arguments.
42 *
43 * When producing a sortable table that presents paged data, pass the output
44 @@ -87,7 +113,7 @@
45 $image = '';
46 }
47 $cell['data'] = l($cell['data'] . $image, $_GET['q'], array('title' => $title), 'sort='. $ts['sort'] .'&order='. urlencode($cell['data']). $ts['query_string'], NULL, FALSE, TRUE);
48 -
49 + $cell['class'] = trim($cell['class'] .' tablesort');
50 unset($cell['field'], $cell['sort']);
51 }
52 return $cell;
53 Index: includes/theme.inc
54 ===================================================================
55 RCS file: /cvs/drupal/drupal/includes/theme.inc,v
56 retrieving revision 1.256
57 diff -u -r1.256 theme.inc
58 --- includes/theme.inc 28 Aug 2005 15:29:34 -0000 1.256
59 +++ includes/theme.inc 31 Aug 2005 23:01:49 -0000
60 @@ -692,15 +692,20 @@
61 *
62 * @param $attributes
63 * An array of HTML attributes to apply to the table tag.
64 + * @param $ajax
65 + * Whether this table should be sorted using Ajax. If set to TRUE, you must
66 + * pass a valid $attributes['id'].
67 * @return
68 * An HTML string representing the table.
69 */
70 function theme_table($header, $rows, $attributes = NULL) {
71 -
72 + // Initialize Ajax tablesort
73 + $shortcircuit = tablesort_ajax($header, $attributes);
74 $output = '<table'. drupal_attributes($attributes) .">\n";
75
76 // Format the table header:
77 if (count($header)) {
78 + // Note: tablesort_init() may modify $attributes
79 $ts = tablesort_init($header);
80 $output .= ' <tr>';
81 foreach ($header as $cell) {
82 @@ -751,6 +756,13 @@
83 }
84
85 $output .= "</table>\n";
86 +
87 + // Print table directly if doing an Ajax request for this table
88 + if ($shortcircuit) {
89 + print $output;
90 + exit;
91 + }
92 +
93 return $output;
94 }
95
96 cvs diff: Diffing misc
97 Index: misc/drupal.css
98 ===================================================================
99 RCS file: /cvs/drupal/drupal/misc/drupal.css,v
100 retrieving revision 1.116
101 diff -u -r1.116 drupal.css
102 --- misc/drupal.css 31 Aug 2005 21:17:26 -0000 1.116
103 +++ misc/drupal.css 31 Aug 2005 23:01:51 -0000
104 @@ -570,6 +570,7 @@
105 background: #0072b9;
106 color: #fff;
107 }
108 +
109 /* Animated throbber */
110 html.js input.form-autocomplete {
111 background: url('throbber.gif') no-repeat 100% 2px;
112 @@ -577,6 +578,12 @@
113 html.js input.throbbing {
114 background-position: 100% -18px;
115 }
116 +html.js th.tablesort {
117 + padding-right: 18px;
118 +}
119 +html.js th.throbbing {
120 + background: url('throbber.gif') no-repeat 100% -18px;
121 +}
122
123 /*
124 ** Progressbar styles
125 Index: misc/tablesort.js
126 ===================================================================
127 RCS file: misc/tablesort.js
128 diff -N misc/tablesort.js
129 --- /dev/null 1 Jan 1970 00:00:00 -0000
130 +++ misc/tablesort.js 31 Aug 2005 23:01:51 -0000
131 @@ -0,0 +1,76 @@
132 +// $Id$
133 +
134 +if (isJsEnabled()) {
135 + addLoadEvent(tablesortAutoAttach);
136 +}
137 +
138 +/**
139 + * Attach the tablesort behaviour to specially marked tables.
140 + */
141 +function tablesortAutoAttach() {
142 + var tables = document.getElementsByTagName('table');
143 + var header, table;
144 + // Find specially marked tables
145 + for (var i = 0; table = tables[i]; i++) {
146 + if (!hasClass(table, 'tablesort')) {
147 + continue;
148 + }
149 + var ts = new tablesort(table);
150 + // Find all the header cells
151 + headers = table.getElementsByTagName('th');
152 + if (headers.length == 0) {
153 + continue;
154 + }
155 + for (var j = 0; header = headers[j]; j++) {
156 + // Find the first link
157 + var links = header.getElementsByTagName('a');
158 + if (links.length == 0) {
159 + continue;
160 + }
161 + var link = links[0];
162 + // Install onclick override
163 + link.onclick = function() {
164 + ts.doSort(this);
165 + this.blur();
166 + this.onclick = function() {
167 + return false;
168 + }
169 + return false;
170 + }
171 + }
172 + }
173 +}
174 +
175 +/**
176 + * A tablesort object tied to a particular <table>.
177 + */
178 +function tablesort(table) {
179 + var ts = this;
180 + this.table = table;
181 +}
182 +
183 +/**
184 + * Sort the table by a new column
185 + */
186 +tablesort.prototype.doSort = function (link) {
187 + var header = link.parentNode;
188 + this.uri = link.href + '&tablesort=' + escape(this.table.id);
189 + addClass(header, 'throbbing');
190 + HTTPGet(this.uri, this.receiveSort, this);
191 +}
192 +
193 +/**
194 + * HTTP callback function. Replaces the entire table with the new one.
195 + */
196 +tablesort.prototype.receiveSort = function(string, xmlhttp, ts) {
197 + if (xmlhttp.status != 200) {
198 + return alert('An HTTP error '+ xmlhttp.status +' occured.\n'+ ts.uri);
199 + }
200 + // Create DOM node for new table
201 + var div = document.createElement('div');
202 + div.innerHTML = string;
203 + // Replace old table
204 + ts.table.parentNode.replaceChild(div, ts.table);
205 + // Re-attach behaviour
206 + tablesortAutoAttach();
207 +}
208 cvs diff: Diffing modules
209 Index: modules/comment.module
210 ===================================================================
211 RCS file: /cvs/drupal/drupal/modules/comment.module,v
212 retrieving revision 1.368
213 diff -u -r1.368 comment.module
214 --- modules/comment.module 30 Aug 2005 15:22:29 -0000 1.368
215 +++ modules/comment.module 31 Aug 2005 23:01:57 -0000
216 @@ -1036,7 +1036,7 @@
217 $rows[] = array(array('data' => t('No comments available.'), 'colspan' => '6'));
218 }
219
220 - return theme('table', $header, $rows);
221 + return theme('table', $header, $rows, array('id' => 'comment-admin-overview'));
222 }
223
224 /**
225 Index: modules/forum.module
226 ===================================================================
227 RCS file: /cvs/drupal/drupal/modules/forum.module,v
228 retrieving revision 1.266
229 diff -u -r1.266 forum.module
230 --- modules/forum.module 30 Aug 2005 15:22:29 -0000 1.266
231 +++ modules/forum.module 31 Aug 2005 23:01:58 -0000
232 @@ -953,7 +953,7 @@
233 }
234 }
235
236 - $output .= theme('table', $forum_topic_list_header, $rows);
237 + $output .= theme('table', $forum_topic_list_header, $rows, array('id' => 'forum-topic-list'));
238
239 return $output;
240 }
241 Index: modules/node.module
242 ===================================================================
243 RCS file: /cvs/drupal/drupal/modules/node.module,v
244 retrieving revision 1.526
245 diff -u -r1.526 node.module
246 --- modules/node.module 30 Aug 2005 15:22:29 -0000 1.526
247 +++ modules/node.module 31 Aug 2005 23:02:03 -0000
248 @@ -920,6 +920,14 @@
249 $output .= form_group(t('Show only items where'), $form);
250
251 // Build query
252 + $header = array(NULL,
253 + array('data' => t('Title'), 'field' => 'n.title'),
254 + array('data' => t('Type'), 'field' => 'n.type'),
255 + array('data' => t('Author'), 'field' => 'u.name'),
256 + array('data' => t('Status'), 'field' => 'n.status'),
257 + array('data' => t('Last Updated'), 'field' => 'n.changed', 'sort' => 'desc'),
258 + t('Operations'));
259 +
260 $where = $args = array();
261 $join = '';
262 foreach ($session as $filter) {
263 @@ -936,7 +944,7 @@
264 $join .= $filters[$key]['join'];
265 }
266 $where = count($where) ? 'WHERE '. implode(' AND ', $where) : '';
267 - $result = pager_query('SELECT n.*, u.name, u.uid FROM {node} n '. $join .' INNER JOIN {users} u ON n.uid = u.uid '. $where .' ORDER BY n.changed DESC', 50, 0, NULL, $args);
268 + $result = pager_query('SELECT n.*, u.name, u.uid FROM {node} n '. $join .' INNER JOIN {users} u ON n.uid = u.uid '. $where . tablesort_sql($header), 50, 0, NULL, $args);
269
270 // Make sure the update controls are disabled if we don't have any rows to select from.
271 $disabled = !db_num_rows($result);
272 @@ -953,8 +961,6 @@
273 $output .= '</div>';
274
275 // Overview table:
276 - $header = array(NULL, t('Title'), t('Type'), t('Author'), t('Status'), t('Operations'));
277 -
278 $destination = drupal_get_destination();
279 while ($node = db_fetch_object($result)) {
280 $rows[] = array(form_checkbox(NULL, 'nodes]['. $node->nid, 1, 0),
281 @@ -962,6 +968,7 @@
282 node_get_name($node),
283 theme('username', $node),
284 ($node->status ? t('published') : t('not published')),
285 + format_date($node->created, 'small'),
286 l(t('edit'), 'node/'. $node->nid .'/edit', array(), $destination));
287 }
288
289 @@ -973,7 +980,7 @@
290 $rows[] = array(array('data' => t('No posts available.'), 'colspan' => '6'));
291 }
292
293 - $output .= theme('table', $header, $rows);
294 + $output .= theme('table', $header, $rows, array('id' => 'node-admin-nodes'));
295 return form($output, 'post', url('admin/node/action'));
296 }
297
298 Index: modules/path.module
299 ===================================================================
300 RCS file: /cvs/drupal/drupal/modules/path.module,v
301 retrieving revision 1.62
302 diff -u -r1.62 path.module
303 --- modules/path.module 25 Aug 2005 21:14:16 -0000 1.62
304 +++ modules/path.module 31 Aug 2005 23:02:04 -0000
305 @@ -277,7 +277,7 @@
306 $rows[] = array(array('data' => t('No URL aliases available.'), 'colspan' => '4'));
307 }
308
309 - return theme('table', $header, $rows);
310 + return theme('table', $header, $rows, array('id' => 'path-overview'));
311 }
312
313 /**
314 Index: modules/statistics.module
315 ===================================================================
316 RCS file: /cvs/drupal/drupal/modules/statistics.module,v
317 retrieving revision 1.204
318 diff -u -r1.204 statistics.module
319 --- modules/statistics.module 25 Aug 2005 21:14:17 -0000 1.204
320 +++ modules/statistics.module 31 Aug 2005 23:02:07 -0000
321 @@ -182,7 +182,7 @@
322 }
323
324 drupal_set_title(check_plain($node->title));
325 - return theme('table', $header, $rows);
326 + return theme('table', $header, $rows, array('id' => 'statistics-node-tracker'));
327 }
328 else {
329 drupal_not_found();
330 @@ -210,7 +210,7 @@
331 }
332
333 drupal_set_title($account->name);
334 - return theme('table', $header, $rows);
335 + return theme('table', $header, $rows, array('id' => 'statistics-user-tracker'));
336 }
337 else {
338 drupal_not_found();
339 @@ -243,7 +243,7 @@
340 $rows[] = array(array('data' => $pager, 'colspan' => '4'));
341 }
342
343 - return theme('table', $header, $rows);
344 + return theme('table', $header, $rows, array('id' => 'statistics-recent-hits'));
345 }
346
347 /**
348 @@ -271,7 +271,7 @@
349 }
350
351 drupal_set_title(t('Top pages in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))));
352 - return theme('table', $header, $rows);
353 + return theme('table', $header, $rows, array('id' => 'statistics-top-pages'));
354 }
355
356 /**
357 @@ -301,7 +301,7 @@
358 }
359
360 drupal_set_title(t('Top visitors in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))));
361 - return theme('table', $header, $rows);
362 + return theme('table', $header, $rows, array('id' => 'statistics-top-visitors'));
363 }
364
365 /**
366 @@ -328,7 +328,7 @@
367 $rows[] = array(array('data' => $pager, 'colspan' => '3'));
368 }
369
370 - return theme('table', $header, $rows);
371 + return theme('table', $header, $rows, array('id' => 'statistics-top-referrers'));
372 }
373
374 /**
375 Index: modules/user.module
376 ===================================================================
377 RCS file: /cvs/drupal/drupal/modules/user.module,v
378 retrieving revision 1.502
379 diff -u -r1.502 user.module
380 --- modules/user.module 25 Aug 2005 21:14:17 -0000 1.502
381 +++ modules/user.module 31 Aug 2005 23:02:12 -0000
382 @@ -1734,7 +1734,7 @@
383 if (!empty($pager)) {
384 $rows[] = array(array('data' => $pager, 'colspan' => '5'));
385 }
386 - return theme('table', $header, $rows);
387 + return theme('table', $header, $rows, array('id' => 'user-admin-account'));
388 }
389
390 function user_configure() {
391 Index: modules/watchdog.module
392 ===================================================================
393 RCS file: /cvs/drupal/drupal/modules/watchdog.module,v
394 retrieving revision 1.126
395 diff -u -r1.126 watchdog.module
396 --- modules/watchdog.module 25 Aug 2005 21:14:17 -0000 1.126
397 +++ modules/watchdog.module 31 Aug 2005 23:02:13 -0000
398 @@ -123,7 +123,7 @@
399 }
400
401 $output = '<div class="container-inline">'. form($form) .'</div>';
402 - $output .= theme('table', $header, $rows);
403 + $output .= theme('table', $header, $rows, array('id' => 'watchdog-overview'));
404
405 return $output;
406 }

  ViewVC Help
Powered by ViewVC 1.1.2