diff --git a/lib/WebGUI/Asset/Story.pm b/lib/WebGUI/Asset/Story.pm index 07dc38b51..a65802d07 100644 --- a/lib/WebGUI/Asset/Story.pm +++ b/lib/WebGUI/Asset/Story.pm @@ -398,6 +398,10 @@ sub getEditForm { name => 'imgUrl'.$photoIndex, value => $photo->{url}, }), + imgDeleteForm => WebGUI::Form::yesNo($session, { + name => 'deletePhoto'.$photoIndex, + value => 0, + }), }; } push @{ $var->{ photo_form_loop } }, { @@ -617,6 +621,7 @@ sub setPhotoData { my $photo = to_json($photoData); ##Update the db. $self->update({photo => $photo}); + delete $self->{_photoData}; return; } @@ -751,6 +756,22 @@ sub viewTemplateVariables { $var->{updatedTimeEpoch} = $self->get('revisionDate'); $var->{crumb_loop} = $self->getCrumbTrail(); + $var->{photo_loop} = []; + PHOTO: foreach my $photo (@{ $self->getPhotoData}) { + next PHOTO unless $photo->{storageId}; + my $storage = WebGUI::Storage->get($session, $photo->{storageId}); + my $file = $storage->getFiles->[0]; + next PHOTO unless $file; + my $imageUrl = $storage->getUrl($file); + push @{ $var->{photo_loop} }, { + imageUrl => $imageUrl, + imageCaption => $photo->{caption}, + imageByline => $photo->{byLine}, + imageAlt => $photo->{alt}, + imageTitle => $photo->{title}, + imageLink => $photo->{url}, + } + } return $var; } diff --git a/lib/WebGUI/Help/Asset_Story.pm b/lib/WebGUI/Help/Asset_Story.pm index 1d58d1464..6652e1747 100644 --- a/lib/WebGUI/Help/Asset_Story.pm +++ b/lib/WebGUI/Help/Asset_Story.pm @@ -38,6 +38,7 @@ our $HELP = { { name => 'imgAltForm', }, { name => 'imgTitleForm', }, { name => 'imgUrlForm', }, + { name => 'imgDeleteForm', }, ], }, ], @@ -79,6 +80,16 @@ our $HELP = { }, ], }, + { name => 'photo_loop', + 'variables' => [ + { name => 'imageUrl', }, + { name => 'imageCaption', }, + { name => 'imageByline', }, + { name => 'imageAlt', }, + { name => 'imageTitle', }, + { name => 'imageLink', }, + ], + }, ], related => [] }, diff --git a/lib/WebGUI/i18n/English/Asset_Story.pm b/lib/WebGUI/i18n/English/Asset_Story.pm index f23de7694..96d929d69 100644 --- a/lib/WebGUI/i18n/English/Asset_Story.pm +++ b/lib/WebGUI/i18n/English/Asset_Story.pm @@ -344,6 +344,12 @@ our $I18N = { lastUpdated => 0, }, + 'imgDeleteForm' => { + message => q|A field to delete the image, along with all data attached to it.|, + context => q|Template variable for edit form.|, + lastUpdated => 0, + }, + 'photo caption' => { message => q|Photo Caption|, context => q|Label in the edit story form. Short for Photograph Caption.|, @@ -374,6 +380,54 @@ our $I18N = { lastUpdated => 0, }, + 'photo delete' => { + message => q|Delete Photo|, + context => q|Label in the edit story form. Request that the photo be deleted, and all information with it.|, + lastUpdated => 0, + }, + + 'photo_loop' => { + message => q|A loop containing photos and information about the photos.|, + context => q|Template variable|, + lastUpdated => 0, + }, + + 'imageUrl' => { + message => q|The URL to the image.|, + context => q|Template variable|, + lastUpdated => 0, + }, + + 'imageCaption' => { + message => q|A caption for the image.|, + context => q|Template variable|, + lastUpdated => 0, + }, + + 'imageByline' => { + message => q|A byline for the image.|, + context => q|Template variable|, + lastUpdated => 0, + }, + + 'imageAlt' => { + message => q|Alternate text for the image, suitable for use as the ALT parameter for an IMG tag.|, + context => q|Template variable|, + lastUpdated => 0, + }, + + 'imageTitle' => { + message => q|Alternate text for the image, suitable for use as the TITLE parameter for an IMG tag.|, + context => q|Template variable|, + lastUpdated => 0, + }, + + 'imageLink' => { + message => q|A URL for the image to link to.|, + context => q|Template variable|, + lastUpdated => 0, + }, + }; 1; diff --git a/t/Asset/Story.t b/t/Asset/Story.t index 635828a4a..fab9bc2c3 100644 --- a/t/Asset/Story.t +++ b/t/Asset/Story.t @@ -21,7 +21,7 @@ use Test::Deep; use Data::Dumper; my $tests = 1; -plan tests => 27 +plan tests => 28 + $tests ; @@ -51,6 +51,9 @@ my $topic = $defaultNode->addChild({ my $archiveTag = WebGUI::VersionTag->getWorking($session); $archiveTag->commit; +my $storage1 = WebGUI::Storage->create($session); +my $storage2 = WebGUI::Storage->create($session); + SKIP: { @@ -80,7 +83,6 @@ $story = $archive->addChild({ }); isa_ok($story, 'WebGUI::Asset::Story', 'Created a Story asset'); -is($story->get('storageId'), '', 'by default, there is no storageId'); is($story->get('photo'), '[]', 'by default, photos is an empty JSON array'); is($story->get('isHidden'), 1, 'by default, stories are hidden'); $story->update({isHidden => 0}); @@ -212,6 +214,30 @@ $story->update({ keywords => "foxtrot tango whiskey", }); is($story->get('highlights'), "one\ntwo\nthree", 'highlights set correctly for template var check'); + +$storage1->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('gooey.jpg')); +$storage2->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('lamp.jpg')); + +$story->setPhotoData([ + { + storageId => $storage1->getId, + caption => 'Mascot for a popular CMS', + byLine => 'Darcy Gibson', + alt => 'Gooey', + title => 'Mascot', + url => 'http://www.webgui.org', + }, + { + storageId => $storage2->getId, + caption => 'The Lamp', + byLine => 'Aladdin', + alt => 'Lamp', + title => '', + url => 'http://www.lamp.com', + }, +]); + + my $viewVariables = $story->viewTemplateVariables; #diag Dumper $viewVariables; cmp_deeply( @@ -236,12 +262,56 @@ cmp_bag( is ($viewVariables->{updatedTimeEpoch}, $story->get('revisionDate'), 'viewTemplateVariables: updatedTimeEpoch'); +cmp_deeply( + $viewVariables->{photo_loop}, + [ + { + imageUrl => re('gooey.jpg'), + imageCaption => 'Mascot for a popular CMS', + imageByline => 'Darcy Gibson', + imageAlt => 'Gooey', + imageTitle => 'Mascot', + imageLink => 'http://www.webgui.org', + }, + { + imageUrl => re('lamp.jpg'), + imageCaption => 'The Lamp', + imageByline => 'Aladdin', + imageAlt => 'Lamp', + imageTitle => '', + imageLink => 'http://www.lamp.com', + }, + ], + 'viewTemplateVariables: photo_loop is okay' +); + +##Simulate someone deleting the file stored in the storage object. +$storage2->deleteFile('lamp.jpg'); +$viewVariables = $story->viewTemplateVariables; + +cmp_deeply( + $viewVariables->{photo_loop}, + [ + { + imageUrl => re('gooey.jpg'), + imageCaption => 'Mascot for a popular CMS', + imageByline => 'Darcy Gibson', + imageAlt => 'Gooey', + imageTitle => 'Mascot', + imageLink => 'http://www.webgui.org', + }, + ], + 'viewTemplateVariables: photo_loop: if the storage has no files, it is not shown' +); + } END { $story->purge if $story; $archive->purge if $archive; $topic->purge if $topic; + $storage1->delete if $storage1; + $storage2->delete if $storage2; $archiveTag->rollback; WebGUI::VersionTag->getWorking($session)->rollback; }