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

View of /WebApplication/WebComponent.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Fri Apr 27 16:02:14 2007 UTC (13 years, 1 month ago) by paczian
Branch: MAIN
*** empty log message ***

package WebComponent;

# WebComponent - abstract web component class 

# $Id: WebComponent.pm,v 1.1 2007/04/27 16:02:14 paczian Exp $

use strict;
use warnings;

use Carp qw( confess );


=pod

=head1 NAME

WebComponent - abstract web component class

=head1 DESCRIPTION

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.

=cut

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

    # check application
    unless (ref $application and $application->isa("WebApplication")) {
      confess "Invalid application in __PACKAGE__ new.";
    }
    
    $id = '' unless (defined $id);

    my $self = { 'application' => $application, 
		 'id'          => $id,
		 'css'         => undef,
	       };
    bless $self, $class;

    return $self;
}


=pod

=item * B<application> ()

Returns the reference to the application object

=cut

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


=pod

=item * B<id> ()

Returns the numerical id of the web component

=cut

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


=pod

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

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

=cut

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

=pod

=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.

=cut

sub require_javascript {
  return [ ];
}


=pod

=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.

=cut

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


=pod

=item * B<output> ()

Returns the html of the web component

=cut

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


1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3