[Jifty-commit] r2810 - in jifty/trunk: . lib lib/Jifty

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Feb 21 08:50:23 EST 2007


Author: sterling
Date: Wed Feb 21 08:50:22 2007
New Revision: 2810

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty.pm
   jifty/trunk/lib/Jifty/Action.pm
   jifty/trunk/lib/Jifty/Action/Autocomplete.pm
   jifty/trunk/lib/Jifty/Action/Record.pm

Log:
added a CUSTOMIZATION section to the Jifty::Action docs

Modified: jifty/trunk/lib/Jifty.pm
==============================================================================
--- jifty/trunk/lib/Jifty.pm	(original)
+++ jifty/trunk/lib/Jifty.pm	Wed Feb 21 08:50:22 2007
@@ -423,11 +423,6 @@
 }
 
 
-=head1 LICENSE
-
-Jifty is Copyright 2005-2006 Best Practical Solutions, LLC.
-Jifty is distributed under the same terms as Perl itself.
-
 =head1 SEE ALSO
 
 L<http://jifty.org>, L<Jifty::Manual::Tutorial>, L<Jifty::Everything>, L<Jifty::Config>, L<Jifty::Handle>, L<Jifty::Logger>, L<Jifty::Handler>, L<Jifty::Web>, L<Jifty::API>, L<Jifty::Subs>, L<IPC::PubSub>, L<Jifty::Plugin>, L<Jifty::ClassLoader>
@@ -436,6 +431,12 @@
 
 Jesse Vincent, Alex Vandiver and David Glasser.
 
+=head1 LICENSE
+
+Jifty is Copyright 2005-2006 Best Practical Solutions, LLC.
+Jifty is distributed under the same terms as Perl itself.
+
+
 
 =cut
 

Modified: jifty/trunk/lib/Jifty/Action.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action.pm	(original)
+++ jifty/trunk/lib/Jifty/Action.pm	Wed Feb 21 08:50:22 2007
@@ -1047,7 +1047,7 @@
 Used to report a warning during validation.  Inside a validator you
 should write:
 
-  return $self->validation_warning( $field => "warning");
+  return $self->validation_warning( $field => _("warning"));
 
 ..where C<$field> is the name of the argument which is at fault.
 
@@ -1087,7 +1087,7 @@
 Used to send an informational message to the user from the canonicalizer.  
 Inside a canonicalizer you can write:
 
-  $self->canonicalization_note( $field => "I changed $field for you");
+  $self->canonicalization_note( $field => _("I changed $field for you"));
 
 ..where C<$field> is the name of the argument which the canonicalizer is 
 processing
@@ -1110,6 +1110,95 @@
 Autogenerated Actions will always return true when this method is called. 
 "Regular" actions will return false.
 
