Fix a bug where the cached data structure was not deleted.

Add template variables for showing the uploaded photos.
Add tests for the template variables.
Add a form field to delete the photo with all data.
This commit is contained in:
Colin Kuskie 2009-03-23 05:01:36 +00:00
parent e5cdfdfae8
commit c8da6cfe26
4 changed files with 158 additions and 2 deletions

View file

@ -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;
}

View file

@ -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 => []
},

View file

@ -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;