function init() { document.getElementById('hmnow').value = 0; } // the application path is stored in the javascript variable : contextPath // console.log("DEBUG : main js : contextPath = " + contextPath); // Variable for holding the file list. var fileList = []; // Send the file URL or the text from the text area where users can paste an SBML file. function submitForm(){ console.log( "file_upload:submitForm called !!" ); const fileListStr = fileList.toString(); console.log( "fileList for ajax query: " + fileListStr); // Making the Ajax call to send url or copy/paste model and launch the conversion jobs $.ajax({ // The URL for the request url: "launchjobs", // The data to send (will be converted to a query string) data: { sessionId: document.getElementById('sessionId').value, inputModelType: encodeURIComponent(document.getElementById('input').value), converterType: encodeURIComponent(document.getElementById('select_convert').value), url_upload: encodeURIComponent(document.getElementById('url_upload').value), text_upload: encodeURIComponent(document.getElementById('text_upload').value), files: fileListStr }, // Set to false if the request should be sent synchronously. async: true, // Whether this is a POST or GET request type: "POST", // The type of data we expect back dataType : "html", // Code to run if the request succeeds; // the response is passed to the function done: function( ) { console.log( "The launchjobs request is done successfully!" ); }, // Code to run if the request fails; the raw request and // status codes are passed to the function fail: function( xhr, status, errorThrown ) { console.log( "Sorry, there was a problem!" ); console.log( "Error: " + errorThrown ); console.log( "Status: " + status ); console.dir( xhr ); }, // Code to run regardless of success or failure always: function( xhr, status ) { console.log("launchjobs always called"); }, success: function(data) { console.log("DATA: " + data); const json = JSON.parse(data); redirectToResults(json["sessionId"]); } }); } function redirectToResults(sessionId){ // redirecting to the result page const resultURL = contextPath + "/results?sessionId=" + sessionId; // console.log("View the conversion results at: " + resultURL); document.location.href = resultURL; // reset the list of files and the table displaying it. fileList.length = 0; $("#uploaderContainer tr:has(td)").remove(); } /* It checks the form. It returns true if the form fields are not empty, false otherwise. */ function checkForm() { console.log("DEBUG : Step 1 : document.getElementById('input').value : " + document.getElementById('input').value); if(document.getElementById('input').value == "" || document.getElementById('input').value == "not_selected") { alert("Error: you must specify your input file format. See Step 1."); return false; } console.log("DEBUG : Step 2 : document.getElementById('select_convert').value : " + document.getElementById('select_convert').value); if(document.getElementById('select_convert').value == "" || document.getElementById('select_convert').value == "not_selected") { alert("Error: you must specify your output file format. See Step 2."); return false; } console.log("DEBUG : Step 4a : fileList.toString() : " + fileList.toString()); console.log("DEBUG : Step 4b : document.getElementById('url_upload').value : " + document.getElementById('url_upload').value); console.log("DEBUG : Step 4c : document.getElementById('text_upload').value : " + document.getElementById('text_upload').value); if (fileList.toString() == "" && (document.getElementById('url_upload').value == "" || document.getElementById('url_upload').value == "Your URL here") && (document.getElementById('text_upload').value == "" || document.getElementById('text_upload').value == "Your Model here")) { alert("Error: you must upload 1 file at least. See Step 4."); return false; } return true; } // Uploads the files. function upload() { console.log("DEBUG : upload : fileList : " + fileList); if (checkForm()) { submitForm(); } } // http://www.ebi.ac.uk/biomodels-main/download?mid=BIOMD0000000461 function resetForm($form) { $form.find('input:text, input:password, input:file, select, textarea').val(''); $form.find('input:radio, input:checkbox') .removeAttr('checked').removeAttr('selected'); }