package Reaction::Types::File;
use MooseX::Types
- -declare => [qw/File/];
+ -declare => [qw/File Upload/];
use MooseX::Types::Moose 'Object';
use Catalyst::Request::Upload;
use aliased 'Reaction::UI::ViewPort::Field::Mutable::ChooseOne';
use aliased 'Reaction::UI::ViewPort::Field::Mutable::ChooseMany';
-#use aliased 'Reaction::UI::ViewPort::Field::Mutable::File';
+use aliased 'Reaction::UI::ViewPort::Field::Mutable::File';
#use aliased 'Reaction::UI::ViewPort::Field::Mutable::TimeRange';
class Action is 'Reaction::UI::ViewPort::Object', which {
$self->_build_simple_field(attribute => $attr, class => String, %$args);
};
- #implements _build_fields_for_type_File => as {
- # my ($self, $attr, $args) = @_;
- # $self->_build_simple_field(attribute => $attr, class => File, %$args);
- #};
+ implements _build_fields_for_type_File => as {
+ my ($self, $attr, $args) = @_;
+ $self->_build_simple_field(attribute => $attr, class => File, %$args);
+ };
implements _build_fields_for_type_Str => as {
my ($self, $attr, $args) = @_;
package Reaction::UI::ViewPort::Field::File;
use Reaction::Class;
+use Reaction::Types::File;
class File is 'Reaction::UI::ViewPort::Field', which {
+ has '+value' => (isa => 'File');
+
has uri => ( is => 'rw', lazy_build => 1);
has action => (isa => 'CodeRef', is => 'rw', required => 1);
--- /dev/null
+package Reaction::UI::ViewPort::Field::Mutable::File;
+
+use Reaction::Class;
+use Reaction::Types::File;
+
+class File is 'Reaction::UI::ViewPort::Field', which {
+ does 'Reaction::UI::ViewPort::Field::Role::Mutable';
+
+ has '+value' => (isa => 'Upload');
+
+ override apply_our_events => sub {
+ my ($self, $ctx, $events) = @_;
+ my $value_key = join(':', $self->location, 'value');
+ if (my $upload = $ctx->req->upload($value_key)) {
+ local $events->{$value_key} = $upload;
+ return super();
+ } else {
+ return super();
+ }
+ };
+
+};
+
+1;
--- /dev/null
+package Reaction::UI::Widget::Field::Image;
+
+use Reaction::UI::WidgetClass;
+
+class Image is 'Reaction::UI::Widget::Field', which {
+
+ implements fragment image {
+ if($_{viewport}->value_string) {
+ arg uri => $_{viewport}->uri;
+ render 'has_image';
+ } else {
+ render 'no_image';
+ }
+ };
+
+};
+
+1;