[Jifty-commit] r4317 - in jifty/trunk: .

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Oct 26 15:40:02 EDT 2007


Author: sterling
Date: Fri Oct 26 15:40:02 2007
New Revision: 4317

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Plugin/AutoReference/Widget.pm

Log:
 r13659 at riddle:  andrew | 2007-10-26 14:38:32 -0500
 Expanded the previous fix to cover sticky values and the initial value in the input tag.


Modified: jifty/trunk/lib/Jifty/Plugin/AutoReference/Widget.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/AutoReference/Widget.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/AutoReference/Widget.pm	Fri Oct 26 15:40:02 2007
@@ -33,6 +33,47 @@
     return $self->SUPER::render(@_);
 }
 
+sub _record_description {
+    my $self = shift;
+
+    my $value = $self->default_value;
+
+    my $name      = $self->name;
+    my $column    = $self->action->record->column($name);
+    my $reference = $column->refers_to;
+    my $brief     = $reference->can('_brief_description') ?
+                        $reference->_brief_description : 'name';
+
+    my $record = $self->action->record->$name;
+    if ($record and $record->id) {
+        return $record->$brief . ' [id:'. $record->id . ']';
+    }
+    else {
+        return;
+    }
+}
+
+sub _switch_current_value_temporarily(&$) {
+    my $code = shift;
+    my $self = shift;
+    
+    my $description = $self->_record_description;
+
+    if ($self->sticky_value and $self->sticky) {
+        my $old_value = $self->sticky_value;
+        $self->sticky_value($description);
+        $code->();
+        $self->sticky_value($old_value);
+    }
+
+    else {
+        my $old_value = $self->default_value;
+        $self->default_value($description);
+        $code->();
+        $self->default_value($old_value);
+    }
+}
+
 sub render_widget {
     my $self = shift;
 
@@ -43,7 +84,9 @@
     $self->_element_id($element_id.'-display');
     my $class = $self->class;
     $self->class(join ' ', ($class||''), 'text');
-    $self->SUPER::render_widget(@_);
+    _switch_current_value_temporarily {
+        $self->SUPER::render_widget(@_);
+    } $self;
     $self->input_name($input_name);
     $self->_element_id($element_id);
     $self->class($class);
@@ -59,17 +102,9 @@
 sub render_value {
     my $self = shift;
 
-    my $value = $self->default_value;
-
-    my $name      = $self->name;
-    my $column    = $self->action->record->column($name);
-    my $reference = $column->refers_to;
-    my $brief     = $reference->can('_brief_description') ?
-                        $reference->_brief_description : 'name';
-
-    $self->default_value($self->action->record->$name->$brief);
-    $self->SUPER::render_value(@_);
-    $self->default_value($value);
+    _switch_current_value_temporarily {
+        $self->SUPER::render_value(@_);
+    } $self;
 
     return '';
 }


More information about the Jifty-commit mailing list