5 my $locus_form = CXGN
::Phenome
::LocusForm
->new();
7 package CXGN
::Phenome
::LocusForm
;
9 use base qw
/CXGN::Page::Form::AjaxFormPage /;
11 use CXGN
::Phenome
::Locus
;
12 use CXGN
::Phenome
::Locus
::LinkageGroup
;
13 use CXGN
::Tools
::Organism
;
15 use CXGN
::People
::Person
;
26 my $self = $class->SUPER::new
(@_);
32 my %args = $self->get_args();
33 my $locus_id = $args{locus_id
} || $args{object_id
};
34 my $user_type = $self->get_user()->get_user_type();
35 my %json_hash= $self->get_json_hash();
37 $self->set_object_id($locus_id);
38 $self->set_object_name('Locus'); #this is useful for email messages
40 CXGN
::Phenome
::Locus
->new( $self->get_dbh(), $self->get_object_id() ) );
41 if ( $self->get_object()->get_obsolete() eq 't' && $user_type ne 'curator' )
43 ##print STDERR "ERROR:: Locus $locus_id is obsolete!";
44 $json_hash{error
}="Locus $locus_id is obsolete!";
46 unless ( ( $locus_id =~ m
/^\d+$/ || !$locus_id ) ) {
47 #print STDERR "ERROR:: 'No locus exists for identifier $locus_id'\n\n";
48 $json_hash{error
}="No locus exists for identifier $locus_id";
50 $self->set_json_hash(%json_hash);
51 $self->set_primary_key("locus_id");
52 $self->set_owners( $self->get_object()->get_owners() );
54 $self->print_json() if $json_hash{error
};
60 my $locus = $self->get_object();
61 my $locus_id = $self->get_object_id();
62 my %args = $self->get_args();
63 my %json_hash = $self->get_json_hash();
64 my $initial_locus_id = $locus_id;
67 $locus->set_common_name_id($args{common_name_id
});
70 $locus->exists_in_database( $args{locus_name
}, $args{locus_symbol
} );
73 $error = " Locus $args{locus_name} (symbol= $args{locus_symbol} ) already exists in the database ";
76 $self->SUPER::store
(); #this sets $json_hash{validate} if the form validation failed.
77 $locus_id = $locus->get_locus_id() ;
79 $error = " An error occurred. Cannot store to the database\n An email message has been sent to the SGN development team";
80 CXGN
::Contact
::send_email
('locus_ajax_form.pl died', $error . "\n" . $_ , 'sgn-bugs@sgn.cornell.edu');
83 #the validate field is false is validation passed for all fields, true if did not pass and the form is re-printed
84 #$json_hash{validate}= $validate;
85 %json_hash= $self->get_json_hash();
86 $validate= $json_hash{validate
};
87 $json_hash{error
} = $error if $error;
89 my $refering_page="/phenome/locus_display.pl?locus_id=$locus_id";
90 $self->send_form_email({subject
=>"[New locus details stored] locus $locus_id", mailing_list
=>'sgn-db-curation@sgn.cornell.edu', refering_page
=>"www.solgenomics.net".$refering_page}) if (!$validate && !$json_hash{error
});
91 $json_hash{refering_page
}=$refering_page if !$initial_locus_id && !$validate && !$error;
93 $self->set_json_hash(%json_hash);
99 ####################################
101 ##Delete the locus (actually set obsolete = 't')
103 my $check = $self->check_modify_privileges();
104 $self->print_json() if $check ; #error or no user privileges
106 my $locus = $self->get_object();
107 my $locus_name = $locus->get_locus_name();
108 my $locus_id = $locus->get_locus_id();
109 my %json_hash= $self->get_json_hash();
110 my $refering_page="/phenome/locus_display.pl?locus_id=$locus_id";
112 if (!$json_hash{error
} ) {
116 $json_hash{error
} = " An error occurred. Cannot delete locus\n An email message has been sent to the SGN development team";
118 $json_hash{reload
} = 1;
120 $self->send_form_email({subject
=>"Locus obsoleted ($locus_name)", mailing_list
=>'sgn-db-curation@sgn.cornell.edu', refering_page
=>"www.solgenomics.net".$refering_page, action
=>'delete'}) if (!$json_hash{error
});
121 $self->set_json_hash(%json_hash);
129 my $form_id = 'edit_locus'; # a form_id is required for ajax forms
130 $self->init_form($form_id) ; ## instantiate static/editable/confirmStore form
132 my $locus = $self->get_object();
133 my %args = $self->get_args();
134 my $form = $self->get_form();
135 my $dbh = $self->get_dbh();
137 my ( $organism_names_ref, $organism_ids_ref ) =
138 CXGN
::Tools
::Organism
::get_all_organisms
( $self->get_dbh() );
140 CXGN
::Phenome
::Locus
::LinkageGroup
::get_all_lgs
( $self->get_dbh() );
142 CXGN
::Phenome
::Locus
::LinkageGroup
::get_lg_arms
( $self->get_dbh() );
144 if ( $self->get_action =~ /new|store/ ) {
146 display_name
=> "Organism ",
147 field_name
=> "common_name_id",
148 contents
=> $locus->get_common_name_id(),
151 getter
=> "get_common_name_id",
152 setter
=> "set_common_name_id",
153 select_list_ref
=> $organism_names_ref,
154 select_id_list_ref
=> $organism_ids_ref,
158 if ( $locus->get_obsolete() eq 't' ) {
160 display_name
=> "Status",
161 field_name
=> "obsolete_stat",
162 contents
=> 'OBSOLETE',
166 display_name
=> "Locus",
167 field_name
=> "Locus",
168 id
=> "genome_locus",
170 getter
=> "get_genome_locus",
171 setter
=> "set_genome_locus",
172 autocomplete
=> '/ajax/locus/genome_autocomplete',
175 display_name
=> "Locus name ",
176 field_name
=> "locus_name",
178 getter
=> "get_locus_name",
179 setter
=> "set_locus_name",
180 validate
=> 'string',
184 display_name
=> "Symbol ",
185 field_name
=> "locus_symbol",
187 getter
=> "get_locus_symbol",
188 setter
=> "set_locus_symbol",
190 formatting
=> '<i>*</i>',
194 display_name
=> "Gene activity ",
195 field_name
=> "gene_activity",
197 getter
=> "get_gene_activity",
198 setter
=> "set_gene_activity",
203 display_name
=> "Description ",
204 field_name
=> "description",
206 getter
=> "get_description",
207 setter
=> "set_description",
213 display_name
=> "Chromosome ",
214 field_name
=> "lg_name",
215 contents
=> $locus->get_linkage_group(),
218 getter
=> "get_linkage_group",
219 setter
=> "set_linkage_group",
220 select_list_ref
=> $lg_names_ref,
221 select_id_list_ref
=> $lg_names_ref,
225 display_name
=> "Arm",
226 field_name
=> "lg_arm",
227 contents
=> $locus->get_lg_arm(),
230 getter
=> "get_lg_arm",
231 setter
=> "set_lg_arm",
232 select_list_ref
=> $lg_arms_ref,
233 select_id_list_ref
=> $lg_arms_ref,
237 field_name
=> "locus_id",
238 contents
=> $locus->get_locus_id(),
242 field_name
=> "action",
247 field_name
=> "sp_person_id",
248 contents
=> $self->get_user()->get_sp_person_id(),
250 setter
=> "set_sp_person_id",
254 field_name
=> "updated_by",
255 contents
=> $self->get_user()->get_sp_person_id(),
257 setter
=> "set_updated_by",
260 if ( $self->get_action() =~ /view|edit/ ) {
261 $form->from_database();
263 field_name
=> "common_name_id",
264 contents
=> $locus->get_common_name_id(),
268 elsif ( $self->get_action() =~ /store/ ) {
269 $form->from_request( %args );