[Jifty-commit] r2185 - in jifty/trunk: . lib/Jifty lib/Jifty/Manual
share/web/static/css share/web/static/js
share/web/templates/__jifty t/TestApp/lib/TestApp/Action t/TestApp/t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Mon Nov 20 16:19:26 EST 2006
Author: falcone
Date: Mon Nov 20 16:19:25 2006
New Revision: 2185
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Action.pm
jifty/trunk/lib/Jifty/Manual/Actions.pod
jifty/trunk/lib/Jifty/Result.pm
jifty/trunk/lib/Jifty/Web/Form/Field.pm
jifty/trunk/share/web/static/css/base.css
jifty/trunk/share/web/static/css/forms.css
jifty/trunk/share/web/static/js/jifty.js
jifty/trunk/share/web/templates/__jifty/validator.xml
jifty/trunk/t/TestApp/lib/TestApp/Action/DoSomething.pm
jifty/trunk/t/TestApp/t/06-validation.t
Log:
r14618 at ketch: falcone | 2006-11-20 16:18:07 -0500
* Add the ability to send "notes" to users from your canonicalizer
this is separate from the warning and error spans used by the validator
* Action picked up a helper method for this (canonicalization_note)
* Result.pm Action.pm and W::F::Field picked up scaffolding to support
passing around canonicalization_note and displaying them
* jifty.js and validator.xml learned to pass the canonicalization_note
back and forth when using ajax canonicalizes
* some ugly default styling changes
Modified: jifty/trunk/lib/Jifty/Action.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action.pm (original)
+++ jifty/trunk/lib/Jifty/Action.pm Mon Nov 20 16:19:25 2006
@@ -689,6 +689,20 @@
return 'warnings-' . $self->form_field_name($field_name);
}
+=head2 canonicalization_note_div_id ARGUMENT
+
+Turn one of this action's L<arguments|Jifty::Manual::Glossary/arguments> into
+the id for the div in which its canonicalization notes live; takes name of the field
+as an argument.
+
+=cut
+
+sub canonicalization_note_div_id {
+ my $self = shift;
+ my $field_name = shift;
+ return 'canonicalization_note-' . $self->form_field_name($field_name);
+}
+
=head1 VALIDATION METHODS
@@ -1060,6 +1074,29 @@
return 1;
}
+=head2 canonicalization_note ARGUMENT => NOTE
+
+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");
+
+..where C<$field> is the name of the argument which the canonicalizer is
+processing
+
+=cut
+
+sub canonicalization_note {
+ my $self = shift;
+ my $field = shift;
+ my $info = shift;
+
+ $self->result->field_canonicalization_note($field => $info);
+
+ return;
+
+}
+
=head2 autogenerated
Autogenerated Actions will always return true when this method is called.
Modified: jifty/trunk/lib/Jifty/Manual/Actions.pod
==============================================================================
--- jifty/trunk/lib/Jifty/Manual/Actions.pod (original)
+++ jifty/trunk/lib/Jifty/Manual/Actions.pod Mon Nov 20 16:19:25 2006
@@ -174,7 +174,9 @@
dynamically in an L<AJAX|Jifty::Manual::Glossary/ajax>-enabled browser
based on what the user has entered. For example, we can let a user
use magic syntax to provide tags for their blog post by surrounding the
-tags with square brackets.
+tags with square brackets. You can also let the user know you're
+doing something magical by using C<canonicalization_note> which
+will display a message to the user.
use Jifty::Param::Schema;
use Jifty::Action schema {
@@ -194,6 +196,7 @@
if ($value =~ s/\[(.*?)\]//) {
# this clobbers, may want to merge
$self->argument_value( tags => $1 );
+ $self->canonicalization_note( title => 'Removed tags from your title' );
}
return $value;
Modified: jifty/trunk/lib/Jifty/Result.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Result.pm (original)
+++ jifty/trunk/lib/Jifty/Result.pm Mon Nov 20 16:19:25 2006
@@ -135,6 +135,32 @@
return %{$self->{field_warnings} || {}};
}
+=head2 field_canonicalization_note FIELD [NOTE]
+
+Gets or sets a canonicalization note for a specific field on the action.
+
+=cut
+
+sub field_canonicalization_note {
+ my $self = shift;
+ my $field = shift;
+
+ $self->{field_canonicalization_notes}{ $field } = shift if @_;
+ return $self->{field_canonicalization_notes}{ $field };
+}
+
+=head2 field_canonicalization_notes
+
+Returns a hash which maps L<argument|Jifty::Manual::Glossary/argument>
+name to canonicalization notes.
+
+=cut
+
+sub field_canonicalization_notes {
+ my $self = shift;
+ return %{$self->{field_canonicalization_notes} || {}};
+}
+
=head2 content [KEY [, VALUE]]
Gets or sets the content C<KEY>. This is used when actions need to
Modified: jifty/trunk/lib/Jifty/Web/Form/Field.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Field.pm (original)
+++ jifty/trunk/lib/Jifty/Web/Form/Field.pm Mon Nov 20 16:19:25 2006
@@ -320,6 +320,7 @@
$self->render_hints();
$self->render_errors();
$self->render_warnings();
+ $self->render_canonicalization_notes();
} elsif ($self->render_mode eq 'read'){
$self->render_value();
}
@@ -660,4 +661,22 @@
return '';
}
+=head2 render_canonicalization_notes
+
+Outputs a <div> with any canonicalization notes for this action, even if there are
+none -- AJAX could fill it in.
+
+=cut
+
+sub render_canonicalization_notes {
+ my $self = shift;
+
+ return unless $self->action;
+
+ Jifty->web->out(
+qq!<span class="canonicalization_note @{[$self->classes]}" id="@{[$self->action->canonicalization_note_div_id($self->name)]}">@{[$self->action->result->field_canonicalization_note( $self->name ) || '']}</span>\n!
+ );
+ return '';
+}
+
1;
Modified: jifty/trunk/share/web/static/css/base.css
==============================================================================
--- jifty/trunk/share/web/static/css/base.css (original)
+++ jifty/trunk/share/web/static/css/base.css Mon Nov 20 16:19:25 2006
@@ -12,6 +12,10 @@
color: #00a0a0;
}
+.canonicalization_note {
+ color: #009966;
+}
+
hr {
clear: both;
}
Modified: jifty/trunk/share/web/static/css/forms.css
==============================================================================
--- jifty/trunk/share/web/static/css/forms.css (original)
+++ jifty/trunk/share/web/static/css/forms.css Mon Nov 20 16:19:25 2006
@@ -31,7 +31,7 @@
color: #999999;
}
-div.form_field .error, div.form_field .warning {
+div.form_field .error, div.form_field .warning, div.form_field .canonicalization_note {
float: right;
width: 88%;
text-align: left;
Modified: jifty/trunk/share/web/static/js/jifty.js
==============================================================================
--- jifty/trunk/share/web/static/js/jifty.js (original)
+++ jifty/trunk/share/web/static/js/jifty.js Mon Nov 20 16:19:25 2006
@@ -176,7 +176,15 @@
}
} else if ((action.nodeName == 'canonicalizeaction') && (action.getAttribute("id") == id)) {
for (var field = action.firstChild; field != null; field = field.nextSibling) {
- // Possibilities for field.nodeName: it could be 'ignored', 'blank' or 'update'
+ // Possibilities for field.nodeName: it could be 'ignored', 'blank' , 'update', or 'info'
+ // info is a separate action from the update
+ if (field.nodeName == 'canonicalization_note') {
+ var note_div= document.getElementById(field.getAttribute("id"));
+ if (note_div != null) {
+ note_div.innerHTML = field.firstChild.data;
+ }
+ }
+
if (field.nodeName == 'update') {
var field_name = field.getAttribute("name");
for (var form_number = 0 ; form_number < document.forms.length; form_number++) {
Modified: jifty/trunk/share/web/templates/__jifty/validator.xml
==============================================================================
--- jifty/trunk/share/web/templates/__jifty/validator.xml (original)
+++ jifty/trunk/share/web/templates/__jifty/validator.xml Mon Nov 20 16:19:25 2006
@@ -48,6 +48,13 @@
or length $action->argument_value($arg) == 0 ) {
$writer->emptyTag( "blank", name => $action->form_field_name($arg) );
} else {
+ if ( $action->result->field_canonicalization_note($arg) ) {
+ $writer->dataElement(
+ "canonicalization_note",
+ $action->result->field_canonicalization_note($arg),
+ id => $action->canonicalization_note_div_id($arg)
+ );
+ }
$writer->dataElement(
"update",
$action->argument_value($arg),
Modified: jifty/trunk/t/TestApp/lib/TestApp/Action/DoSomething.pm
==============================================================================
--- jifty/trunk/t/TestApp/lib/TestApp/Action/DoSomething.pm (original)
+++ jifty/trunk/t/TestApp/lib/TestApp/Action/DoSomething.pm Mon Nov 20 16:19:25 2006
@@ -14,6 +14,7 @@
my $self = shift;
my $address = shift;
+ $self->canonicalization_note(email => "Lowercased your email");
return lc($address);
}
Modified: jifty/trunk/t/TestApp/t/06-validation.t
==============================================================================
--- jifty/trunk/t/TestApp/t/06-validation.t (original)
+++ jifty/trunk/t/TestApp/t/06-validation.t Mon Nov 20 16:19:25 2006
@@ -5,7 +5,7 @@
use lib 't/lib';
use Jifty::SubTest;
-use Jifty::Test tests => 13;
+use Jifty::Test tests => 14;
use Jifty::Test::WWW::Mechanize;
my $server = Jifty::Test->make_server;
@@ -40,4 +40,5 @@
"Getting validator.xml output for a canonicalization");
$mech->content_contains('<update name="J:A:F-email-dosomething">upper at email.com</update>',
" ... canonicalizer returned all lower case (good)");
-
+$mech->content_contains('<canonicalization_note id="canonicalization_note-J:A:F-email-dosomething">Lowercased your email</canonicalization_note>',
+ " ... canonicalizer warned user");
More information about the Jifty-commit
mailing list