5 my $image_ajax_form = CXGN
::ImageAjaxForm
->new();
7 package CXGN
::ImageAjaxForm
;
9 use CatalystX
::GlobalContext
'$c';
11 use base
"CXGN::Page::Form::AjaxFormPage";
20 my %json_hash = $self->get_json_hash();
22 # call set_object_id, set_object and set_primary_key here
23 # with the appropriate parameters.
25 my %args = $self->get_args();
27 if ( !exists( $args{object_id
} ) ) {
28 $json_hash{error
} = "No object_id provided";
31 $self->set_object_name('image');
32 $self->set_object_id( $args{object_id
} );
34 SGN
::Image
->new( $self->get_dbh(), $self->get_object_id(), $c ) );
35 $self->set_primary_key("object_id");
36 $self->set_owners( $self->get_object()->get_sp_person_id() );
37 $self->set_json_hash(%json_hash);
43 my $form_id = 'image_form';
44 my %args = $self->get_args();
46 $self->init_form($form_id);
47 my $form = $self->get_form();
49 my $image = $self->get_object();
50 my $object_id = $self->get_object_id();
51 my $submitter = CXGN
::People
::Person
->new( $self->get_dbh(), $image->get_sp_person_id() );
52 my $sp_person_id = $submitter->get_sp_person_id();
53 my $submitter_name = ($submitter->get_first_name() || '') . " " . ($submitter->get_last_name() || '');
54 my $submitter_link = qq |<a href
="/solpeople/personal-info.pl?sp_person_id=$sp_person_id">$submitter_name </a
> |;
59 if ( $self->get_action() =~ /view|edit/i ) {
60 $name = $image->get_name();
61 $description = $image->get_description();
63 if ( $self->get_action() =~ /edit/i ) {
64 $name ||= $args{name
};
65 $description ||= $args{description
};
67 if ( $self->get_action() =~ /store/i ) {
69 $description = $args{description
};
73 display_name
=> "Image Name:",
82 display_name
=> "Image Description: ",
83 field_name
=> "description",
84 contents
=> $description,
87 getter
=> "get_description",
88 setter
=> "set_description"
91 display_name
=> "Image ID",
92 field_name
=> "object_id",
93 contents
=> $object_id
96 display_name
=> "Action",
97 field_name
=> "action",
101 display_name
=> "Uploaded by: ",
102 field_name
=> "submitter",
103 contents
=> $submitter_link,
105 $self->set_form($form);
112 $self->check_modify_privileges
113 or $self->print_json;
116 my %json = $self->get_json_hash;
119 $self->get_object->delete;
122 $json{error
} = "Deletion failed ($_)";
125 #$self->set_json_hash( %json );
133 my $image = $self->get_object();
134 my $image_id = $self->get_object_id();
135 my %args = $self->get_args();
136 my %json_hash = $self->get_json_hash();
139 $self->SUPER::store
(); #this sets $json_hash{validate} if the form validation failed.
140 $image_id = $image->get_image_id;
142 $error = " An error occurred. Cannot store to the database\n An email message has been sent to the SGN development team";
143 CXGN
::Contact
::send_email
('image_ajax_form.pl died', $error . "\n" . $_ , 'sgn-bugs@sgn.cornell.edu');
145 #the validate field is false is validation passed for all fields, true if did not pass and the form is re-printed
147 %json_hash= $self->get_json_hash();
148 my $validate= $json_hash{validate
};
149 $json_hash{error
} = $error if $error;
151 my $refering_page="/image/index.pl?image_id=$image_id";
152 $self->send_form_email({subject
=>"[New image details stored] image $image_id", mailing_list
=>'sgn-db-curation@sgn.cornell.edu', refering_page
=>"www.solgenomics.net".$refering_page}) if (!$validate && !$json_hash{error
});
153 $json_hash{refering_page
}=$refering_page if !$validate && !$error;
155 $self->set_json_hash(%json_hash);