minor tweak of announcement.
[sgn.git] / cgi-bin / phenome / locus_synonym.pl
blob00a8b448aed9ab96ec5df58c138def793060b629
2 use strict;
4 my $locus_synonym_detail_page = CXGN::Phenome::LocusSynonymDetailPage->new();
6 package CXGN::Phenome::LocusSynonymDetailPage;
9 use CXGN::Page;
10 use CXGN::Page::FormattingHelpers qw / info_section_html page_title_html /;
11 use CXGN::Phenome::LocusSynonym;
12 use CXGN::Phenome::Locus;
13 use CXGN::Feed;
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("locus_synonym.pl");
22 return $self;
26 sub define_object {
27 my $self = shift;
28 # call set_object_id, set_object and set_primary_key here
29 # with the appropriate parameters.
31 my %args = $self->get_args();
32 $self->set_object_id($args{locus_alias_id});
33 $self->set_object(CXGN::Phenome::LocusSynonym->new($self->get_dbh(), $self->get_object_id())
35 $self->set_primary_key("locus_alias_id");
36 $self->set_owners();
39 # override store to check if a locus synonym with the submitted name already exists
41 sub store {
42 my $self = shift;
44 my $locus_synonym = $self->get_object();
46 my $locus_synonym_id = $self->get_object_id();
47 my %args = $self->get_args();
49 my $not_new_locus_synonym = "";
50 my ($existing_id, $obsolete) = CXGN::Phenome::LocusSynonym::exists_locus_synonym_named($self->get_dbh(), $args{locus_alias}, $args{locus_id});
51 if ($existing_id && $obsolete == 0) {
53 $self->get_page()->header();
54 print $not_new_locus_synonym = "Locus synonym '".$args{locus_alias}. "' already exists <br />";
55 print qq { <a href="javascript:history.back(1)">back to locus synonyms</a> };
56 $self->get_page()->footer();
57 exit();
58 }else {
59 $self->SUPER::store(1);
60 $self->send_synonym_email();
63 my $locus_id= $args{locus_id};
64 $self->get_page()->client_redirect("/phenome/locus_synonym.pl?locus_id=$locus_id&action=new");
67 sub delete_dialog {
68 my $self = shift;
69 $self->delete();
72 sub delete {
73 my $self = shift;
74 my %args = $self->get_args();
76 $self->check_modify_privileges();
78 my $locus;
79 my $locus_name;
80 my $image;
81 my $image_name;
83 my $locus_synonym_name = $self->get_object()->get_locus_alias();
85 if ($args{locus_id}) {
86 $locus = CXGN::Phenome::Locus->new($self->get_dbh(), $args{locus_id});
87 $locus_name = $locus->get_locus_name();
88 $locus->remove_locus_alias($args{locus_alias_id});
89 $self->send_synonym_email('delete');
91 if ($locus) {
92 my $locus_id= $args{locus_id};
93 $self->get_page()->client_redirect("/phenome/locus_synonym.pl?locus_id=$locus_id&action=new");
97 sub generate_form {
98 my $self = shift;
100 my %args = $self->get_args();
101 my $locus_synonym = $self->get_object();
102 my $locus_synonym_id = $self->get_object_id();
104 $self->init_form();
106 # generate the form with the appropriate values filled in.
107 # if we view, then take the data straight out of the database
108 # if we edit, take data from database and override with what's
109 # in the submitted form parameters.
110 # if we store, only take the form parameters into account.
111 # for new, we don't do anything - we present an empty form.
114 # add form elements
116 $self->get_form()->add_field(display_name=>"Locus synonym: ",
117 field_name=>"locus_alias",
118 length=>20,
119 object=>$locus_synonym,
120 getter=>"get_locus_alias",
121 setter=>"set_locus_alias",
122 validate=>"string"
125 $self->get_form()->add_hidden( field_name=>"action", contents=>"store" );
126 $self->get_form()->add_hidden( field_name=>"locus_alias_id", contents=>$locus_synonym_id );
128 $self->get_form()->add_hidden( field_name=>"locus_id",
129 contents=>$args{locus_id},
130 object=>$locus_synonym,
131 getter=>"get_locus_id",
132 setter=>"set_locus_id"
134 $self->get_form()->add_hidden (
135 field_name => "sp_person_id",
136 contents =>$self->get_user()->get_sp_person_id(),
137 object => $locus_synonym,
138 setter =>"set_sp_person_id",
141 # populate the form
142 # (do nothing here because synonyms cannot be edited).
143 #if ($self->get_action()=~/view|edit/i) {
144 # $self->get_form()->from_database();
146 if ($self->get_action()=~/store/i) {
147 $args{locus_alias}=lc($args{locus_alias}); # somehow this doesn't work -- would like to lowercase all tags...
148 $self->get_form()->from_request(%args);
154 sub display_page {
155 my $self = shift;
156 my %args = $self->get_args();
158 # generate an appropriate edit link
160 my $script_name = $self->get_script_name();
162 # generate some locus and/or image information
164 my $locus;
165 my $locus_name;
166 my $image;
167 my $image_name;
169 my @locus_synonyms = ();
170 my @image_tags = ();
171 my @experiment_tags = ();
173 # render the form
175 $self->get_page()->header();
177 print page_title_html( qq { SGN <a href="/search/direct_search.pl?search=loci">genes</a> database } );
179 print qq { <b>Locus synonyms</b> };
181 if ($args{locus_id}) {
182 $locus = CXGN::Phenome::Locus->new($self->get_dbh(), $args{locus_id});
183 @locus_synonyms=$locus->get_locus_aliases('f', 'f');
184 my $locus_id = $locus->get_locus_id();
185 print "for locus ".$locus->get_locus_name()."<br /><br />\n";
186 foreach my $ls (@locus_synonyms) {
187 my $locus_synonym_id = $ls->get_locus_alias_id();
188 print $ls->get_locus_alias(). qq { \n <a href="locus_synonym.pl?locus_id=$locus_id&amp;locus_alias_id=$locus_synonym_id&amp;action=confirm_delete">[Remove]</a> <br />\n };
192 if (!@locus_synonyms && !@image_tags) { print "<b>None found</b><br /><br />\n"; }
194 print qq { <br /><br /><b>Add another locus synonym</b>: };
196 print qq { <center> };
198 $self->get_form()->as_table();
200 print qq { </center> };
202 print qq { <a href="/locus/$args{locus_id}/view">back to locus page</a> };
204 $self->get_page()->footer();
208 sub send_synonym_email {
209 my $self=shift;
210 my $action=shift;
211 my %args = $self->get_args();
212 my $locus_id= $args{locus_id};
214 my $locus_synonym_id=$self->get_object()->get_locus_alias_id();
215 my $locus_synonym_name= $self->get_object->get_locus_alias();
217 my $username= $self->get_user()->get_first_name()." ".$self->get_user()->get_last_name();
218 my $sp_person_id=$self->get_user()->get_sp_person_id();
219 my $usermail=$self->get_user()->get_private_email();
220 my $locus_link= qq |http://solgenomics.net/locus/$locus_id/view|;
221 my $user_link = qq |http://solgenomics.net/solpeople/personal-info.pl?sp_person_id=$sp_person_id|;
223 my $fdbk_body;
224 my $subject;
225 if ($action eq 'delete') {
226 $subject="[A locus synonym deleted] locus $locus_id";
227 $fdbk_body="$username ($user_link)\n has deleted locus synonym $locus_synonym_name \n from locus ($locus_link)\n"; }
228 else {
229 $subject="[New locus synonym stored] locus $locus_id";
230 $fdbk_body="$username ($user_link)\n has submitted a new synonym $locus_synonym_name \n for locus ($locus_link)\n"; }
232 CXGN::Contact::send_email($subject,$fdbk_body, 'sgn-db-curation@sgn.cornell.edu');
233 CXGN::Feed::update_feed($subject,$fdbk_body);