[Jifty-commit] jifty branch, master, updated. 1.10214-1-gd4e1aa4
Jifty commits
jifty-commit at lists.jifty.org
Wed Feb 16 11:11:14 EST 2011
The branch, master has been updated
via d4e1aa497499a6ec18059265af2ae36493ad9b42 (commit)
from c7a29b803ba878741031cbba337a744870930cbe (commit)
Summary of changes:
lib/Jifty/Action/Record.pm | 5 +----
lib/Jifty/Record.pm | 24 +++++++++++++++++-------
2 files changed, 18 insertions(+), 11 deletions(-)
- Log -----------------------------------------------------------------
commit d4e1aa497499a6ec18059265af2ae36493ad9b42
Author: Thomas Sibley <trs at bestpractical.com>
Date: Wed Feb 16 11:06:25 2011 -0500
brief_description now always works
_brief_description (note the underscore) checks if a name method is
available. If not, it returns 'id' instead of 'name'.
This makes brief_description and _brief_description easier to use in
other code since you don't have to check if it's going to fail.
diff --git a/lib/Jifty/Action/Record.pm b/lib/Jifty/Action/Record.pm
index 9713d23..43d9457 100644
--- a/lib/Jifty/Action/Record.pm
+++ b/lib/Jifty/Action/Record.pm
@@ -456,14 +456,11 @@ sub _default_valid_values {
);
$collection->find_all_rows;
- # Fetch the _brief_description() method
- my $method = $refers_to->_brief_description();
-
# FIXME: we should get value_from with the actualy refered by key
# Setup the list of valid values
@valid = (
- { display_from => $refers_to->can($method) ? $method : "id",
+ { display_from => $refers_to->_brief_description(),
value_from => 'id',
collection => $collection
}
diff --git a/lib/Jifty/Record.pm b/lib/Jifty/Record.pm
index ed4f8a6..a0ef52d 100644
--- a/lib/Jifty/Record.pm
+++ b/lib/Jifty/Record.pm
@@ -4,6 +4,7 @@ use strict;
package Jifty::Record;
use Jifty::Config;
+use List::MoreUtils qw();
=head1 NAME
@@ -574,6 +575,8 @@ sub delete {
Display the friendly name of the record according to _brief_description.
+To change what this returns, override L<_brief_description> instead.
+
=cut
sub brief_description {
@@ -584,15 +587,22 @@ sub brief_description {
=head2 _brief_description
-When displaying a list of records, Jifty can display a friendly value
-rather than the column's unique id. Out of the box, Jifty always
-tries to display the 'name' field from the record. You can override
-this method to return the name of a method on your record class which
-will return a nice short human readable description for this record.
+When displaying a list of records, Jifty can display a friendly value rather
+than the column's unique id. Out of the box, Jifty always tries to display the
+'name' field from the record. If there is no 'name' field, Jifty falls back to
+the record id.
+
+You can override this method to return the name of a method on your record
+class which will return a nice short human readable description for this
+record.
=cut
-sub _brief_description {'name'}
+sub _brief_description {
+ my $self = shift;
+ return 'name' if $self->can('name');
+ return 'id';
+}
=head2 null_reference
@@ -867,7 +877,7 @@ sub column_serialized_as {
sub default_serialized_as_columns {
my $class = shift;
- return ('id', $class->_brief_description);
+ return (List::MoreUtils::uniq 'id', $class->_brief_description);
}
=head2 jifty_serialize_format
-----------------------------------------------------------------------
More information about the Jifty-commit
mailing list