OME::Web - The parent class of OME web pages
package OME::Web::Home;
use strict;
use OME;
use base qw/OME::Web/;
our $VERSION;
$VERSION = $OME::VERSION;
sub getPageTitle {
return "Open Microscopy Environment";
}
sub getPageBody {
$self->contentType('text/html');
$HTML = <<ENDHTML;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML><HEAD>
<TITLE>Open Microscopy Environment</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX">
</HEAD>
ENDHTML
return ('HTML', $HTML);
}
1;
This class is meant to be sub-classed by web pages in OME. This class is only meant to provide common functionality.
This method should be over-ridden in a sub-class and return a text string with the page title, which will normally appear in the window's title bar.
This method must be over-ridden in a sub-class and return two scalars. The first scalar is treated as a status message to determine what to do with the second scalar. For example,
return ('HTML',$HTML);
Accepted status strings are HTML, IMAGE, SVG, JNLP,
FILE, REDIRECT, XML, and ERROR,
If the returned status is HTML, then the page is appropriately decorated to match the other pages in OME.
No special processing is currently done for IMAGE, SVG, and JNLP. For JNLP the filename that should
be used on the client must also be returned e.g.
return ('JNLP', $JNLP, $filename);
A FILE status is used for downloading files to the browser. In this case, the second scalar is a hash reference
containing information to control the download process. The hash may contain the following:
filename - a path to the file on the server to be downloaded. downloadFilename - The name of the file that should be used on the client (the browser). temp - A flag that if true, will cause the downloaded file to be deleted on the server.
return ('FILE',{filename => $myFile, downloadFilename => 'foo.txt', temp => 1});
A REDIRECT status is used to get the browser to go to a different URL specified by the second scalar:
return ('REDIRECT','http://ome.org/somewhere/else.html');
A XML status indicates that the results being returned should be
labelled with content-type "application/xml". The contents will
also be wrapped in <OME>..</OME> tags to insure well-formedness.
A ERROR status means an error has occurred. The error message should be sent as the second scalar.
return ('ERROR','Something really bad happened');
The script can generate the same effect by calling
die ('Something really bad happened');
unless ($self->{_popup} or $self->{_nomenu}) {
my $menu_template;
$menu_template = OME::Web::TemplateManager->getActionTemplate("Menu.tmpl");
$menu_template->param(guest => ($self->Session()->isGuestSession()));
$menu = $menu_template->output();
}
return $menu;
}
=head2 getHeader
=cut
sub getHeader{
my $self = shift;
my $header;
my $CGI = $self->{CGI};
my $session = OME::Session->instance();
unless ($self->{_popup} or $self->{_nomenu}) {
my ($project_links,$dataset_links);
my $full_name = $session->User->FirstName . ' ' . $session->User->LastName;
if (my $obj = $session->project()) { $project_links = $CGI->a({href => OME::Web->getObjDetailURL( $obj ), class => 'ome_quiet'}, $obj->name()); } # Recent Project
if (my $obj = $session->dataset()) { $dataset_links = $CGI->a({href => OME::Web->getObjDetailURL( $obj ), class => 'ome_quiet'}, $obj->name()); } # Recent dataset
my $header_template;
$header_template = OME::Web::TemplateManager->getActionTemplate("Header.tmpl");
$header_template->param(guest => $session->isGuestSession());
$header_template->param(user => $full_name);
$header_template->param(project => $project_links);
$header_template->param(dataset => $dataset_links);
$header = $header_template->output();
}
return $header;
}
# lookup(customTable, defaultTable, key) # --------------------------------------
| sub lookup { | ||
| my $custom | = shift; | |
| my $default = shift; | ||
| my $key | = shift; |
if (defined $custom->{$key}) {
return $custom->{$key};
} else {
return $default->{$key};
}
}
# combine(default, custom, ...) # ----------------------------------
| sub combine { | ||
| #my $custom | = shift; | |
| my $table; | ||
| my %result; | ||
| my ($key,$value); |
foreach $table (@_) {
while (($key,$value) = each %$table)
{
$result{$key} = $value;
}
}
return \%result;
}
# space(n) # -------- sub space { my $n = shift; my $result = ''; my $i;
for ($i = 0; $i < $n; $i++)
{
$result .= ' ';
}
return $result;
}
# font(params, ...) # ----------------- sub font { my $self = shift; my $CGI = $self->{CGI}; my $params = shift; my @content = @_;
return $CGI->font(combine($self->{fontDefaults},$params),@content);
}
# contentType # ----------------- # Implemented the same way as Session - acessor for __contentType
# table(params, ...) # ------------------
| sub table { | ||
| my $self | = shift; | |
| my $CGI | = $self->{CGI}; | |
| my $params | = shift; | |
| my @content = @_; |
return $CGI->table(combine($self->{tableDefaults},$params),@content) . "\n";
}
# tableHeaders(rowParams, columnParams, ...) # ------------------------------------------
| sub tableHeaders { | ||
| my $self | = shift; | |
| my $CGI | = $self->{CGI}; | |
| my $rowParams = shift; | ||
| my $colParams = shift; | ||
| #my @content = @_; | ||
| my ($h,$hs); |
$hs = "";
foreach $h (@_) {
$hs .= $CGI->td(combine($self->{tableHeaderDefaults},$colParams),
$self->font({color => 'WHITE'},
$CGI->small($CGI->b(space(2).$h.space(2)))));
$hs .= "\n";
}
my $x = $CGI->Tr(combine($self->{tableHeaderRowDefaults},$rowParams),$hs);
return $x . "\n";
}
# tableRow(params, ...) # ---------------------
| sub tableColoredRow { | ||
| my $self | = shift; | |
| my $CGI | = $self->{CGI}; | |
| my $params | = shift; |
my $rowColor = $self->{tableRowColors}->[$self->{nextRowColor}];
$self->{nextRowColor} = 1 - $self->{nextRowColor};
return $CGI->Tr(combine($self->{tableRowDefaults},{bgcolor => $rowColor},$params),@_) . "\n";
}
| sub tableRow { | ||
| my $self | = shift; | |
| my $CGI | = $self->{CGI}; | |
| my $params | = shift; |
return $CGI->Tr(combine($self->{tableRowDefaults},$params),@_) . "\n";
}
# tableCell(params, ...) # ----------------------
| sub tableCell { | ||
| my $self | = shift; | |
| my $CGI | = $self->{CGI}; | |
| my $params | = shift; |
my $thisRowColor = $self->{nextRowColor};
my $rowColor = $self->{tableRowColors}->[$thisRowColor];
return $CGI->td(combine($self->{tableCellDefaults},{bgcolor => $rowColor},$params),
$self->font({},
space(1),
@_,
space(1))) . "\n";
}
# spacer(width,height) # --------------------
| sub spacer { | ||
| my $self = shift; | ||
| my $CGI | = $self->{CGI}; | |
| my $width = shift; | ||
| my $height = shift; |
return $CGI->img({src => "/perl/spacer.gif", width => $width, height => $height});
}
# tableLine(width) # ----------------
| sub tableLine { | ||
| my $self = shift; | ||
| my $CGI | = $self->{CGI}; | |
| my $width = shift; | ||
| my $height = shift; |
my $params = {colspan => $width};
if (defined $height) {
$params->{height} = $height;
}
return $CGI->Tr($self->{tableHeaderRowDefaults},
$CGI->td(combine($self->{tableHeaderDefaults},$params),
$self->spacer(1,1))) . "\n";
}
my ($package_name, $common_name, $formal_name, $ST) =
$self->_loadTypeAndGetInfo( $type );
$type can be a DBObject name ("OME::Image"), an Attribute name ("@Pixels"), or an instance of either
Loads the package appropriately and returns descriptive information.
$package_name is the name of the DBObject package $common_name is a name suitable for display $formal_name is the name suitable for passing as a parameter or to functions (package name for standard DBObjects, @AttrName for Attributes) $ST is the Semantic Type if $type is a ST or attribute. Otherwise it's undef.
my $url_to_obj_detail = $self->getObjDetailURL( $obj, %url_params );
$obj should be a DBObject instance. Attributes are fine. %url_params is optional. If specified, it should contain a list of URL parameters such as ( Popup => 1 ).
returns a url to a detailed view of the object
my $search_url = $self->getSearchAccessorURL( $obj, $method );
$obj should be a DBObject instance. Attributes are fine. $method should be a 'has-many' or 'many-to-many' method of $obj
returns a url to a search page for whatever is returned from $obj's $method
my $search_url = $self->getSearchURL( $obj_type, @search_params );
same input parameters as $factory->findObjects()
returns a url to a search page that corresponds to that kind of DB search
my $table_url = $self->getTableURL( $obj_type, @search_params );
same input parameters as $factory->findObjects()
returns a url to a tab delimited table page that contains the search results.
for some pages that need Template parameters in the URL but may only have them in the referer, we grab the parameter out of the referer and redirect to new url including this parameter.
getExternalLinkText - get the appropriate url for an object of a given type =cut
sub getExternalLinkText { my $self=shift; my ($q,$type,$obj) = @_;
my @maps;
my $mapType = $type."ExternalLinkList";
my $text ="";
eval { @maps = $obj->$mapType()};
if (@maps && scalar(@maps) > 0 && !$@) {
foreach my $map (@maps) {
my $link = $map->ExternalLink();
next unless $link;
my $desc = $link->Description();
my $url = $self->getExternalLinkURL($link);
if ($url ne "") {
$text .= "<span class=\"ome_ext_link_text\">" .
$q->a({href=>$url,class=>"ome_ext_link_text"},$desc) .
"</span>";
}
}
}
# if no maps exist to build up links, return nothing
return $text;
}
$self->getExternalLinkURL($externalLink);
return the url associated with an external link. 3 possibilities
1) if the link has a url, return it.
2) if the link has a template, use that template and the link id
to construct a url
3) else return null.
Douglas Creager <dcreager@alum.mit.edu>, Josiah Johnston <siah@nih.gov>, Ilya Goldberg <igg@nih.gov>, Open Microscopy Environment