Changeset 412
- Timestamp:
- 11/03/08 13:48:21 (3 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
UnitTestContrib/test/unit/FormDefTests.pm (modified) (1 diff)
-
core/lib/TWiki/Form.pm (modified) (4 diffs)
-
core/lib/TWiki/Form/FieldDefinition.pm (modified) (1 diff)
-
core/lib/TWiki/Meta.pm (modified) (1 diff)
-
core/lib/TWiki/UI/Edit.pm (modified) (1 diff)
-
core/lib/TWiki/UI/Save.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/UnitTestContrib/test/unit/FormDefTests.pm
r14 r412 176 176 } 177 177 178 sub test_makeFromMeta { 179 my $this = shift; 180 $this->{twiki}->{store}->saveTopic( 181 $this->{twiki}->{user}, $this->{test_web}, 'SplodgeOne', <<FORM); 182 %META:FORM{name="NonExistantForm"}% 183 %META:FIELD{name="Ecks" attributes="" title="X" value="Blah"}% 184 FORM 185 my ($meta, $text) = 186 $this->{twiki}->{store}->readTopic( 187 undef, $this->{test_web}, 'SplodgeOne'); 188 my $form = new TWiki::Form( 189 $this->{twiki}, $this->{test_web}, 'NonExistantForm', $meta); 190 my $f = $form->getField('Ecks'); 191 $this->assert_str_equals('', $f->getDefaultValue()); 192 $this->assert_str_equals('Ecks', $f->{name}); 193 $this->assert_str_equals('X', $f->{title}); 194 $this->assert_str_equals('', $f->{size}); 195 } 196 178 197 1; -
trunk/core/lib/TWiki/Form.pm
r411 r412 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 -
trunk/core/lib/TWiki/Form/FieldDefinition.pm
r411 r412 36 36 $attrs{attributes} ||= ''; 37 37 $attrs{type} ||= ''; # default 38 $attrs{size} ||= ''; 38 39 $attrs{size} =~ s/^\s*//; 39 40 $attrs{size} =~ s/\s*$//; -
trunk/core/lib/TWiki/Meta.pm
r411 r412 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 } -
trunk/core/lib/TWiki/UI/Edit.pm
r411 r412 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 359 # Update with field values from the query 362 360 $formDef->getFieldValuesFromQuery( $session->{request}, $meta ); 363 361 -
trunk/core/lib/TWiki/UI/Save.pm
r411 r412 237 237 $formDef = new TWiki::Form( $session, $webName, $formName ); 238 238 unless ($formDef) { 239 throw TWiki::OopsException( 240 'attention', 241 def => 'no_form_def', 242 web => $session->{webName}, 243 topic => $session->{topicName}, 244 params => [ $webName, $formName ] 245 ); 239 unless ($prevMeta) { 240 throw TWiki::OopsException( 241 'attention', 242 def => 'no_form_def', 243 web => $session->{webName}, 244 topic => $session->{topicName}, 245 params => [ $webName, $formName ] 246 ); 247 } 248 249 # Recreate the form fields from the previous rev of the topic. 250 $formDef = 251 new TWiki::Form( $session, $webName, $formName, $prevMeta ); 246 252 } 247 253 $newMeta->put( 'FORM', { name => $formName } );
Note: See TracChangeset
for help on using the changeset viewer.
