[Bio] / SubsystemEditor / WebPage / ShowSubsystem.pm Repository:
ViewVC logotype

Diff of /SubsystemEditor/WebPage/ShowSubsystem.pm

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

revision 1.1, Tue Jul 31 21:54:24 2007 UTC revision 1.2, Mon Nov 19 15:51:39 2007 UTC
# Line 12  Line 12 
12    
13  1;  1;
14    
15  ##################################################  ##############################################################
16  # Method for registering components etc. for the #  # Method for registering components etc. for the application #
17  # application                                    #  ##############################################################
 ##################################################  
18  sub init {  sub init {
19    my ( $self ) = @_;    my ( $self ) = @_;
20    
21    $self->application->register_component(  'Table', 'sstable'  );    $self->application->register_component(  'Table', 'sstable'  );
22  }  }
23    
24    #################################
25    # File where Javascript resides #
26    #################################
27    sub require_javascript {
28    
29      return [ './Html/showfunctionalroles.js' ];
30    
31    }
32    
33  ##############################################  ##############################################
34  # Website content is returned by this method #  # Website content is returned by this method #
35  ##############################################  ##############################################
36  sub output {  sub output {
37    my ( $self ) = @_;    my ( $self ) = @_;
38    
39      use Data::Dumper;
40    
41    my $fig = new FIG;    my $fig = new FIG;
42    my $cgi = $self->application->cgi;    my $cgi = $self->application->cgi;
43    
44      # subsystem name and 'nice name' #
45    my $name = $cgi->param( 'subsystem' );    my $name = $cgi->param( 'subsystem' );
46    my $ssname = $name;    my $ssname = $name;
47    $ssname =~ s/\_/ /g;    $ssname =~ s/\_/ /g;
48    
49      # look if someone is logged in and can write the subsystem #
50      my $can_alter = 0;
51      my $user = $self->application->session->user;
52      if ( $user && $user->has_right( $self->application, 'edit', 'subsystem', $name ) ) {
53        $can_alter = 1;
54        $fig->set_user( $user->login );
55      }
56    
57    ######################    ######################
58    # Construct the menu #    # Construct the menu #
59    ######################    ######################
# Line 46  Line 65 
65    $menu->add_category( 'Functional Roles', "SubsysEditor.cgi?page=ShowFunctionalRoles&subsystem=$name" );    $menu->add_category( 'Functional Roles', "SubsysEditor.cgi?page=ShowFunctionalRoles&subsystem=$name" );
66    $menu->add_category( 'Subsystem Diagram', "SubsysEditor.cgi?page=ShowDiagram&subsystem=$name" );    $menu->add_category( 'Subsystem Diagram', "SubsysEditor.cgi?page=ShowDiagram&subsystem=$name" );
67    $menu->add_category( 'Subsystem Spreadsheet', "SubsysEditor.cgi?page=ShowSpreadsheet&subsystem=$name" );    $menu->add_category( 'Subsystem Spreadsheet', "SubsysEditor.cgi?page=ShowSpreadsheet&subsystem=$name" );
68      $menu->add_category( 'Subsystem Check', "SubsysEditor.cgi?page=ShowCheck&subsystem=$name" );
69    $menu->add_category( 'Subsystem Tree', "SubsysEditor.cgi?page=ShowTree&subsystem=$name" );    $menu->add_category( 'Subsystem Tree', "SubsysEditor.cgi?page=ShowTree&subsystem=$name" );
70    
71    
# Line 53  Line 73 
73    # Construct the page content #    # Construct the page content #
74    ##############################    ##############################
75    
76    my $content = "<H2>Subsystem Info</H2>";    my $content = qq~
77    <STYLE>
78    .hideme {
79       display: none;
80    }
81    .showme {
82       display: all;
83    }
84    </STYLE>
85    ~;
86    
87      $content .= "<H2>Subsystem Info</H2>";
88      my $subsystem = new Subsystem( $name, $fig, 0 );
89    
90      if ( defined( $cgi->param( 'SUBMIT' ) ) ) {
91    
92        # set description and notes
93        my $descrp = $cgi->param( 'SSDESC' );
94        chomp $descrp;
95        $descrp .= "\n";
96        $subsystem->set_description( $descrp );
97        my $notes = $cgi->param( 'SSNOTES' );
98        chomp $notes;
99        $notes .= "\n";
100        $subsystem->set_notes( $notes );
101    
102        my $class1 = '';
103        my $class2 = '';
104    
105        if ( defined( $cgi->param( 'Classification' ) ) ) {
106          if ( $cgi->param( 'Classification' ) eq 'User-defined' ) {
107            if ( defined( $cgi->param( "SUBSYSH1TF" ) ) ) {
108              $class1 = $cgi->param( "SUBSYSH1TF" );
109            }
110          }
111          else {
112            if ( defined( $cgi->param( "SUBSYSH1" ) ) ) {
113              $class1 = $cgi->param( "SUBSYSH1" );
114            }
115          }
116        }
117    
118        if ( defined( $cgi->param( 'Classification' ) ) ) {
119          if ( $cgi->param( 'Classification' ) eq 'User-defined' ) {
120            if ( defined( $cgi->param( "SUBSYSH2TF" ) ) ) {
121              $class2 = $cgi->param( "SUBSYSH2TF" );
122            }
123          }
124          else {
125            if ( defined( $cgi->param( "SUBSYSH2" ) ) ) {
126              $class2 = $cgi->param( "SUBSYSH2" );
127            }
128          }
129        }
130        $subsystem->set_classification( [ $class1, $class2 ] );
131    
132        # here we really edit the files in the subsystem directory #
133        $subsystem->incr_version();
134        $subsystem->db_sync();
135        $subsystem->write_subsystem();
136      }
137    
138      $subsystem = new Subsystem( $name, $fig, 0 );
139    
140      $content .= $self->start_form( 'form', { subsystem => $name } );
141    
142    my ( $ssversion, $sscurator, $pedigree, $ssroles ) = $fig->subsystem_info( $name );    my ( $ssversion, $sscurator, $pedigree, $ssroles ) = $fig->subsystem_info( $name );
143    my $mod_time = get_mod_time( $name );    my $mod_time = get_mod_time( $name );
144    my $class = $fig->subsystem_classification( $name );    my $class = $fig->subsystem_classification( $name );
   my $subsystem = new Subsystem( $name, $fig, 0 );  
145    my $ssnotes = $subsystem->get_notes();    my $ssnotes = $subsystem->get_notes();
   my $ssdesc = "";  
146    
147      if ( !defined( $ssnotes ) ) {
148        $ssnotes = '';
149      }
150      my $ssdesc = $subsystem->get_description();
151    
152      if ( !defined( $ssdesc ) ) {
153        $ssdesc = '';
154      }
155    
156      my $classification_stuff;
157      if ( $can_alter ) {
158        $classification_stuff = get_classification_boxes( $fig, $cgi, $class->[0], $class->[1] );
159      }
160      else {
161        $classification_stuff = "<TR><TH>Classification:</TH><TD>$class->[0]</TD></TR>";
162        $classification_stuff .= "<TR><TH></TH><TD>$class->[1]</TD></TR>";
163      }
164    
165    my $infotable = "<TABLE><TR><TH>Name:</TH><TD>$ssname</TD><TR>";    my $infotable = "<TABLE><TR><TH>Name:</TH><TD>$ssname</TD><TR>";
166    $infotable .= "<TR><TH>Author:</TH><TD>$sscurator</TD></TR>";    $infotable .= "<TR><TH>Author:</TH><TD>$sscurator</TD></TR>";
167    $infotable .= "<TR><TH>Version:</TH><TD>$ssversion</TD></TR>";    $infotable .= "<TR><TH>Version:</TH><TD>$ssversion</TD></TR>";
168    $infotable .= "<TR><TH>Last Modified:</TH><TD>$mod_time</TD></TR>";    $infotable .= "<TR><TH>Last Modified:</TH><TD>$mod_time</TD></TR>";
169    $infotable .= "<TR><TH>Classification:</TH><TD>$class->[0]</TD></TR>";    if ( $can_alter ) {
   $infotable .= "<TR><TH></TH><TD>$class->[1]</TD></TR>";  
170    $infotable .= "<TR><TH>Description</TH><TD><TEXTAREA NAME='SSDESC' ROWS=6 STYLE='width: 772px;'>$ssdesc</TEXTAREA></TD></TR>";    $infotable .= "<TR><TH>Description</TH><TD><TEXTAREA NAME='SSDESC' ROWS=6 STYLE='width: 772px;'>$ssdesc</TEXTAREA></TD></TR>";
171    $infotable .= "<TR><TH>Notes</TH><TD><TEXTAREA NAME='SSNOTES' ROWS=6 STYLE='width: 772px;'>$ssnotes</TEXTAREA></TD></TR>";    $infotable .= "<TR><TH>Notes</TH><TD><TEXTAREA NAME='SSNOTES' ROWS=6 STYLE='width: 772px;'>$ssnotes</TEXTAREA></TD></TR>";
172      }
173      else {
174        # do a little formating because the notes often contain many many blanks and newlines
175        my $ssdesc_brs = $ssdesc;
176        $ssdesc_brs =~ s/\n/<BR>/g;
177        $ssdesc_brs =~ s/(\n\s)+/\n/g;
178        my $ssnotes_brs = $ssnotes;
179        $ssnotes_brs =~ s/(\n\s)+/\n/g;
180        $ssnotes_brs =~ s/\n/<BR>/g;
181        $infotable .= "<TR><TH>Description</TH><TD>$ssdesc_brs</TD></TR>";
182        $infotable .= "<TR><TH>Notes</TH><TD>$ssnotes_brs</TD></TR>";
183      }
184      $infotable .= $classification_stuff;
185    $infotable .= "</TABLE>";    $infotable .= "</TABLE>";
186    
187      if ( $can_alter ) {
188        $infotable .= "<INPUT TYPE=SUBMIT VALUE='Save Changes' ID='SUBMIT' NAME='SUBMIT'>";
189      }
190    
191    $content .= $infotable;    $content .= $infotable;
192      $content .= $self->end_form();
193    
194    return $content;    return $content;
195  }  }
# Line 99  Line 215 
215    }    }
216        return "$FIG_Config::data/Subsystems/$ssa/Backup";        return "$FIG_Config::data/Subsystems/$ssa/Backup";
217  }  }
218    
219    
220    sub get_classification_boxes {
221      my ( $fig, $cgi, $class1, $class2 ) = @_;
222      my $classified = 1;
223    
224      my $sdContent = '';
225      my $SUBSYSH1 = $class1;
226      my $SUBSYSH2 = $class2;
227    
228      # variables that monitor if we have selected a box
229      my $putinh1 = 0;
230      my $putinh2 = 0;
231    
232      if ( !defined( $SUBSYSH1 ) ){
233        $putinh1 = 1;
234      }
235      if ( !defined( $SUBSYSH2 ) ){
236        $putinh2 = 1;
237      }
238    
239      my $inh1 = '';
240      if ( defined( $cgi->param( 'SUBSYSH1TF' ) ) ) {
241        $inh1 = $cgi->param( 'SUBSYSH1TF' );
242      }
243      elsif ( defined( $SUBSYSH1 ) ) {
244        if ( !$putinh1 ) {
245          $inh1 = $SUBSYSH1;
246        }
247      }
248      my $inh2 = '';
249      if ( defined( $cgi->param( 'SUBSYSH2TF' ) ) ) {
250        $inh2 = $cgi->param( 'SUBSYSH2TF' );
251      }
252      elsif ( defined( $SUBSYSH2 ) ) {
253        if ( !$putinh2 ) {
254          $inh2 = $SUBSYSH2;
255        }
256      }
257    
258      my @ssclassifications = $fig->all_subsystem_classifications();
259      my $ssclass;
260      foreach my $ssc ( @ssclassifications ) {
261        next if ( ( !defined( $ssc->[0] ) ) || ( !defined( $ssc->[1] ) ) );
262        next if ( ( $ssc->[0] eq '' ) || ( $ssc->[1] eq '' ) );
263        next if ( ( $ssc->[0] =~ /^\s+$/ ) || ( $ssc->[1] =~ /^\s+$/ ) );
264        push @{ $ssclass->{ $ssc->[0] } }, $ssc->[1];
265      }
266    
267    
268      my @options;
269      foreach my $firstc ( keys %$ssclass ) {
270        my $opt = "<SELECT SIZE=5 ID='$firstc' NAME='SUBSYSH2' STYLE='width: 386px;' class='hideme'>";
271        my $optstring = '';
272        foreach my $secc ( sort @{ $ssclass->{ $firstc } } ) {
273          if ( defined( $SUBSYSH2 ) && $SUBSYSH2 eq $secc ) {
274            $optstring .= "<OPTION SELECTED VALUE='$secc'>$secc</OPTION>";
275            # we have to show the selectbox if there is a selected value
276            $opt = "<SELECT SIZE=5 ID='$firstc' NAME='SUBSYSH2' STYLE='width: 386px;' class='showme'>";
277            $putinh2 = 1;
278          }
279          else {
280            $optstring .= "<OPTION VALUE='$secc'>$secc</OPTION>";
281          }
282        }
283        $opt .= $optstring;
284        $opt .= "</SELECT>";
285        push @options, $opt;
286      }
287    
288      if ( $classified ) {
289        $sdContent .= "<TR><TH><INPUT TYPE=\"RADIO\" NAME=\"Classification\" VALUE=\"Classified\" CHECKED onchange='radioclassification();'>Classification:</TH><TD><SELECT SIZE=5 ID='SUBSYSH1' NAME='SUBSYSH1' STYLE='width: 386px;' onclick='gethiddenoption();'>";
290      }
291      else {
292        $sdContent .= "<TR><TD><INPUT TYPE=\"RADIO\" NAME=\"Classification\" VALUE=\"Classified\" onchange='radioclassification();'>Classification:</TD><TD><SELECT SIZE=5 ID='SUBSYSH1' NAME='SUBSYSH1' STYLE='width: 386px;' onclick='gethiddenoption();' DISABLED=DISABLED>";
293      }
294      foreach my $firstc ( sort keys %$ssclass ) {
295        if ( defined( $SUBSYSH1 ) && $SUBSYSH1 eq $firstc ) {
296          $sdContent .= "\n<OPTION SELECTED VALUE='$firstc'>$firstc</OPTION>\n";
297          $putinh1 = 1;
298        }
299        else {
300          $sdContent .= "\n<OPTION VALUE='$firstc'>$firstc</OPTION>\n";
301        }
302      }
303      $sdContent .= "</SELECT>";
304    
305      foreach my $opt ( @options ) {
306        $sdContent .= $opt;
307      }
308    
309      $sdContent .= "</TD></TR>";
310      if ( $classified ) {
311        $sdContent .= "<TR><TH><INPUT TYPE=\"RADIO\" NAME=\"Classification\" VALUE=\"User-defined\" onchange='radioclassification();'>User-defined:</TH><TD><INPUT TYPE=TEXT  STYLE='width: 386px;' NAME='SUBSYSH1TF' ID='SUBSYSH1TF' VALUE='' DISABLED=\"DISABLED\"><INPUT TYPE=TEXT  STYLE='width: 386px;' NAME='SUBSYSH2TF' ID='SUBSYSH2TF' VALUE='' DISABLED=DISABLED></TD></TR>";
312      }
313      else {
314        $sdContent .= "<TR><TH><INPUT TYPE=\"RADIO\" NAME=\"Classification\" VALUE=\"User-defined\" CHECKED onchange='radioclassification();'>User-defined:</TH><TD><INPUT TYPE=TEXT  STYLE='width: 386px;' NAME='SUBSYSH1TF' ID='SUBSYSH1TF' VALUE='$inh1'><INPUT TYPE=TEXT  STYLE='width: 386px;' NAME='SUBSYSH2TF' ID='SUBSYSH2TF' VALUE='$inh2'></TD></TR>";
315      }
316    
317    
318      return $sdContent;
319    }
320    
321    sub supported_rights {
322    
323      return [ [ 'edit', 'subsystem', '*' ] ];
324    
325    }
326    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3