diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 42f4579ca..d7d9bae98 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -2131,7 +2131,9 @@ sub processTemplate { } $template = WebGUI::Asset->new($self->session, $templateId,"WebGUI::Asset::Template") unless (defined $template); + warn("templateId: $templateId: template: $template"); if (defined $template) { + warn("templateId: $templateId: template: $template: id: ", $template->getId()); $var = { %{ $var }, %{ $self->getMetaDataAsTemplateVariables } }; $var->{'controls'} = $self->getToolbar if $self->session->var->isAdminOn; my %vars = ( @@ -2140,6 +2142,7 @@ sub processTemplate { 'menuTitle' => $self->getMenuTitle, %{$var}, ); + warn("templateId: $templateId: template: $template"); return $template->process(\%vars); } else { @@ -2606,6 +2609,11 @@ NOTE: Don't try to override or overload this method. It won't work. What you are sub www_editSave { my $self = shift; + + my $annotations = ""; + if ($self->isa("WebGUI::Asset::File::Image")) { + $annotations = $self->get("annotations"); + } ##If this is a new asset (www_add), the parent may be locked. We should still be able to add a new asset. my $isNewAsset = $self->session->form->process("assetId") eq "new" ? 1 : 0; return $self->session->privilege->locked() if (!$self->canEditIfLocked and !$isNewAsset); @@ -2644,6 +2652,12 @@ sub www_editSave { } } + if ($self->isa("WebGUI::Asset::File::Image")) { + $object->update({ annotations => $annotations }); + } + + ### + $object->updateHistory("edited"); # we handle auto commit assets here in case they didn't handle it themselves diff --git a/lib/WebGUI/Asset/File/Image.pm b/lib/WebGUI/Asset/File/Image.pm index 5df71ac9b..63c396ae8 100644 --- a/lib/WebGUI/Asset/File/Image.pm +++ b/lib/WebGUI/Asset/File/Image.pm @@ -112,6 +112,10 @@ sub definition { fieldType => 'textarea', defaultValue => 'style="border-style:none;"', }, + annotations => { + fieldType => 'textarea', + defaultValue => '', + }, }, }; return $class->SUPER::definition($session,$definition); @@ -236,17 +240,38 @@ sub view { return $out if $out; } my %var = %{$self->get}; + my ($crop_js, $domMe) = $self->annotate_js({ just_image => 1 }); + + if ($crop_js) { + my ($style, $url) = $self->session->quick(qw(style url)); + + $style->setLink($url->extras('yui/build/resize/assets/skins/sam/resize.css'), {rel=>'stylesheet', type=>'text/css'}); + $style->setLink($url->extras('yui/build/fonts/fonts-min.css'), {rel=>'stylesheet', type=>'text/css'}); + $style->setLink($url->extras('yui/build/imagecropper/assets/skins/sam/imagecropper.css'), {rel=>'stylesheet', type=>'text/css'}); + + $style->setScript($url->extras('yui/build/yahoo-dom-event/yahoo-dom-event.js'), {type=>'text/javascript'}); + $style->setScript($url->extras('yui/build/element/element-beta-min.js'), {type=>'text/javascript'}); + $style->setScript($url->extras('yui/build/dragdrop/dragdrop-min.js'), {type=>'text/javascript'}); + $style->setScript($url->extras('yui/build/resize/resize-min.js'), {type=>'text/javascript'}); + $style->setScript($url->extras('yui/build/imagecropper/imagecropper-beta-min.js'), {type=>'text/javascript'}); + } + $var{controls} = $self->getToolbar; $var{fileUrl} = $self->getFileUrl; $var{fileIcon} = $self->getFileIconUrl; $var{thumbnail} = $self->getThumbnailUrl; - my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate}); + $var{annotateJs} = "$crop_js$domMe"; + $var{parameters} = sprintf("id=%s", $self->getId()); + warn("annotateJs: $var{annotateJs}"); + my $form = $self->session->form; + my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate}); if (!$self->session->var->isAdminOn && $self->get("cacheTimeout") > 10) { WebGUI::Cache->new($self->session,"view_".$self->getId)->set($out,$self->get("cacheTimeout")); } return $out; } + #---------------------------------------------------------------------------- =head2 setFile ( filename ) @@ -288,31 +313,17 @@ sub www_undo { my $previous = (@{$self->getRevisions()})[1]; # instantiate assetId if ($previous) { - warn("here"); # my $session = $self->session; - warn("here"); # my $cache = WebGUI::Cache->new($self->session, ["asset",$self->getId,$self->getRevisionDate]); - warn("here"); # $cache->flush; - warn("here"); # my $cache = WebGUI::Cache->new($previous->session, ["asset",$previous->getId,$previous->getRevisionDate]); - warn("here"); # $cache->flush; - warn("here"); - warn("$previous"); - warn(ref $previous); - warn($previous->getId); $self = $self->purgeRevision(); # $self = undef; - warn("here"); # $self = WebGUI::Asset->new($previous->session, $previous->getId, ref $previous, $previous->getRevisionDate); $self = $previous; - warn("$self"); - warn(ref $self); - warn($self->getId); - warn($self->session->cache); $self->generateThumbnail; } return $self->www_edit(); @@ -330,22 +341,16 @@ sub www_annotate { my $self = shift; return $self->session->privilege->insufficient() unless $self->canEdit; return $self->session->privilege->locked() unless $self->canEditIfLocked; - if ($self->session->form->process("annotate_text")) { + if (1) { my $newSelf = $self->addRevision(); delete $newSelf->{_storageLocation}; - warn("here"); - $newSelf->getStorageLocation->annotate($newSelf->get("filename"),$newSelf->session->form); - warn("here"); + $newSelf->getStorageLocation->annotate($newSelf->get("filename"),$newSelf,$newSelf->session->form); $newSelf->setSize($newSelf->getStorageLocation->getFileSize($newSelf->get("filename"))); - warn("here"); $self = $newSelf; - warn("here"); $self->generateThumbnail; - warn("here"); } my ($style, $url) = $self->session->quick(qw(style url)); - # http://www.kryogenix.org/code/browser/annimg/annimg.html (creative commons) # $style->setLink($url->extras('annotate/imageMap.css'), {rel=>'stylesheet', type=>'text/css'}); $style->setLink($url->extras('yui/build/resize/assets/skins/sam/resize.css'), {rel=>'stylesheet', type=>'text/css'}); @@ -358,50 +363,21 @@ sub www_annotate { $style->setScript($url->extras('yui/build/resize/resize-min.js'), {type=>'text/javascript'}); $style->setScript($url->extras('yui/build/imagecropper/imagecropper-beta-min.js'), {type=>'text/javascript'}); - my $imageAsset = $self->session->db->getRow("ImageAsset","assetId",$self->getId); + # my $imageAsset = $self->session->db->getRow("ImageAsset","assetId",$self->getId); - warn("annotations: " . $self->{annotations}); - my @pieces = split(/\n/, $imageAsset->{annotations}); + my @pieces = split(/\n/, $self->get('annotations')); # my ($top_left, $width_height, $note) = split(/\n/, $imageAsset->{annotations}); - my $crop_js = qq( - - ); my $image = '
'.$self->get(
'; - # my $image = '
'.$self->get(
'; my ($width, $height) = $self->getStorageLocation->getSize($self->get("filename")); @@ -409,60 +385,6 @@ sub www_annotate { my $i18n = WebGUI::International->new($self->session,"Asset_Image"); my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl); - my $hotspots = ''; - my $domMe = ''; - - for (my $i = 0; $i < $#pieces; $i += 3) { - my $top_left = $pieces[$i]; - my $width_height = $pieces[$i + 1]; - my $note = $pieces[$i + 2]; - - # next if 3 == $i; - - $domMe .= qq( - - - - - - - ); - - - push(@checkboxes, $f->checkbox( - -label=>$i18n->get('delete') . " '$note'", - -checked=>0, - -name=>"delAnnotate$i", - -value=>"1" - ) - ); - $f->hidden( - -name=>"annotates", - -value=>"$i" - ); - - # last; - } - $self->getAdminConsole->addSubmenuItem($self->getUrl('func=edit'),$i18n->get("edit image")); $f->hidden( -name=>"func", @@ -499,9 +421,116 @@ sub www_annotate { -extras=>'onclick="switchState();"', ); $f->submit; + my ($crop_js, $domMe) = $self->annotate_js(); return $self->getAdminConsole->render($f->print."$image$crop_js$domMe",$i18n->get("annotate image")); } +#------------------------------------------------------------------- +sub annotate_js { + my $self = shift; + my $opts = shift; + + my @pieces = split(/\n/, $self->get('annotations')); + + warn("pieces: $#pieces: ". $self->getId()); + return "" if !@pieces && $opts->{just_image}; + + my ($img_null, $tooltip_block, $tooltip_none) = ('', '', ''); + for (my $i = 0; $i < $#pieces; $i += 3) { + $img_null .= "YAHOO.img.container.tt$i = null;\n"; + $tooltip_block .= "YAHOO.util.Dom.setStyle('tooltip$i', 'display', 'block');\n"; + $tooltip_none .= "YAHOO.util.Dom.setStyle('tooltip$i', 'display', 'none');\n"; + my $j = $i + 2; + # warn("i: $i: ", $self->session->form->process("delAnnotate$i")); + } + + my $id = $$opts{just_image} ? $self->getId : "yui_img"; + + my $crop_js = qq( + + ); + + my $hotspots = ''; + my $domMe = ''; + + for (my $i = 0; $i < $#pieces; $i += 3) { + my $top_left = $pieces[$i]; + my $width_height = $pieces[$i + 1]; + my $note = $pieces[$i + 2]; + + if ($top_left =~ /top: (\d+)px; left: (\d+)px;/) { + $top_left = "xy[0]+$1, xy[1]+$2"; + } + + my ($width, $height) = ("", ""); + if ($width_height =~ /width: (\d+)px; height: (\d+)px;/) { + ($width, $height) = ("$1px", "$2px"); + } + + # next if 3 == $i; + + $domMe .= qq( + + + + + + + ); + } + + return($crop_js, $domMe); +} + #------------------------------------------------------------------- sub www_rotate { my $self = shift; @@ -797,7 +826,7 @@ sub www_crop { # Use superclass method for now. sub www_view { my $self = shift; - $self->SUPER::www_view; + return($self->SUPER::www_view); } #sub www_view { diff --git a/lib/WebGUI/Storage.pm b/lib/WebGUI/Storage.pm index f1e6c2b1b..83b9c7f64 100644 --- a/lib/WebGUI/Storage.pm +++ b/lib/WebGUI/Storage.pm @@ -1169,8 +1169,8 @@ Text to add. sub annotate { my $self = shift; my $filename = shift; + my $asset = shift; my $form = shift; - warn("there"); unless (defined $filename) { $self->session->errorHandler->error("Can't rotate when you haven't specified a file."); return 0; @@ -1179,34 +1179,50 @@ sub annotate { $self->session->errorHandler->error("Can't rotate something that's not an image."); return 0; } - warn("there"); - # form->process("degree") + # unless ($annotate_text) { + # $self->session->errorHandler->error("Can't annotate with no text."); + # return 0; + # } + # unless ($annotate_top && $annotate_left && $annotate_width && $annotate_height) { + # $self->session->errorHandler->error("Can't annotate with no dimensions."); + # return 0; + # } + + my $annotate = $asset->get('annotations'); + my $save_annotate = ""; + my @pieces = split(/\n/, $annotate); + for (my $i = 0; $i < $#pieces; $i += 3) { + my $top_left = $pieces[$i]; + my $width_height = $pieces[$i + 1]; + my $note = $pieces[$i + 2]; + + # warn("i: $i: ", $form->process("delAnnotate$i")); + next if $form->process("delAnnotate$i"); + + if ($save_annotate) { + $save_annotate .= "\n"; + } + $save_annotate .= "$top_left\n$width_height\n$note"; + } + my $annotate_text = $form->process("annotate_text"); my $annotate_top = $form->process("annotate_top"); my $annotate_left = $form->process("annotate_left"); my $annotate_width = $form->process("annotate_width"); my $annotate_height = $form->process("annotate_height"); - warn("there"); - unless ($annotate_text) { - $self->session->errorHandler->error("Can't annotate with no text."); - return 0; + # warn(qq(unless ($annotate_top && $annotate_left && $annotate_width && $annotate_height && $annotate_text !~ /^\s*$/))); + if ($annotate_top && $annotate_left && $annotate_width && $annotate_height && $annotate_text !~ /^\s*$/) { + if ($save_annotate) { + $save_annotate .= "\n"; + } + # warn(qq($save_annotate .= "top: ${annotate_top}px; left: ${annotate_left}px;\nwidth: ${annotate_width}px; height: ${annotate_height}px;\n'$annotate_text'")); + $save_annotate .= "top: ${annotate_top}px; left: ${annotate_left}px;\nwidth: ${annotate_width}px; height: ${annotate_height}px;\n$annotate_text"; } - warn("there"); + # warn($save_annotate); - my $imageAsset = $self->session->db->getRow("ImageAsset","assetId",$self->getId); - if ($imageAsset->{annotations} =~ /\n/) { - $imageAsset->{annotations} .= "\n"; - } - warn("there: $imageAsset->{annotations}"); - $imageAsset->{annotations} .= "top: ${annotate_top}px; left: ${annotate_left}px;\nwidth: ${annotate_width}px; height: ${annotate_height}px;\n$annotate_text"; - warn("there: $imageAsset->{annotations}"); - # $self->{_data}{annotations} = $imageAsset->{annotations}; - # warn("there: $self->{_data}{annotations}"); - # $self->session->db->setRow("ImageAsset","assetId",$self->{_data}); - - foreach my $k (sort keys %{ $self->{_data} }) { - # warn("$k => $$self{_data}{$k}"); - } + $asset->update({ annotations => $save_annotate }); + $save_annotate = $asset->get('annotations'); + # warn($save_annotate); return 1; }