Commit dbfb6140 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Update minified js

parent fc4c218b
if(!dgenies){throw"dgenies wasn't included!"}dgenies.result={};// GLOBAL VARIABLES:
dgenies.result.id_res=null;dgenies.result.init=function(id_res){dgenies.result.id_res=id_res;dgenies.result.add_to_list();d3.boxplot.init()};dgenies.result.add_to_list=function(){console.log("pass",dgenies.result.id_res);let cookies=$.cookie("results");cookies=cookies!==undefined?cookies.split("|"):[];console.log(cookies);if(cookies.indexOf(dgenies.result.id_res)===-1){console.log("oui");cookies.splice(0,0,dgenies.result.id_res);dgenies.save_cookies(cookies);dgenies.update_results(cookies)}};dgenies.result.remove_job_from_cookie=function(job){let cookies=$.cookie("results");cookies=cookies!==undefined?cookies.split("|"):[];let index=cookies.indexOf(job);let need_update=false;if(index>-1){need_update=true;cookies.splice(index,1)}$.cookie("results",cookies.join("|"),{path:"/"});if(need_update){dgenies.update_results(cookies)}};
dgenies.result.id_res=null;dgenies.result.init=function(id_res){dgenies.result.id_res=id_res;dgenies.result.add_to_list();d3.boxplot.init()};dgenies.result.add_to_list=function(){let cookies=$.cookie("results");cookies=cookies!==undefined?cookies.split("|"):[];if(cookies.indexOf(dgenies.result.id_res)===-1){cookies.splice(0,0,dgenies.result.id_res);dgenies.save_cookies(cookies);dgenies.update_results(cookies)}};dgenies.result.remove_job_from_cookie=function(job){let cookies=$.cookie("results");cookies=cookies!==undefined?cookies.split("|"):[];let index=cookies.indexOf(job);let need_update=false;if(index>-1){need_update=true;cookies.splice(index,1)}$.cookie("results",cookies.join("|"),{path:"/"});if(need_update){dgenies.update_results(cookies)}};
if(!dgenies||!dgenies.result){throw"dgenies.result wasn't included!"}dgenies.result.controls={};dgenies.result.controls.init=function(){$("#sort-contigs").click(dgenies.result.controls.launch_sort_contigs);$("#hide-noise").click(dgenies.result.controls.launch_hide_noise);$("#summary").click(dgenies.result.controls.summary);$("#delete-job").click(dgenies.result.controls.delete_job);$("form#select-zone input.submit").click(dgenies.result.controls.select_zone);$("form#export select").change(dgenies.result.export.export)};dgenies.result.controls.summary=function(){dgenies.show_loading("Building...");window.setTimeout(()=>{dgenies.post(`/summary/${dgenies.result.id_res}`,{},function(data){dgenies.hide_loading();if(data["success"]){if(data["status"]==="done"){dgenies.result.summary.show(data["percents"])}else if(data["status"]==="waiting"){dgenies.result.controls.summary()}}else{dgenies.notify(data["message"]||"An error occurred! Please contact us to report the bug","danger")}})},0)};dgenies.result.controls.launch_sort_contigs=function(){d3.boxplot.zoom.reset_scale();window.setTimeout(()=>{dgenies.show_loading("Building...");window.setTimeout(()=>{dgenies.post(`/sort/${dgenies.result.id_res}`,{},function(data){if(data["success"]){dgenies.reset_loading_message();window.setTimeout(()=>{d3.boxplot.launch(data,true)},0)}else{dgenies.hide_loading();dgenies.notify(data["message"]||"An error occurred! Please contact us to report the bug","danger")}})},0)},0)};dgenies.result.controls.launch_reverse_contig=function(){if(d3.boxplot.query_selected!==null){d3.boxplot.zoom.reset_scale();window.setTimeout(()=>{dgenies.show_loading("Building...");window.setTimeout(()=>{dgenies.post(`/reverse-contig/${dgenies.result.id_res}`,{"contig":d3.boxplot.query_selected},function(data){if(data["success"]){dgenies.reset_loading_message();window.setTimeout(()=>{d3.boxplot.launch(data,true)},0)}else{dgenies.hide_loading();dgenies.notify(data["message"]||"An error occurred! Please contact us to report the bug","danger")}})},0)},0)}else{dgenies.notify("Error: no query selected. Please contact us to report the bug","danger")}};dgenies.result.controls.launch_hide_noise=function(){d3.boxplot.zoom.reset_scale();window.setTimeout(()=>{dgenies.show_loading("Building...");window.setTimeout(()=>{dgenies.post(`/freenoise/${dgenies.result.id_res}`,{noise:dgenies.noise?0:1},function(data){if(data["success"]){dgenies.noise=!dgenies.noise;dgenies.reset_loading_message();window.setTimeout(()=>{d3.boxplot.launch(data,true,true)},0)}else{dgenies.hide_loading();dgenies.notify(data["message"]||"An error occurred! Please contact us to report the bug","danger")}})},0)},0)};dgenies.result.controls.select_zone=function(){let contig_select=$("#select-contig").find(":selected");let target_select=$("#select-target").find(":selected");if(contig_select.val()!=="###NONE###"&&target_select.val()!=="###NONE###"){d3.boxplot.select_zone(null,null,target_select.val(),contig_select.val(),true)}else{dgenies.notify("Please select zones into zoom!","danger",2000)}};dgenies.result.controls.do_delete_job=function(){dgenies.post(`/delete/${dgenies.result.id_res}`,{},function(data){if(data["success"]){dgenies.notify("Your job has been deleted!","success",1500);window.setTimeout(()=>{dgenies.result.remove_job_from_cookie(dgenies.result.id_res);window.location="/"},1500)}else{dgenies.notify("error"in data?data["error"]:"An error has occurred. Please contact the support","danger")}})};dgenies.result.controls.delete_job=function(){let dialog=$("<div>").attr("id","dialog-confirm").attr("title","Delete job?");let icon=$("<span>").attr("class","ui-icon ui-icon-help").css("float","left").css("margin","12px 12px 20px 0");let body=$("<p>");body.append(icon);body.append("Confirm deletion of this job? This operation is definitive.");dialog.append(body);dialog.dialog({resizable:false,height:"auto",width:500,modal:true,buttons:{"Yes":function(){$(this).dialog("close");dgenies.result.controls.do_delete_job()},"No":function(){$(this).dialog("close")}}})};
if(!dgenies||!dgenies.result){throw"dgenies.result wasn't included!"}dgenies.result.export={};dgenies.result.export.get_svg=function(){return"<svg width='5000px' height='5000px' viewBox='0 0 100 100'>"+$("#draw-in").find(">svg").html()+"</svg>"};dgenies.result.export.save_file=function(blob,format){dgenies.hide_loading();saveAs(blob,`map_${d3.boxplot.name_y}_to_${d3.boxplot.name_x}.${format}`)};dgenies.result.export.export_png=function(){dgenies.show_loading("Building picture...",210);window.setTimeout(()=>{let export_div=$("div#export-pict");export_div.html("").append($("<canvas>"));canvg(export_div.find("canvas")[0],dgenies.result.export.get_svg());let canvas=export_div.find("canvas")[0];canvas.toBlob(function(blob){dgenies.result.export.save_file(blob,"png");export_div.html("")},"image/png")},0)};dgenies.result.export.export_svg=function(){dgenies.show_loading("Building picture...",180);window.setTimeout(()=>{let transform=d3.boxplot.container.attr("transform");let after=function(){let blob=new Blob([dgenies.result.export.get_svg()],{type:"image/svg+xml"});d3.boxplot.zoom.restore_scale(transform);dgenies.result.export.save_file(blob,"svg")};d3.boxplot.zoom.reset_scale(true,after)},0)};dgenies.result.export.export_paf=function(){let export_div=$("div#export-pict");export_div.html("");export_div.append($("<a>").attr("href",`/paf/${dgenies.result.id_res}`).attr("download",`map_${d3.boxplot.name_y}_to_${d3.boxplot.name_x}.paf`).attr("id","my-download").text("download"));dgenies.hide_loading();document.getElementById("my-download").click()};dgenies.result.export.dl_fasta=function(gzip=false){let export_div=$("div#export-pict");export_div.html("");export_div.append($("<a>").attr("href",`/fasta-query/${dgenies.result.id_res}`).attr("download",d3.boxplot.name_y+(gzip?".fasta.gz":".fasta")).attr("id","my-download").text("download"));dgenies.hide_loading();document.getElementById("my-download").click()};dgenies.result.export.export_fasta=function(compress=false){dgenies.show_loading("Building file...",180);dgenies.post("/get-fasta-query/"+dgenies.result.id_res,{gzip:compress},function(data,success){if(data["status"]===0){window.setTimeout(()=>{dgenies.result.export.export_fasta()},10000)}else if(data["status"]===2){dgenies.result.export.dl_fasta(data["gzip"])}else if(data["status"]===1){dgenies.hide_loading();dgenies.notify("We are building your Fasta file. You will receive by mail a link to download it soon!","info")}else{dgenies.hide_loading();dgenies.notify("An error has occurred. Please contact us to report the bug","danger")}})};dgenies.result.export.ask_export_fasta=function(){if(dgenies.mode==="webserver"){let dialog=$("<div>").attr("id","dialog-confirm").attr("title","Gzip?");let icon=$("<span>").attr("class","ui-icon ui-icon-help").css("float","left").css("margin","12px 12px 20px 0");let body=$("<p>");body.append(icon);body.append("Compression is recommanded on slow connections. Download Gzip file?");dialog.append(body);dialog.dialog({resizable:false,height:"auto",width:500,modal:true,buttons:{"Use default":function(){$(this).dialog("close");dgenies.result.export.export_fasta(false)},"Use Gzip":function(){$(this).dialog("close");dgenies.result.export.export_fasta(true)},Cancel:function(){$(this).dialog("close")}}})}else{dgenies.result.export.export_fasta(false)}};dgenies.result.export.export_association_table=function(){let export_div=$("div#export-pict");export_div.html("");export_div.append($("<a>").attr("href",`/qt-assoc/${dgenies.result.id_res}`).attr("download",d3.boxplot.name_y+"_"+d3.boxplot.name_x+"_assoc.tsv").attr("id","my-download").text("download"));dgenies.hide_loading();document.getElementById("my-download").click()};dgenies.result.export.export_no_association_file=function(to){window.setTimeout(()=>{dgenies.show_loading("Building file...",180);let on=to==="query"?"target":"query";dgenies.post("/no-assoc/"+dgenies.result.id_res,{"to":to},function(data,success){dgenies.hide_loading();if(!data["empty"]){let blob=new Blob([data["file_content"]],{type:"text/plain"});saveAs(blob,`no_${to}_matches_${d3.boxplot.name_y}_to_${d3.boxplot.name_x}.txt`)}else{dgenies.notify(`No contigs in ${to} have None match with any ${on}!`,"success")}})},0)};dgenies.result.export.export_query_as_reference_fasta_webserver=function(){dgenies.post(`/build-query-as-reference/${dgenies.result.id_res}`,{},function(data,success){if(data["success"]){dgenies.notify("You will receive a mail soon with the link to download your Fasta file","success")}else{dgenies.notify(`An error has occurred. Please contact the support`,"danger")}})};dgenies.result.export.export_query_as_reference_fasta_standalone=function(){dgenies.show_loading("Building file...",180);window.setTimeout(()=>{dgenies.post(`/build-query-as-reference/${dgenies.result.id_res}`,{},function(data,success){if(data["success"]){let export_div=$("div#export-pict");export_div.html("");export_div.append($("<a>").attr("href",`/get-query-as-reference/${dgenies.result.id_res}`).attr("download",`as_reference_${d3.boxplot.name_y}.fasta`).attr("id","my-download").text("download"));document.getElementById("my-download").click();dgenies.hide_loading()}else{dgenies.notify(`An error has occurred. Please contact the support`,"danger")}})},0)};dgenies.result.export.export=function(){let select=$("form#export select");let selection=parseInt(select.val());window.setTimeout(()=>{if(selection>0){let async=false;if(selection===1){dgenies.result.export.export_svg();async=true}else if(selection===2){dgenies.result.export.export_png();async=true}else if(selection===3)dgenies.result.export.export_paf();else if(selection===4){dgenies.result.export.ask_export_fasta();async=true}else if(selection===5){dgenies.result.export.export_association_table()}else if(selection===6){dgenies.result.export.export_no_association_file("query");async=true}else if(selection===7){dgenies.result.export.export_no_association_file("target");async=true}else if(selection===8){if(dgenies.mode==="webserver"){dgenies.result.export.export_query_as_reference_fasta_webserver()}else{dgenies.result.export.export_query_as_reference_fasta_standalone();async=true}}else dgenies.notify("Not supported yet!","danger",2000);if(!async)dgenies.hide_loading();select.val("0")}},0)};
if(!dgenies||!dgenies.result){throw"dgenies.result wasn't included!"}dgenies.result.summary={};dgenies.result.summary.percents={};dgenies.result.summary.show=function(percents){dgenies.result.summary.percents=percents;let svgcontainer=d3.select("#draw-stats").html("").append("svg:svg").attr("width","500px").attr("height","220px");let container=svgcontainer.append("svg:g");let percents_order=["-1","0","1","2","3"];let x=0;let percent_value=0;for(let i in percents_order){let percent=percents_order[i];let label=dgenies.result.summary._get_label(percent);x+=percent_value;percent_value=percent in percents?percents[percent]:0;container.append("rect").attr("x",x+"%").attr("y",0).attr("width",percent_value+"%").attr("height","50px").attr("stroke","none").attr("fill",d3.boxplot.color_idy[d3.boxplot.color_idy_theme][percent]);container.append("rect").attr("x",5).attr("y",70+i*30).attr("width","10px").attr("height","10px").attr("fill",d3.boxplot.color_idy[d3.boxplot.color_idy_theme][percent]).style("stroke","#000").style("stroke-width","1px");container.append("text").attr("x",30).attr("y",82+i*30).attr("font-family","sans-serif").attr("font-size","12pt").text(label+":");container.append("text").attr("x",110).attr("y",82+i*30).attr("font-family","sans-serif").attr("font-size","12pt").text(percent_value.toFixed(2)+" %")}container.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","50px").style("stroke","#000").style("fill","none").style("stroke-width","1px");$("#modal-stats").dialog({title:"Summary of identity",width:"560px",buttons:[{text:"Export TSV",click:dgenies.result.summary.export_tsv},{text:"Export PNG",click:dgenies.result.summary.export_png},{text:"Export SVG",click:dgenies.result.summary.export_svg},{text:"Close",click:function(){$(this).dialog("close")},default:true}],open:function(){$(this).parents().find(".ui-dialog-buttonpane button")[3].focus()}})};dgenies.result.summary._get_label=function(percent_class){switch(percent_class){case"-1":return"No match";case"0":return"< 25 %";case"1":return"< 50 %";case"2":return"< 75 %";case"3":return"> 75 %";}};dgenies.result.summary.get_svg=function(){return $("#draw-stats").html()};dgenies.result.summary.save_file=function(blob,format){saveAs(blob,`summary_${d3.boxplot.name_y}_to_${d3.boxplot.name_x}.${format}`)};dgenies.result.summary.export_tsv=function(){let content="category\tpercent\n";for(let percent in dgenies.result.summary.percents){content+=`${dgenies.result.summary._get_label(percent)}\t${dgenies.result.summary.percents[percent]}\n`}dgenies.result.summary.save_file(new Blob([content],{type:"plain/text"}),"tsv")};dgenies.result.summary.export_svg=function(){let blob=new Blob([dgenies.result.summary.get_svg()],{type:"image/svg+xml"});dgenies.result.summary.save_file(blob,"svg")};dgenies.result.summary.export_png=function(){let export_div=$("div#export-pict");export_div.html("").append($("<canvas>"));canvg(export_div.find("canvas")[0],dgenies.result.summary.get_svg());let canvas=export_div.find("canvas")[0];canvas.toBlob(function(blob){dgenies.result.summary.save_file(blob,"png");export_div.html("")},"image/png")};
......
if(!dgenies){throw"dgenies wasn't included!"}dgenies.run={};// Init global variables:
dgenies.run.s_id=null;dgenies.run.allowed_ext=[];dgenies.run.max_upload_file_size=-1;dgenies.run.files=[undefined,undefined];dgenies.run.allow_upload=false;dgenies.run.ping_interval=null;dgenies.run.target_example="";dgenies.run.query_example="";dgenies.run.init=function(s_id,allowed_ext,max_upload_file_size=1073741824,target_example="",query_example=""){dgenies.run.s_id=s_id;dgenies.run.allowed_ext=allowed_ext;dgenies.run.max_upload_file_size=max_upload_file_size;dgenies.run.target_example=target_example;dgenies.run.query_example=query_example;dgenies.run.restore_form();dgenies.run.set_events();dgenies.run.init_fileuploads()};dgenies.run.restore_form=function(){dgenies.run.change_fasta_type("query",$("select.query").find(":selected").text().toLowerCase(),true);dgenies.run.change_fasta_type("target",$("select.target").find(":selected").text().toLowerCase(),true)};dgenies.run.upload_next=function(){let next=dgenies.run.files.pop();while(next===undefined&&dgenies.run.files.length>0){next=dgenies.run.files.pop()}if(next!==undefined){next.submit();return true}dgenies.run.do_submit();return false};dgenies.run.__upload_server_error=function(fasta,data){dgenies.notify("message"in data?data["message"]:`An error has occured when uploading <b>${fasta}</b> file. Please contact us to report the bug!`,"danger");dgenies.run.enable_form()};dgenies.run.allowed_file=function(filename){return filename.indexOf(".")!==-1&&(dgenies.run.allowed_ext.indexOf(filename.rsplit(".",1)[1].toLowerCase())!==-1||dgenies.run.allowed_ext.indexOf(filename.rsplit(".",2).splice(1).join(".").toLowerCase())!==-1)};dgenies.run.init_fileuploads=function(){$("input.file-query").fileupload({dataType:"json",formData:{"s_id":dgenies.run.s_id},add:function(e,data){let filename=data.files[0].name;if(dgenies.run.allowed_file(filename))dgenies.run.files[0]=data;else{$("input.file-query").trigger("change");// The value is null after fired
dgenies.run.s_id=null;dgenies.run.allowed_ext=[];dgenies.run.max_upload_file_size=-1;dgenies.run.files=[undefined,undefined];dgenies.run.allow_upload=false;dgenies.run.ping_interval=null;dgenies.run.target_example="";dgenies.run.query_example="";dgenies.run.tool_has_ava={};dgenies.run.init=function(s_id,allowed_ext,max_upload_file_size=1073741824,target_example="",query_example="",tool_has_ava={}){dgenies.run.s_id=s_id;dgenies.run.allowed_ext=allowed_ext;dgenies.run.max_upload_file_size=max_upload_file_size;dgenies.run.target_example=target_example;dgenies.run.query_example=query_example;dgenies.run.tool_has_ava=tool_has_ava;dgenies.run.restore_form();dgenies.run.set_events();dgenies.run.init_fileuploads()};dgenies.run.restore_form=function(){dgenies.run.change_fasta_type("query",$("select.query").find(":selected").text().toLowerCase(),true);dgenies.run.change_fasta_type("target",$("select.target").find(":selected").text().toLowerCase(),true)};dgenies.run.upload_next=function(){let next=dgenies.run.files.pop();while(next===undefined&&dgenies.run.files.length>0){next=dgenies.run.files.pop()}if(next!==undefined){next.submit();return true}dgenies.run.do_submit();return false};dgenies.run.__upload_server_error=function(fasta,data){dgenies.notify("message"in data?data["message"]:`An error has occured when uploading <b>${fasta}</b> file. Please contact us to report the bug!`,"danger");dgenies.run.enable_form()};dgenies.run.allowed_file=function(filename){return filename.indexOf(".")!==-1&&(dgenies.run.allowed_ext.indexOf(filename.rsplit(".",1)[1].toLowerCase())!==-1||dgenies.run.allowed_ext.indexOf(filename.rsplit(".",2).splice(1).join(".").toLowerCase())!==-1)};dgenies.run.init_fileuploads=function(){$("input.file-query").fileupload({dataType:"json",formData:{"s_id":dgenies.run.s_id},add:function(e,data){let filename=data.files[0].name;if(dgenies.run.allowed_file(filename))dgenies.run.files[0]=data;else{$("input.file-query").trigger("change");// The value is null after fired
dgenies.notify(`File <b>${filename}</b> is not supported!`,"danger",3000)}},progressall:function(e,data){var progress=parseInt(data.loaded/data.total*100,10);$("#progress-query").find(".bar").css("width",progress+"%")},success:function(data,success){if(data["success"]!=="OK"){dgenies.run.__upload_server_error("query",data)}else if("error"in data["files"][0]){dgenies.run.add_error("Query file: "+data["files"][0]["error"],"error");dgenies.run.enable_form()}else{$("input#query").val(data["files"][0]["name"]);dgenies.run.hide_loading("query");dgenies.run.show_success("query");dgenies.run.upload_next()}},error:function(data,success){dgenies.run.__upload_server_error("query",data)}});$("input.file-target").fileupload({dataType:"json",formData:{"s_id":dgenies.run.s_id},add:function(e,data){let filename=data.files[0].name;if(dgenies.run.allowed_file(filename))dgenies.run.files[1]=data;else{$("input.file-target").trigger("change");// The value is null after fired
dgenies.notify(`File <b>${filename}</b> is not supported!`,"danger",3000)}},progressall:function(e,data){var progress=parseInt(data.loaded/data.total*100,10);$("#progress-target").find(".bar").css("width",progress+"%")},success:function(data,success){if(data["success"]!=="OK"){dgenies.run.__upload_server_error("target",data)}else if("error"in data["files"][0]){dgenies.run.add_error("Target file: "+data["files"][0]["error"],"error");dgenies.run.enable_form()}else{$("input#target").val(data["files"][0]["name"]);dgenies.run.hide_loading("target");dgenies.run.show_success("target");dgenies.run.upload_next()}},error:function(data,success){dgenies.run.__upload_server_error("target",data)}});//Trigger events on hidden file inputs:
$("button#button-query").click(function(){$("input.file-query").trigger("click")});$("button#button-target").click(function(){$("input.file-target").trigger("click")})};dgenies.run.get_file_size_str=function(size){if(size<1000){return size+" O"}else if(size<1000000){return Math.round(size/1024)+" Ko"}else if(size<1000000000){return Math.round(size/1048576)+" Mo"}return Math.round(size/1073741824)+" Go"};dgenies.run.fill_examples=function(){$("select.target").val("1").trigger("change");$("input#target").val("example://"+dgenies.run.target_example);if(dgenies.run.query_example!==""){$("select.query").val("1").trigger("change");$("input#query").val("example://"+dgenies.run.query_example)}};dgenies.run.set_events=function(){let max_file_size_txt=dgenies.run.get_file_size_str(dgenies.run.max_upload_file_size);$("input.file-query").change(function(){let file_size_query=$("div.file-size.query");if(this.files.length>0){if(this.files[0].size<=dgenies.run.max_upload_file_size){file_size_query.html(dgenies.run.get_file_size_str(this.files[0].size));dgenies.run.set_filename(this.files[0].name,"query")}else{$(this).val("");dgenies.run.set_filename("","query");dgenies.notify(`File exceed the size limit (${max_file_size_txt})`,"danger",2000);file_size_query.html("")}}else{dgenies.run.set_filename("","query");file_size_query.html("")}});$("input.file-target").change(function(){let file_size_target=$("div.file-size.target");if(this.files.length>0){if(this.files[0].size<=dgenies.run.max_upload_file_size){file_size_target.html(dgenies.run.get_file_size_str(this.files[0].size));dgenies.run.set_filename(this.files[0].name,"target")}else{$(this).val("");dgenies.run.set_filename("","target");dgenies.notify(`File exceed the size limit (${max_file_size_txt})`,"danger",2000);file_size_target.html("")}}else{dgenies.run.set_filename("","target");file_size_target.html("")}});$("button#submit").click(function(){dgenies.run.submit()});$("select.query").change(function(){dgenies.run.change_fasta_type("query",$("select.query").find(":selected").text().toLowerCase())});$("select.target").change(function(){dgenies.run.change_fasta_type("target",$("select.target").find(":selected").text().toLowerCase())});$("button#example").click(function(){dgenies.run.fill_examples()})};dgenies.run.change_fasta_type=function(fasta,type,keep_url=false){let button=$("button#button-"+fasta);let input=$("input#"+fasta);let container=$("div."+fasta+"-label");$("input.file-"+fasta).val("");if(type==="local"){button.show();input.prop("readonly",true);input.val("");container.width(300)}else{button.hide();input.prop("readonly",false);if(!keep_url)input.val("");container.width(348)}$("div.file-size."+fasta).html("")};dgenies.run.set_filename=function(name,fasta){$("input#"+fasta).val(name)};dgenies.run.disable_form=function(){$("input, select, button").prop("disabled",true)};dgenies.run.enable_form=function(){$(".progress").find(".bar").css("width","0%");$("input, select, button").prop("disabled",false);$("div#uploading-loading").hide();$("button#submit").show();dgenies.run.hide_loading("query");dgenies.run.hide_loading("target");dgenies.run.hide_success("query");dgenies.run.hide_success("target");dgenies.run.files=[undefined,undefined];dgenies.run.restore_form()};dgenies.run.do_submit=function(){$("div#uploading-loading").html("Submitting form...");dgenies.post("/launch_analysis",{"id_job":$("input#id_job").val(),"email":dgenies.mode==="webserver"?$("input#email").val():"","query":$("input#query").val(),"query_type":$("select.query").find(":selected").text().toLowerCase(),"target":$("input#target").val(),"target_type":$("select.target").find(":selected").text().toLowerCase(),"s_id":dgenies.run.s_id},function(data,status){if(data["success"]){window.location=data["redirect"]}else{if(dgenies.run.ping_interval!==null){clearInterval(dgenies.run.ping_interval);dgenies.run.ping_interval=null}if("errors"in data){for(let i=0;i<data["errors"].length;i++){dgenies.notify(data["errors"][i],"danger",3000)}}else{dgenies.notify("An error has occurred. Please contact the support","danger",3000)}dgenies.run.enable_form()}})};dgenies.run.add_error=function(error){$("div.errors-submit ul.flashes").append($("<li>").append(error))};dgenies.run.valid_form=function(){let has_errors=false;// Check name:
$("button#button-query").click(function(){$("input.file-query").trigger("click")});$("button#button-target").click(function(){$("input.file-target").trigger("click")})};dgenies.run.get_file_size_str=function(size){if(size<1000){return size+" O"}else if(size<1000000){return Math.round(size/1024)+" Ko"}else if(size<1000000000){return Math.round(size/1048576)+" Mo"}return Math.round(size/1073741824)+" Go"};dgenies.run.fill_examples=function(){$("select.target").val("1").trigger("change");$("input#target").val("example://"+dgenies.run.target_example);if(dgenies.run.query_example!==""){$("select.query").val("1").trigger("change");$("input#query").val("example://"+dgenies.run.query_example)}};dgenies.run.set_events=function(){let max_file_size_txt=dgenies.run.get_file_size_str(dgenies.run.max_upload_file_size);$("input.file-query").change(function(){let file_size_query=$("div.file-size.query");if(this.files.length>0){if(this.files[0].size<=dgenies.run.max_upload_file_size){file_size_query.html(dgenies.run.get_file_size_str(this.files[0].size));dgenies.run.set_filename(this.files[0].name,"query")}else{$(this).val("");dgenies.run.set_filename("","query");dgenies.notify(`File exceed the size limit (${max_file_size_txt})`,"danger",2000);file_size_query.html("")}}else{dgenies.run.set_filename("","query");file_size_query.html("")}});$("input.file-target").change(function(){let file_size_target=$("div.file-size.target");if(this.files.length>0){if(this.files[0].size<=dgenies.run.max_upload_file_size){file_size_target.html(dgenies.run.get_file_size_str(this.files[0].size));dgenies.run.set_filename(this.files[0].name,"target")}else{$(this).val("");dgenies.run.set_filename("","target");dgenies.notify(`File exceed the size limit (${max_file_size_txt})`,"danger",2000);file_size_target.html("")}}else{dgenies.run.set_filename("","target");file_size_target.html("")}});$("button#submit").click(function(){dgenies.run.submit()});$("select.query").change(function(){dgenies.run.change_fasta_type("query",$("select.query").find(":selected").text().toLowerCase())});$("select.target").change(function(){dgenies.run.change_fasta_type("target",$("select.target").find(":selected").text().toLowerCase())});$("button#example").click(function(){dgenies.run.fill_examples()})};dgenies.run.change_fasta_type=function(fasta,type,keep_url=false){let button=$("button#button-"+fasta);let input=$("input#"+fasta);let container=$("div."+fasta+"-label");$("input.file-"+fasta).val("");if(type==="local"){button.show();input.prop("readonly",true);input.val("");container.width(300)}else{button.hide();input.prop("readonly",false);if(!keep_url)input.val("");container.width(348)}$("div.file-size."+fasta).html("")};dgenies.run.set_filename=function(name,fasta){$("input#"+fasta).val(name)};dgenies.run.disable_form=function(){$("input, select, button").prop("disabled",true)};dgenies.run.enable_form=function(){$(".progress").find(".bar").css("width","0%");$("input, select, button").prop("disabled",false);$("div#uploading-loading").hide();$("button#submit").show();dgenies.run.hide_loading("query");dgenies.run.hide_loading("target");dgenies.run.hide_success("query");dgenies.run.hide_success("target");dgenies.run.files=[undefined,undefined];dgenies.run.restore_form()};dgenies.run.do_submit=function(){$("div#uploading-loading").html("Submitting form...");dgenies.post("/launch_analysis",{"id_job":$("input#id_job").val(),"email":dgenies.mode==="webserver"?$("input#email").val():"","query":$("input#query").val(),"query_type":$("select.query").find(":selected").text().toLowerCase(),"target":$("input#target").val(),"target_type":$("select.target").find(":selected").text().toLowerCase(),"s_id":dgenies.run.s_id,"tool":$("input[name=tool]:checked").val()},function(data,status){if(data["success"]){window.location=data["redirect"]}else{if(dgenies.run.ping_interval!==null){clearInterval(dgenies.run.ping_interval);dgenies.run.ping_interval=null}if("errors"in data){for(let i=0;i<data["errors"].length;i++){dgenies.notify(data["errors"][i],"danger",3000)}}else{dgenies.notify("An error has occurred. Please contact the support","danger",3000)}dgenies.run.enable_form()}})};dgenies.run.add_error=function(error){$("div.errors-submit ul.flashes").append($("<li>").append(error))};dgenies.run.valid_form=function(){let has_errors=false;// Check name:
if($("input#id_job").val().length===0){$("label.id-job").addClass("error");dgenies.run.add_error("Name of your job is required!");has_errors=true}// Check mail:
if(dgenies.mode==="webserver"){let email=$("input#email").val();let mail_re=/^.+@.+\..+$/;if(email.match(mail_re)===null){$("label.email").addClass("error");if(email==="")dgenies.run.add_error("Email is required!");else dgenies.run.add_error("Email is not correct!");has_errors=true}}//Check input target:
if($("input#target").val().length===0){$("label.file-target").addClass("error");dgenies.run.add_error("Target fasta is required!");has_errors=true}// Returns
if($("input#target").val().length===0){$("label.file-target").addClass("error");dgenies.run.add_error("Target fasta is required!");has_errors=true}//Check input query:
let tool=$("input[name=tool]:checked").val();if(!dgenies.run.tool_has_ava[tool]&&$("input#query").val().length===0){$("label.file-query").addClass("error");dgenies.run.add_error("Query fasta is required!");has_errors=true}// Returns
return!has_errors};dgenies.run.show_loading=function(fasta){$(".loading-file."+fasta).show()};dgenies.run.hide_loading=function(fasta){$(".loading-file."+fasta).hide()};dgenies.run.show_success=function(fasta){$(".upload-success."+fasta).show()};dgenies.run.hide_success=function(fasta){$(".upload-success."+fasta).hide()};dgenies.run.reset_errors=function(){$("label").removeClass("error");$("div.errors-submit ul.flashes").find("li").remove()};dgenies.run.ask_for_upload=function(){console.log("Ask for upload...");dgenies.post("/ask-upload",{"s_id":dgenies.run.s_id},function(data,status){if(data["success"]){let allow_upload=data["allowed"];if(allow_upload){$("div#uploading-loading").html("Uploading files...");dgenies.run.ping_interval=window.setInterval(dgenies.run.ping_upload,15000);dgenies.run.upload_next()}else{window.setTimeout(dgenies.run.ask_for_upload,15000)}}else{dgenies.notify("message"in data?data["message"]:"An error has occurred. Please contact the support","danger",3000)}},undefined,false)};dgenies.run.ping_upload=function(){dgenies.post("/ping-upload",{"s_id":dgenies.run.s_id},function(data,status){})};dgenies.run.check_url=function(url){return url.startsWith("http://")||url.startsWith("https://")||url.startsWith("ftp://")||url.startsWith("example://")};dgenies.run.start_uploads=function(){let query_type=parseInt($("select.query").val());let has_uploads=false;let query_val=$("input#query").val();if(query_type===0&&query_val.length>0){$("button#button-query").hide();dgenies.run.show_loading("query");has_uploads=true}else{dgenies.run.files[0]=undefined;if(query_val!==""&&!dgenies.run.check_url(query_val)){dgenies.run.add_error("Query file: invalid URL","error");dgenies.run.enable_form();return false}}let target_type=parseInt($("select.target").val());let target_val=$("input#target").val();if(target_type===0&&target_val.length>0){$("button#button-target").hide();dgenies.run.show_loading("target");has_uploads=true}else{dgenies.run.files[1]=undefined;if(target_val!==""&&!dgenies.run.check_url(target_val)){dgenies.run.add_error("Target file: invalid URL","error");dgenies.run.enable_form();return false}}if(has_uploads){$("div#uploading-loading").html("Asking for upload...");dgenies.run.ask_for_upload()}else{dgenies.run.upload_next()}};dgenies.run.show_global_loading=function(){$("button#submit").hide();$("button#example").hide();$("div#uploading-loading").show()};dgenies.run.submit=function(){dgenies.run.reset_errors();if(dgenies.run.valid_form()){dgenies.run.disable_form();dgenies.run.show_global_loading();dgenies.run.start_uploads()}};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment