search stocks by location
[sgn.git] / cgi-bin / insitu / detail / experiment.pl
blob681b5f4ed7634b5833fda397b952d7feba25e73e
2 use strict;
4 my $experiment_detail_page = CXGN::Insitu::Experiment_detail_page->new('insitu');
6 package CXGN::Insitu::Experiment_detail_page;
8 use CXGN::Insitu::Experiment;
9 use CXGN::Insitu::Organism;
10 use CXGN::Insitu::Toolbar;
11 use SGN::Image;
12 use CXGN::Tag;
13 use CXGN::Page::FormattingHelpers qw / blue_section_html page_title_html /;
14 use CXGN::People::Person;
16 use CatalystX::GlobalContext '$c';
18 use base qw / CXGN::Page::Form::SimpleFormPage /;
20 sub new {
21 my $class = shift;
22 my $self = $class->SUPER::new(@_);
23 #$self->set_script_name("experiment.pl");
25 return $self;
28 sub define_object {
29 my $self = shift;
31 # call set_object_id, set_object and set_primary_key here
32 # with the appropriate parameters.
34 my %args = $self->get_args();
35 $self->set_object_id($args{experiment_id});
36 $self->set_object(CXGN::Insitu::Experiment->new($self->get_dbh(),
37 $self->get_object_id())
39 $self->set_primary_key("experiment_id");
40 $self->set_owners($self->get_object()->get_user_id());
43 sub delete {
44 my $self = shift;
45 $self->check_modify_privileges();
46 my $experiment = $self->get_object();
47 my $experiment_name = $experiment->get_name();
48 my $error = $experiment->delete();
49 $self->get_page()->message_page("The experiment $experiment_name has been deleted.");
53 sub generate_form {
54 my $self = shift;
56 $self->init_form();
57 my %args = $self->get_args();
58 my $experiment = $self->get_object();
59 my $experiment_id = $self->get_object_id();
61 # get some organism and probe information for the drop down menus
63 my ($organism_names_ref, $organism_ids_ref) = CXGN::Insitu::Organism::get_all_organisms($self->get_dbh());
64 my ($probe_names_ref, $probe_ids_ref) = CXGN::Insitu::Probe::get_all_probes($self->get_dbh());
65 my $types_names_ref = [ "Insitu", "Immunolocalization", "Histochemical localization" ];
67 my %field = (
68 experiment_name => "",
69 date => "",
70 tissue => "",
71 stage => "",
72 description => "",
73 probe_id => "",
74 probe_name => "",
75 organism_id => "",
76 user_id =>"",
78 my $organism_name = "";
79 my $organism_link = "";
80 my $submitter;
81 my $submitter_name="";
82 my $probe_name="";
84 if ($self->get_action()=~/view|edit/i) {
85 $field{type} = $experiment->get_type();
86 $field{probe_id} = $experiment->get_probe_id();
87 $field{user_id} = $experiment->get_user_id();
88 $probe_name = $experiment->get_probe()->get_name();
89 $field{organism_id} = $experiment -> get_organism_id();
90 $organism_name = $experiment->get_organism();
91 $organism_link = qq { <a href="organism.pl?organism_id=$field{organism_id}&amp;action=view">$organism_name</a> };
92 $field{user_id} = $experiment->get_user_id();
93 $submitter = CXGN::People::Person->new($self->get_dbh(), $field{user_id});
94 $submitter_name = $submitter->get_first_name()." ".$submitter->get_last_name();
96 # if ($self->get_action()=~/edit/i) {
97 # $submitter ||= CXGN::People::Person->new($field{user_id});
98 # $submitter_name ||= $submitter->get_first_name()." ".$submitter->get_last_name();
101 if ($self->get_action()=~/store/i) {
102 $probe_name = CXGN::Insitu::Probe->new($self->get_dbh(), $field{probe_id})->get_name();
103 $organism_name = CXGN::Insitu::Organism->new($self->get_dbh(), $field{organism_id})->get_name();
104 $submitter = CXGN::People::Person->new($self->get_dbh(), $field{user_id});
105 $submitter_name = $submitter->get_first_name()." ".$submitter->get_last_name();
109 # generate the form using CXGN::Form.
110 # setup the form using the CXGN::Page::Form functions for editable content
112 $self->get_form()-> add_field( display_name=>"Name", field_name=>"name", contents=>$field{name}, length=>20, object=>$experiment, getter=>"get_name", setter=>"set_name", validate=>"string" );
114 $self->get_form()-> add_field( display_name=>"Date", field_name=>"date", contents=>$field{date}, length=>15, object=>$experiment, getter=>"get_date", setter=>"set_date", validate=>"date");
118 $self->get_form -> add_field( display_name=>"Tissue", field_name=>"tissue", contents=> $field{tissue}, length=>15, object=>$experiment, getter=>"get_tissue", setter=>"set_tissue");
120 $self->get_form -> add_field( display_name=>"Stage", field_name=>"stage", contents=>$field{stage}, length=>20, object=>$experiment, getter=>"get_stage", setter=>"set_stage" );
122 $self->get_form -> add_field( display_name=>"Other info", field_name=>"description", contents=> $field{description}, length=>30, object=>$experiment, getter=>"get_description", setter=>"set_description" );
124 $self->get_form -> add_hidden( field_name => "experiment_id", contents=>$experiment_id );
126 $self->get_form -> add_hidden( field_name => "action", contents=>"store" );
128 # if ($self->get_action() =~/edit|new|store/) {
130 $self->get_form -> add_select( display_name=>"Type", field_name=>"type", contents=>$field{type}, length=>20, object => $experiment, getter=>"get_type", setter=>"set_type", select_list_ref=>$types_names_ref, select_id_list_ref=>$types_names_ref );
132 $self->get_form->add_select( display_name=>"Organism", field_name=>"organism_id", contents=>$field{organism_id}, length=>10, object=>$experiment, getter=>"get_organism_id", setter=>"set_organism_id", select_list_ref=>$organism_names_ref, select_id_list_ref=>$organism_ids_ref );
134 $self->get_form->add_select( display_name=>"Probe", field_name=>"probe_id", contents=>$field{probe_id}, length=>10, object=>$experiment, getter=>"get_probe_id", setter=>"set_probe_id", select_list_ref=>$probe_names_ref, select_id_list_ref=>$probe_ids_ref );
137 # elsif ($self->get_action() eq "view") {
139 # $self->get_form -> add_field( display_name=>"Type", field_name=>"type", contents=>$field{type}, length=>20, object => $experiment, getter=>"get_type", setter=>"set_type" );
141 # $self->get_form->add_field( display_name=>"Organism", field_name=>"organism_id", contents=>$organism_link, length=>20, validate=>"integer" );
143 # $self->get_form()->add_field( display_name=>"Probe", field_name=>"probe_id", contents=> qq { <a href="probe.pl?probe_id=$field{probe_id}">$probe_name</a> } , length=>20, validate=>"integer" );
146 $self->get_form()->add_label( display_name=>"Submitter",
147 field_name=>"submitter",
148 contents=>$submitter_name,
151 if ($self->get_action()=~ /edit|view/) {
152 $self->get_form()->from_database();
154 if ($self->get_action()=~/store/) {
155 $self->get_form()->from_request(%args);
161 sub display_page {
162 my $self = shift;
164 my %args = $self->get_args();
165 my $experiment = $self->get_object();
166 my $experiment_id = $self->get_object_id();
167 my $user_id = $experiment->get_user_id();
168 my $user = CXGN::People::Person->new($self->get_dbh(), $user_id);
170 # display and edit and delete link if we are not currently
171 # in editing mode...
173 my $edit_link = "";
174 my $delete_link = "";
175 if ($self->get_action eq "new" ) {
176 $edit_link = " <a href=\"/insitu/manage.pl\">[Cancel]</a>";
178 elsif ($self->get_action() eq "edit") {
179 $edit_link = " <a href=\"experiment.pl?experiment_id=$experiment_id&amp;action=view\">[View]</a>";
181 else {
182 $edit_link = " <a href=\"experiment.pl?experiment_id=$experiment_id&amp;action=edit\">[Edit]</a>";
183 $delete_link = "<a href=\"experiment.pl?experiment_id=$experiment_id&amp;action=confirm_delete\">[Delete]</a>";
186 # get some information that will be displayed statically only
188 my $page_title = page_title_html("<a href=\"/insitu/\">Insitu</a> Experiment \"".$experiment->get_name()."\"");
190 my $username = $experiment->get_user()->get_first_name()." ".$experiment->get_user()->get_last_name();
191 if (!$username) {
192 $username=$user->get_first_name()." ".$user->get_last_name();
195 my $submit_user_id = $experiment->get_user()->get_sp_person_id();
196 my $probe_id = $experiment->get_probe()->get_probe_id();
197 my $probe_name = $experiment->get_probe()->get_name();
199 my $categories = ""; # $experiment->get_categories();
200 my $organism_name = $experiment -> get_organism();
201 my $organism_id = $experiment->get_organism_id();
202 my $action = $self->get_action();
204 #print STDERR "***** Organism: $organism_name id: $organism_id\n";
205 my $image_count = $experiment->get_images();
207 $self->get_page()->add_style(text => ".centered {text-align: center}");
208 $self->get_page()->header();
210 CXGN::Insitu::Toolbar::display_toolbar();
212 my $categories = "";
214 print <<HTML;
216 $page_title
217 <h3>$action</h3>
219 <b>Experiment Info</b> $edit_link $delete_link<br /><br />
221 HTML
223 $self->get_form()->as_table();
225 my $tag_count = scalar($experiment->get_tags());
227 print qq { <br /><br /><b>Associated tags</b> [<a href="/tag/?experiment_id=$experiment_id&amp;action=new">add/remove</a>]: <b>$tag_count</b> };
229 foreach my $tag ($experiment->get_tags()) {
230 print $tag->get_name()." ";
233 my $assoc_imgs_html = qq {<br /><br /><b>Associated images</b>: $image_count<br /><br />};
235 $assoc_imgs_html .= "<table width=\"90%\" cellpadding=\"0\" cellspacing=\"0\" class=\"centered\"><tr>\n";
237 my $i = 0;
238 for ($i; $i< (my @image = $experiment->get_image_ids()); $i++) {
239 my $image_id = $image[$i];
240 my $image = SGN::Image->new( $self->get_dbh(), $image_id, $c );
241 $assoc_imgs_html .= "<td valign=\"top\"><a href=\"/image/view/$image_id\">".$image->get_img_src_tag("small")."</a>&nbsp;<br />";
243 if ($self->get_action() eq "edit") {
244 $assoc_imgs_html .= qq {<a href="/image/?image_id=$image_id&amp;type=experiment&amp;type_id=$experiment_id&amp;action=confirm_delete">Delete</a><br />};
247 $assoc_imgs_html .= qq { </td><td width="20">&nbsp;</td> };
248 if (($i+1) % 3 == 0 ) { $assoc_imgs_html .= "</tr><tr>"; }
251 $assoc_imgs_html .= "<td></td></tr></table>"; #in xhtml 1.0+, a <tr> must have <td> children -- Evan, 1/6/07
253 print $assoc_imgs_html;
255 if ($self->get_action() eq "edit") {
256 print qq {<a href="/image/add?type=experiment&amp;type_id=$experiment_id&amp;action=new">Add new image</a> };
258 $self->get_page()->footer();