4 CXGN::Form.pm -- classes to deal with user-modifiable web forms
12 Lukas Mueller (lam87@cornell.edu)
19 package CXGN
::Insitu
::Form
;
34 my $self = bless {}, $class;
51 my $screen_name = shift;
52 my $field_name = shift;
58 my $field = CXGN
::Insitu
::Field
->new($screen_name, $field_name, $contents, $length, $object, $getter, $setter);
59 $self->add_field_obj($field);
76 if (!exists($self->{fields
})) { $self->{fields
}=(); }
77 push @
{$self->{fields
}}, $field;
108 $self->{action
}=shift;
124 return $self->{action
};
140 return @
{$self->{fields
}};
143 =head2 get_form_start
177 =head2 get_field_hash
191 foreach my $f ($self->get_fields()) {
192 $hash{$f->get_field_name()} = $f->render();
195 $hash{FORM_START
}=$self->get_form_start();
196 $hash{FORM_END
} = $self->get_form_end();
215 foreach my $f ($self->get_fields()) {
216 my $setter = $f->get_setter();
217 $f->get_object()->$setter($$args{$k});
219 $f->get_object->store();
223 package CXGN
::Insitu
::EditableForm
;
225 use base qw
/ CXGN::Insitu::Form /;
229 return $class->SUPER::new
(@_);
234 my $screen_name = shift;
235 my $field_name = shift;
236 my $contents = shift;
241 my $field = CXGN
::Insitu
::EditableField
->new($screen_name, $field_name, $contents, $length, $object, $getter, $setter);
242 if (!exists($self->{fields
})) { $self->{fields
}=(); }
243 push @
{$self->{fields
}}, $field;
253 return "<input type=\"submit\" value=\"Store\" />
254 <input type=\"reset\" value=\"Reset form\" />
266 Lukas Mueller (lam87@cornell.edu)
271 package CXGN
::Insitu
::Field
;
286 my $screen_name = shift;
287 my $field_name = shift;
288 my $contents = shift;
294 my $self = bless {}, $class;
297 print "Setting contents from object to ".$object->$getter."\n";
298 $self->set_contents($object->$getter);
299 $self->set_name($screen_name);
301 $self->set_field_name($field_name);
302 if ($contents) { $self->set_contents($contents); }
303 $self->set_length($length);
321 return $self->{name
};
341 =head2 get_field_name
354 return $self->{field_name
};
358 =head2 set_field_name
371 $self->{field_name
}=shift;
387 return $self->{length};
404 $self->{length}=shift;
420 return $self->{contents
};
437 $self->{contents
}=shift;
453 return $self->{object
};
470 $self->{object
}=shift;
473 =head2 get_object_setter
484 sub get_object_setter
{
486 return $self->{object_setter
};
490 =head2 set_object_setter
501 sub set_object_setter
{
503 $self->{object_setter
}=shift;
506 =head2 get_object_getter
517 sub get_object_getter
{
519 return $self->{object_getter
};
523 =head2 set_object_getter
534 sub set_object_getter
{
536 $self->{object_getter
}=shift;
554 return $self->get_contents()."\n";
559 package CXGN
::Insitu
::EditableField
;
561 use base qw
/ CXGN::Insitu::Field /;
565 return $class->SUPER::new
(@_);
570 return " <input name=\"".$self->get_field_name()."\" value=\"".$self->get_contents()."\" size=\"".$self->get_length()."\" />\n";