Changeset 413
- Timestamp:
- 11/03/08 13:48:54 (3 years ago)
- Location:
- branches/Release04x02
- Files:
-
- 6 edited
-
lib/TWiki/Form.pm (modified) (4 diffs)
-
lib/TWiki/Form/FieldDefinition.pm (modified) (1 diff)
-
lib/TWiki/Meta.pm (modified) (1 diff)
-
lib/TWiki/UI/Edit.pm (modified) (1 diff)
-
lib/TWiki/UI/Save.pm (modified) (1 diff)
-
twikiplugins/UnitTestContrib/test/unit/FormDefTests.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/Release04x02/lib/TWiki/Form.pm
r21 r413 44 44 =pod 45 45 46 ---++ ClassMethod new ( $session, $web, $form, $def )46 ---++ ClassMethod new ( $session, $web, $form, \@def ) 47 47 48 48 Looks up a form in the session object or, if it hasn't been read yet, 49 49 reads it frm the form definition topic on disc. 50 * $web - default web to recover form from, if $form doesn't specify a web 51 * =$form= - topic name to read form definition from 52 * =$def= - optional. a reference to a list of field definitions. if present, 53 these definitions will be used, rather than those in =$form=. 50 * =$web= - default web to recover form from, if =$form= doesn't 51 specify a web 52 * =$form= - name of the form 53 * =\@def= - optional. A reference to a list of field definitions. 54 If present, these definitions will be used, rather than any read from 55 the form definition topic. Note that this array should not be modified 56 again after being passed into this constructor (it is not copied). 54 57 55 58 May throw TWiki::OopsException … … 81 84 82 85 # Read topic that defines the form 83 unless ( $store->topicExists( $web, $form ) ) { 86 if ( $store->topicExists( $web, $form ) ) { 87 my ( $meta, $text ) = 88 $store->readTopic( $session->{user}, $web, $form, undef ); 89 90 $this->{fields} = _parseFormDefinition( $this, $meta, $text ); 91 } 92 else { 93 delete $session->{forms}->{"$web.$form"}; 84 94 return undef; 85 95 } 86 my ( $meta, $text ) = 87 $store->readTopic( $session->{user}, $web, $form, undef ); 88 89 $this->{fields} = _parseFormDefinition( $this, $meta, $text ); 90 96 } 97 elsif ( ref($def) eq 'ARRAY' ) { 98 $this->{fields} = $def; 91 99 } 92 100 else { 93 101 94 $this->{fields} = $def;95 102 # TWiki::Meta object 103 $this->{fields} = $this->_extractPseudoFieldDefs($def); 96 104 } 97 105 } … … 182 190 $vals =~ s/^\s+//g; 183 191 $vals =~ s/\s+$//g; 184 185 # SMELL: This expansion of $users is undocumented, AFAICT not186 # used, and downright *dangerous* (it won't work with a non-TWiki187 # user mapping for example) so in the interests of good hygiene,188 # I have removed it (CC, 30 Jun 07).189 #if( $vals eq '$users' ) {190 # $vals = $TWiki::cfg{UsersWebName} . '.' .191 # join( ", ${TWiki::cfg{UsersWebName}}.",192 # ( $store->getTopicNames( $TWiki::cfg{UsersWebName} )));193 #}194 192 195 193 $tooltip ||= ''; … … 566 564 } 567 565 566 # extractPseudoFieldDefs( $meta ) -> $fieldDefs 567 # Examine the FIELDs in $meta and reverse-engineer a set of field 568 # definitions that can be used to construct a new "pseudo-form". This 569 # fake form can be used to support editing of topics that have an attached 570 # form that has no definition topic. 571 sub _extractPseudoFieldDefs { 572 my ( $this, $meta ) = @_; 573 my @fields = $meta->find('FIELD'); 574 my @fieldDefs; 575 require TWiki::Form::FieldDefinition; 576 foreach my $field (@fields) { 577 578 # Fields are name, value, title, but there is no other type 579 # information so we have to treat them all as "text" :-( 580 my $fieldDef = new TWiki::Form::FieldDefinition( 581 session => $this->{session}, 582 name => $field->{name}, 583 title => $field->{title} || $field->{name}, 584 attributes => $field->{attributes} || '' 585 ); 586 push( @fieldDefs, $fieldDef ); 587 } 588 return \@fieldDefs; 589 } 590 568 591 1; 569 592 -
branches/Release04x02/lib/TWiki/Form/FieldDefinition.pm
r21 r413 36 36 $attrs{attributes} ||= ''; 37 37 $attrs{type} ||= ''; # default 38 $attrs{size} ||= ''; 38 39 $attrs{size} =~ s/^\s*//; 39 40 $attrs{size} =~ s/\s*$//; -
branches/Release04x02/lib/TWiki/Meta.pm
r21 r413 628 628 } 629 629 else { 630 return CGI::span( { class => 'twikiAlert' }, 631 "Form definition '$fname' not found" ); 630 631 # Make pseudo-form from field data 632 $form = 633 new TWiki::Form( $this->{_session}, $this->{_web}, $fname, $this ); 634 return CGI::span( 635 { class => 'twikiAlert' }, 636 "%MAKETEXT{\"Form definition '[_1]' not found\" args=\"$fname\"}%" 637 ) . $form->renderForDisplay($this); 632 638 } 633 639 } -
branches/Release04x02/lib/TWiki/UI/Edit.pm
r21 r413 351 351 require TWiki::Form; 352 352 my $formDef = new TWiki::Form( $session, $templateWeb, $form ); 353 unless ($formDef) { 354 throw TWiki::OopsException( 355 'attention', 356 def => 'no_form_def', 357 web => $session->{webName}, 358 topic => $session->{topicName}, 359 params => [ $templateWeb, $form ] 360 ); 361 } 353 if ( !$formDef ) { 354 355 # Reverse-engineer a form definition from the meta-data. 356 $formDef = new TWiki::Form( $session, $templateWeb, $form, $meta ); 357 } 358 # Update with field values from the query 359 362 360 $formDef->getFieldValuesFromQuery( $session->{cgiQuery}, $meta ); 363 361 -
branches/Release04x02/lib/TWiki/UI/Save.pm
r21 r413 226 226 $formDef = new TWiki::Form( $session, $webName, $formName ); 227 227 unless ($formDef) { 228 throw TWiki::OopsException( 229 'attention', 230 def => 'no_form_def', 231 web => $session->{webName}, 232 topic => $session->{topicName}, 233 params => [ $webName, $formName ] 234 ); 228 unless ($prevMeta) { 229 throw TWiki::OopsException( 230 'attention', 231 def => 'no_form_def', 232 web => $session->{webName}, 233 topic => $session->{topicName}, 234 params => [ $webName, $formName ] 235 ); 236 } 237 238 # Recreate the form fields from the previous rev of the topic. 239 $formDef = 240 new TWiki::Form( $session, $webName, $formName, $prevMeta ); 235 241 } 236 242 $newMeta->put( 'FORM', { name => $formName } ); -
branches/Release04x02/twikiplugins/UnitTestContrib/test/unit/FormDefTests.pm
r21 r413 179 179 } 180 180 181 sub test_makeFromMeta { 182 my $this = shift; 183 $this->{twiki}->{store}->saveTopic( 184 $this->{twiki}->{user}, $this->{test_web}, 'SplodgeOne', <<FORM); 185 %META:FORM{name="NonExistantForm"}% 186 %META:FIELD{name="Ecks" attributes="" title="X" value="Blah"}% 187 FORM 188 my ($meta, $text) = 189 $this->{twiki}->{store}->readTopic( 190 undef, $this->{test_web}, 'SplodgeOne'); 191 my $form = new TWiki::Form( 192 $this->{twiki}, $this->{test_web}, 'NonExistantForm', $meta); 193 my $f = $form->getField('Ecks'); 194 $this->assert_str_equals('', $f->getDefaultValue()); 195 $this->assert_str_equals('Ecks', $f->{name}); 196 $this->assert_str_equals('X', $f->{title}); 197 $this->assert_str_equals('', $f->{size}); 198 } 199 181 200 1;
Note: See TracChangeset
for help on using the changeset viewer.
