Merge pull request #5243 from solgenomics/topic/observations_upload_catch_error
[sgn.git] / mason / tracking_activities / add_new_activity_project.mas
blobe5d780da6d28f7b61f9383cca6401d25a18b9aec
1 <%args>
2 $programs
3 $locations
4 </%args>
7 <& /util/import_javascript.mas, classes => ['CXGN.TrialTreeFolders'] &>
9 <div class="modal fade" id="create_activity_project_dialog" name="create_activity_project_dialog" tabindex="-1" role="dialog" aria-labelledby="createActivityProjectDialog">
10     <div class="modal-dialog modal-xl" role="document">
11         <div class="modal-content ui-front">
12             <div class="modal-header">
13                 <button type="reset" class="close" id="add_activity_project_dismiss_button_1" name="add_activity_project_dismiss_button" aria-label="Close"><span aria-hidden="true">&times;</span></button>
14                 <center><h4 class="modal-title" id="creatActivityProjectDialog">Add New Tracking Activities Project</h4></center>
15             </div>
16             <div class="modal-body">
17                 <div class="container-fluid">
19                     <&| /util/workflow.mas, id=> "add_tracking_activity_project_workflow" &>
20                         <&| /util/workflow.mas:step, title=> "Intro" &>
21                             <& /page/page_title.mas, title=>"Tracking Activities Tool" &>
22                             <p>You can use tracking tool to track and record activity information related to materials stored in the database (i.e. tracking tissue culture process of an accession). Data types of each process can be customized (please contact us).</p>
23                             <ul>
24                                 <li>Tracking identifier is a globally unique name assigned to each material for capturing tracking information.</li>
25                                 <li>Tracking identifiers are organized using Tracking Activities projects</li>
26                                 <li>You can generate tracking identifiers by using a link on the Tracking Activities project page</li>
27                                 <li>Record page allows you to record inputs of different data types. The link can be found on the project page. To record new information, you can retrieve any tracking identifier by scanning a barcode.</li>
28                                 <li>Each tracking identifier has its own details page. In addition to the record page, you can record data directly using this details page. Tracking Identifier details page displays details of each data entry including an input, operator and timestamp as well as a summary of multiple entries of the same data type</li>
29                                 <li>If you would like to track preparation process for requested items from ordering tool, ordering tool can be connected with tracking tool (please contact us).</li>
30                             </ul>
31                             <hr>
32                             <center>
33                                 <button id="next_step_add_new_project" class="btn btn-primary" onclick="Workflow.complete(this);">Go to Next Step</button>
34                             </center>
35                         </&>
37                         <form class="form-horizontal" role="form" name="create_activity_project_form" id="create_activity_project_form">
38                             <&| /util/workflow.mas:step, title=> "Add project info" &>
39                                 <& /page/page_title.mas, title=>"Enter basic information about the project" &>
40                                     <br/>
41                                     <div class="form-group">
42                                         <label class="col-sm-3 control-lable">Project Name: </label>
43                                         <div class="col-sm-9">
44                                             <input class="form-control" type="text" id="activity_project_name" name="activity_project_name"  />
45                                         </div>
46                                     </div><br/>
47                                     <div class="form-group">
48                                         <label class="col-sm-3 control-label">Activity Type: </label>
49                                         <div class="col-sm-9">
50                                             <select class="form-control" id="activity_type" name="activity_type">
51                                                 <option value="">Select an activity type</option>
52                                                 <option value="tissue_culture">Tissue Culture</option>
53                                                 <option value="transformation">Transformation</option>                                                
54                                             </select>
55                                         </div>
56                                     </div><br/>
57                                     <div class="form-group">
58                                         <label class="col-sm-3 control-label">Breeding Program: </label>
59                                         <div class="col-sm-9">
60                                             <select class="form-control" id="activity_project_program" name="activity_project_program">
61                                                 <option value="">Select Breeding Program</option>
62 <%perl>
63 foreach my $program (@$programs) {
64     if (@$program[3]) {
65         print "<option selected=\"selected\" value='".@$program[0]."'>".@$program[1]."</option>";
66     } else {
67         print "<option value='".@$program[0]."'>".@$program[1]."</option>";
68     }
70 </%perl>
71                                             </select>
72                                         </div>
73                                     </div><br/>
74                                     <div class="form-group">
75                                         <label class="col-sm-3 control-label">Location of this project: </label>
76                                         <div class="col-sm-9">
77                                             <select class="form-control" id="activity_project_location" name="activity_project_location">
78                                                 <option value="">Select Location</option>
79 <%perl>
80     foreach my $location_hashref (@$locations) {
81         my $properties = $location_hashref->{'properties'};
82         my $program = $properties->{'Program'};
83         my $name = $properties->{'Name'};
84         print "<option value=\"$name\" data-program=\"$program\">".$name."</option>";
85     }
86 </%perl>
87                                             </select>
88                                         </div>
89                                     </div><br/>
90                                     <div class="form-group">
91                                         <label class="col-sm-3 control-label">Year:</label>
92                                         <div class="col-sm-9">
93                                             <div id="activity_project_year" name="activity_project_year" ></div>
94                                         </div>
95                                     </div><br/>
96                                     <div class="form-group">
97                                         <label class="col-sm-3 control-label">Description:</label>
98                                         <div class="col-sm-9">
99                                             <textarea class="form-control" id="activity_project_description" name="activity_project_description" ></textarea>
100                                         </div>
101                                     </div>
102                                 <br/>
103                                 <br/>
104                                 <br/>
105                                 <center>
106                                     <button type="button" class="btn btn-primary" onclick="Workflow.complete(this, false);" name="create_activity_project_submit" id="create_activity_project_submit">Submit</button>
107                                 </center>
108                             </&>
109                         </form>
111                         <&| /util/workflow.mas:complete, title=> "Complete" &>
112                             <& /page/page_title.mas, title=>"Your project is now in the database" &>
113                             <ul>
114                                 <center><li>Please use "Generate Tracking Identifiers" link on your tracking activities project page to generate tracking identifiers for each project.</li></center>
115                             </ul>
116                             <br/>
117                         </&>
118                     </&><!-- End of workflow -->
119                 </div>
120             </div>
121             <div class="modal-footer">
122                 <button id="add_activity_project_dismiss_button_2" name="add_activity_project_dismiss_button" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
123             </div>
124         </div>
125     </div>
126 </div>
128 <script>
130 jQuery(document).ready(function(){
132     var selectedProgram = jQuery('#activity_project_program option:selected').text()
134     filter_options(selectedProgram, 'program', 'activity_project_location');
136     jQuery('#activity_project_program').change(function() {
137         filter_options(jQuery('#activity_project_program option:selected').text(), 'program', 'activity_project_location');
138     });
140     jQuery("[name='add_activity_project_dismiss_button']").click(function() {
141         jQuery('#create_activity_project_dialog').modal('hide');
142         jQuery('#activity_project_name').val('');
143         jQuery('#activity_project_program').val('');
144         jQuery('#activity_project_location').val('');
145         jQuery('#activity_project_project_year').val('');
146         jQuery('#activity_project_description').val('');
147     });
149     jQuery('#create_activity_project_submit').click(function() {
150         var project_name = jQuery("#activity_project_name").val();
151         if (!project_name) {
152             alert("Project name is required");
153             return;
154         }
156         var activity_type = jQuery("#activity_type").val();
157         if (!activity_type) {
158             alert("Activity type is required");
159             return;
160         }
162         var breeding_program = jQuery("#activity_project_program").val();
163         if (!breeding_program) {
164             alert("Breeding program is required");
165             return;
166         }
168         var project_location = jQuery("#activity_project_location").val();
169         if (!project_location) {
170             alert ("Location is required");
171             return;
172         }
174         var year = jQuery("#activity_project_year_select").val();
175         if (!year) {
176             alert ("Year is required");
177             return;
178         }
180         var project_description = jQuery("#activity_project_description").val();
181         if (!project_description) {
182             alert ("Description is required");
183             return;
184         }
186         jQuery.ajax({
187             url: '/ajax/tracking_activity/create_tracking_activity_project',
188             dataType: "json",
189             type: 'POST',
190             data : {
191                 'project_name' : project_name,
192                 'activity_type': activity_type,
193                 'breeding_program': breeding_program,
194                 'project_location': project_location,
195                 'year': year,
196                 'project_description': project_description
197             },
198             beforeSend: function(response){
199                 jQuery('#working_modal').modal('show');
200             },
201             success: function(response) {
202                 if (response.error) {
203                     jQuery('#working_modal').modal('hide');
204                     alert(response.error);
205                 } else {
206                     refreshActivityJsTree(0);
207                     Workflow.focus("#add_tracking_activity_project_workflow", -1); //Go to success page
208                     Workflow.check_complete("#add_tracking_activity_project_workflow");
209                     jQuery('#working_modal').modal('hide');
210                 }
211             },
212             error: function(response){
213                 jQuery('#working_modal').modal('hide');
214                 alert('An error occurred saving new tracking activities project');
215             }
216         });
217     });
221 </script>