Merge branch 'master' of https://github.com/solgenomics/sgn
[sgn.git] / cgi-bin / phenome / allele_synonym.pl
blob4e7602b5fa5aac8c6dc86c1e8554e7f3cfb31929
2 use strict;
3 use warnings;
6 my $allele_synonym_detail_page = CXGN::Phenome::AlleleSynonymDetailPage->new();
8 package CXGN::Phenome::AlleleSynonymDetailPage;
11 use CXGN::Page;
12 use CXGN::Page::FormattingHelpers qw / info_section_html page_title_html /;
13 use CXGN::Phenome::AlleleSynonym;
14 use CXGN::Phenome::Allele;
15 use CXGN::Phenome::Locus;
17 use base qw / CXGN::Page::Form::SimpleFormPage /;
19 sub new {
20 my $class = shift;
21 my $self = $class->SUPER::new(@_);
22 $self->set_script_name("allele_synonym.pl");
24 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 my $allele_alias_id= $args{allele_alias_id};
37 $self->set_object_id($allele_alias_id);
38 $self->set_object(CXGN::Phenome::AlleleSynonym->new($self->get_dbh(), $self->get_object_id())
40 $self->set_primary_key("allele_alias_id");
41 $self->set_owners();
44 # override store to check if an allele synonym with the submitted name already exists
46 sub store {
47 my $self = shift;
49 my $allele_synonym = $self->get_object();
51 my $allele_synonym_id = $self->get_object_id();
52 my %args = $self->get_args();
55 my $not_new_allele_synonym = "";
56 # print STDERR "*** STORING ALLELE SYNONYM ***\n";
57 my $existing_id = CXGN::Phenome::AlleleSynonym::exists_allele_synonym_named($self->get_dbh(), $args{allele_alias}, $args{allele_id});
58 if ($existing_id) {
59 print STDERR "**Allele Synonym already exists...\n";
61 $self->get_page()->header();
62 print $not_new_allele_synonym = "Allele synonym '".$args{allele_alias}. "' already exists <br />";
63 print qq { <a href="javascript:history.back(1)">back to allele synonyms</a> };
64 $self->get_page()->footer();
65 exit();
67 else {
68 $self->SUPER::store(1);
71 my $allele;
72 my $image;
73 my $allele_id= $self->get_object()->get_allele_id();
74 if ( $allele_id ) {
75 $allele = CXGN::Phenome::Allele->new($self->get_dbh(), $args{allele_id});
76 $allele->add_allele_aliases($allele_synonym);
78 $self->get_page()->client_redirect("/phenome/allele_synonym.pl?allele_id=$allele_id&action=new");
82 sub delete_dialog {
83 my $self = shift;
84 $self->delete();
87 sub delete {
88 my $self = shift;
89 my %args = $self->get_args();
91 $self->check_modify_privileges();
93 my ($allele, $allele_name, $allele_symbol);
95 my $allele_synonym_name = $self->get_object()->get_allele_alias();
97 if ($args{allele_id}) {
98 $allele = CXGN::Phenome::Allele->new($self->get_dbh(), $args{allele_id});
99 $allele_name = $allele->get_allele_name();
100 $allele_symbol= $allele->get_allele_symbol();
101 $allele->remove_allele_alias($args{allele_alias_id});
105 $self->get_page()->header();
107 if ($allele) {
108 print qq { Removed allele synonym "$allele_synonym_name" association from allele "$allele_symbol" ($allele_name).<br /> };
109 print qq { <a href="allele_synonym.pl?allele_id=$args{allele_id}&amp;action=new">Back to allele synonyms page</a> };
112 $self->get_page()->footer();
116 sub generate_form {
117 my $self = shift;
119 my %args = $self->get_args();
120 my $allele_synonym = $self->get_object();
121 my $allele_synonym_id = $self->get_object_id();
124 $self->init_form();
126 # generate the form with the appropriate values filled in.
127 # if we view, then take the data straight out of the database
128 # if we edit, take data from database and override with what's
129 # in the submitted form parameters.
130 # if we store, only take the form parameters into account.
131 # for new, we don't do anything - we present an empty form.
134 # add form elements
136 $self->get_form()->add_field(display_name=>"Allele synonym: ",
137 field_name=>"allele_alias",
138 length=>20,
139 object=>$allele_synonym,
140 getter=>"get_allele_alias",
141 setter=>"set_allele_alias",
142 validate=>"token"
146 $self->get_form()->add_hidden( field_name=>"action", contents=>"store" );
147 $self->get_form()->add_hidden( field_name=>"allele_alias_id", contents=>$allele_synonym_id );
149 $self->get_form()->add_hidden( field_name=>"allele_id",
150 contents=>$args{allele_id},
151 object=>$allele_synonym,
152 getter=>"get_allele_id",
153 setter=>"set_allele_id"
156 $self->get_form()->add_hidden (
157 field_name => "sp_person_id",
158 contents =>$self->get_user()->get_sp_person_id(),
159 object => $allele_synonym,
160 setter =>"set_sp_person_id",
163 # populate the form
164 # (do nothing here because synonyms cannot be edited).
165 #if ($self->get_action()=~/view|edit/i) {
166 # $self->get_form()->from_database();
168 if ($self->get_action()=~/store/i) {
169 $args{allele_alias}=lc($args{allele_alias}); # somehow this doesn't work -- would like to lowercase all tags...
170 $self->get_form()->from_request(%args);
176 sub display_page {
177 my $self = shift;
178 my %args = $self->get_args();
180 # generate an appropriate edit link
182 my $script_name = $self->get_script_name();
184 # generate some locus and/or image information
186 my $allele;
187 my $allele_name;
188 my $allele_symbol;
189 my $allele_id;
190 my @allele_synonyms = ();
191 my $locus_id;
192 # render the form
194 $self->get_page()->header();
196 print page_title_html( qq { <h3>SGN <a href="/search/direct_search.pl?search=loci">genes</a> database } );
198 print qq { <b>Allele synonyms</b> };
200 if ($args{allele_id}) {
201 $allele = CXGN::Phenome::Allele->new($self->get_dbh(), $args{allele_id});
202 @allele_synonyms=$allele->get_allele_aliases();
203 $allele_id = $allele->get_allele_id();
204 $locus_id= $allele->get_locus_id();
205 print "for allele ".$allele->get_allele_symbol()." (".$allele->get_allele_name().")<br /><br />\n";
206 foreach my $as (@allele_synonyms) {
207 my $allele_synonym_id = $as->get_allele_alias_id();
208 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 };
213 if (!@allele_synonyms) { print "<b>None found</b><br /><br />\n"; }
215 print qq { <br /><br /><b>Add another allele synonym</b>: };
217 print qq { <center> };
219 $self->get_form()->as_table();
221 print qq { </center> };
223 print qq { <a href = "/phenome/allele.pl?allele_id=$allele_id&amp;action=view">back to allele page</a><br> };
224 print qq { <a href="/locus/$locus_id/view">back to locus page</a> };
225 $self->get_page()->footer();