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
(@_);
27 ### $self->get_ajax_page()->send_http_header();
35 my %args = $self->get_args();
36 my $locus_id = $args{locus_id
} || $args{object_id
};
37 my $user_type = $self->get_user()->get_user_type();
38 my %json_hash= $self->get_json_hash();
40 $self->set_object_id($locus_id);
41 $self->set_object_name('Locus'); #this is useful for email messages
43 CXGN
::Phenome
::Locus
->new( $self->get_dbh(), $self->get_object_id() ) );
44 if ( $self->get_object()->get_obsolete() eq 't' && $user_type ne 'curator' )
46 ##print STDERR "ERROR:: Locus $locus_id is obsolete!";
47 $json_hash{error
}="Locus $locus_id is obsolete!";
49 unless ( ( $locus_id =~ m
/^\d+$/ || !$locus_id ) ) {
50 #print STDERR "ERROR:: 'No locus exists for identifier $locus_id'\n\n";
51 $json_hash{error
}="No locus exists for identifier $locus_id";
53 $self->set_json_hash(%json_hash);
54 $self->set_primary_key("locus_id");
55 $self->set_owners( $self->get_object()->get_owners() );
57 $self->return_json() if $json_hash{error
};
62 my %json_hash = $self->get_json_hash();
64 if (!($json_hash{html
}) ) { $json_hash{html
} = $self->get_form()->as_table_string() ; }
65 $self->check_modify_privileges();
67 $json_hash{"user_type"} = $self->get_user()->get_user_type();
68 $json_hash{"is_owner"} = $self->get_is_owner();
70 $json_hash{"editable_form_id"} = $self->get_form()->get_form_id();
73 $self->set_json_hash(%json_hash);
80 my $locus = $self->get_object();
81 my $locus_id = $self->get_object_id();
82 my %args = $self->get_args();
83 my %json_hash = $self->get_json_hash();
84 my $initial_locus_id = $locus_id;
87 $locus->set_common_name_id($args{common_name_id
});
90 $locus->exists_in_database( $args{locus_name
}, $args{locus_symbol
} );
93 $error = " Locus $args{locus_name} (symbol= $args{locus_symbol} ) already exists in the database ";
96 $self->SUPER::store
(); #this sets $json_hash{validate} if the form validation failed.
97 $locus_id = $locus->get_locus_id() ;
99 $error = " An error occurred. Cannot store to the database\n An email message has been sent to the SGN development team";
100 CXGN
::Contact
::send_email
('locus_ajax_form.pl died', $error . "\n" . $_ , 'sgn-bugs@sgn.cornell.edu');
103 #the validate field is false is validation passed for all fields, true if did not pass and the form is re-printed
104 #$json_hash{validate}= $validate;
105 %json_hash= $self->get_json_hash();
106 $validate= $json_hash{validate
};
107 $json_hash{error
} = $error if $error;
109 my $refering_page="/phenome/locus_display.pl?locus_id=$locus_id";
110 $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
});
111 $json_hash{refering_page
}=$refering_page if !$initial_locus_id && !$validate && !$error;
113 $self->set_json_hash(%json_hash);
115 $self->return_json();
119 ####################################
121 ##Delete the locus (actually set obsolete = 't')
123 my $check = $self->check_modify_privileges();
124 $self->return_json() if $check ; #error or no user privileges
126 my $locus = $self->get_object();
127 my $locus_name = $locus->get_locus_name();
128 my $locus_id = $locus->get_locus_id();
129 my %json_hash= $self->get_json_hash();
130 my $refering_page="/phenome/locus_display.pl?locus_id=$locus_id";
132 if (!$json_hash{error
} ) {
136 $json_hash{error
} = " An error occurred. Cannot delete locus\n An email message has been sent to the SGN development team";
138 $json_hash{reload
} = 1;
140 $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
});
141 $self->set_json_hash(%json_hash);
142 $self->return_json();
149 my $form_id = 'edit_locus'; # a form_id is required for ajax forms
151 $self->init_form($form_id) ; ## instantiate static/editable/confirmStore form
153 my $locus = $self->get_object();
154 my %args = $self->get_args();
155 my $form = $self->get_form();
156 my $dbh = $self->get_dbh();
158 my ( $organism_names_ref, $organism_ids_ref ) =
159 CXGN
::Tools
::Organism
::get_all_organisms
( $self->get_dbh() );
161 CXGN
::Phenome
::Locus
::LinkageGroup
::get_all_lgs
( $self->get_dbh() );
163 CXGN
::Phenome
::Locus
::LinkageGroup
::get_lg_arms
( $self->get_dbh() );
165 if ( $self->get_action =~ /new|store/ ) {
166 $self->get_form->add_select(
167 display_name
=> "Organism ",
168 field_name
=> "common_name_id",
169 contents
=> $locus->get_common_name_id(),
172 getter
=> "get_common_name_id",
173 setter
=> "set_common_name_id",
174 select_list_ref
=> $organism_names_ref,
175 select_id_list_ref
=> $organism_ids_ref,
179 if ( $locus->get_obsolete() eq 't' ) {
181 display_name
=> "Status",
182 field_name
=> "obsolete_stat",
183 contents
=> 'OBSOLETE',
187 display_name
=> "Locus name ",
188 field_name
=> "locus_name",
190 getter
=> "get_locus_name",
191 setter
=> "set_locus_name",
192 validate
=> 'string',
196 display_name
=> "Symbol ",
197 field_name
=> "locus_symbol",
199 getter
=> "get_locus_symbol",
200 setter
=> "set_locus_symbol",
202 formatting
=> '<i>*</i>',
206 display_name
=> "Gene activity ",
207 field_name
=> "gene_activity",
209 getter
=> "get_gene_activity",
210 setter
=> "set_gene_activity",
215 display_name
=> "Description ",
216 field_name
=> "description",
218 getter
=> "get_description",
219 setter
=> "set_description",
225 display_name
=> "Chromosome ",
226 field_name
=> "lg_name",
227 contents
=> $locus->get_linkage_group(),
230 getter
=> "get_linkage_group",
231 setter
=> "set_linkage_group",
232 select_list_ref
=> $lg_names_ref,
233 select_id_list_ref
=> $lg_names_ref,
237 display_name
=> "Arm",
238 field_name
=> "lg_arm",
239 contents
=> $locus->get_lg_arm(),
242 getter
=> "get_lg_arm",
243 setter
=> "set_lg_arm",
244 select_list_ref
=> $lg_arms_ref,
245 select_id_list_ref
=> $lg_arms_ref,
249 field_name
=> "locus_id",
250 contents
=> $locus->get_locus_id(),
254 field_name
=> "action",
259 field_name
=> "sp_person_id",
260 contents
=> $self->get_user()->get_sp_person_id(),
262 setter
=> "set_sp_person_id",
266 field_name
=> "updated_by",
267 contents
=> $self->get_user()->get_sp_person_id(),
269 setter
=> "set_updated_by",
272 if ( $self->get_action() =~ /view|edit/ ) {
273 $form->from_database();
275 field_name
=> "common_name_id",
276 contents
=> $locus->get_common_name_id(),
280 elsif ( $self->get_action() =~ /store/ ) {
281 $form->from_request( %args );