Merge pull request #5248 from solgenomics/topic/batch_update_trials
[sgn.git] / mason / stock / upload_additional_accessions_file.mas
blob51429567e38a7147e446978812b3c24e50d7a2c1
1 <%args>
2 $stock_id
3 </%args>
5 <& /util/import_javascript.mas, classes => [ 'jquery.iframe-post-form' ] &>
7 <div id="stock_additional_uploaded_files_div">
8 [Loading...]
9 </div>
11 <div class="modal fade" id="accession_upload_additional_file_dialog" name="stock_upload_additional_file_dialog" tabindex="-1" role="dialog" aria-labelledby="stockUploadAdditionalFileDialog">
12     <div class="modal-dialog" role="document">
13         <div class="modal-content">
14             <div class="modal-header">
15                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
16                 <h4 class="modal-title" id="stockUploadAdditionalFileDialog">Upload Additional File to Accession</h4>
17             </div>
18             <div class="modal-body">
19                 <div class="container-fluid">
20                     <&| /page/explanation.mas, title=>'Template information' &>
21                         <p>
22                             <b>File upload information</b>
23                             <br>
24                             <a id="accession_upload_additional_file_format">Upload Information</a>
25                         </p>
26                     </&>
28                     <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" encoding="multipart/form-data" id="accession_upload_additional_file_form" name="accession_upload_additional_file_form">
30                         <div class="form-group">
31                             <label class="col-sm-4 control-label">Upload File: </label>
32                             <div class="col-sm-8" >
33                                 <input type="file" name="accession_upload_additional_file" id="accession_upload_additional_file" encoding="multipart/form-data" />
34                             </div>
35                         </div>
37                     </form>
38                 </div>
39             </div>
40             <div class="modal-footer">
41                 <button type="button" class="btn btn-default" name="accession_upload_additional_file_cancel_button" id="accession_upload_additional_file_cancel_button"     data-dismiss="modal">Close</button>
42                 <button type="button" class="btn btn-primary" name="accession_upload_additional_file_submit_button" id="accession_upload_additional_file_submit_button" title="Submit">Submit</button>
43             </div>
44         </div>
45     </div>
46 </div>
48 <div class="modal fade" id="accession_upload_additional_file_info_dialog" name="accession_upload_additional_file_info_dialog" tabindex="-1" role="dialog" aria-labelledby="stockUploadAdditionalFileInfoDialog">
49     <div class="modal-dialog modal-lg" role="document">
50         <div class="modal-content">
51             <div class="modal-header" style="text-align: center">
52                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
53                 <h4 class="modal-title" id="stockUploadAdditionalFileInfoDialog">Upload Information</h4>
54             </div>
55             <div class="modal-body">
56                 <div class="container-fluid">
57                     <b>This is for uploading any additional files you may have for the accession.</b>
58                     <br/><br/>
59                     <p>Possible additional files inlude, but are not limited to:</p>
60                     <ul>
61                         <li>Accession Related Images, such as a physical field image or an aerial picture of the field.</li>
62                         <li>Accession Related Documentation, such as protocols or permits for the accession.</li>
63                         <li>Accession Related Reports, such as supplementary information or publications.</li>
64                         <li>Accession Related Recordings, whether audio or video.</li>
65                     </ul>
66                 </div>
67             </div>
68             <div class="modal-footer">
69                 <button id="close_accession_upload_additional_file_info_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
70             </div>
71         </div>
72     </div>
73 </div>
75 <script>
77     jQuery(document).ready(function(){
79         display_stock_additional_upload_files();
81         jQuery('#accession_upload_additional_files_link').click( function(){
82             jQuery('#accession_upload_additional_file_dialog').modal('show');
83         });
85         jQuery('#accession_upload_additional_file_format').click( function(){
86             jQuery('#accession_upload_additional_file_info_dialog').modal('show');
87         });
89         jQuery('#accession_upload_additional_file_submit_button').click(function () {
91             var uploadFile = jQuery("#accession_upload_additional_file").val();
93             if (uploadFile === '') {
94                 alert("Please select a file");
95                 return;
96             }
97             jQuery('#accession_upload_additional_file_form').attr("action", "/stock/"+<% $stock_id %>+"/upload_additional_file");
98             jQuery("#accession_upload_additional_file_form").submit();
99         });
101         jQuery('#accession_upload_additional_file_form').iframePostForm({
102             json: false,
103             post: function () {
104                 console.log("Responseeee" , "response");
105                 jQuery('#working_modal').modal("show");
106             },
107             complete: function (r) {
108                 var clean_r = r.replace(/^<pre[^>]*>/, '');
109                 clean_r = clean_r.replace('</pre>', '');
110                 response = JSON.parse(clean_r);
112                 jQuery('#working_modal').modal("hide");
114                 if (response.error) {
115                     alert(response.error);
116                     return;
117                 }
118                 if (response.error_string) {
119                     alert(response.error_string);
120                     return;
121                 }
122                 if (response.success) {
123                     alert("File uploaded successfully");
124                     location.reload();
125                 }
126             }
127         });
130         function display_stock_additional_upload_files (){
131             jQuery.ajax ({
132                 url : '/stock/'+<% $stock_id %>+'/get_uploaded_additional_file',
133                 beforeSend : function(){
134                     jQuery('#stock_additional_uploaded_files_div').html("[LOADING...]");
135                 },
136                 success: function(response){
137                     console.log("response" ,response);
138                     var html = "<table class='table table-hover table-condensed table-bordered' id='stock_additional_uploaded_files_table'><thead><tr><th>Filename</th><th>Date Uploaded</th><th>Uploaded By</th><th>Options</th></tr></thead><tbody>";
139                     for (i=0; i<response.files.length; i++) {
140                         html = html + '<tr><td>'+response.files[i][4]+'</td><td>'+response.files[i][1]+'</td><td><a href="/solpeople/profile/'+response.files[i][2]+'">'+response.files[i][3]+'</a></td><td><a href="/breeders/phenotyping/download/'+response.files[i][0]+'">Download</a> </td></tr>';
141                     }
142                     html = html + "</tbody></table>";
143                     jQuery('#stock_additional_uploaded_files_div').html(html);
144                     jQuery('#stock_additional_uploaded_files_table').DataTable();
145                 },
146                 error: function(response){
147                     alert("Error retrieving additional uploaded files.");
148                 }
149             });
150         }                          
153         function obsolete_additional_file(stock_id, file_id) {
154             var yes = confirm('Are you sure you want to obsolete this file? This operation cannot be undone.');
155             if (yes) {
156                 jQuery.ajax({
157                     url: '/stock/'+stock_id+'/obsolete_uploaded_additional_file/'+file_id,
158                     success: function(r) {
159                         if (r.error) { alert(r.error); }
160                         else {
161                             jQuery('#stock_additional_uploaded_files_table').DataTable().clear().draw();
162                             alert("The file has been obsoleted.");
163                         }
164                     },
165                     error: function(r) {  alert("An error occurred!") }
166                 });
167             }
168         }
172 });                      
173 </script>