+=head1 CUSTOMIZATION
+
+=head2 Canonicalization
+
+If you wish to have the data in a field normalized into a particular format (such as changing a date into YYYY-MM-DD format, adding commas to numbers, capitalizing words, or whatever you need) you can do so using a canonicalizer. 
+
+This is just a method titled C<canonicalize_FIELD> where C<FIELD> is the name of the field be normalized. Here is an example:
+
+  sub canonicalize_foo {
+      my ($self, $value) = @_;
+
+      # do something to canonicalize the value
+      my $normal_form = lc($value);
+      
+      return $normal_form;
+  }
+
+In this case, all values in the "foo" field will be changed into lower case.
+
+While doing this you might also want to call the L</canonicalization_note> to inform the client of the modification:
+
+  my $normal_form = lc($value);
+  $self->canonicalization_note( 
+      foo => _('Foo values are always in lowercase.'));
+
+If the "foo" field has "ajax canoncalizes" set in the action schema, then this process will be performed automatically as the form is being filled without reloading the page.
+
+=head2 Validation
+
+If a value must follow a certain format, you can provide a validation method for fields to make sure that no value enters the database until it is in a valid form.
+
+A validation method is one named C<validate_FIELD> where C<FIELD> is the name of the field being checked. Here is an example:
+
+  sub validate_foo {
+      my ($self, $value) = @_;
+
+      # Check for uppercase letters
+      if ($value =~ /\p{Lu}/) {
+          return $self->validation_warning(
+              foo => _("Foo cannot contain uppercase letters."));
+      }
+
+      # Check for -, *, +, and ?
+      elsif ($value =~ /[\-\*\+\?]/) {
+          return $self->validation_error(
+              foo => _("Foo cannot contain -, *, +, or ?."));
+      }
+
+      return 1;
+  }
+
+Here the "foo" field should not contain uppercase letters and must not contain the characters '-', '*', '+', or '?'. You can use L</validation_error> and L</validation_warning> to return the results of your validation to the user or simply return 1 to indicate a valid value.
+
+If you just have a list of valid values, you may want to use the C<valid_values> schema parameter to perform this task instead.
+
+=head2 Autocompletion
+
+Autocompletion provides a way of suggesting choices to the client based upon partial data entry. This doesn't necessarily force the client to use one of the choices given but gives hints in an application specific way.
+
+To create an autocompletion field, you implement a method named C<autocomplete_FIELD> where C<FIELD> is the field to autocomplete. This is generally done with fields rendered as 'Text'. Here is an example:
+
+  sub autocomplete_foo {
+      my ($self, $value) = @_;
+
+      # Be careful to validate your input! You don't want a malicious user
+      # hacking your system.
+      my ($match_value) = $value =~ /^(\w+)$/;
+
+      my $foos = MyApp::Model::FooCollection->new;
+      $foos->limit(
+          column   => 'name',
+          operator => 'LIKE',
+          value    => '%$value%',
+      );
+
+      return map { $_->name } @{ $foos->item_array_ref };
+  }
+
+In this example, the "foo" field is autocompleted from names matched from the C<MyApp::Model::Foo> table. The match, in this case, matches any substring found in the database. I could have matched any item that starts with the string, ends with the string, matches other fields than the one returned, etc. It's up to you to decide.
+
+Note also that I have untainted the value coming in to make sure a malicious user doesn't get anyway. You should always perform a check like this when data is coming in from an outside source.
+
+If you need a more complicated solution, you can return the autocompletion values as a list of hash references containing the keys C<value> and (optionally) C<label>:
+
+  return map { { value => $_->name, label => $_->label } }
+            @{ $foos->item_array_ref };
+
+In this case, the labels will be shown to the client, but the selected value would be returned to your application.
+
 =cut
 
 sub autogenerated {0}

Modified: jifty/trunk/lib/Jifty/Action/Autocomplete.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Autocomplete.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Autocomplete.pm	Wed Feb 21 08:50:22 2007
@@ -3,7 +3,7 @@
 
 =head1 NAME
 
-Jifty::Action::Autocomplete
+Jifty::Action::Autocomplete - An action for making autocompletion suggestions
 
 =head1 DESCRIPTION
 
@@ -71,5 +71,16 @@
     return 1;
 }
 
+=head1 SEE ALSO
+
+L<Jifty::Action>
+
+=head1 LICENSE
+
+Jifty is Copyright 2005-2006 Best Practical Solutions, LLC.
+Jifty is distributed under the same terms as Perl itself.
+
+=cut
+
 1;
 

Modified: jifty/trunk/lib/Jifty/Action/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record.pm	Wed Feb 21 08:50:22 2007
@@ -11,8 +11,9 @@
 
 Represents a web-based action that is a create, update, or delete of a
 L<Jifty::Record> object.  This automatically populates the arguments
-method of L<Jifty::Action> so that you don't need to bother.  To
-actually use this class, you probably want to inherit from one of
+method of L<Jifty::Action> so that you don't need to bother.  
+
+To actually use this class, you probably want to inherit from one of
 L<Jifty::Action::Record::Create>, L<Jifty::Action::Record::Update>, or
 L<Jifty::Action::Record::Delete> and override the C<record_class>
 method.
@@ -392,7 +393,13 @@
 =head1 SEE ALSO
 
 L<Jifty::Action>, L<Jifty::Record>, L<Jifty::DBI::Record>,
-L<Jifty::Action::Record::Create>, L<Jifty::Action::Record::Update>
+L<Jifty::Action::Record::Create>, L<Jifty::Action::Record::Update>,
+L<Jifty::Action::Reocrd::Delete>
+
+=head LICENSE
+
+Jifty is Copyright 2005-2006 Best Practical Solutions, LLC.
+Jifty is distributed under the same terms as Perl itself.
 
 =cut
 


More information about the Jifty-commit mailing list