on second though, remove post-only restriction on organism tree image cache flushing...
[sgn.git] / cgi-bin / phenome / locus_synonym.pl
blob3eb69931b4ba74f6d02bbb4af50d04a424e902d0
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;
29 # call set_object_id, set_object and set_primary_key here
30 # with the appropriate parameters.
32 my %args = $self->get_args();
33 $self->set_object_id($args{locus_alias_id});
34 $self->set_object(CXGN::Phenome::LocusSynonym->new($self->get_dbh(), $self->get_object_id())
36 $self->set_primary_key("locus_alias_id");
37 $self->set_owners();
40 # override store to check if a locus synonym with the submitted name already exists
42 sub store {
43 my $self = shift;
45 my $locus_synonym = $self->get_object();
47 my $locus_synonym_id = $self->get_object_id();
48 my %args = $self->get_args();
51 my $not_new_locus_synonym = "";
52 # print STDERR "*** STORING LOCUS SYNONYM ***\n";
53 my ($existing_id, $obsolete) = CXGN::Phenome::LocusSynonym::exists_locus_synonym_named($self->get_dbh(), $args{locus_alias}, $args{locus_id});
54 print STDERR "******$existing_id, $obsolete\n";
55 if ($existing_id && $obsolete == 0) {
56 print STDERR "**Locus Synonym already exists...\n";
58 $self->get_page()->header();
59 print $not_new_locus_synonym = "Locus synonym '".$args{locus_alias}. "' already exists <br />";
60 print qq { <a href="javascript:history.back(1)">back to locus synonyms</a> };
61 $self->get_page()->footer();
62 exit();
63 }else {
64 $self->SUPER::store(1);
65 $self->send_synonym_email();
68 my $locus_id= $args{locus_id};
69 $self->get_page()->client_redirect("/phenome/locus_synonym.pl?locus_id=$locus_id&action=new");
72 sub delete_dialog {
73 my $self = shift;
74 $self->delete();
77 sub delete {
78 my $self = shift;
79 my %args = $self->get_args();
81 $self->check_modify_privileges();
83 my $locus;
84 my $locus_name;
85 my $image;
86 my $image_name;
88 my $locus_synonym_name = $self->get_object()->get_locus_alias();
90 if ($args{locus_id}) {
91 $locus = CXGN::Phenome::Locus->new($self->get_dbh(), $args{locus_id});
92 $locus_name = $locus->get_locus_name();
93 $locus->remove_locus_alias($args{locus_alias_id});
94 $self->send_synonym_email('delete');
98 if ($locus) {
99 my $locus_id= $args{locus_id};
100 $self->get_page()->client_redirect("/phenome/locus_synonym.pl?locus_id=$locus_id&action=new");
104 sub generate_form {
105 my $self = shift;
107 my %args = $self->get_args();
108 my $locus_synonym = $self->get_object();
109 my $locus_synonym_id = $self->get_object_id();
111 $self->init_form();
113 # generate the form with the appropriate values filled in.
114 # if we view, then take the data straight out of the database
115 # if we edit, take data from database and override with what's
116 # in the submitted form parameters.
117 # if we store, only take the form parameters into account.
118 # for new, we don't do anything - we present an empty form.
121 # add form elements
123 $self->get_form()->add_field(display_name=>"Locus synonym: ",
124 field_name=>"locus_alias",
125 length=>20,
126 object=>$locus_synonym,
127 getter=>"get_locus_alias",
128 setter=>"set_locus_alias",
129 validate=>"string"
133 $self->get_form()->add_hidden( field_name=>"action", contents=>"store" );
134 $self->get_form()->add_hidden( field_name=>"locus_alias_id", contents=>$locus_synonym_id );
136 $self->get_form()->add_hidden( field_name=>"locus_id",
137 contents=>$args{locus_id},
138 object=>$locus_synonym,
139 getter=>"get_locus_id",
140 setter=>"set_locus_id"
142 $self->get_form()->add_hidden (
143 field_name => "sp_person_id",
144 contents =>$self->get_user()->get_sp_person_id(),
145 object => $locus_synonym,
146 setter =>"set_sp_person_id",
149 # populate the form
150 # (do nothing here because synonyms cannot be edited).
151 #if ($self->get_action()=~/view|edit/i) {
152 # $self->get_form()->from_database();
154 if ($self->get_action()=~/store/i) {
155 $args{locus_alias}=lc($args{locus_alias}); # somehow this doesn't work -- would like to lowercase all tags...
156 $self->get_form()->from_request(%args);
162 sub display_page {
163 my $self = shift;
164 my %args = $self->get_args();
166 # generate an appropriate edit link
168 my $script_name = $self->get_script_name();
170 # generate some locus and/or image information
172 my $locus;
173 my $locus_name;
174 my $image;
175 my $image_name;
177 my @locus_synonyms = ();
178 my @image_tags = ();
179 my @experiment_tags = ();
181 # render the form
183 $self->get_page()->header();
185 print page_title_html( qq { SGN <a href="/search/direct_search.pl?search=loci">genes</a> database } );
187 print qq { <b>Locus synonyms</b> };
189 if ($args{locus_id}) {
190 $locus = CXGN::Phenome::Locus->new($self->get_dbh(), $args{locus_id});
191 @locus_synonyms=$locus->get_locus_aliases('f', 'f');
192 my $locus_id = $locus->get_locus_id();
193 print "for locus ".$locus->get_locus_name()."<br /><br />\n";
194 foreach my $ls (@locus_synonyms) {
195 my $locus_synonym_id = $ls->get_locus_alias_id();
196 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 };
201 if (!@locus_synonyms && !@image_tags) { print "<b>None found</b><br /><br />\n"; }
203 print qq { <br /><br /><b>Add another locus synonym</b>: };
205 print qq { <center> };
207 $self->get_form()->as_table();
209 print qq { </center> };
211 print qq { <a href="locus_display.pl?locus_id=$args{locus_id}&amp;action=view">back to locus page</a> };
213 $self->get_page()->footer();
219 sub send_synonym_email {
220 my $self=shift;
221 my $action=shift;
222 my %args = $self->get_args();
223 my $locus_id= $args{locus_id};
225 my $locus_synonym_id=$self->get_object()->get_locus_alias_id();
226 my $locus_synonym_name= $self->get_object->get_locus_alias();
228 my $username= $self->get_user()->get_first_name()." ".$self->get_user()->get_last_name();
229 my $sp_person_id=$self->get_user()->get_sp_person_id();
230 my $usermail=$self->get_user()->get_private_email();
231 my $locus_link= qq |http://www.sgn.cornell.edu/phenome/locus_display.pl?locus_id=$locus_id|;
232 my $user_link = qq |http://www.sgn.cornell.edu/solpeople/personal-info.pl?sp_person_id=$sp_person_id|;
234 my $fdbk_body;
235 my $subject;
236 if ($action eq 'delete') {
237 $subject="[A locus synonym deleted] locus $locus_id";
238 $fdbk_body="$username ($user_link)\n has deleted locus synonym $locus_synonym_name \n from locus ($locus_link)\n"; }
239 else {
240 $subject="[New locus synonym stored] locus $locus_id";
241 $fdbk_body="$username ($user_link)\n has submitted a new synonym $locus_synonym_name \n for locus ($locus_link)\n"; }
244 CXGN::Contact::send_email($subject,$fdbk_body, 'sgn-db-curation@sgn.cornell.edu');
245 CXGN::Feed::update_feed($subject,$fdbk_body);