4 package CXGN
::Chado
::Pub
::PubForm
;
5 my $pub_form = CXGN
::Chado
::Pub
::PubForm
->new();
7 use base qw
/CXGN::Page::Form::AjaxFormPage /;
10 use Bio
::Chado
::Schema
;
11 use CXGN
::Chado
::Publication
;
13 use CXGN
::People
::Person
;
15 use CXGN
::Page
::FormattingHelpers qw
/
22 use CatalystX
::GlobalContext
qw( $c );
27 my $self = $class->SUPER::new(@_);
33 my %args = $self->get_args();
34 my $pub_id = $args{pub_id} || $args{object_id};
35 my $user_type = $self->get_user()->get_user_type();
36 my %json_hash= $self->get_json_hash();
38 my $sp_person_id = $c->user() ? $c->user->get_object()->get_sp_person_id() : undef;
39 my $schema = $c->dbic_schema( 'Bio::Chado::Schema', 'sgn_chado', $sp_person_id );
40 my $dbh = $schema->storage->dbh;
41 $self->set_object_id($pub_id);
42 $self->set_object_name('publication'); #this is useful for email messages
43 $self->set_object( CXGN::Chado::Publication->new($dbh, $pub_id) );
46 unless ( ( $pub_id =~ m /^\d+$/ || !$pub_id ) ) {
47 $json_hash{error}="No publication exists for identifier $pub_id";
49 $self->set_json_hash(%json_hash);
50 $self->set_primary_key("pub_id");
53 $self->print_json() if $json_hash{error};
60 my $pub = $self->get_object();
61 my $pub_id = $self->get_object_id();
63 my %args = $self->get_args();
64 my %json_hash = $self->get_json_hash();
65 my $initial_pub_id = $pub_id;
70 $pub->set_title($args{title});
71 $pub->set_series_name($args{series});
72 $pub->set_volume($args{volume});
73 $pub->set_issue($args{issue});
74 $pub->set_pyear($args{pyear});
75 $pub->set_pages($args{pages});
76 $pub->set_abstract($args{abstract});
77 $pub->set_author_string($args{authors});
78 $pub->set_cvterm_name($args{cvterm_name});
84 $self->SUPER::store(); #this sets $json_hash{validate} if the form validation failed.
85 $pub_id = $pub->get_pub_id() ;
87 $error = " An error occurred. Cannot store to the database\n An email message has been sent to the SGN development team";
88 CXGN::Contact::send_email('pub_ajax_form.pl died', $error . "\n" . $_ , 'sgn-bugs@sgn.cornell.edu');
91 #the validate field is false is validation passed for all fields, true if did not pass and the form is re-printed
93 %json_hash= $self->get_json_hash();
94 $validate= $json_hash{validate};
95 $json_hash{error} = $error if $error;
97 my $refering_page="/publication/$pub_id/view";
98 $self->send_form_email({subject=>"[New publication details stored] publication $pub_id", mailing_list=>'sgn-db-curation@sgn.cornell.edu', refering_page=>"www.solgenomics.net".$refering_page}) if (!$validate && !$json_hash{error});
99 $json_hash{refering_page}=$refering_page if !$initial_pub_id && !$validate && !$error;
101 $self->set_json_hash(%json_hash);
106 ####################################
109 my $check = $self->check_modify_privileges();
110 $self->print_json() if $check ; #error or no user privileges
112 my $pub = $self->get_object();
113 my $pub_id = $pub->get_pub_id;
116 my %json_hash= $self->get_json_hash();
117 my $refering_page="/publication/$pub_id/view";
120 if ($pub_id && !$json_hash{error} ) {
121 $pub_title = $pub->get_title;
124 $message = $pub->delete ;
125 $json_hash{error} = $message;
127 $json_hash{error} = " An error occurred. Cannot delete publication\n An email message has been sent to the SGN development team";
128 $self->send_form_email({subject=>"Publication delete failed! ($pub_id) $_", mailing_list=>'sgn-db-curation@sgn.cornell.edu', refering_page=>"www.solgenomics.net".$refering_page, action=>'delete'});
130 $json_hash{reload} = 1;
133 $self->send_form_email({subject=>"Publication deleted ($pub_id)", mailing_list=>'sgn-db-curation@sgn.cornell.edu', refering_page=>"www.solgenomics.net".$refering_page, action=>'delete'}) if (!$json_hash{error});
134 $self->set_json_hash(%json_hash);
143 my $form_id = 'edit_pub'; # a form_id is required for ajax forms
145 $self->init_form($form_id) ; ## instantiate static/editable/confirmStore form
146 my $pub = $self->get_object();
147 my %args = $self->get_args();
148 my $form = $self->get_form();
149 my $type = $args{type};
150 my $type_id = $args{type_id};
151 my $refering_page= $args{refering_page};
153 my @types = qw |journal book curator |;
156 my $author_example = tooltipped_text('Authors', 'Author names should be entered in the order of last name, followed by "," then first name followed by ".". e.g Darwin, Charles. van Rijn, Henk. Giorgio,AB');
158 if ($self->get_action =~ /new|edit/ ) {
160 display_name => "Publication type",
161 field_name => "cvterm_name",
162 contents => $pub->get_cvterm_name(),
165 getter => "get_cvterm_name",
166 setter => "set_cvterm_name",
167 select_list_ref => \@types,
168 select_id_list_ref => \@types,
172 display_name => "Title",
173 field_name => "title",
175 getter => "get_title",
176 setter => "set_title",
177 validate => 'string',
182 display_name => "Series name",
183 field_name => "series_name",
185 getter => "get_series_name",
186 setter => "set_series_name",
187 validate => 'string',
191 display_name => "Volume",
192 field_name => "volume",
194 getter => "get_volume",
195 setter => "set_volume",
198 display_name => "Issue",
199 field_name => "issue",
201 getter => "get_issue",
202 setter => "set_issue",
205 display_name => "Year",
206 field_name => "year",
208 getter => "get_pyear",
209 setter => "set_pyear",
210 validate => 'integer',
213 display_name => "Pages",
214 field_name => "pages",
216 getter => "get_pages",
217 setter => "set_pages",
218 validate => 'string',
221 display_name => $author_example,
222 field_name => "author",
224 getter => "get_authors_as_string",
225 setter => "set_author_string",
231 display_name => "Abstract",
232 field_name => "abstract",
234 getter => "get_abstract",
235 setter => "set_abstract",
241 field_name => "pub_id",
242 contents => $pub->get_pub_id(),
244 getter => "get_pub_id",
245 setter => "set_pub_id",
249 field_name => "type",
253 field_name => "type_id",
254 contents => $type_id,
257 field_name => "refering_page",
258 contents => $refering_page,
261 field_name => "action",
266 if ( $self->get_action() =~ /view|edit/ ) {
267 $form->from_database();
269 elsif ( $self->get_action() =~ /store/ ) {
270 my %json_hash = $self->get_json_hash() ;
271 print $json_hash{html} ;
272 $form->from_request( %args );