on second though, remove post-only restriction on organism tree image cache flushing...
[sgn.git] / cgi-bin / phenome / allele_synonym.pl
blobeb2687605a6371b06cf81e06add15ea0eb670692
2 use strict;
4 my $allele_synonym_detail_page = CXGN::Phenome::AlleleSynonymDetailPage->new();
6 package CXGN::Phenome::AlleleSynonymDetailPage;
9 use CXGN::Page;
10 use CXGN::Page::FormattingHelpers qw / info_section_html page_title_html /;
11 use CXGN::Phenome::AlleleSynonym;
12 use CXGN::Phenome::Allele;
13 use CXGN::Phenome::Locus;
15 use base qw / CXGN::Page::Form::SimpleFormPage /;
17 sub new {
18 my $class = shift;
19 my $self = $class->SUPER::new(@_);
20 $self->set_script_name("allele_synonym.pl");
22 return $self;
26 sub define_object {
27 my $self = shift;
29 # call set_object_id, set_object and set_primary_key here
30 # with the appropriate parameters.
32 my %args = $self->get_args();
33 my $allele_alias_id= $args{allele_alias_id};
35 $self->set_object_id($allele_alias_id);
36 $self->set_object(CXGN::Phenome::AlleleSynonym->new($self->get_dbh(), $self->get_object_id())
38 $self->set_primary_key("allele_alias_id");
39 $self->set_owners();
42 # override store to check if an allele synonym with the submitted name already exists
44 sub store {
45 my $self = shift;
47 my $allele_synonym = $self->get_object();
49 my $allele_synonym_id = $self->get_object_id();
50 my %args = $self->get_args();
53 my $not_new_allele_synonym = "";
54 # print STDERR "*** STORING ALLELE SYNONYM ***\n";
55 my $existing_id = CXGN::Phenome::AlleleSynonym::exists_allele_synonym_named($self->get_dbh(), $args{allele_alias}, $args{allele_id});
56 if ($existing_id) {
57 print STDERR "**Allele Synonym already exists...\n";
59 $self->get_page()->header();
60 print $not_new_allele_synonym = "Allele synonym '".$args{allele_alias}. "' already exists <br />";
61 print qq { <a href="javascript:history.back(1)">back to allele synonyms</a> };
62 $self->get_page()->footer();
63 exit();
65 else {
66 $self->SUPER::store(1);
69 my $allele;
70 my $image;
71 my $allele_id= $args{allele_id};
72 if (exists($args{allele_id}) && defined($args{allele_id})) {
73 $allele = CXGN::Phenome::Allele->new($self->get_dbh(), $args{allele_id});
74 $allele->add_allele_aliases($allele_synonym);
76 $self->get_page()->client_redirect("/phenome/allele_synonym.pl?allele_id=$allele_id&action=new");
80 sub delete_dialog {
81 my $self = shift;
82 $self->delete();
85 sub delete {
86 my $self = shift;
87 my %args = $self->get_args();
89 $self->check_modify_privileges();
91 my ($allele, $allele_name, $allele_symbol);
93 my $allele_synonym_name = $self->get_object()->get_allele_alias();
95 if ($args{allele_id}) {
96 $allele = CXGN::Phenome::Allele->new($self->get_dbh(), $args{allele_id});
97 $allele_name = $allele->get_allele_name();
98 $allele_symbol= $allele->get_allele_symbol();
99 $allele->remove_allele_alias($args{allele_alias_id});
103 $self->get_page()->header();
105 if ($allele) {
106 print qq { Removed allele synonym "$allele_synonym_name" association from allele "$allele_symbol" ($allele_name).<br /> };
107 print qq { <a href="allele_synonym.pl?allele_id=$args{allele_id}&amp;action=new">Back to allele synonyms page</a> };
110 $self->get_page()->footer();
114 sub generate_form {
115 my $self = shift;
117 my %args = $self->get_args();
118 my $allele_synonym = $self->get_object();
119 my $allele_synonym_id = $self->get_object_id();
122 $self->init_form();
124 # generate the form with the appropriate values filled in.
125 # if we view, then take the data straight out of the database
126 # if we edit, take data from database and override with what's
127 # in the submitted form parameters.
128 # if we store, only take the form parameters into account.
129 # for new, we don't do anything - we present an empty form.
132 # add form elements
134 $self->get_form()->add_field(display_name=>"Allele synonym: ",
135 field_name=>"allele_alias",
136 length=>20,
137 object=>$allele_synonym,
138 getter=>"get_allele_alias",
139 setter=>"set_allele_alias",
140 validate=>"token"
144 $self->get_form()->add_hidden( field_name=>"action", contents=>"store" );
145 $self->get_form()->add_hidden( field_name=>"allele_alias_id", contents=>$allele_synonym_id );
147 $self->get_form()->add_hidden( field_name=>"allele_id",
148 contents=>$args{allele_id},
149 object=>$allele_synonym,
150 getter=>"get_allele_id",
151 setter=>"set_allele_id"
154 $self->get_form()->add_hidden (
155 field_name => "sp_person_id",
156 contents =>$self->get_user()->get_sp_person_id(),
157 object => $allele_synonym,
158 setter =>"set_sp_person_id",
161 # populate the form
162 # (do nothing here because synonyms cannot be edited).
163 #if ($self->get_action()=~/view|edit/i) {
164 # $self->get_form()->from_database();
166 if ($self->get_action()=~/store/i) {
167 $args{allele_alias}=lc($args{allele_alias}); # somehow this doesn't work -- would like to lowercase all tags...
168 $self->get_form()->from_request(%args);
174 sub display_page {
175 my $self = shift;
176 my %args = $self->get_args();
178 # generate an appropriate edit link
180 my $script_name = $self->get_script_name();
182 # generate some locus and/or image information
184 my $allele;
185 my $allele_name;
186 my $allele_symbol;
187 my $allele_id;
188 my @allele_synonyms = ();
189 my $locus_id;
190 # render the form
192 $self->get_page()->header();
194 print page_title_html( qq { <h3>SGN <a href="/search/direct_search.pl?search=loci">genes</a> database } );
196 print qq { <b>Allele synonyms</b> };
198 if ($args{allele_id}) {
199 $allele = CXGN::Phenome::Allele->new($self->get_dbh(), $args{allele_id});
200 @allele_synonyms=$allele->get_allele_aliases();
201 $allele_id = $allele->get_allele_id();
202 $locus_id= $allele->get_locus_id();
203 print "for allele ".$allele->get_allele_symbol()." (".$allele->get_allele_name().")<br /><br />\n";
204 foreach my $as (@allele_synonyms) {
205 my $allele_synonym_id = $as->get_allele_alias_id();
206 print $as->get_allele_alias(). qq { \n <a href="allele_synonym.pl?allele_id=$allele_id&amp;allele_alias_id=$allele_synonym_id&amp;locus_id=$locus_id&amp;action=confirm_delete">[Remove]</a> <br />\n };
211 if (!@allele_synonyms) { print "<b>None found</b><br /><br />\n"; }
213 print qq { <br /><br /><b>Add another allele synonym</b>: };
215 print qq { <center> };
217 $self->get_form()->as_table();
219 print qq { </center> };
221 print qq { <a href = "allele.pl?allele_id=$allele_id&amp;action=view">back to allele page</a><br> };
222 print qq { <a href="locus_display.pl?locus_id=$locus_id&amp;action=view">back to locus page</a> };
224 $self->get_page()->footer();