added an accessor for db backend information
[cxgn-corelibs.git] / lib / CXGN / Insitu / Form.pm
blob8ea0bf747ad1c369451b3c5281bab6de854f9da3
2 =head1 NAME
4 CXGN::Form.pm -- classes to deal with user-modifiable web forms
6 =head1 DESCRIPTION
8 The classes F
10 =head1 AUTHOR(S)
12 Lukas Mueller (lam87@cornell.edu)
14 =cut
17 use strict;
19 package CXGN::Insitu::Form;
21 =head2 new
23 Usage:
24 Desc:
25 Ret:
26 Args:
27 Side Effects:
28 Example:
30 =cut
32 sub new {
33 my $class = shift;
34 my $self = bless {}, $class;
35 return $self;
38 =head2 add_field
40 Usage:
41 Desc:
42 Ret:
43 Args:
44 Side Effects:
45 Example:
47 =cut
49 sub add_field {
50 my $self = shift;
51 my $screen_name = shift;
52 my $field_name = shift;
53 my $contents = shift;
54 my $length = shift;
55 my $object = shift;
56 my $getter = shift;
57 my $setter = shift;
58 my $field = CXGN::Insitu::Field->new($screen_name, $field_name, $contents, $length, $object, $getter, $setter);
59 $self->add_field_obj($field);
62 =head2 add_field_obj
64 Usage:
65 Desc:
66 Ret:
67 Args:
68 Side Effects:
69 Example:
71 =cut
73 sub add_field_obj {
74 my $self = shift;
75 my $field = shift;
76 if (!exists($self->{fields})) { $self->{fields}=(); }
77 push @{$self->{fields}}, $field;
80 =head2 add_selection
82 Usage:
83 Desc:
84 Ret:
85 Args:
86 Side Effects:
87 Example:
89 =cut
91 sub add_selection {
92 my $self = shift;
95 =head2 set_action
97 Usage:
98 Desc:
99 Ret:
100 Args:
101 Side Effects:
102 Example:
104 =cut
106 sub set_action {
107 my $self = shift;
108 $self->{action}=shift;
111 =head2 get_action
113 Usage:
114 Desc:
115 Ret:
116 Args:
117 Side Effects:
118 Example:
120 =cut
122 sub get_action {
123 my $self = shift;
124 return $self->{action};
127 =head2 get_fields
129 Usage:
130 Desc:
131 Ret:
132 Args:
133 Side Effects:
134 Example:
136 =cut
138 sub get_fields {
139 my $self = shift;
140 return @{$self->{fields}};
143 =head2 get_form_start
145 Usage:
146 Desc:
147 Ret:
148 Args:
149 Side Effects:
150 Example:
152 =cut
155 sub get_form_start {
156 my $self = shift;
157 return "";
160 =head2 get_form_end
162 Usage:
163 Desc:
164 Ret:
165 Args:
166 Side Effects:
167 Example:
169 =cut
172 sub get_form_end {
173 my $self = shift;
174 return "";
177 =head2 get_field_hash
179 Usage:
180 Desc:
181 Ret:
182 Args:
183 Side Effects:
184 Example:
186 =cut
188 sub get_field_hash {
189 my $self = shift;
190 my %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();
198 return %hash;
201 =head2 store
203 Usage:
204 Desc:
205 Ret:
206 Args:
207 Side Effects:
208 Example:
210 =cut
212 sub store {
213 my $self = shift;
214 my $args = shift;
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 /;
227 sub new {
228 my $class = shift;
229 return $class->SUPER::new(@_);
232 sub add_field {
233 my $self = shift;
234 my $screen_name = shift;
235 my $field_name = shift;
236 my $contents = shift;
237 my $length = shift;
238 my $object = shift;
239 my $getter = shift;
240 my $setter = 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;
246 sub get_form_start {
247 my $self = shift;
248 return "<form>";
251 sub get_form_end {
252 my $self = shift;
253 return "<input type=\"submit\" value=\"Store\" />
254 <input type=\"reset\" value=\"Reset form\" />
255 </form>";
258 =head1 NAME
260 CXGN::Insitu::Field
262 =head1 DESCRIPTION
264 =head1 AUTHOR(S)
266 Lukas Mueller (lam87@cornell.edu)
268 =cut
271 package CXGN::Insitu::Field;
273 =head2 new
275 Usage:
276 Desc:
277 Ret:
278 Args:
279 Side Effects:
280 Example:
282 =cut
284 sub new {
285 my $class = shift;
286 my $screen_name = shift;
287 my $field_name = shift;
288 my $contents = shift;
289 my $length = shift;
290 my $object = shift;
291 my $getter = shift;
292 my $setter = shift;
294 my $self = bless {}, $class;
295 print "HELLO!\n";
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);
305 return $self;
308 =head2 get_name
310 Usage:
311 Desc:
312 Ret:
313 Args:
314 Side Effects:
315 Example:
317 =cut
319 sub get_name {
320 my $self=shift;
321 return $self->{name};
325 =head2 set_name
327 Usage:
328 Desc:
329 Ret:
330 Args:
331 Side Effects:
332 Example:
334 =cut
336 sub set_name {
337 my $self=shift;
338 $self->{name}=shift;
341 =head2 get_field_name
343 Usage:
344 Desc:
345 Ret:
346 Args:
347 Side Effects:
348 Example:
350 =cut
352 sub get_field_name {
353 my $self=shift;
354 return $self->{field_name};
358 =head2 set_field_name
360 Usage:
361 Desc:
362 Ret:
363 Args:
364 Side Effects:
365 Example:
367 =cut
369 sub set_field_name {
370 my $self=shift;
371 $self->{field_name}=shift;
374 =head2 get_length
376 Usage:
377 Desc:
378 Ret:
379 Args:
380 Side Effects:
381 Example:
383 =cut
385 sub get_length {
386 my $self=shift;
387 return $self->{length};
391 =head2 set_length
393 Usage:
394 Desc:
395 Ret:
396 Args:
397 Side Effects:
398 Example:
400 =cut
402 sub set_length {
403 my $self=shift;
404 $self->{length}=shift;
407 =head2 get_contents
409 Usage:
410 Desc:
411 Ret:
412 Args:
413 Side Effects:
414 Example:
416 =cut
418 sub get_contents {
419 my $self=shift;
420 return $self->{contents};
424 =head2 set_contents
426 Usage:
427 Desc:
428 Ret:
429 Args:
430 Side Effects:
431 Example:
433 =cut
435 sub set_contents {
436 my $self=shift;
437 $self->{contents}=shift;
440 =head2 get_object
442 Usage:
443 Desc:
444 Ret:
445 Args:
446 Side Effects:
447 Example:
449 =cut
451 sub get_object {
452 my $self=shift;
453 return $self->{object};
457 =head2 set_object
459 Usage:
460 Desc:
461 Ret:
462 Args:
463 Side Effects:
464 Example:
466 =cut
468 sub set_object {
469 my $self=shift;
470 $self->{object}=shift;
473 =head2 get_object_setter
475 Usage:
476 Desc:
477 Ret:
478 Args:
479 Side Effects:
480 Example:
482 =cut
484 sub get_object_setter {
485 my $self=shift;
486 return $self->{object_setter};
490 =head2 set_object_setter
492 Usage:
493 Desc:
494 Ret:
495 Args:
496 Side Effects:
497 Example:
499 =cut
501 sub set_object_setter {
502 my $self=shift;
503 $self->{object_setter}=shift;
506 =head2 get_object_getter
508 Usage:
509 Desc:
510 Ret:
511 Args:
512 Side Effects:
513 Example:
515 =cut
517 sub get_object_getter {
518 my $self=shift;
519 return $self->{object_getter};
523 =head2 set_object_getter
525 Usage:
526 Desc:
527 Ret:
528 Args:
529 Side Effects:
530 Example:
532 =cut
534 sub set_object_getter {
535 my $self=shift;
536 $self->{object_getter}=shift;
541 =head2 render
543 Usage:
544 Desc:
545 Ret:
546 Args:
547 Side Effects:
548 Example:
550 =cut
552 sub render {
553 my $self = shift;
554 return $self->get_contents()."\n";
559 package CXGN::Insitu::EditableField;
561 use base qw / CXGN::Insitu::Field /;
563 sub new {
564 my $class = shift;
565 return $class->SUPER::new(@_);
568 sub render {
569 my $self = shift;
570 return " <input name=\"".$self->get_field_name()."\" value=\"".$self->get_contents()."\" size=\"".$self->get_length()."\" />\n";
575 return 1;