[Jifty-commit] r5891 - in jifty/trunk/lib/Jifty/Action: Record
Jifty commits
jifty-commit at lists.jifty.org
Sun Sep 28 02:04:29 EDT 2008
Author: clkao
Date: Sun Sep 28 02:04:29 2008
New Revision: 5891
Modified:
jifty/trunk/lib/Jifty/Action/Record.pm
jifty/trunk/lib/Jifty/Action/Record/Update.pm
Log:
Add report_detailed_messages option in record actions.
Modified: jifty/trunk/lib/Jifty/Action/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record.pm (original)
+++ jifty/trunk/lib/Jifty/Action/Record.pm Sun Sep 28 02:04:29 2008
@@ -27,8 +27,9 @@
__PACKAGE__->mk_accessors(qw(record _cached_arguments));
-our $ARGUMENT_PROTOTYPE_CACHE = {};
+use constant report_detailed_messages => 1;
+our $ARGUMENT_PROTOTYPE_CACHE = {};
=head1 METHODS
@@ -43,6 +44,13 @@
name of the record class, or the name of the class can be passed to
the constructor.
+=head2 report_detailed_messages
+
+If the action returns true for C<report_detailed_message>, report the
+message returned by the model classes as the resulting message. For
+Update actions, Put the per-field message in C<detailed_messages>
+field of action result content. The default is false.
+
=cut
sub record_class {
Modified: jifty/trunk/lib/Jifty/Action/Record/Update.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record/Update.pm (original)
+++ jifty/trunk/lib/Jifty/Action/Record/Update.pm Sun Sep 28 02:04:29 2008
@@ -101,6 +101,8 @@
# Prepare the event for later publishing
my $event_info = $self->_setup_event_before_action();
+ my $detailed_messages = {};
+
# Iterate through all the possible arguments
for my $field ( $self->argument_names ) {
@@ -184,17 +186,23 @@
# Calculate the name of the setter and set; asplode on failure
my $setter = "set_$field";
my ( $val, $msg ) = $self->record->$setter( $value );
- $self->result->field_error($field, $msg || _('Permission denied'))
- if not $val;
-
- # Remember that we changed something (if we did)
- $changed = 1 if $val;
+ if ($val) {
+ # Remember that we changed something (if we did)
+ $changed = 1;
+ $detailed_messages->{$field} = $msg;
+ }
+ else {
+ $self->result->field_error($field, $msg || _('Permission denied'));
+ }
}
# Report success if there's a change and no error, otherwise say nah-thing
$self->report_success
if $changed and not $self->result->failure;
+ $self->result->content( detailed_messages => $detailed_messages )
+ if $self->report_detailed_messages;
+
# Publish the update event
$self->_setup_event_after_action($event_info);
More information about the Jifty-commit
mailing list