[Bio] / FigWebServices / protein.cgi Repository:
ViewVC logotype

Diff of /FigWebServices/protein.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.93, Thu Mar 3 23:54:03 2005 UTC revision 1.94, Fri Mar 4 18:29:21 2005 UTC
# Line 1  Line 1 
1    # -*- perl -*-
2  use FIG;  use FIG;
3    
4  my $sproutAvail = eval {  my $sproutAvail = eval {
# Line 594  Line 594 
594  sub print_kv_pairs {  sub print_kv_pairs {
595      my($fig_or_sprout,$cgi,$html,$peg) = @_;      my($fig_or_sprout,$cgi,$html,$peg) = @_;
596    
597        # RAE: modified this to allow the users to edit the key/value pairs.
598        # there will be two choices: when the "Edit Attributes" button is pressed
599        # we will redraw the table with input fields and what not.
600    
601        # If the Add Changes button is pressed we will save the changes
602        # we will do this first before displaying the results
603    
604        my @attr = &feature_attributes($fig_or_sprout,$peg);
605        my $prot=$cgi->param('prot');
606    print STDERR "PROTEIN IS $prot\n";
607        if ($cgi->param('Add Changes')) {
608          my ($deleted, $added, $changed)=(undef, undef, undef);
609    
610          foreach my $key (@attr) {
611             unless ($cgi->param("key.".$key->[0])) {
612                $fig_or_sprout->delete_attribute($prot, $key->[0]);
613                push @$deleted, [@$key, ["deleted", "td colspan=2 style=\"text-align: center\""]];
614             }
615             if (($cgi->param("value.".$key->[0]) ne $key->[1]) || ($cgi->param("url.".$key->[0]) ne $key->[2])) {
616                $fig_or_sprout->change_attribute($prot, $key->[0], $cgi->param("value.".$key->[0]), $cgi->param("url.".$key->[0]));
617                push @$changed, [@$key, $cgi->param("value.".$key->[0]), $cgi->param("url.".$key->[0])];
618             }
619          }
620          for (my $i=0; $i<=5; $i++) {
621             if ($cgi->param("key.$i")) {
622                $fig_or_sprout->add_attribute($prot, $cgi->param("key.$i"), $cgi->param("value.$i"), $cgi->param("url.$i"));
623                push @$added, [$cgi->param("key.$i"), ["added", "td colspan=2 style=\"text-align: center\""], $cgi->param("value.$i"), $cgi->param("url.$i")];
624             }
625          }
626    
627          my $tab = [];
628          my $col_hdrs=["Attribute", "Original Value", "Original URL", "New Value", "New URL"];
629          if ($changed) {push @$tab, [["<strong>Changed Attributes", "td colspan=5 bgcolor=gray style=\"text-align: center\""]], @$changed}
630          if ($deleted) {push @$tab, [["<strong>Deleted Attributes", "td colspan=5 bgcolor=gray style=\"text-align: center\""]], @$deleted}
631          if ($added)   {push @$tab, [["<strong>Added Attributes",   "td colspan=5 bgcolor=gray style=\"text-align: center\""]], @$added}
632    
633          push(@$html,&HTML::make_table($col_hdrs,$tab,"Changed Data"));
634        }
635    
636      my @attr = &feature_attributes($fig_or_sprout,$peg);      my @attr = &feature_attributes($fig_or_sprout,$peg);
637        my $col_hdrs=["Key","Value"];
638    
639      if (@attr > 0) {      if (@attr > 0) {
640          my $tab = [];          my $tab = [];
641          foreach $_ (@attr) {          if ($cgi->param('Edit Attributes') && $cgi->param('user')) {
642               push @$col_hdrs, "URL";
643               foreach my $key (sort {$a->[0] cmp $b->[0]} @attr) {
644                  push @$tab,
645                    [
646                      $cgi->textfield(-name=>"key.".$key->[0], -default=>$key->[0], -size=>30),
647                      $cgi->textfield(-name=>"value.".$key->[0], -default=>$key->[1], -size=>30),
648                      $cgi->textfield(-name=>"url.".$key->[0], -default=>$key->[2], -size=>30),
649                    ];
650               }
651               for (my $i=0; $i<=5; $i++) {
652                  push @$tab,
653                    [
654                      $cgi->textfield(-name=>"key.$i", -size=>30),
655                      $cgi->textfield(-name=>"value.$i", -size=>30),
656                      $cgi->textfield(-name=>"url.$i", -size=>30),
657                    ];
658               }
659            }
660            else {
661               foreach $_ (sort {$a->[0] cmp $b->[0]} @attr) {
662              my($tag,$val,$url) = @$_;              my($tag,$val,$url) = @$_;
663              next unless ($url =~ /^http/);              next unless ($url =~ /^http/);
664              push(@$tab,[$tag,$url ? "<a href=\"$url\">$val</a>" : $val]);              push(@$tab,[$tag,$url ? "<a href=\"$url\">$val</a>" : $val]);
665          }          }
666          push(@$html,$cgi->br,$cgi->hr,&HTML::make_table(["Key","Value"],[sort { $a->[0] cmp $b->[0] } @$tab],"Attributes"),$cgi->hr);          }
667    
668            # Add the appropriate submit button to the table
669            if ($cgi->param('user') && $cgi->param('Edit Attributes')) {
670               # we want a Add button
671               push @$tab, [[$cgi->submit('Add Changes'), "td colspan=3 style=\"text-align: center\""]];
672            }
673            elsif ($cgi->param('user')) {
674               push @$tab, [[$cgi->submit('Edit Attributes'), "td colspan=2 style=\"text-align: center\""]];
675            }
676            push(@$html,$cgi->start_form(-action=>"protein.cgi"), $cgi->hidden("prot"), $cgi->hidden("user"));
677            push(@$html,$cgi->br,$cgi->hr,&HTML::make_table($col_hdrs, $tab,"Attributes"),$cgi->hr);
678      }      }
679  }  }
680    

Legend:
Removed from v.1.93  
changed lines
  Added in v.1.94

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3