[Jifty-commit] jifty branch, jquery_with_ui, updated. 730e3903a6a58c80acd409034390681c02440227
Jifty commits
jifty-commit at lists.jifty.org
Sat Jan 30 08:18:54 EST 2010
The branch, jquery_with_ui has been updated
via 730e3903a6a58c80acd409034390681c02440227 (commit)
from 43eb2d11d8baa59ae8f8e728ffc561b824c7355a (commit)
Summary of changes:
lib/Jifty/Request.pm | 3 ++-
lib/Jifty/Web.pm | 1 +
lib/Jifty/Web/Form/Field/{Upload.pm => Uploads.pm} | 10 +++++++---
share/web/static/css/main.css | 1 +
share/web/static/css/uploads.css | 3 +++
share/web/static/js/uploads.js | 14 ++++++++++++++
6 files changed, 28 insertions(+), 4 deletions(-)
copy lib/Jifty/Web/Form/Field/{Upload.pm => Uploads.pm} (72%)
create mode 100644 share/web/static/css/uploads.css
create mode 100644 share/web/static/js/uploads.js
- Log -----------------------------------------------------------------
commit 730e3903a6a58c80acd409034390681c02440227
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat Jan 30 21:04:31 2010 +0800
Uploads form field
diff --git a/lib/Jifty/Request.pm b/lib/Jifty/Request.pm
index b83950b..2f38df5 100644
--- a/lib/Jifty/Request.pm
+++ b/lib/Jifty/Request.pm
@@ -269,7 +269,8 @@ sub from_cgi {
for my $k (keys %args) {
my $val = $args{$k};
if(ref($val) && ref($val) eq 'ARRAY') {
- $args{$k} = [map {Jifty::I18N->promote_encoding($_, $ENV{CONTENT_TYPE})} @$val];
+ $args{$k} = [map { ref eq 'Fh' ?
+ Jifty::Web::FileUpload->new_from_fh($_) : Jifty::I18N->promote_encoding($_, $ENV{CONTENT_TYPE})} @$val];
} elsif(!ref($val)) {
$args{$k} = Jifty::I18N->promote_encoding($val, $ENV{CONTENT_TYPE});
}
diff --git a/lib/Jifty/Web.pm b/lib/Jifty/Web.pm
index d194c16..3b6cc2d 100644
--- a/lib/Jifty/Web.pm
+++ b/lib/Jifty/Web.pm
@@ -68,6 +68,7 @@ __PACKAGE__->javascript_libs([qw(
ui.core.js
ui.sortable.js
ordered-list.js
+ uploads.js
)]);
use Class::Trigger;
diff --git a/lib/Jifty/Web/Form/Field/Uploads.pm b/lib/Jifty/Web/Form/Field/Uploads.pm
new file mode 100644
index 0000000..a78243e
--- /dev/null
+++ b/lib/Jifty/Web/Form/Field/Uploads.pm
@@ -0,0 +1,64 @@
+use warnings;
+use strict;
+
+package Jifty::Web::Form::Field::Uploads;
+
+=head1 NAME
+
+Jifty::Web::Form::Field::Uploads - File uploads field
+
+=head1 DESCRIPTION
+
+An input field that renders using C<< <input type="file" /> >>. The
+argument value that the action recieves from this field via
+L<Jifty::Action/argument_value> will be a filehandle, which can be
+read in the usual ways.
+
+=cut
+
+use base qw/Jifty::Web::Form::Field/;
+
+=head2 render_widget
+
+Renders the file upload widget.
+
+=cut
+
+sub render_widget {
+ my $self = shift;
+ my $field = qq!<div class="uploads">!;
+ $field .= qq!<input type="file" name="@{[ $self->input_name ]}" !;
+ $field .= $self->_widget_class();
+ $field .= $self->javascript;
+ $field .= qq!/>!;
+ $field .= qq!<a href="#" class="attach-more">!;
+ $field .= _('Attach another file');
+ $field .= qq!</a></div>!;
+ Jifty->web->out($field);
+ '';
+}
+
+
+=head2 render_value
+
+The 'value', rendered, is empty so that BLOBs and the like don't get
+streamed to the browser.
+
+=cut
+
+sub render_value {
+ '';
+}
+
+=head2 classes
+
+Add 'upload' to the rest of the classes
+
+=cut
+
+sub classes {
+ my $self = shift;
+ return join(' ', 'upload', ($self->SUPER::classes));
+}
+
+1;
diff --git a/share/web/static/css/main.css b/share/web/static/css/main.css
index 815ec44..50c29e9 100644
--- a/share/web/static/css/main.css
+++ b/share/web/static/css/main.css
@@ -20,4 +20,5 @@
@import "facebox.css";
@import "datetime.css";
@import "ordered-list.css";
+ at import "uploads.css";
@import "app-late.css";
diff --git a/share/web/static/css/uploads.css b/share/web/static/css/uploads.css
new file mode 100644
index 0000000..2aede1f
--- /dev/null
+++ b/share/web/static/css/uploads.css
@@ -0,0 +1,3 @@
+.uploads input, .uploads a {
+ display: block;
+}
diff --git a/share/web/static/js/uploads.js b/share/web/static/js/uploads.js
new file mode 100644
index 0000000..032972c
--- /dev/null
+++ b/share/web/static/js/uploads.js
@@ -0,0 +1,14 @@
+jQuery(document).ready(function(){
+ jQuery('div.uploads .attach-more').click(
+ function () {
+ var box = jQuery(this).closest('div.uploads');
+ var name = box.find('input[type=file]:first').attr('name');
+ var cla = box.find('input[type=file]:first').attr('class');
+ jQuery('<input type="file" name=' + name + '" class="' + cla + '" />').insertBefore(this);
+
+ // actually, firefox doesn't really support "click" here
+ box.find('input[type=file]:last').click();
+ return false;
+ } );
+});
+
-----------------------------------------------------------------------
More information about the Jifty-commit
mailing list