4242
4343< body >
4444 < h1 > Batch Cloning Gene List</ h1 >
45- < form action =" /batch_cloning " method =" post " enctype =" multipart/form-data " >
45+ < form >
4646 < label for ="gene_list "> Enter your list of genes (one gene per line):</ label > < br >
4747 < textarea id ="gene_list " name ="gene_list " required > SPAPB1A10.09
4848SPBC15D4.01c</ textarea > < br >
@@ -68,7 +68,7 @@ <h1>Batch Cloning Gene List</h1>
6868
6969 < div id ="addgene_input ">
7070 < label for ="addgene_id "> AddGene Identifier:</ label > < br >
71- < input value ="39296 " type ="text " id ="addgene_id " name ="addgene_id "> < br > < br >
71+ < input value ="19343 " type ="text " id ="addgene_id " name ="addgene_id "> < br > < br >
7272 </ div >
7373
7474 < div >
@@ -106,7 +106,10 @@ <h1>Batch Cloning Gene List</h1>
106106 </ div >
107107
108108 < br >
109- < input type ="submit " value ="Submit ">
109+ < input type ="submit " value ="Submit " id ="submit-button ">
110+ < div id ="loading-message " style ="display: none; ">
111+ Processing request, please wait...
112+ </ div >
110113 < script >
111114 function togglePlasmidInput ( ) {
112115 var selectedOption = document . querySelector ( 'input[name="plasmid_option"]:checked' ) . value ;
@@ -133,6 +136,53 @@ <h1>Batch Cloning Gene List</h1>
133136 window . onload = ( ) => {
134137 togglePrimerCheck ( ) ;
135138 togglePlasmidInput ( ) ;
139+
140+ // Add form submit handler
141+ document . querySelector ( 'form' ) . addEventListener ( 'submit' , async function ( e ) {
142+ e . preventDefault ( ) ; // Prevent default form submission
143+
144+ document . getElementById ( 'submit-button' ) . style . display = 'none' ;
145+ document . getElementById ( 'loading-message' ) . style . display = 'block' ;
146+
147+ try {
148+ const formData = new FormData ( this ) ;
149+ const response = await fetch ( '/batch_cloning' , {
150+ method : 'POST' ,
151+ body : formData
152+ } ) ;
153+
154+ if ( ! response . ok ) {
155+ throw new Error ( ( await response . json ( ) ) . detail ) ;
156+ }
157+
158+ // Get the filename from the Content-Disposition header if available
159+ const contentDisposition = response . headers . get ( 'Content-Disposition' ) ;
160+ let filename = 'batch_cloning_results.zip' ;
161+ if ( contentDisposition ) {
162+ const filenameMatch = contentDisposition . match ( / f i l e n a m e = " ? ( [ ^ " ] + ) " ? / ) ;
163+ if ( filenameMatch ) {
164+ filename = filenameMatch [ 1 ] ;
165+ }
166+ }
167+
168+ // Convert the response to a blob and download it
169+ const blob = await response . blob ( ) ;
170+ const url = window . URL . createObjectURL ( blob ) ;
171+ const a = document . createElement ( 'a' ) ;
172+ a . href = url ;
173+ a . download = filename ;
174+ document . body . appendChild ( a ) ;
175+ a . click ( ) ;
176+ window . URL . revokeObjectURL ( url ) ;
177+ document . body . removeChild ( a ) ;
178+ } catch ( error ) {
179+ console . error ( 'Error:' , error ) ;
180+ alert ( error . message ) ;
181+ } finally {
182+ document . getElementById ( 'submit-button' ) . style . display = 'block' ;
183+ document . getElementById ( 'loading-message' ) . style . display = 'none' ;
184+ }
185+ } ) ;
136186 }
137187 </ script >
138188 </ form >
0 commit comments