%link{ :href=>"/jsme/jsa.css", :rel=>"stylesheet", :property=>"stylesheet"} %script{:src=>"/jsme/jsme.nocache.js"} :javascript var HttpClient = function() { this.get = function(aUrl, aCallback) { var anHttpRequest = new XMLHttpRequest(); anHttpRequest.onreadystatechange = function() { if (anHttpRequest.readyState == 4 && anHttpRequest.status == 200) aCallback(anHttpRequest.responseText); } anHttpRequest.open( "GET", aUrl, true ); anHttpRequest.send( null ); } }; /*$(function() { $('a[data-toggle="tab"]').on('click', function (e) { localStorage.setItem('lastTab', $(e.target).attr('href')); }); var lastTab = localStorage.getItem('lastTab'); if (lastTab) { $('a[href="'+lastTab+'"]').click(); } });*/ function getInput(){ identifier = document.getElementById("identifier").value.trim(); fileselect = document.getElementById("fileselect").value; if (fileselect != ""){ return 1; }; if (identifier != ""){ return 2; }; return 0; }; function showcircle() { switch (getInput()){ case 0: alert("Please draw or insert a chemical structure."); return false; break; case 1: if (checkfile() && checkboxes()){ button = document.getElementById("submit"); image = document.getElementById("circle"); button.parentNode.replaceChild(image, button); $("img.circle").show(); return true; }; return false; break; case 2: if (checksmiles() && checkboxes()){ button = document.getElementById("submit"); image = document.getElementById("circle"); button.parentNode.replaceChild(image, button); $("img.circle").show(); return true; }; return false; break; default: false; }; return false; }; function checkfile() { var fileinput = document.getElementById("fileselect"); if(fileinput.value != "") { //TODO check file type is csv return true; }; alert("Please select a file (csv)."); return false; }; function checksmiles () { getsmiles(); if (document.form.identifier.value == "") { alert("Please draw or insert a chemical structure."); document.form.identifier.focus(); $("img.circle").hide(); return false; }; return true; }; function checkboxes () { var checked = false; $('input[type="checkbox"]').each(function() { if ($(this).is(":checked")) { checked = true; }; }); if (checked == false){ alert("Please select an endpoint."); $("img.circle").hide(); return false; }; return true; }; function jsmeOnLoad() { jsmeApplet = new JSApplet.JSME("appletContainer", "380px", "340px", { //optional parameters "options" : "polarnitro" }); document.JME = jsmeApplet; }; function getsmiles() { if (document.JME.smiles() != '') { document.form.identifier.value = document.JME.smiles() ; }; }; function loadDetails(id) { button = document.getElementById("link"+id); span = button.childNodes[1]; if (span.className == "fa fa-caret-right"){ span.className = "fa fa-caret-down"; } else if (span.className = "fa fa-caret-down"){ span.className = "fa fa-caret-right"; }; image = document.getElementById("circle"+id); if ($('modeldetails'+id).length == 0) { $(button).hide(); $(image).show(); aClient = new HttpClient(); aClient.get("#{to("/predict/modeldetails/")}"+id, function(response) { var details = document.createElement("modeldetails"+id); details.innerHTML = response; document.getElementById("details"+id).appendChild(details); $(button).show(); $(image).hide(); addExternalLinks(); }); } } // whole site content needs to be in one form. Input and checkboxes are proofed by js functions. %form{:name => "form", :action => to('/predict'), :method => "post", :enctype => "multipart/form-data", :onsubmit => "return !!(showcircle())" } %fieldset#top.card.bg-light #insert.card-body %h2.card-title 1. Draw a chemical structure %label   #appletContainer.d-flex %br %p %label{:for => 'identifier'} or enter the %a{:href => "http://en.wikipedia.org/wiki/Simplified_molecular_input_line_entry_specification", :rel => "external"} SMILES string: %input.form-control{:type => 'text', :name => 'identifier', :id => 'identifier'} %p{:style=>"display:none;"} %label{:for=>"fileselect"} or upload a CSV file for batch predictions: %br %input.form-control-file{:type=>"file", :name=> "fileselect", :id=>"fileselect", :accept=>"text/csv"} %fieldset#middle.card.bg-light #models.card-body %h2.card-title 2. Select one or more endpoints - @endpoints.each do |endpoint| %div.card{:id=>endpoint.gsub(/\s+/, "_")} %div.card-header %h5.card-title=endpoint %div.card-body - @models.select{|m| m.endpoint == endpoint}.each do |model| %div.row{:id => model.id,:style=>"margin-bottom:1em;"} %span.col-6 %input{:type => "checkbox", :name => "selection[#{model.id}]", :id => "selection[#{model.species.gsub(/\s+/, "_")}]", :value => true, :disabled => false} %label{:for => "selection[#{model.species.gsub(/\s+/, "_")}]"} = model.species %span.col-6 %a.btn.btn-outline-info{:role=>"button", :data=>{:toggle=>"collapse"}, :href=>"#details#{model.id}", :aria=>{:expanded=>"false", :controls=>"details#{model.id}"}, :onclick=>"loadDetails('#{model.id}')", :id => "link#{model.id}", :style=>"font-size:small;"} %span.fa.fa-caret-right Details | Validation %img.h2{:src=>"/images/wait30trans.gif", :id=>"circle#{model.id}", :class=>"circle#{model.id}", :alt=>"wait", :style=>"display:none;"} %div.collapse{:id=>"details#{model.id}", :style=>"margin-left:1em;"} %fieldset#bottom.card.bg-light %div.card-body %h2.card-title 3. Predict %button.has-feedback.btn.btn-primary.btn-lg{:type => "submit", :id => "submit", :value=>"", :onclick => "getsmiles()"} %span.fa.fa-play %img.h2{:src=>"/images/wait30trans.gif", :id=>"circle", :class=>"circle", :alt=>"wait", :style=>"display:none;"}