*** TablePlugin.pm.orig Mon Dec 1 23:29:38 2003 --- TablePlugin.pm Sat Jan 3 20:34:46 2004 *************** *** 247,252 **** --- 247,286 ---- $tmp = TWiki::Func::extractNameValuePair( $args, "datacolor" ); @dataColor = split( /,\s*/, $tmp ) if( $tmp ); + # + # START -- Table Entry Code Built into TablePlugin.pm library + # + + #Added template name that defines the template format you want to use + my $template = ""; + $tmp = &TWiki::Func::extractNameValuePair ( $args, "template" ); + $template = $tmp if ( $tmp ); + + #Added table name that defines the table name and META tags to look for + my $tableName = ""; + $tmp = &TWiki::Func::extractNameValuePair ( $args, "tablename" ); + $tableName = $tmp if ( $tmp ); + + #Added topic to the list of parameters since this information is lost + #inside the plugin + my $tableTopic = ""; + $tmp = &TWiki::Func::extractNameValuePair ( $args, "topic" ); + $tableTopic = $tmp if ( $tmp ); + + #Added action to tell the table plugin special operations + my $action = ""; + $tmp = &TWiki::Func::extractNameValuePair ( $args, "action" ); + $action = $tmp if ( $tmp ); + + if (($template ne "") && ($tableName ne "")) { + return &tableTemplateHeader($template, $tableName, $tableTopic, $action); + } + + # + # END -- Table Entry Code Built into TablePlugin.pm library + # + + return "$currTablePre"; } *************** *** 613,617 **** --- 647,799 ---- return $text; } + # + # START -- Table Entry Code Built into TablePlugin.pm library + # + + # ========================= + # Added sub-routines to support in-line table editing functionality. Current + # implementation uses the $meta variables to store the elements. + # + # --Date-- ----Who------ -----------Comment------------------------ + # 20020506 ShawnBradford Initial Design + # ========================= + sub tableTemplateHeader + { + + my ( $template, $tableName, $tableTopic, $action ) = @_; + my $header = ""; + + my $cgi = &TWiki::Func::getCgiQuery(); + $sortCol = $cgi->param( 'sortcol' ); + + # Need to read the verification template and generate a header + my $webName = &TWiki::handleCommonTags( "%WEB%" ); + + if ( $action eq "on" ) { + $header .= "{ Add }\n"; + } + $header .= " Table Name: $tableName"; + $header .= " | Template: $webName . $template
\n"; + + my @fieldDefs = &TWiki::Form::getFormDef( $webName, $template ); + if( ! @fieldDefs ) { + return "No Table template found: $webName . $template"; + } + else { + my $tableHeader .= renderForDisplay( @fieldDefs ); + $tableHeader =~ s/^(\s*)\|(.*)/&processTR($1,$2)/eo; + $insideTABLE = 1; + # Need to reed the META entries and look for TABLE entries + my( $meta, $text ) = &TWiki::Store::readTopic( $webName, $tableTopic ); + my @tables = $meta->find( "TABLE" ); + foreach my $table ( @tables ) { + if ($table->{"tablename"} eq $tableName) { + my $tableEntry .= renderEntryForDisplay( $table, $tableTopic, $template, $tableName, @fieldDefs ); + $tableEntry =~ s/^(\s*)\|(.*)/&processTR($1,$2)/eo; + } + } + } + + return &TWiki::handleCommonTags( $header ); + + } + + sub renderForDisplay + { + + my ( @fieldDefs ) = @_; + my $tableHeader = "| "; + + # Get each field definition + # | *Name:* | *Type:* | *Size:* | *Value:* | *Tooltip message:* | + foreach my $fieldDefP ( @fieldDefs ) { + my @fieldDef = @$fieldDefP; + my( $name, $title, $type, $size, $posValuesS, $tooltip ) = @fieldDef; + $tableHeader .= "*$title* | "; + } + + return $tableHeader; + + } + + sub renderEntryForDisplay + { + + my ( $table, $tableTopic, $template, $tableName, @fieldDefs ) = @_; + my $tableEntry = "| "; + my $count = 0; + + # Get each field definition + # | *Name:* | *Type:* | *Size:* | *Value:* | *Tooltip message:* | + foreach my $fieldDefP ( @fieldDefs ) { + my @fieldDef = @$fieldDefP; + my $entryName = shift @fieldDef; + my $value = $table->{$entryName}; + if ($count==0) { + my $name = stringConvert($table->{"name"}); + $tableEntry .= "$value | "; + } else { + $tableEntry .= "$value | "; + } + $count = $count + 1; + } + + return &TWiki::handleCommonTags($tableEntry); + + } + # ========================= + # Add/update Table entries for a topic + # $text is full set of attachments, new attachments will be added to the end. + sub updateTable + { + + my ( $meta, $template, $tableName, @fieldElements ) = @_; + my @args = formTableEntry ( $template, $tableName ); + push @args, @fieldElements; + $meta->put ( "TABLE", @args ); + + } + + sub formTableEntry + { + my ( $template, $tableName ) = @_; + + my @args = ( + "tablename" => $tableName, + "template" => $template ); + + return @args; + + } + + sub carriageReturnConvert + { + my ( $string ) = @_; + + if ( $string =~ /\/ ) { + $string =~ s/\/\n/g; #Converts all '\n' characters to '
' characters + } else { + $string =~ s/\n/\/g; #Converts all '\n' characters to '
' characters + $string =~ s/\r//g; #Converts all '\n' characters to '
' characters + } + + return ( $string ); + } + + sub stringConvert + { + my ( $string ) = @_; + + # $string =~ s/\+/\._./g; #Converts all '+' characters to '._.' characters + $string =~ s/\ /+/g; #Uses '+' character to denote spaces + + return ( $string ); + } + + # + # END -- Table Entry Code Built into TablePlugin.pm library + # + 1;