Skip to content

Commit

Permalink
Merged r2795 through r94889 from trunk to production.
Browse files Browse the repository at this point in the history
Punch list changes, including relativization of xml paths.


git-svn-id: svn://vm36.atech.tufts.edu/TAPER/production@94890 30e6160e-469f-4000-86ef-8ea788e09201
  • Loading branch information
dorlea01 committed Jan 26, 2011
1 parent 3c07965 commit 32fbb20
Show file tree
Hide file tree
Showing 56 changed files with 938 additions and 501 deletions.
4 changes: 2 additions & 2 deletions TAPER/Makefile.PL
Expand Up @@ -23,8 +23,8 @@ requires 'Catalyst::Model::DBIC::Schema';
requires 'DateTime::Format::MySQL';
requires 'SQL::Translator';
requires 'Config::Any' => '0.18';
requires 'HTML::FormFu' => '0.06000';
requires 'Catalyst::Controller::HTML::FormFu' => '0.06000';
requires 'HTML::FormFu' => '0.08002';
requires 'Catalyst::Controller::HTML::FormFu' => '0.08002';
requires 'DBIx::Class::Schema';
requires 'Moose';
requires 'Moose::Util::TypeConstraints';
Expand Down
117 changes: 117 additions & 0 deletions TAPER/lib/HTML/FormFu/Element/RepeatableSelect.pm
@@ -0,0 +1,117 @@
package HTML::FormFu::Element::RepeatableSelect;

use strict;
use base 'HTML::FormFu::Element::Select';
use MRO::Compat;
use mro 'c3';
use Scalar::Util qw( reftype );

sub prepare_attrs {
my ( $self, $render ) = @_;

my $submitted = $self->form->submitted;
my $default = $self->default;

my $value
= defined $self->name
? $self->get_nested_hash_value( $self->form->input, $self->nested_name )
: undef;

my $i = $self->_index_in_group;
if ( defined $i ) {
if ( ( reftype($value) || '' ) eq 'ARRAY' ) {
$value = $value->[ $i ];
}
if ( ( reftype($default) || '' ) eq 'ARRAY' ) {
$default = $default->[ $i ];
}
}

if ( !$submitted && defined $default ) {
for my $deflator ( @{ $self->_deflators } ) {
$default = $deflator->process($default);
}
}

for my $option ( @{ $render->{options} } ) {
if ( exists $option->{group} ) {
for my $item ( @{ $option->{group} } ) {
$self->_prepare_attrs( $submitted, $value, $default, $item );
}
}
else {
$self->_prepare_attrs( $submitted, $value, $default, $option );
}
}

# Skip the parent method.
$self->HTML::FormFu::Element::_Input::prepare_attrs($render);

return;
}

sub _index_in_group {
my ( $self ) = @_;

my $elems = $self->form->get_fields({ nested_name => $self->nested_name });
if ( $#$elems ) {
# There are multiple fields with the same name; assume
# none are multi-value fields, i.e. only one selected
# option per field. (Otherwise it might be ambiguous
# which option came from which field.)
for ( 0 .. @$elems - 1 ) {
if ( $self == $elems->[$_] ) {
return $_;
}
}
}
}

sub type { return 'Select'; }

1;

__END__
=head1 NAME
HTML::FormFu::Element::RepeatableSelect - Select form field that can be inside a Repeatable
=head1 METHODS
=over
=item prepare_attrs
Override prepare_attrs of Select (actually defined in _Group) to fix
the behavior when there are multiple fields with the same name. In
this case, the value and default are arrays of values that correspond
to the fields, so we have to pick out the one that corresponds to this
field.
=item type
Returns 'Select' rather than 'RepeatableSelect' so that the HTML
class comes out the same as a non-patched select.
=back
=head1 SEE ALSO
Is a sub-class of, and inherits methods from
L<HTML::FormFu::Element::Select>,
L<HTML::FormFu::Element::_Group>,
L<HTML::FormFu::Element::_Input>,
L<HTML::FormFu::Element::_Field>,
L<HTML::FormFu::Element>
L<HTML::FormFu>
=head1 AUTHOR
Doug Orleans, C<dougorleans@gmail.com>
=head1 LICENSE
This library is free software, you can redistribute it and/or modify it under
the same terms as Perl itself.
8 changes: 6 additions & 2 deletions TAPER/lib/TAPER.pm
Expand Up @@ -35,6 +35,9 @@ our $VERSION = '0.01';
# Turn on Session's flash-to-stash feature.
__PACKAGE__->config( session => { flash_to_stash => 1 } );

# Provide an empty config for the Cache plugin, because otherwise it complains.
__PACKAGE__->config( 'Plugin::Cache' => { } );

# Check for an env var pointing to a different site-config file.
if ( defined $ENV{TAPER_SITE_CONFIG} ) {
__PACKAGE__->config( 'Plugin::ConfigLoader' => {
Expand Down Expand Up @@ -201,11 +204,12 @@ An interface to Standard Submission Agreement XML documents and related metdata.
=head1 AUTHOR
Jason McIntosh, Appleseed Software Consulting <jmac@applseed-sc.com>
Jason McIntosh, Appleseed Software Consulting <jmac@appleseed-sc.com>
Doug Orleans, Appleseed Software Consulting <dougo@appleseed-sc.com>
=head1 COPYRIGHT
Copyright (c) 2009 Tufts University.
Copyright (c) 2009-2010 Tufts University.
=cut

Expand Down
4 changes: 2 additions & 2 deletions TAPER/lib/TAPER/Controller/Auth.pm
Expand Up @@ -30,7 +30,7 @@ sub login_FORM_SUBMITTED {
if ( $taper_user ) {
# Yep, they're good to go.
# Now kick the user to the front page.
$c->res->redirect($c->uri_for('/'));
$c->res->redirect($c->uri_for( $c->req->params->{page} || '/' ));
}
else {
# This user is Tufts-valid, but unknown to this application.
Expand Down Expand Up @@ -58,7 +58,7 @@ sub logout : Local {
$c->logout;
}

$c->res->redirect($c->uri_for('/'));
$c->res->redirect($c->uri_for('/auth/login'));
}

1;
Expand Down
3 changes: 2 additions & 1 deletion TAPER/lib/TAPER/Controller/CreateRsa.pm
Expand Up @@ -19,7 +19,8 @@ sub create_rsa : PathPart('create_rsa') Chained('/') CaptureArgs(0) {
my ( $c ) = @_;

unless ( defined $c->taper_user ) {
$c->res->redirect( $c->uri_for( '/auth/login' ) );
$c->res->redirect( $c->uri_for( '/auth/login',
{ page => '/create_rsa' } ) );
$c->detach;
}
}
Expand Down
3 changes: 1 addition & 2 deletions TAPER/lib/TAPER/Controller/Dca.pm
Expand Up @@ -25,8 +25,7 @@ sub dca : Chained('/') CaptureArgs(0) {
}

} else {
# TO DO: should the login page bring the user back here afterward?
$c->res->redirect( $c->uri_for ( '/auth/login' ) );
$c->res->redirect( $c->uri_for ( '/auth/login', { page => '/dca' } ) );
$c->detach;
}

Expand Down
30 changes: 28 additions & 2 deletions TAPER/lib/TAPER/Controller/Dca/Offices.pm
Expand Up @@ -17,7 +17,8 @@ sub list_FORM_VALID {
my $form = $c->stash->{form};

my $name = $form->param_value( 'name' );
$c->model( 'TAPERDB::Office' )->create( { name => $name } );
my $office = $c->model( 'TAPERDB::Office' )->create( { name => $name } );
$c->stash->{office} = $office;

# Clear the form so it can be used to add another office.
# This depends on the fields having force_default = 1.
Expand Down Expand Up @@ -55,6 +56,24 @@ sub edit_FORM_VALID {
$office->update;
}

sub delete : Chained('office') Args(0) {
my $self = shift;
my ( $c ) = @_;

my $office = $c->stash->{office};
$c->flash->{office} = $office;

if ( !$office || $office->ssas > 0 ) {
$c->flash->{office_not_deleted} = 1;
} else {
$office->delete;
$c->flash->{office_deleted} = 1;
}

$c->res->redirect( $c->uri_for( '/dca/offices/list' ) );
$c->detach;
}

1;

=head1 NAME
Expand Down Expand Up @@ -102,6 +121,13 @@ Path: dca/offices/office/$office_id/edit
Displays and handles a form that allows DCA staff to edit an office.
=item delete
Path: dca/offices/offices/$office_id/delete
Deletes an office. The office will not be deleted if it has any
associated SSAs.
=back
=head1 AUTHOR
Expand All @@ -112,6 +138,6 @@ Doug Orleans, Appleseed Software Consulting <dougo@appleseed-sc.com>
=head1 COPYRIGHT
Copyright (c) 2009 by Tufts University.
Copyright (c) 2009-2010 by Tufts University.
=cut
31 changes: 31 additions & 0 deletions TAPER/lib/TAPER/Controller/Dca/Rsas.pm
Expand Up @@ -72,6 +72,8 @@ sub edit_FORM_VALID {

# Now have it update itself.
$rsa->update_from_form( $form );

$c->forward( '_populate_preservation_rules_menu' );
}

sub edit_FORM_NOT_SUBMITTED {
Expand All @@ -85,13 +87,39 @@ sub edit_FORM_NOT_SUBMITTED {
$rsa->populate_form( $form );
}

sub edit_FORM_RENDER {
my $self = shift;
my ( $c ) = @_;

$c->forward( '_populate_preservation_rules_menu' );
}

sub _populate_preservation_rules_menu : Private {
my $self = shift;
my ( $c ) = @_;

my $form = $c->stash->{form};
my $fields = $form->get_fields( 'sipToAip' );
my @rules = $c->model( 'TAPERDB::PreservationRule' )->search( undef, {
order_by => 'number' } );
for my $field ( @$fields ) {
$field->options(
[ [ '', '- Preservation Rule -' ],
map {
[ $_->number, 'Rule ' . $_->number . ': ' . $_->description ]
} @rules ] );
}
}

sub inventory : Chained('rsa') {
my $self = shift;
my ( $c ) = @_;

my $rsa = $c->stash->{rsa};
$c->res->body( $rsa->inventory_zip );
$c->res->content_type( 'application/zip' );
$c->res->header( 'Content-Disposition' =>
'attachment; filename="inventory.zip"' );
}

sub delete_inventory : Chained('rsa') {
Expand Down Expand Up @@ -154,6 +182,8 @@ sub _list : Private {
else {
$c->res->body( $c->model( 'RSA' )->zip( @$rsas ) );
$c->res->content_type( 'application/x-zip-compressed' );
$c->res->header( 'Content-Disposition' =>
'attachment; filename="agreements.zip"' );
$c->detach;
}
}
Expand Down Expand Up @@ -207,6 +237,7 @@ If the supplied RSA ID isn't valid, redirects the user to /dca.
=item edit_FORM_SUBMITTED
=item edit_FORM_VALID
=item edit_FORM_NOT_SUBMITTED
=item edit_FORM_RENDER
Path: dca/rsas/rsa/$rsa_id/edit
Expand Down
16 changes: 13 additions & 3 deletions TAPER/lib/TAPER/Controller/Dca/Ssa.pm
Expand Up @@ -32,7 +32,8 @@ sub list : Chained('ssas') Args(0) {
my $self = shift;
my ( $c ) = @_;

$c->stash->{offices} = [ $c->model( 'TAPERDB::Office' )->all ];
my $model = $c->model( 'TAPERDB::Office' );
$c->stash->{offices} = [ $model->search( undef, { order_by => 'name' } ) ];

$c->stash->{template} = 'dca/ssa/list.tt';
}
Expand All @@ -47,7 +48,7 @@ sub edit : Chained('ssa') FormConfig('dca/ssa.yml') {

# Little cheat: Change the name of the submit button.
my $submit_button = $form->get_field( { name => 'ssa_submit' } );
$submit_button->value( 'Update this SSA' );
$submit_button->value( 'Update this Transfer Template' );

$c->stash->{template} = 'dca/ssa/edit.tt';
}
Expand Down Expand Up @@ -92,6 +93,14 @@ sub create : Chained('ssas') FormConfig('dca/ssa.yml') {
my $self = shift;
my ( $c ) = @_;

my $form = $c->stash->{form};

$form->default_values({
warrantToCollect => 'Tufts University Records Policy',
retentionPeriod => 'Permanent',
archivalDescriptionStandard => 'DACS',
});

$c->forward( 'populate_office_menu' );

$c->stash->{template} = 'dca/ssa/create.tt';
Expand Down Expand Up @@ -226,9 +235,10 @@ Private helper action for validating a submitted SSA form.
=head1 AUTHOR
Jason McIntosh, Appleseed Software Consulting <jmac@appleseed-sc.com>
Doug Orleans, Appleseed Software Consulting <dougo@appleseed-sc.com>
=head1 COPYRIGHT
Copyright (c) 2009 by Tufts University.
Copyright (c) 2009-2010 by Tufts University.
=cut

0 comments on commit 32fbb20

Please sign in to comment.