cvsuser     02/03/28 08:18:15

  Modified:    P5EEx/Blue/P5EEx/Blue Widget.pm
  Log:
  first cut at all methods documented
  
  Revision  Changes    Path
  1.12      +309 -35   p5ee/P5EEx/Blue/P5EEx/Blue/Widget.pm
  
  Index: Widget.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/P5EEx/Blue/P5EEx/Blue/Widget.pm,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -w -r1.11 -r1.12
  --- Widget.pm 28 Mar 2002 15:22:01 -0000      1.11
  +++ Widget.pm 28 Mar 2002 16:18:15 -0000      1.12
  @@ -1,6 +1,6 @@
   
   #############################################################################
  -## $Id: Widget.pm,v 1.11 2002/03/28 15:22:01 spadkins Exp $
  +## $Id: Widget.pm,v 1.12 2002/03/28 16:18:15 spadkins Exp $
   #############################################################################
   
   package P5EEx::Blue::Widget;
  @@ -235,6 +235,8 @@
   
   Returns a list of attributes which a service of this type would like to
   absorb from its container service.
  +This is a *static* method.
  +It doesn't require an instance of the class to call it.
   
       * Signature: $attribs = P5EEx::Blue::Service->absorbable_attribs()
       * Param:     void
  @@ -243,23 +245,34 @@
       * Since:     0.01
   
       $attribs = $widget->absorbable_attribs();
  +    @attribs = @{$widget->absorbable_attribs()};
   
   =cut
   
  -# NOTE:  This is a *static* method.
  -#        It doesn't require an instance of the class to call it.
  -# Usage: @attribs = @{$w->absorbable_attribs()};
  -#        $attribsref = $w->absorbable_attribs();
   sub absorbable_attribs {
       # for the general widget, there are only a few universal absorbable attributes
       [ "lang", "dict" ];
   }
   
  -######################################################################
  -# EVENTS
  -######################################################################
  +#############################################################################
  +# Method: handle_event()
  +#############################################################################
  +
  +=head2 handle_event()
  +
  +    * Signature: $handled = $self->handle_event($widget_name,$event,@args);
  +    * Param:     $widget_name    string
  +    * Param:     $event          string
  +    * Param:     @args           any
  +    * Return:    $handled        boolean
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    $handled = $widget->handle_event("app.table.sort","click","up",4,20);
  +    $handled = $widget->handle_event("app.table","sort","down","last_name");
  +
  +=cut
   
  -# Usage: $widget->handle_event($ename, $event, @args);
   sub handle_event {
       my $self = shift;
       my ($name, $wc, $container, $w);
  @@ -287,9 +300,22 @@
       }
   }
   
  -######################################################################
  -# SET/GET METHODS
  -######################################################################
  +#############################################################################
  +# Method: set_value()
  +#############################################################################
  +
  +=head2 set_value()
  +
  +    * Signature: $self->set_value($value);
  +    * Param:     $value          any
  +    * Return:    void
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    $widget->set_value("hello");
  +    $widget->set_value(43);
  +
  +=cut
   
   sub set_value {
       my ($self, $value) = @_;
  @@ -302,6 +328,22 @@
       }
   }
   
  +#############################################################################
  +# Method: get_value()
  +#############################################################################
  +
  +=head2 get_value()
  +
  +    * Signature: $value = $self->get_value();
  +    * Param:     void
  +    * Return:    $value          any
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    $value = $widget->get_value();
  +
  +=cut
  +
   sub get_value {
       my ($self, $default, $setdefault) = @_;
       my $name = $self->{name};
  @@ -313,6 +355,24 @@
       }
   }
   
  +#############################################################################
  +# Method: fget_value()
  +#############################################################################
  +
  +=head2 fget_value()
  +
  +    * Signature: $formatted_value = $self->fget_value();
  +    * Signature: $formatted_value = $self->fget_value($format);
  +    * Param:     $format            string
  +    * Return:    $formatted_value   scalar
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    $formatted_date = $date_widget->fget_value();  # use default format
  +    $formatted_date = $date_widget->fget_value("%Y-%m-%d"); # supply format
  +
  +=cut
  +
   sub fget_value {
       my ($self, $format) = @_;
       $format = $self->get("format") if (!defined $format);
  @@ -330,52 +390,182 @@
       }
   }
   
  +#############################################################################
  +# Method: get_values()
  +#############################################################################
  +
  +=head2 get_values()
  +
  +    * Signature: $values = $self->get_values();
  +    * Signature: $values = $self->get_values($default);
  +    * Signature: $values = $self->get_values($default,$setdefault);
  +    * Param:     $default        any
  +    * Param:     $setdefault     boolean
  +    * Return:    $values         []
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    $values = $widget->get_values();
  +
  +=cut
  +
   sub get_values {
       my ($self, $default, $setdefault) = @_;
       my $values = $self->get_value($default, $setdefault);
       return (ref($values) eq "ARRAY") ? @$values : ($values);
   }
   
  +#############################################################################
  +# Method: set()
  +#############################################################################
  +
  +=head2 set()
  +
  +    * Signature: $self->set($attribute,$value);
  +    * Param:     $attribute      string
  +    * Param:     $value          any
  +    * Return:    void
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    $widget->set("last_name","Jones");
  +
  +=cut
  +
   sub set {
       my ($self, $var, $value) = @_;
       $self->{context}->wset($self->{name}, $var, $value);
   }
   
  +#############################################################################
  +# Method: get()
  +#############################################################################
  +
  +=head2 get()
  +
  +    * Signature: $value = $self->get($attribute);
  +    * Signature: $value = $self->get($attribute,$default);
  +    * Signature: $value = $self->get($attribute,$default,$setdefault);
  +    * Param:     $attribut       string
  +    * Param:     $default        any
  +    * Param:     $setdefault     boolean
  +    * Return:    $value          any
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    $last_name = $widget->get("last_name");
  +    $is_adult = $widget->get("adult_ind","Y");   # assume adult
  +    $is_adult = $widget->get("adult_ind","Y",1); # assume adult, remember
  +
  +=cut
  +
   sub get {
       my ($self, $var, $default, $setdefault) = @_;
       $self->{context}->wget($self->{name}, $var, $default, $setdefault);
   }
   
  +#############################################################################
  +# Method: delete()
  +#############################################################################
  +
  +=head2 delete()
  +
  +    * Signature: $self->delete($attribute);
  +    * Param:     $attribute      string
  +    * Return:    void
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    $widget->delete("voter_id");
  +
  +=cut
  +
   sub delete {
       my ($self, $var) = @_;
       $self->{context}->wdelete($self->{name}, $var);
   }
   
  +#############################################################################
  +# Method: set_default()
  +#############################################################################
  +
  +=head2 set_default()
  +
  +    * Signature: $self->set_default($attribute,$default);
  +    * Param:     $attribute      string
  +    * Param:     $default        any
  +    * Return:    void
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    $widget->set_default("adult_ind","Y");
  +
  +=cut
  +
   sub set_default {
       my ($self, $var, $default) = @_;
       $self->{context}->wget($self->{name}, $var, $default, 1);
   }
   
  -# $value = P5EEx::Blue::Widget->format($value, $type, $format);
  +#############################################################################
  +# Method: format()
  +#############################################################################
  +
  +=head2 format()
  +
  +    * Signature: $formatted_value = $self->format($value, $type, $format);
  +    * Param:     $value             scalar
  +    * Param:     $type              string
  +    * Param:     $format            string
  +    * Return:    $formatted_value   string
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    $formatted_value = $widget->format("20020127","date","%Y-%m-%d");
  +    $formatted_value = $widget->format("27-Jan-02","date","%Y-%m-%d");
  +    $formatted_value = $widget->format("01/27/2002","date","%Y-%m-%d");
  +    $formatted_value = P5EEx::Blue::Widget->format("01/27/2002","date","%Y-%m-%d");
  +
  +A static method.
  +
  +=cut
  +
   sub format {
       my ($self, $value, $type, $format) = @_;
       return "" if (!defined $value || $value eq "");
       if ($type eq "date") {
  -        if ($value eq "0000-00-00") {
  -            return "";
  +        if ($value =~ /^([0-9]{4})([0-9]{2})([0-9]{2})$/) {
  +            $value = "$1-$2-$3";  # time2str doesn't get YYYYMMDD
           }
  -        else {
  +        return "" if ($value eq "0000-00-00");
               return time2str($format, str2time($value));
           }
       }
  -}
   
  -######################################################################
  -# METHODS
  -######################################################################
  +#############################################################################
  +# Method: translate()
  +#############################################################################
  +
  +=head2 translate()
  +
  +    * Signature: $translated_label = $widget->translate($label, $lang);
  +    * Param:     $label               string
  +    * Param:     $lang                string
  +    * Return:    $translated_label    string
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    $translated_label = $widget->translate($label, $lang);
  +    print $w->translate("Hello","fr");     # "Bonjour"
  +    print $w->translate("Hello","fr_ca");  # "Bonjour, eh" (french canadian)
  +
  +Translates the label into the desired language based on the dictionary
  +which is current in the widget at the time.
  +This dictionary is usually a reference to a global dictionary
  +which is absorbed from the container widget.
  +
  +=cut
   
  -# Usage: print $w->translate("Hello","fr");     # "Bonjour"
  -#        print $w->translate("Hello","fr_ca");  # "Bonjour, eh" (french canadian) 
;-)
   sub translate {
       my ($self, $label, $lang) = @_;
   
  @@ -398,11 +588,30 @@
       return $langlabel;
   }
   
  -# Usage: print $w->label();           # "Allez!"  (if current lang is "fr")
  -#        print $w->label("name");     # "Jacques" (translation of alternate 
