Skip to content

Commit 6e5da21

Browse files
committedOct 16, 2011
Custom edit template for the GalleryAlbum asset.
1 parent 0ff98ac commit 6e5da21

File tree

2 files changed

+37
-157
lines changed

2 files changed

+37
-157
lines changed
 

‎lib/WebGUI/Asset/Wobject/GalleryAlbum.pm

+27-155
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,12 @@ Gets an array reference of asset IDs for all the files in this album.
425425
sub getFileIds {
426426
my $self = shift;
427427

428-
if ( !$self->session->stow->get( 'fileIds-' . $self->getId ) ) {
429-
my $gallery = $self->getParent;
428+
##Assets created by www_add do not have a lineage.
429+
return [] unless $self->lineage;
430+
my $session = $self->session;
431+
$self->getParent;
432+
433+
if ( !$session->stow->get( 'fileIds-' . $self->getId ) ) {
430434

431435
# Deal with "pending" files.
432436
my %pendingRules;
@@ -437,7 +441,7 @@ sub getFileIds {
437441
$pendingRules{ statusToInclude } = [ 'pending', 'approved' ];
438442
$pendingRules{ whereClause } = q{
439443
(
440-
status = "approved" || ownerUserId = "} . $self->session->user->userId . q{"
444+
status = "approved" || ownerUserId = } . $session->db->quote($session->user->userId) . q{
441445
)
442446
};
443447
}
@@ -810,16 +814,18 @@ approval workflow.
810814
811815
=cut
812816

813-
sub processEditForm {
817+
override processEditForm => sub {
814818
my $self = shift;
815819
my $form = $self->session->form;
816820
my $errors = $self->next::method || [];
817821

822+
$self->processFileSynopsis;
823+
818824
# Return if error
819825
return $errors if @$errors;
820826

821827
### Passes all checks
822-
}
828+
};
823829

824830
#----------------------------------------------------------------------------
825831

@@ -1382,17 +1388,13 @@ sub _moveFileAjaxRequest {
13821388

13831389
#----------------------------------------------------------------------------
13841390

1385-
=head2 www_edit ( )
1391+
=head2 getEditTemplate ( )
13861392
13871393
Show the form to add / edit a GalleryAlbum asset.
13881394
1389-
Due to the advanced requirements of this form, we will ALWAYS post back to
1390-
this page. This page will decide whether or not to make C<www_editSave>
1391-
handle things.
1392-
13931395
=cut
13941396

1395-
sub www_edit {
1397+
sub getEditTemplate {
13961398
my $self = shift;
13971399
my $session = $self->session;
13981400
my $form = $self->session->form;
@@ -1401,100 +1403,13 @@ sub www_edit {
14011403

14021404
return $session->privilege->insufficient unless $self->canEdit;
14031405

1404-
# Handle the button that was pressed
1405-
# Save button
1406-
if ( $form->get("save") ) {
1407-
$self->processFileSynopsis;
1408-
return $self->www_editSave;
1409-
}
1410-
# Cancel button
1411-
elsif ( $form->get("cancel") ) {
1412-
return $self->www_view;
1413-
}
1414-
# Promote the file
1415-
elsif ( grep { $_ =~ /^promote-(.{22})$/ } $form->param ) {
1416-
my $assetId = ( grep { $_ =~ /^promote-(.{22})$/ } $form->param )[0];
1417-
$assetId =~ s/^promote-//;
1418-
my $asset = WebGUI::Asset->newById( $session, $assetId );
1419-
if ( $asset ) {
1420-
$asset->promote;
1421-
}
1422-
else {
1423-
$session->log->error("Couldn't promote asset '$assetId' because we couldn't instantiate it.");
1424-
}
1425-
}
1426-
# Demote the file
1427-
elsif ( grep { $_ =~ /^demote-(.{22})$/ } $form->param ) {
1428-
my $assetId = ( grep { $_ =~ /^demote-(.{22})$/ } $form->param )[0];
1429-
$assetId =~ s/^demote-//;
1430-
my $asset = WebGUI::Asset->newById( $session, $assetId );
1431-
if ( $asset ) {
1432-
$asset->demote;
1433-
}
1434-
else {
1435-
$session->log->error("Couldn't demote asset '$assetId' because we couldn't instantiate it.");
1436-
}
1437-
}
1438-
# Rotate to the left
1439-
elsif ( grep { $_ =~ /^rotateLeft-(.{22})$/ } $form->param ) {
1440-
my $assetId = ( grep { $_ =~ /^rotateLeft-(.{22})$/ } $form->param )[0];
1441-
$assetId =~ s/^rotateLeft-//;
1442-
my $asset = eval { WebGUI::Asset->newById( $session, $assetId ); };
1443-
1444-
if ( ! Exception::Class->caught() ) {
1445-
# Add revision and create a new version tag by doing so
1446-
my $tag = WebGUI::VersionTag->create( $session, { workflowId => $asset->getAutoCommitWorkflowId } );
1447-
my $newRevision = $asset->addRevision({ tagId => $tag->getId, status => "pending" });
1448-
$newRevision->setVersionLock;
1449-
# Rotate photo (i.e. all attached image files) by 90° CCW
1450-
$newRevision->rotate(-90);
1451-
# Auto-commit version tag
1452-
$newRevision->requestAutoCommit;
1453-
}
1454-
else {
1455-
$session->log->error("Couldn't rotate asset '$assetId' because we couldn't instantiate it.");
1456-
}
1457-
}
1458-
# Rotate to the right
1459-
elsif ( grep { $_ =~ /^rotateRight-(.{22})$/ } $form->param ) {
1460-
my $assetId = ( grep { $_ =~ /^rotateRight-(.{22})$/ } $form->param )[0];
1461-
$assetId =~ s/^rotateRight-//;
1462-
my $asset = WebGUI::Asset->newById( $session, $assetId );
1463-
1464-
if ( Exception::Class->caught() ) {
1465-
# Add revision and create a new version tag by doing so
1466-
my $tag = WebGUI::VersionTag->create( $session, { workflowId => $asset->getAutoCommitWorkflowId } );
1467-
my $newRevision = $asset->addRevision({ tagId => $tag->getId, status => "pending" });
1468-
$newRevision->setVersionLock;
1469-
# Rotate photo (i.e. all attached image files) by 90° CW
1470-
$newRevision->rotate(90);
1471-
# Auto-commit version tag
1472-
$newRevision->requestAutoCommit;
1473-
}
1474-
else {
1475-
$session->log->error("Couldn't rotate asset '$assetId' because we couldn't instantiate it.");
1476-
}
1477-
}
1478-
# Delete the file
1479-
elsif ( grep { $_ =~ /^delete-(.{22})$/ } $form->param ) {
1480-
my $assetId = ( grep { $_ =~ /^delete-(.{22})$/ } $form->param )[0];
1481-
$assetId =~ s/^delete-//;
1482-
my $asset = WebGUI::Asset->newById( $session, $assetId );
1483-
if ( $asset ) {
1484-
$asset->purge;
1485-
}
1486-
else {
1487-
$session->log->error( "Couldn't delete asset '$assetId' because we couldn't instanciate it.");
1488-
}
1489-
}
1490-
14911406
# Generate the form
14921407
if ($form->get("func") eq "add") {
14931408
# Add page is exempt from our button handling code since it calls the Gallery www_editSave
14941409
$var->{ isNewAlbum } = 1;
14951410
$var->{ form_start }
14961411
= WebGUI::Form::formHeader( $session, {
1497-
action => $self->getParent->getUrl('func=editSave;assetId=new;class='.__PACKAGE__),
1412+
action => $self->getParent->getUrl('func=addSave;assetId=new;className='.__PACKAGE__),
14981413
extras => 'name="galleryAlbumAdd"',
14991414
})
15001415
. WebGUI::Form::hidden( $session, {
@@ -1503,31 +1418,18 @@ sub www_edit {
15031418
});
15041419

15051420
# Put in the buttons that may ignore button handling code
1506-
$var->{ form_cancel }
1507-
= WebGUI::Form::button( $session, {
1508-
name => "cancel",
1509-
value => $i18n->get("cancel"),
1510-
extras => 'onclick="history.go(-1)"',
1511-
});
15121421
}
15131422
else {
15141423
$var->{ form_start }
15151424
= WebGUI::Form::formHeader( $session, {
1516-
action => $self->getUrl('func=edit'),
1425+
action => $self->getUrl('func=editSave'),
15171426
extras => 'name="galleryAlbumEdit"',
15181427
})
15191428
. WebGUI::Form::hidden( $session, {
15201429
name => "ownerUserId",
15211430
value => $self->ownerUserId,
15221431
});
15231432

1524-
# Put in the buttons that may ignore button handling code
1525-
$var->{ form_cancel }
1526-
= WebGUI::Form::submit( $session, {
1527-
name => "cancel",
1528-
value => $i18n->get("cancel"),
1529-
extras => 'onclick="history.go(-1)"',
1530-
});
15311433
}
15321434
$var->{ form_start }
15331435
.= WebGUI::Form::hidden( $session, {
@@ -1536,6 +1438,13 @@ sub www_edit {
15361438
})
15371439
;
15381440

1441+
$var->{ form_cancel }
1442+
= WebGUI::Form::submit( $session, {
1443+
name => "cancel",
1444+
value => $i18n->get("cancel"),
1445+
extras => 'onclick="history.go(-1)"',
1446+
});
1447+
15391448
$var->{ form_end }
15401449
= WebGUI::Form::formFooter( $session );
15411450

@@ -1576,45 +1485,6 @@ sub www_edit {
15761485
id => "assetIdThumbnail_$file->{ assetId }",
15771486
} );
15781487

1579-
my $promoteLabel = $i18n->get( 'Move Up', 'Icon' );
1580-
$file->{ form_promote }
1581-
= WebGUI::Form::submit( $session, {
1582-
name => "promote-$file->{assetId}",
1583-
value => $i18n->get( 'Move Up', 'Icon' ),
1584-
class => "promote",
1585-
});
1586-
1587-
my $demoteLabel = $i18n->get( 'Move Down', 'Icon' );
1588-
$file->{ form_demote }
1589-
= WebGUI::Form::submit( $session, {
1590-
name => "demote-$file->{assetId}",
1591-
value => $i18n->get( 'Move Down', 'Icon' ),
1592-
class => "demote",
1593-
});
1594-
1595-
my $deleteConfirm = $i18n->get( 'template delete message', 'Asset_Photo' );
1596-
$file->{ form_delete }
1597-
= WebGUI::Form::submit( $session, {
1598-
name => "delete-$file->{assetId}",
1599-
value => $i18n->get( 'Delete', 'Icon' ),
1600-
class => "delete",
1601-
extras => "onclick=\"return confirm('$deleteConfirm')\"",
1602-
});
1603-
1604-
$file->{ form_rotateLeft }
1605-
= WebGUI::Form::submit( $session, {
1606-
name => "rotateLeft-$file->{assetId}",
1607-
value => $i18n->get( 'rotate left' ),
1608-
class => "rotateLeft",
1609-
});
1610-
1611-
$file->{ form_rotateRight }
1612-
= WebGUI::Form::submit( $session, {
1613-
name => "rotateRight-$file->{assetId}",
1614-
value => $i18n->get( 'rotate right' ),
1615-
class => "rotateRight",
1616-
});
1617-
16181488
$file->{ form_synopsis }
16191489
= WebGUI::Form::HTMLArea( $session, {
16201490
name => "fileSynopsis_$file->{assetId}",
@@ -1625,9 +1495,11 @@ sub www_edit {
16251495
});
16261496
}
16271497

1628-
return $self->processStyle(
1629-
$self->processTemplate( $var, $self->getParent->templateIdEditAlbum )
1630-
);
1498+
my $gallery = $self->getParent;
1499+
my $template = WebGUI::Asset->newById($session, $gallery->templateIdEditAlbum);
1500+
$template->style($gallery->getStyleTemplateId);
1501+
$template->setParam( %{ $var } );
1502+
return $template;
16311503
}
16321504

16331505
#----------------------------------------------------------------------------

‎t/Asset/Wobject/GalleryAlbum/edit.t

+10-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ if ( !$mech->success ) {
7272
plan skip_all => "Cannot load URL '$baseUrl'. Will not test.";
7373
}
7474

75-
plan tests => 11; # Increment this number for each test you create
76-
7775
#----------------------------------------------------------------------------
7876
# Visitor user cannot add albums
7977
$mech = Test::WWW::Mechanize->new;
@@ -111,6 +109,10 @@ $mech->content_contains(
111109
my $album = WebGUI::Asset->newById( $session, $gallery->getAlbumIds->[0] );
112110
cmp_deeply( $properties, subhashof( $album->get ), "Properties from edit form are set correctly" );
113111

112+
SKIP: {
113+
114+
skip 'rotation, deletion, reordering no longer a part of the edit form', 5;
115+
114116
#----------------------------------------------------------------------------
115117
# Photos can be rotated using the respective form buttons
116118

@@ -170,6 +172,12 @@ foreach my $file ( @{$storage->getFiles('showAll') } ) {
170172
# Compare dimensions
171173
cmp_deeply( \@oldDims, \@newerDims, "Check if all files were rotated by 90° CCW" );
172174

175+
}
176+
177+
}
178+
179+
done_testing;
180+
173181
#----------------------------------------------------------------------------
174182
# getMechLogin( baseUrl, WebGUI::User, "identifier" )
175183
# Returns a Test::WWW::Mechanize session after logging in the given user using

0 commit comments

Comments
 (0)
Please sign in to comment.