[Bio] / WebApplication / WebComponent.pm Repository:
ViewVC logotype

View of /WebApplication/WebComponent.pm

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.6 - (download) (as text) (annotate)
Mon Aug 2 12:14:47 2010 UTC (9 years, 11 months ago) by paczian
Branch: MAIN
CVS Tags: rast_rel_2010_0928, rast_rel_2010_0827
Changes since 1.5: +2 -1 lines
added singleton mode for components

package WebComponent;

# WebComponent - abstract web component class 

# $Id: WebComponent.pm,v 1.6 2010/08/02 12:14:47 paczian Exp $

use strict;
use warnings;
use FIG_Config;


=head1 NAME

WebComponent - abstract web component class


This module is the abstract WebComponent class used by the web application
framework. A web component is a reusable page element inherited from this
class. Each component is assigned an unique id (to support javascript 
operations on the components). 

Using a web component is done by requesting the component from the application,
then setting parameters as supported by the specific component and finally
returning the html output of the component.

=head1 METHODS

=over 4

=item * B<new> (I<application>, I<id>)

Creates a new instance of the WebComponent object. The constructor requires
a reference to the web application object and an (unique) id. Unique ids 
are used to manipulate html elements by javascript.


sub new {
    my ($class, $application, $id) = @_;

    # check application
    unless (ref $application and $application->isa("WebApplication")) {
      die "Invalid application in __PACKAGE__ new.";
    $id = '' unless (defined $id);
    my $sv_url = "$FIG_Config::cgi_url/seedviewer.cgi";
    if (FIGRules::nmpdr_mode($application->cgi) && $FIG_Config::linkinSV) {
	$sv_url = $FIG_Config::linkinSV;
    my $self = { 'application' => $application, 
		 'id'          => $id,
		 'css'         => undef,
                 'svURL'       => $sv_url,
		 'sigleton'    => 0,
    bless $self, $class;

    return $self;


=item * B<application> ()

Returns the reference to the application object


sub application {
  return $_[0]->{'application'};


=item * B<svURL> ()

Returns the Seed Viewer URL


sub svURL {
    return $_[0]->{svURL};


=item * B<id> ()

Returns the numerical id of the web component


sub id {
  return $_[0]->{'id'};


=item * B<get_trigger> (I<action_name>)

Returns a unique cgi action param based on the I<action_name>.


sub get_trigger {
  return 'wac_'.$_[0]->id.'_'.$_[1];


=item * B<require_javascript> ()

Returns a reference to an array of javascript files to include into the 
output page. By default the method returns the reference to an empty 
array. Overload in inherited web components as needed.


sub require_javascript {
  return [ ];


=item * B<require_css> (I<css_file>)

Returns the name of the css file to include into the the html of the web component.
If the optional parameter I<css_file> is given, the component will require that
css file instead of the default one.


sub require_css {
  if ($_[1]) {
    $_[0]->{'css'} = $_[1];
  return $_[0]->{'css'};


=item * B<output> ()

Returns the html of the web component


sub output {
  die "Abstract method 'output' must be implemented in __PACKAGE__.\n";

=head3 JavaCall

    my $string = $comp->JavaCall($name => @parms);

Format a call to a java function. The parameters will all be converted to
string literals and assembled with the method name.

=over 4

=item name

Name of the Java method to call.

=item parms

A list of strings. The strings will be converted to Javascript string literals
and specified as parameters on the method call.

=item RETURN

Returns a string that can be used as an event parameter to call the specified
Javascript method passing in the specified literal values.



sub JavaCall {
    # Get the parameters.
    my ($self, $name, @parms) = @_;
    # Quote the strings.
    my @literals;
    for my $parm (@parms) {
        $parm =~ s/\n/\\n/g;
        $parm =~ s/'/\\'/g;
        push @literals, "'$parm'";
    # Assemble the call.
    my $retVal = "$name(" . join(", ", @literals) . ")";
    # Return the result.
    return $retVal;


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3