transformation project deletion section
[sgn.git] / mason / order / add_catalog_item_dialog.mas
blob976ec58f30945b9929f2ed05c50d5235b6623965
1 <%args>
2 $timestamp => localtime()
3 $ordering_type => undef
4 </%args>
6 <div class="modal fade" id="add_catalog_item_dialog" name="add_catalog_item_dialog" tabindex="-1" role="dialog" aria-labelledby="addCatalogItemDialog">
7     <div class="modal-dialog modal-lg" role="document">
8         <div class="modal-content">
9             <div class="modal-header">
10                 <h4 class="modal-title" id="addCatalogItemDialog">Add New Catalog Item</h4>
11             </div>
12             <div class="modal-body" id = "catalog_dialog">
13                 <div class="container-fluid">
14                     <form class="form-horizontal" role="form" method="post" id="add_new_catalog_item_form" name="add_new_catalog_form">
15                         <div class="form-group" id = "get_item_name">
16                             <label class="col-sm-3 control-label">Item Name: </label>
17                             <div class="col-sm-9" >
18                                 <input class="form-control" type="text" id="item_name" name="item_name" placeholder="Item name must be in the database">
19                             </div>
20                         </div>
21                         <div class="form-group">
22                             <label class="col-sm-3 control-label">Category: </label>
23                             <div class="col-sm-9">
24                                 <select class="form-control" id="item_category">
25                                     <option value="">Please select a category</option>
26                                     <option value="released variety">released variety</option>
27                                     <option value="pathogen assay ">pathogen assay</option>
28                                     <option value="control">control</option>
29                                     <option value="transgenic line">transgenic line</option>
30                                 </select>
31                             </div>
32                         </div>
33                         <div class="form-group">
34                             <label class="col-sm-3 control-label">Additional Info: </label>
35                             <div class="col-sm-9" >
36                                 <input class="form-control" id="item_additional_info" placeholder="optional">
37                             </div>
38                         </div>
39                         <div class="form-group">
40                             <label class="col-sm-3 control-label">Material Source: </label>
41                             <div class="col-sm-9" >
42                                 <input class="form-control" id="item_material_source" placeholder="optional">
43                             </div>
44                         </div>
45                         <div class="form-group">
46                             <label class="col-sm-3 control-label">Breeding Program: </label>
47                             <div class="col-sm-9" >
48                                 <div id="item_breeding_program_div"></div>
49                             </div>
50                         </div>
51                         <div class="form-group">
52                             <label class="col-sm-3 control-label">Contact Person Username: </label>
53                             <div class="col-sm-9" >
54                                 <input class="form-control" id="contact_person_name" placeholder="Please provide contact person username">
55                             </div>
56                         </div>
57                     </div>
58                 </div>
59                 <div class="modal-footer">
60                     <button type="reset" id="close_add_item_dialog" name="close_add_item_dialog" class="btn btn-default" >Close</button>
61                     <button id="submit_catalog_item" type="button" class="btn btn-primary" >Add</button>
62                 </div>
63             </form>
64         </div>
65     </div>
66 </div>
68 <div class="modal fade" id="add_item_saved_dialog_message" name="add_item_saved_dialog_message" tabindex="-1" role="dialog" aria-labelledby="addItemSavedDialog">
69     <div class="modal-dialog" role="document">
70         <div class="modal-content">
71             <div class="modal-header">
72                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
73                 <h4 class="modal-title" id="addItemSavedDialog">Success</h4>
74             </div>
75             <div class="modal-body">
76                 <div class="container-fluid">
77                     <p>
78                         <span class="ui-icon ui-icon-circle-check" style="float: left; margin: 0 7px 50px 0;"></span>
79                         The catalog item was saved successfully.
80                     </p>
81                 </div>
82             </div>
83             <div class="modal-footer">
84                 <button id="dismiss_item_saved_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close & Reload</button>
85             </div>
86         </div>
87     </div>
88 </div>
91 <script>
92 jQuery(document).ready(function(){
94     jQuery("#add_catalog_item_button").click( function() {
96         jQuery("#item_name").autocomplete({
97             source: '/ajax/stock/accession_or_seedlot_or_population_or_vector_construct_autocomplete',
98             appendTo : catalog_dialog
99         });
101         jQuery('#add_catalog_item_dialog').modal('show');
102         get_select_box('breeding_programs', 'item_breeding_program_div', { 'name' : 'item_breeding_program_id', 'id' : 'item_breeding_program_id', 'empty': 1 });
104     });
106     jQuery('#submit_catalog_item').click( function() {
107         var name = jQuery('#item_name').val();
108         var category = jQuery('#item_category').val();
109         var additional_info = jQuery('#item_additional_info').val();
110         var material_source = jQuery('#item_material_source').val();
111         var breeding_program = jQuery('#item_breeding_program_id').val();
112         var contact_person = jQuery('#contact_person_name').val();
114         if (name == '') {
115             alert("Please provide a name");
116             return;
117         }
118         if (category == '') {
119             alert("Please select a category");
120             return;
121         }
122         if (breeding_program == '') {
123             alert("Please select a program");
124             return;
125         }
126         if (contact_person == '') {
127             alert("Please provide contact username");
128             return;
129         }
131         jQuery.ajax({
132             url: '/ajax/catalog/add_item',
133             dataType: "json",
134             type: 'POST',
135             data : {
136                 'name' : name,
137                 'category': category,
138                 'additional_info': additional_info,
139                 'material_source': material_source,
140                 'breeding_program_id': breeding_program,
141                 'contact_person': contact_person,
142             },
143             beforeSend: function(response){
144                 jQuery('#working_modal').modal('show');
145             },
146             success: function(response) {
147                 jQuery('#working_modal').modal('hide');
148                 if (response.success == 1) {
149                     jQuery('#add_catalog_item_dialog').modal('hide');
150                     jQuery('#add_item_saved_dialog_message').modal("show");
151                 }
152                 if (response.error_string) {
153                     alert(response.error_string);
154                 }
155             },
156             error: function(response){
157                 jQuery('#working_modal').modal('hide');
158                 alert('An error occurred adding item');
159             }
160         });
161     });
163     jQuery("#close_add_item_dialog").click(function() {
164         jQuery("#add_catalog_item_dialog").modal('hide');
165         location.reload();
166     });
168     jQuery("#dismiss_item_saved_dialog").click(function(){
169         location.reload();
170     });
174 </script>