attribute) (if curr lang is "fr")
  -#        print $w->label("name","en");# "Jack"    (translation of alternate 
attribute) (override lang is "en")
  -#        print $w->label("","en");    # "Go!"     (default label, overridden lang 
of "en")
  -#        print $w->label("","en_ca"); # "Go! eh?" (default label, overridden lang 
of "en_ca")
  +#############################################################################
  +# Method: label()
  +#############################################################################
  +
  +=head2 label()
  +
  +    * Signature: $label = $self->label();
  +    * Signature: $label = $self->label($attrib);
  +    * Signature: $label = $self->label($attrib,$lang);
  +    * Param:     $widget_name    string
  +    * Param:     $event          string
  +    * Param:     @args           any
  +    * Return:    $handled        boolean
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    print $w->label();           # "Allez!"  (if current lang is "fr")
  +    print $w->label("name");     # "Jacques" (translation of alternate attribute) 
(if curr lang is "fr")
  +    print $w->label("name","en");# "Jack"    (translation of alternate attribute) 
(override lang is "en")
  +    print $w->label("","en");    # "Go!"     (default label, overridden lang of 
"en")
  +    print $w->label("","en_ca"); # "Go! eh?" (default label, overridden lang of 
"en_ca")
  +
  +=cut
  +
   sub label {
       my ($self, $attrib, $lang) = @_;
       my ($label, $langlabel);
  @@ -421,6 +630,25 @@
       return $langlabel;
   }
   
  +#############################################################################
  +# Method: values_labels()
  +#############################################################################
  +
  +=head2 values_labels()
  +
  +    * Signature: ($values, $labels) = $self->values_labels();
  +    * Param:     void
  +    * Return:    $values       []
  +    * Return:    $labels       {}
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    ($values, $labels) = $gender_widget->values_labels();
  +    # $values = [ "M", "F" ];
  +    # $labels = { "M" => "Male", "F" => "Female" };
  +
  +=cut
  +
   sub values_labels {
       my ($self) = @_;
       my ($domain, $values, $labels);
  @@ -445,10 +673,28 @@
       ($values, $labels);
   }
   
  -# Usage: $labelhashref = $w->labels();
  -#        $labelhashref = $w->labels("names");
  -#        $labelhashref = $w->labels("","en");      # English
  -#        $labelhashref = $w->labels("","en_ca");   # Canadian English
  +#############################################################################
  +# Method: labels()
  +#############################################################################
  +
  +=head2 labels()
  +
  +    * Signature: $labels = $self->labels();
  +    * Signature: $labels = $self->labels($attribute);
  +    * Signature: $labels = $self->labels($attribute,$lang);
  +    * Param:     $attribute      string
  +    * Param:     $lang           string
  +    * Return:    $labels         {}
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    $labels = $w->labels();
  +    $labels = $w->labels("names");
  +    $labels = $w->labels("","en");      # English
  +    $labels = $w->labels("","en_ca");   # Canadian English
  +
  +=cut
  +
   sub labels {
       my ($self, $attrib, $lang) = @_;
       my ($labels, $langlabels, $key);
  @@ -471,9 +717,21 @@
       return $langlabels;
   }
   
  -######################################################################
  -# OUTPUT METHODS
  -######################################################################
  +#############################################################################
  +# Method: dump()
  +#############################################################################
  +
  +=head2 dump()
  +
  +    * Signature: $text = $self->dump();
  +    * Param:     void
  +    * Return:    $text           text
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    $text = $widget->dump();
  +
  +=cut
   
   use Data::Dumper;
   
  @@ -483,6 +741,22 @@
       $d->Indent(1);
       $d->Dump();
   }
  +
  +#############################################################################
  +# Method: print()
  +#############################################################################
  +
  +=head2 print()
  +
  +    * Signature: $self->print();
  +    * Param:     void
  +    * Return:    void
  +    * Throws:    P5EEx::Blue::Exception
  +    * Since:     0.01
  +
  +    $w->print();
  +
  +=cut
   
   sub print {
       my $self = shift;
  
  
  


Reply via email to