Merge pull request #5123 from solgenomics/topic/wishlist
[sgn.git] / mason / order / re_order_dialog.mas
blob9f2451f489e50e5695915bef7f4246a8ab2675d9
1 <%args>
3 $ordering_service_name => undef
4 $additional_order_info => undef
5 $ordering_type => undef
6 $order_properties => undef
7 $order_properties_dialog => undef
8 $order_values => undef
10 </%args>
12 <& /util/import_javascript.mas, classes => [ 'jquery.iframe-post-form', 'jquery', 'jquery.dataTables', 'CXGN.List'] &>
13 <& /util/import_css.mas, paths => ['/documents/inc/datatables/jquery.dataTables.css'] &>
15 <div class="modal fade" id="re_order_dialog" name="re_order_dialog" tabindex="-1" role="dialog" aria-labelledby="reOrderDialog">
16     <div class="modal-dialog modal-lg" role="document">
17         <div class="modal-content">
18             <div class="modal-header">
19                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
20                 <h4 class="modal-title" id="reOrderDialog">Ordering Information</h4>
21             </div>
22             <div class="modal-body">
23                 <div class="container-fluid">
24                     <div id="ordering_info_div">
25                     </div>
26                 </div>
27             </div>
28             <div class="modal-footer">
29                 <button id="close_re_order_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
30                 <button id="re_order_submit" type="button" class="btn btn-primary" >Submit</button>
31             </div>
32         </div>
33     </div>
34 </div>
36 <div class="modal fade" id="re_order_response_dialog" name="re_order_response_dialog" tabindex="-1" role="dialog" aria-labelledby="reOrderResponseDialog">
37     <div class="modal-dialog" role="document">
38         <div class="modal-content">
39             <div class="modal-header">
40                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
41                 <h4 class="modal-title" id="reOrderResponseDialog">Your Order</h4>
42             </div>
43             <div class="modal-body">
44                 <div class="container-fluid">
45                     <div id="re_order_response_div"></div>
46                 </div>
47             </div>
48             <div class="modal-footer">
49                 <button id="dismiss_re_order_response_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
50             </div>
51         </div>
52     </div>
53 </div>
57 <script>
59 jQuery(document).ready( function() {
60     var order_properties = "<% $order_properties %>";
61     var properties = order_properties.split(",");
62     properties.unshift("Item Name");
64     var order_values = "<% $order_values %>";
66     jQuery('#re_order_link').click(function(){
67         reOrderInfo(order_properties, order_values)
68     });
70     jQuery('#re_order_submit').click(function(){
71         var order_details = {};
72         var item_name = jQuery('#0').val();
73         for(var i=1; i<properties.length; i++){
74             var each_value = jQuery('#'+ i +'').val();
75             order_details[properties[i]] = each_value;
76         }
78         jQuery.ajax({
79             url: '/ajax/order/single_step_submission',
80             dataType: "json",
81             type: 'POST',
82             data : {
83                 'item_name' : item_name,
84                 'order_details': JSON.stringify(order_details),
85             },
86             beforeSend: function(response){
87                 jQuery('#working_modal').modal('show');
88             },
89             success: function(response) {
90                 jQuery('#working_modal').modal('hide');
91                 if (response.success) {
92                     jQuery('#re_order_response_div').html(response.success);
94                     jQuery('#re_order_response_dialog').modal('show');
95                     jQuery('#re_order_dialog').modal('hide');
96                 }
97                 if (response.error_string) {
98                     alert(response.error_string);
99                 }
100             },
101             error: function(response){
102                 jQuery('#working_modal').modal('hide');
103                 alert('An error occurred saving your request');
104             }
105         });
106     });
111 function reOrderInfo(order_properties, order_values){
112     var properties = order_properties.split(",");
113     properties.unshift("Item Name");
114     var values = order_values.split(",");
115     var html = '';
117     for(var i=0; i<properties.length; i++){
118         var each_property_info = properties[i].split(":");
119         if (each_property_info.length == 1) {
120             html = html + '<label class="col-sm-3 control-label">'+ properties[i] +'</label><div class="col-sm-9" ><input class="form-control" id= '+ i +' name= '+ i +' value="'+values[i]+'" ></div><br><br>';
121         } else {
122             html = html + '<label class="col-sm-3 control-label">'+ each_property_info[0] +'</label><div class="col-sm-9" ><select class="form-control" id= '+ i +' name= '+ i +'> ';
123             for (var j=1; j<each_property_info.length; j++) {
124                 html = html + "<option value='"+each_property_info[j]+"'>" + each_property_info[j] + "</option>";
125             }
126             html = html + "</select></div><br><br><br>";
127         }
128     }
129     html = html + '</div></div></form>';
131     jQuery('#ordering_info_div').html(html);
132     jQuery('#re_order_dialog').modal('show');
137 </script>