From 13a97f336442e480856147ae463b726b831332fb Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Tue, 28 Aug 2012 03:00:34 -0400 Subject: [PATCH] listings sort when you click headers --- metaform.php | 2 +- metaform/template.html | 8 ++++---- metaform/template.php | 18 ++++++++++++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/metaform.php b/metaform.php index b4ec6e0..3a6e70d 100644 --- a/metaform.php +++ b/metaform.php @@ -304,7 +304,7 @@ function make_html($whole_file = true) { } if(show_in_listing($type, $input, $format, $sql)) { - $listing_headers[] = array('caption' => format_caption($name)); + $listing_headers[] = array('caption' => format_caption($name), 'name' => $name); $listing_field = array('name' => $name); if($format == 'bool' || $format == 'yesno') { $listing_field['enc'] = 'yesno'; diff --git a/metaform/template.html b/metaform/template.html index b2e791f..89f850a 100644 --- a/metaform/template.html +++ b/metaform/template.html @@ -126,14 +126,14 @@
Cancel
- +

~plural cap~ Listing

- +

[Add a new ~singular~]

- + @@ -141,7 +141,7 @@
~caption~ 
~caption~ 
~~~name~ ~enc~~~(blank) [delete this ~singular~]
- +

No ~plural~ in database.

diff --git a/metaform/template.php b/metaform/template.php index fa05c07..6479fc5 100644 --- a/metaform/template.php +++ b/metaform/template.php @@ -143,8 +143,22 @@ function ~file_name~_main_delete($id) { }~}~~opt_listing {~ function ~file_name~_main_listing() { - $listing_rows = db_get_assocs('~table_name~', 'id~listing_fields_1 {~,~name~~}~', 'order by ~always_field~ limit 1000'); - tem_set('listings', $listing_rows); + $data = array(); + $desc = ''; + $sort = _REQUEST_cut('sort'); + if($sort && substr($sort, 0, 1) === '-') { + $sort = substr($sort, 1); + $desc = ' DESC '; + } else { + $data["sorting-by-$sort"] = '-'; + } + $legal_sorts = explode(',', ~file_name upper~_DB_FIELDS); + if(!$sort || !in_array($sort, $legal_sorts)) { + $sort = '~always_field~'; + } + + $data['rows'] = db_get_assocs('~table_name~', 'id~listing_fields_1 {~,~name~~}~', "order by $sort $desc limit 1000"); + tem_set('listings', $data); }~}~ function ~file_name~_main_form($id = false) {~pulldowns {~ -- 1.7.10.4