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 $schema = $c->dbic_schema( 'Bio::Chado::Schema', 'sgn_chado' );
39 my $dbh = $schema->storage->dbh;
40 $self->set_object_id($pub_id);
41 $self->set_object_name('publication'); #this is useful for email messages
42 $self->set_object( CXGN::Chado::Publication->new($dbh, $pub_id) );
45 unless ( ( $pub_id =~ m /^\d+$/ || !$pub_id ) ) {
46 $json_hash{error}="No publication exists for identifier $pub_id";
48 $self->set_json_hash(%json_hash);
49 $self->set_primary_key("pub_id");
52 $self->print_json() if $json_hash{error};
59 my $pub = $self->get_object();
60 my $pub_id = $self->get_object_id();
62 my %args = $self->get_args();
63 my %json_hash = $self->get_json_hash();
64 my $initial_pub_id = $pub_id;
69 $pub->set_title($args{title});
70 $pub->set_series_name($args{series});
71 $pub->set_volume($args{volume});
72 $pub->set_issue($args{issue});
73 $pub->set_pyear($args{pyear});
74 $pub->set_pages($args{pages});
75 $pub->set_abstract($args{abstract});
76 $pub->set_author_string($args{authors});
77 $pub->set_cvterm_name($args{cvterm_name});
83 $self->SUPER::store(); #this sets $json_hash{validate} if the form validation failed.
84 $pub_id = $pub->get_pub_id() ;
86 $error = " An error occurred. Cannot store to the database\n An email message has been sent to the SGN development team";
87 CXGN::Contact::send_email('pub_ajax_form.pl died', $error . "\n" . $_ , 'sgn-bugs@sgn.cornell.edu');
90 #the validate field is false is validation passed for all fields, true if did not pass and the form is re-printed
92 %json_hash= $self->get_json_hash();
93 $validate= $json_hash{validate};
94 $json_hash{error} = $error if $error;
96 my $refering_page="/publication/$pub_id/view";
97 $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});
98 $json_hash{refering_page}=$refering_page if !$initial_pub_id && !$validate && !$error;
100 $self->set_json_hash(%json_hash);
105 ####################################
108 my $check = $self->check_modify_privileges();
109 $self->print_json() if $check ; #error or no user privileges
111 my $pub = $self->get_object();
112 my $pub_id = $pub->get_pub_id;
115 my %json_hash= $self->get_json_hash();
116 my $refering_page="/publication/$pub_id/view";
119 if ($pub_id && !$json_hash{error} ) {
120 $pub_title = $pub->get_title;
123 $message = $pub->delete ;
124 $json_hash{error} = $message;
126 $json_hash{error} = " An error occurred. Cannot delete publication\n An email message has been sent to the SGN development team";
127 $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'});
129 $json_hash{reload} = 1;
132 $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});
133 $self->set_json_hash(%json_hash);
142 my $form_id = 'edit_pub'; # a form_id is required for ajax forms
144 $self->init_form($form_id) ; ## instantiate static/editable/confirmStore form
145 my $pub = $self->get_object();
146 my %args = $self->get_args();
147 my $form = $self->get_form();
148 my $type = $args{type};
149 my $type_id = $args{type_id};
150 my $refering_page= $args{refering_page};
152 my @types = qw |journal book curator |;
155 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');
157 if ($self->get_action =~ /new|edit/ ) {
159 display_name => "Publication type",
160 field_name => "cvterm_name",
161 contents => $pub->get_cvterm_name(),
164 getter => "get_cvterm_name",
165 setter => "set_cvterm_name",
166 select_list_ref => \@types,
167 select_id_list_ref => \@types,
171 display_name => "Title",
172 field_name => "title",
174 getter => "get_title",
175 setter => "set_title",
176 validate => 'string',
181 display_name => "Series name",
182 field_name => "series_name",
184 getter => "get_series_name",
185 setter => "set_series_name",
186 validate => 'string',
190 display_name => "Volume",
191 field_name => "volume",
193 getter => "get_volume",
194 setter => "set_volume",
197 display_name => "Issue",
198 field_name => "issue",
200 getter => "get_issue",
201 setter => "set_issue",
204 display_name => "Year",
205 field_name => "year",
207 getter => "get_pyear",
208 setter => "set_pyear",
209 validate => 'integer',
212 display_name => "Pages",
213 field_name => "pages",
215 getter => "get_pages",
216 setter => "set_pages",
217 validate => 'string',
220 display_name => $author_example,
221 field_name => "author",
223 getter => "get_authors_as_string",
224 setter => "set_author_string",
230 display_name => "Abstract",
231 field_name => "abstract",
233 getter => "get_abstract",
234 setter => "set_abstract",
240 field_name => "pub_id",
241 contents => $pub->get_pub_id(),
243 getter => "get_pub_id",
244 setter => "set_pub_id",
248 field_name => "type",
252 field_name => "type_id",
253 contents => $type_id,
256 field_name => "refering_page",
257 contents => $refering_page,
260 field_name => "action",
265 if ( $self->get_action() =~ /view|edit/ ) {
266 $form->from_database();
268 elsif ( $self->get_action() =~ /store/ ) {
269 my %json_hash = $self->get_json_hash() ;
270 print $json_hash{html} ;
271 $form->from_request( %args );