check if stock_dbxref exists before transferring new as it might violate a unique...
[sgn.git] / mason / tracking_activities / add_new_activity_project.mas
blob9f3a655ba5ea1c5e50a71cc46ad8c9cb7a92e633
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/><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                                             </select>
54                                         </div>
55                                     </div><br/><br/>
56                                     <div class="form-group">
57                                         <label class="col-sm-3 control-label">Breeding Program: </label>
58                                         <div class="col-sm-9">
59                                             <select class="form-control" id="activity_project_program" name="activity_project_program">
60                                                 <option value="">Select Breeding Program</option>
61 <%perl>
62 foreach my $program (@$programs) {
63     if (@$program[3]) {
64         print "<option selected=\"selected\" value='".@$program[0]."'>".@$program[1]."</option>";
65     } else {
66         print "<option value='".@$program[0]."'>".@$program[1]."</option>";
67     }
69 </%perl>
70                                             </select>
71                                         </div>
72                                     </div><br/><br/>
73                                     <div class="form-group">
74                                         <label class="col-sm-3 control-label">Location of this project: </label>
75                                         <div class="col-sm-9">
76                                             <select class="form-control" id="activity_project_location" name="activity_project_location">
77                                                 <option value="">Select Location</option>
78 <%perl>
79     foreach my $location_hashref (@$locations) {
80         my $properties = $location_hashref->{'properties'};
81         my $program = $properties->{'Program'};
82         my $name = $properties->{'Name'};
83         print "<option value=\"$name\" data-program=\"$program\">".$name."</option>";
84     }
85 </%perl>
86                                             </select>
87                                         </div>
88                                     </div><br/><br/>
89                                     <div class="form-group">
90                                         <label class="col-sm-3 control-label">Year:</label>
91                                         <div class="col-sm-9">
92                                             <div id="activity_project_year" name="activity_project_year" ></div>
93                                         </div>
94                                     </div><br/><br/>
95                                     <div class="form-group">
96                                         <label class="col-sm-3 control-label">Description:</label>
97                                         <div class="col-sm-9">
98                                             <textarea class="form-control" id="activity_project_description" name="activity_project_description" ></textarea>
99                                         </div>
100                                     </div>
101                                 <br/>
102                                 <br/>
103                                 <br/>
104                                 <center>
105                                     <button type="button" class="btn btn-primary" onclick="Workflow.complete(this, false);" name="create_activity_project_submit" id="create_activity_project_submit">Submit</button>
106                                 </center>
107                             </&>
108                         </form>
110                         <&| /util/workflow.mas:complete, title=> "Complete" &>
111                             <& /page/page_title.mas, title=>"Your project is now in the database" &>
112                             <ul>
113                                 <center><li>Please use "Generate Tracking Identifiers" link on your tracking activities project page to generate tracking identifiers for each project.</li></center>
114                             </ul>
115                             <br/>
116                         </&>
117                     </&><!-- End of workflow -->
118                 </div>
119             </div>
120             <div class="modal-footer">
121                 <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>
122             </div>
123         </div>
124     </div>
125 </div>
127 <script>
129 jQuery(document).ready(function(){
131     var selectedProgram = jQuery('#activity_project_program option:selected').text()
133     filter_options(selectedProgram, 'program', 'activity_project_location');
135     jQuery('#activity_project_program').change(function() {
136         filter_options(jQuery('#activity_project_program option:selected').text(), 'program', 'activity_project_location');
137     });
139     jQuery("[name='add_activity_project_dismiss_button']").click(function() {
140         jQuery('#create_activity_project_dialog').modal('hide');
141         jQuery('#activity_project_name').val('');
142         jQuery('#activity_project_program').val('');
143         jQuery('#activity_project_location').val('');
144         jQuery('#activity_project_project_year').val('');
145         jQuery('#activity_project_description').val('');
146     });
148     jQuery('#create_activity_project_submit').click(function() {
149         var project_name = jQuery("#activity_project_name").val();
150         if (!project_name) {
151             alert("Project name is required");
152             return;
153         }
155         var activity_type = jQuery("#activity_type").val();
156         if (!activity_type) {
157             alert("Activity type is required");
158             return;
159         }
161         var breeding_program = jQuery("#activity_project_program").val();
162         if (!breeding_program) {
163             alert("Breeding program is required");
164             return;
165         }
167         var project_location = jQuery("#activity_project_location").val();
168         if (!project_location) {
169             alert ("Location is required");
170             return;
171         }
173         var year = jQuery("#activity_project_year_select").val();
174         if (!year) {
175             alert ("Year is required");
176             return;
177         }
179         var project_description = jQuery("#activity_project_description").val();
180         if (!project_description) {
181             alert ("Description is required");
182             return;
183         }
185         jQuery.ajax({
186             url: '/ajax/tracking_activity/create_tracking_activity_project',
187             dataType: "json",
188             type: 'POST',
189             data : {
190                 'project_name' : project_name,
191                 'activity_type': activity_type,
192                 'breeding_program': breeding_program,
193                 'project_location': project_location,
194                 'year': year,
195                 'project_description': project_description
196             },
197             beforeSend: function(response){
198                 jQuery('#working_modal').modal('show');
199             },
200             success: function(response) {
201                 if (response.error) {
202                     jQuery('#working_modal').modal('hide');
203                     alert(response.error);
204                 } else {
205                     refreshActivityJsTree(0);
206                     Workflow.focus("#add_tracking_activity_project_workflow", -1); //Go to success page
207                     Workflow.check_complete("#add_tracking_activity_project_workflow");
208                     jQuery('#working_modal').modal('hide');
209                 }
210             },
211             error: function(response){
212                 jQuery('#working_modal').modal('hide');
213                 alert('An error occurred saving new tracking activities project');
214             }
215         });
216     });
220 </script>